From 9b57967f5279c4bd88f573c9e0d4a103fc1cdea9 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Mon, 18 Nov 2024 04:15:29 -0800 Subject: [PATCH 1/7] frame-timestamp --- Cargo.lock | 9 +---- substrate/frame/timestamp/Cargo.toml | 33 ++++--------------- substrate/frame/timestamp/src/benchmarking.rs | 5 +-- substrate/frame/timestamp/src/lib.rs | 18 ++++++---- substrate/frame/timestamp/src/mock.rs | 7 ++-- substrate/frame/timestamp/src/tests.rs | 4 ++- substrate/frame/timestamp/src/weights.rs | 3 +- 7 files changed, 32 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 182d8f6bacad..ed4794ef12e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15449,17 +15449,10 @@ name = "pallet-timestamp" version = "27.0.0" dependencies = [ "docify", - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-inherents 26.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", - "sp-storage 19.0.0", "sp-timestamp 26.0.0", ] diff --git a/substrate/frame/timestamp/Cargo.toml b/substrate/frame/timestamp/Cargo.toml index 0eff0530c7e2..f3e3fdacb427 100644 --- a/substrate/frame/timestamp/Cargo.toml +++ b/substrate/frame/timestamp/Cargo.toml @@ -20,46 +20,27 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive", "max-encoded-len"], workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-inherents = { workspace = true } -sp-io = { optional = true, workspace = true } -sp-runtime = { workspace = true } -sp-storage = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } sp-timestamp = { workspace = true } docify = { workspace = true } -[dev-dependencies] -sp-core = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } +# [dev-dependencies] +# sp-core = { workspace = true, default-features = true } +# sp-io = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "scale-info/std", - "sp-core/std", - "sp-inherents/std", - "sp-io?/std", - "sp-runtime/std", - "sp-storage/std", "sp-timestamp/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-io", - "sp-runtime/runtime-benchmarks", + "frame/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", + "frame/try-runtime", ] diff --git a/substrate/frame/timestamp/src/benchmarking.rs b/substrate/frame/timestamp/src/benchmarking.rs index ef4d36c57691..6218d31fcedb 100644 --- a/substrate/frame/timestamp/src/benchmarking.rs +++ b/substrate/frame/timestamp/src/benchmarking.rs @@ -18,12 +18,13 @@ //! Timestamp pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] - +/* use frame_benchmarking::{benchmarking::add_to_whitelist, v2::*}; use frame_support::traits::OnFinalize; use frame_system::RawOrigin; use sp_storage::TrackedStorageKey; - +*/ +use frame::{benchmarking::prelude::*, traits::TrackedStorageKey}; use crate::*; const MAX_TIME: u32 = 100; diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index 5cb6c859c417..b893b7d76465 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -52,12 +52,11 @@ //! //! ``` //! use pallet_timestamp::{self as timestamp}; +//! use frame::prelude::*; //! -//! #[frame_support::pallet] +//! #[frame::pallet] //! pub mod pallet { //! use super::*; -//! use frame_support::pallet_prelude::*; -//! use frame_system::pallet_prelude::*; //! //! #[pallet::pallet] //! pub struct Pallet(_); @@ -134,18 +133,24 @@ mod tests; pub mod weights; use core::{cmp, result}; +/* use frame_support::traits::{OnTimestampSet, Time, UnixTime}; use sp_runtime::traits::{AtLeast32Bit, SaturatedConversion, Scale, Zero}; +*/ +use frame::{prelude::*, runtime::prelude::derive_impl, arithmetic::AtLeast32Bit, traits::{Scale, OnTimestampSet, Time, UnixTime}}; use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER}; pub use weights::WeightInfo; pub use pallet::*; -#[frame_support::pallet] +// #[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; + /* use frame_support::{derive_impl, pallet_prelude::*}; use frame_system::pallet_prelude::*; + */ /// Default preludes for [`Config`]. pub mod config_preludes { @@ -157,7 +162,8 @@ pub mod pallet { #[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)] impl frame_system::DefaultConfig for TestDefaultConfig {} - #[frame_support::register_default_impl(TestDefaultConfig)] + // #[frame_support::register_default_impl(TestDefaultConfig)] + #[frame::prelude::register_default_impl(TestDefaultConfig)] impl DefaultConfig for TestDefaultConfig { type Moment = u64; type OnTimestampSet = (); @@ -354,7 +360,7 @@ impl Time for Pallet { /// A type that represents a unit of time. type Moment = T::Moment; - fn now() -> Self::Moment { + fn now() -> as Time>::Moment { Now::::get() } } diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index eb4fdbe71fa7..a3217228bf64 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -19,15 +19,16 @@ use super::*; use crate as pallet_timestamp; - +/* use frame_support::{derive_impl, parameter_types, traits::ConstU64}; use sp_io::TestExternalities; use sp_runtime::BuildStorage; - +*/ +use frame::{prelude::*, runtime::{testing_prelude::BuildStorage, prelude::*}, testing_prelude::TestExternalities}; type Block = frame_system::mocking::MockBlock; type Moment = u64; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, diff --git a/substrate/frame/timestamp/src/tests.rs b/substrate/frame/timestamp/src/tests.rs index a83855561889..d49aafb3b9ed 100644 --- a/substrate/frame/timestamp/src/tests.rs +++ b/substrate/frame/timestamp/src/tests.rs @@ -18,7 +18,9 @@ //! Tests for the Timestamp module. use crate::mock::*; -use frame_support::assert_ok; +//use frame_support::assert_ok; + +use frame::testing_prelude::*; #[test] fn timestamp_works() { diff --git a/substrate/frame/timestamp/src/weights.rs b/substrate/frame/timestamp/src/weights.rs index 9f16a82653a9..d522982edf7b 100644 --- a/substrate/frame/timestamp/src/weights.rs +++ b/substrate/frame/timestamp/src/weights.rs @@ -46,7 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_timestamp`. From 97d397b7b711d9aed705519408c760be3e46cda6 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Wed, 4 Dec 2024 20:39:48 -0800 Subject: [PATCH 2/7] add prdoc and delete comments --- prdoc/pr_6523.prdoc | 14 ++++++++++++++ substrate/frame/timestamp/src/benchmarking.rs | 2 +- substrate/frame/timestamp/src/lib.rs | 18 ++++++------------ substrate/frame/timestamp/src/mock.rs | 7 +------ substrate/frame/timestamp/src/tests.rs | 2 -- 5 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 prdoc/pr_6523.prdoc diff --git a/prdoc/pr_6523.prdoc b/prdoc/pr_6523.prdoc new file mode 100644 index 000000000000..e7f1a79ae1d5 --- /dev/null +++ b/prdoc/pr_6523.prdoc @@ -0,0 +1,14 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: migrate pallet-timestamp to umbrella crate + +doc: + - audience: Runtime Dev + description: | + This pull request adapts the frame umbrella crate into pallet-timestamp + by importing existing system into the pallet. + +crates: + - name: pallet-timestamp + bump: minor \ No newline at end of file diff --git a/substrate/frame/timestamp/src/benchmarking.rs b/substrate/frame/timestamp/src/benchmarking.rs index 6218d31fcedb..26c97453c96f 100644 --- a/substrate/frame/timestamp/src/benchmarking.rs +++ b/substrate/frame/timestamp/src/benchmarking.rs @@ -24,8 +24,8 @@ use frame_support::traits::OnFinalize; use frame_system::RawOrigin; use sp_storage::TrackedStorageKey; */ -use frame::{benchmarking::prelude::*, traits::TrackedStorageKey}; use crate::*; +use frame::{benchmarking::prelude::*, traits::TrackedStorageKey}; const MAX_TIME: u32 = 100; diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index b893b7d76465..c822cc11974b 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -133,24 +133,19 @@ mod tests; pub mod weights; use core::{cmp, result}; -/* -use frame_support::traits::{OnTimestampSet, Time, UnixTime}; -use sp_runtime::traits::{AtLeast32Bit, SaturatedConversion, Scale, Zero}; -*/ -use frame::{prelude::*, runtime::prelude::derive_impl, arithmetic::AtLeast32Bit, traits::{Scale, OnTimestampSet, Time, UnixTime}}; +use frame::{ + prelude::*, + runtime::prelude::derive_impl, + traits::{AtLeast32Bit, OnTimestampSet, Scale, Time, UnixTime}, +}; use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER}; pub use weights::WeightInfo; pub use pallet::*; -// #[frame_support::pallet] #[frame::pallet] pub mod pallet { use super::*; - /* - use frame_support::{derive_impl, pallet_prelude::*}; - use frame_system::pallet_prelude::*; - */ /// Default preludes for [`Config`]. pub mod config_preludes { @@ -162,8 +157,7 @@ pub mod pallet { #[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)] impl frame_system::DefaultConfig for TestDefaultConfig {} - // #[frame_support::register_default_impl(TestDefaultConfig)] - #[frame::prelude::register_default_impl(TestDefaultConfig)] + #[register_default_impl(TestDefaultConfig)] impl DefaultConfig for TestDefaultConfig { type Moment = u64; type OnTimestampSet = (); diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index a3217228bf64..7123c3f8e189 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -19,12 +19,7 @@ use super::*; use crate as pallet_timestamp; -/* -use frame_support::{derive_impl, parameter_types, traits::ConstU64}; -use sp_io::TestExternalities; -use sp_runtime::BuildStorage; -*/ -use frame::{prelude::*, runtime::{testing_prelude::BuildStorage, prelude::*}, testing_prelude::TestExternalities}; +use frame::{prelude::*, testing_prelude::*}; type Block = frame_system::mocking::MockBlock; type Moment = u64; diff --git a/substrate/frame/timestamp/src/tests.rs b/substrate/frame/timestamp/src/tests.rs index d49aafb3b9ed..bd45f554e1eb 100644 --- a/substrate/frame/timestamp/src/tests.rs +++ b/substrate/frame/timestamp/src/tests.rs @@ -18,8 +18,6 @@ //! Tests for the Timestamp module. use crate::mock::*; -//use frame_support::assert_ok; - use frame::testing_prelude::*; #[test] From 4bfb6b59c4bab7170c8607a9a6729d8413ae061d Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Wed, 4 Dec 2024 20:51:50 -0800 Subject: [PATCH 3/7] sp-storage benchmarking import --- substrate/frame/timestamp/Cargo.toml | 4 ---- substrate/frame/timestamp/src/benchmarking.rs | 10 ++-------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/substrate/frame/timestamp/Cargo.toml b/substrate/frame/timestamp/Cargo.toml index f3e3fdacb427..40088618f369 100644 --- a/substrate/frame/timestamp/Cargo.toml +++ b/substrate/frame/timestamp/Cargo.toml @@ -25,10 +25,6 @@ sp-timestamp = { workspace = true } docify = { workspace = true } -# [dev-dependencies] -# sp-core = { workspace = true, default-features = true } -# sp-io = { workspace = true, default-features = true } - [features] default = ["std"] std = [ diff --git a/substrate/frame/timestamp/src/benchmarking.rs b/substrate/frame/timestamp/src/benchmarking.rs index 26c97453c96f..59239ac1011b 100644 --- a/substrate/frame/timestamp/src/benchmarking.rs +++ b/substrate/frame/timestamp/src/benchmarking.rs @@ -18,14 +18,8 @@ //! Timestamp pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] -/* -use frame_benchmarking::{benchmarking::add_to_whitelist, v2::*}; -use frame_support::traits::OnFinalize; -use frame_system::RawOrigin; -use sp_storage::TrackedStorageKey; -*/ use crate::*; -use frame::{benchmarking::prelude::*, traits::TrackedStorageKey}; +use frame::benchmarking::prelude::*; const MAX_TIME: u32 = 100; @@ -38,7 +32,7 @@ mod benchmarks { let t = MAX_TIME; // Ignore write to `DidUpdate` since it transient. let did_update_key = DidUpdate::::hashed_key().to_vec(); - add_to_whitelist(TrackedStorageKey { + add_to_whitelist(frame::deps::sp_storage::TrackedStorageKey { key: did_update_key, reads: 0, writes: 1, From 8b7fc14647f5912d48828c7ed74b78decbae4f5c Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Thu, 5 Dec 2024 18:27:16 -0800 Subject: [PATCH 4/7] prelude --- substrate/frame/timestamp/src/benchmarking.rs | 2 +- substrate/frame/timestamp/src/lib.rs | 3 +-- substrate/frame/timestamp/src/mock.rs | 2 +- substrate/frame/timestamp/src/weights.rs | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/substrate/frame/timestamp/src/benchmarking.rs b/substrate/frame/timestamp/src/benchmarking.rs index 59239ac1011b..cf9a8c971a1f 100644 --- a/substrate/frame/timestamp/src/benchmarking.rs +++ b/substrate/frame/timestamp/src/benchmarking.rs @@ -32,7 +32,7 @@ mod benchmarks { let t = MAX_TIME; // Ignore write to `DidUpdate` since it transient. let did_update_key = DidUpdate::::hashed_key().to_vec(); - add_to_whitelist(frame::deps::sp_storage::TrackedStorageKey { + add_to_whitelist(frame::traits::TrackedStorageKey { key: did_update_key, reads: 0, writes: 1, diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index c822cc11974b..d65048a17e8f 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -134,8 +134,7 @@ pub mod weights; use core::{cmp, result}; use frame::{ - prelude::*, - runtime::prelude::derive_impl, + runtime::prelude::*, traits::{AtLeast32Bit, OnTimestampSet, Scale, Time, UnixTime}, }; use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER}; diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index 7123c3f8e189..87f45655e74b 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -19,7 +19,7 @@ use super::*; use crate as pallet_timestamp; -use frame::{prelude::*, testing_prelude::*}; +use frame::testing_prelude::*; type Block = frame_system::mocking::MockBlock; type Moment = u64; diff --git a/substrate/frame/timestamp/src/weights.rs b/substrate/frame/timestamp/src/weights.rs index d522982edf7b..f0fed92780ee 100644 --- a/substrate/frame/timestamp/src/weights.rs +++ b/substrate/frame/timestamp/src/weights.rs @@ -46,7 +46,6 @@ #![allow(unused_imports)] #![allow(missing_docs)] -// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use frame::weights_prelude::*; use core::marker::PhantomData; From 78c4f03113b0e4dae6a8a0f6168aed25f013b33b Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Wed, 11 Dec 2024 19:57:52 -0800 Subject: [PATCH 5/7] remove prdoc --- prdoc/pr_6523.prdoc | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 prdoc/pr_6523.prdoc diff --git a/prdoc/pr_6523.prdoc b/prdoc/pr_6523.prdoc deleted file mode 100644 index e7f1a79ae1d5..000000000000 --- a/prdoc/pr_6523.prdoc +++ /dev/null @@ -1,14 +0,0 @@ -# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 -# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json - -title: migrate pallet-timestamp to umbrella crate - -doc: - - audience: Runtime Dev - description: | - This pull request adapts the frame umbrella crate into pallet-timestamp - by importing existing system into the pallet. - -crates: - - name: pallet-timestamp - bump: minor \ No newline at end of file From 1fbe0dc89388aa7f1e5e9e0654e12fc6cac652b0 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Mon, 30 Dec 2024 11:46:14 +0100 Subject: [PATCH 6/7] nit --- substrate/frame/src/lib.rs | 3 +++ substrate/frame/timestamp/src/lib.rs | 2 +- substrate/frame/timestamp/src/mock.rs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 03d815e349df..aa9cb1e8c402 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -216,6 +216,9 @@ pub mod prelude { /// All hashing related things pub use super::hashing::*; + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; + /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index d65048a17e8f..a6a5059008e9 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -135,7 +135,7 @@ pub mod weights; use core::{cmp, result}; use frame::{ runtime::prelude::*, - traits::{AtLeast32Bit, OnTimestampSet, Scale, Time, UnixTime}, + traits::{OnTimestampSet, Scale, Time, UnixTime}, }; use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER}; pub use weights::WeightInfo; diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index 87f45655e74b..e13ccdbdc4e0 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -20,7 +20,7 @@ use super::*; use crate as pallet_timestamp; use frame::testing_prelude::*; -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; type Moment = u64; construct_runtime!( From f69f2a367f13f3ad7e8bbf8b7db650d7110977e6 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Sat, 4 Jan 2025 13:22:09 +0100 Subject: [PATCH 7/7] match merge --- substrate/frame/timestamp/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index a6a5059008e9..3992701f806c 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -87,22 +87,22 @@ //! included in a block. //! //! To provide inherent data to the runtime, this pallet implements -//! [`ProvideInherent`](frame_support::inherent::ProvideInherent). It will only create an inherent -//! if the [`Call::set`] dispatchable is called, using the -//! [`inherent`](frame_support::pallet_macros::inherent) macro which enables validator nodes to call +//! [`ProvideInherent`](frame::deps::frame_support::inherent::ProvideInherent). It will only create +//! an inherent if the [`Call::set`] dispatchable is called, using the +//! [`inherent`](frame::pallet_macros::inherent) macro which enables validator nodes to call //! into the runtime to check that the timestamp provided is valid. -//! The implementation of [`ProvideInherent`](frame_support::inherent::ProvideInherent) specifies a -//! constant called `MAX_TIMESTAMP_DRIFT_MILLIS` which is used to determine the acceptable range for -//! a valid timestamp. If a block author sets a timestamp to anything that is more than this -//! constant, a validator node will reject the block. +//! The implementation of [`ProvideInherent`](frame::deps::frame_support::inherent::ProvideInherent) +//! specifies a constant called `MAX_TIMESTAMP_DRIFT_MILLIS` which is used to determine the +//! acceptable range for a valid timestamp. If a block author sets a timestamp to anything that is +//! more than this constant, a validator node will reject the block. //! //! The pallet also ensures that a timestamp is set at the start of each block by running an -//! assertion in the `on_finalize` runtime hook. See [`frame_support::traits::Hooks`] for more +//! assertion in the `on_finalize` runtime hook. See [`frame::traits::Hooks`] for more //! information about how hooks work. //! //! Because inherents are applied to a block in the order they appear in the runtime //! construction, the index of this pallet in -//! [`construct_runtime`](frame_support::construct_runtime) must always be less than any other +//! [`construct_runtime`](construct_runtime) must always be less than any other //! pallet that depends on it. //! //! The [`Config::OnTimestampSet`] configuration trait can be set to another pallet we want to