From 27df8ea0b75e49b39c158b4643c929bec96c821a Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 9 Oct 2024 13:59:25 +0100 Subject: [PATCH 01/35] pallet-proxy --- Cargo.lock | 6 +- substrate/frame/multisig/Cargo.toml | 25 +---- substrate/frame/multisig/src/benchmarking.rs | 19 ++-- substrate/frame/multisig/src/lib.rs | 35 ++---- substrate/frame/multisig/src/migrations.rs | 21 ++-- substrate/frame/multisig/src/tests.rs | 15 +-- substrate/frame/multisig/src/weights.rs | 5 +- substrate/frame/src/lib.rs | 106 ++++++++++++++++--- substrate/frame/support/src/lib.rs | 18 +++- substrate/frame/system/src/lib.rs | 3 + 10 files changed, 144 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a572c37a4060..db9e63c66c80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11907,15 +11907,11 @@ dependencies = [ name = "pallet-multisig" version = "28.0.0" dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", "log", "pallet-balances", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/multisig/Cargo.toml b/substrate/frame/multisig/Cargo.toml index b24df856bcd7..b0f6ad3a55ec 100644 --- a/substrate/frame/multisig/Cargo.toml +++ b/substrate/frame/multisig/Cargo.toml @@ -18,11 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } # third party log = { workspace = true } @@ -34,25 +30,12 @@ pallet-balances = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "log/std", - "pallet-balances/std", "scale-info/std", - "sp-io/std", - "sp-runtime/std", + "frame/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", + "frame/try-runtime", ] diff --git a/substrate/frame/multisig/src/benchmarking.rs b/substrate/frame/multisig/src/benchmarking.rs index ebe19df5dc43..6e71a89c7a89 100644 --- a/substrate/frame/multisig/src/benchmarking.rs +++ b/substrate/frame/multisig/src/benchmarking.rs @@ -20,9 +20,8 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::v1::{account, benchmarks}; -use frame_system::RawOrigin; -use sp_runtime::traits::Bounded; +#[allow(deprecated)] +use frame::benchmarking::v1::*; use crate::Pallet as Multisig; @@ -61,7 +60,7 @@ benchmarks! { let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call)) verify { // If the benchmark resolves, then the call was dispatched successfully. @@ -78,7 +77,7 @@ benchmarks! { let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, Weight::zero()) verify { assert!(Multisigs::::contains_key(multi_account_id, call_hash)); @@ -101,7 +100,7 @@ benchmarks! { let caller2 = signatories2.remove(0); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::zero()) verify { let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; @@ -133,7 +132,7 @@ benchmarks! { assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::MAX) verify { assert!(!Multisigs::::contains_key(&multi_account_id, call_hash)); @@ -150,7 +149,7 @@ benchmarks! { let call_hash = call.using_encoded(blake2_256); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); // Create the multi }: approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, Weight::zero()) verify { @@ -181,7 +180,7 @@ benchmarks! { let caller2 = signatories2.remove(0); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, Weight::zero()) verify { let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; @@ -204,7 +203,7 @@ benchmarks! { assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash) verify { assert!(!Multisigs::::contains_key(multi_account_id, call_hash)); diff --git a/substrate/frame/multisig/src/lib.rs b/substrate/frame/multisig/src/lib.rs index 51c36773bdad..0876600b1091 100644 --- a/substrate/frame/multisig/src/lib.rs +++ b/substrate/frame/multisig/src/lib.rs @@ -49,28 +49,15 @@ mod tests; pub mod weights; extern crate alloc; - use alloc::{boxed::Box, vec, vec::Vec}; -use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{ - dispatch::{ - DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, - PostDispatchInfo, - }, - ensure, - traits::{Currency, Get, ReservableCurrency}, - weights::Weight, - BoundedVec, -}; -use frame_system::{self as system, pallet_prelude::BlockNumberFor, RawOrigin}; -use scale_info::TypeInfo; -use sp_io::hashing::blake2_256; -use sp_runtime::{ - traits::{Dispatchable, TrailingZeroInput, Zero}, - DispatchError, RuntimeDebug, +use frame::{ + hashing::blake2_256, + prelude::*, + traits::{Currency, ReservableCurrency}, }; -pub use weights::WeightInfo; +use weights::WeightInfo; +/// Re-export all pallet items. pub use pallet::*; /// The log target of this pallet. @@ -127,11 +114,9 @@ enum CallOrHash { Hash([u8; 32]), } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; #[pallet::config] pub trait Config: frame_system::Config { @@ -167,7 +152,7 @@ pub mod pallet { type MaxSignatories: Get; /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; + type WeightInfo: weights::WeightInfo; } /// The in-code storage version. @@ -641,8 +626,8 @@ impl Pallet { /// The current `Timepoint`. pub fn timepoint() -> Timepoint> { Timepoint { - height: >::block_number(), - index: >::extrinsic_index().unwrap_or_default(), + height: >::block_number(), + index: >::extrinsic_index().unwrap_or_default(), } } diff --git a/substrate/frame/multisig/src/migrations.rs b/substrate/frame/multisig/src/migrations.rs index e6402600d0d3..cef06d38f563 100644 --- a/substrate/frame/multisig/src/migrations.rs +++ b/substrate/frame/multisig/src/migrations.rs @@ -17,21 +17,15 @@ // Migrations for Multisig Pallet -use super::*; -use frame_support::{ - traits::{GetStorageVersion, OnRuntimeUpgrade, WrapperKeepOpaque}, - Identity, -}; - -#[cfg(feature = "try-runtime")] -use frame_support::ensure; +use crate::*; +use frame::prelude::*; pub mod v1 { use super::*; - type OpaqueCall = WrapperKeepOpaque<::RuntimeCall>; + type OpaqueCall = frame::traits::WrapperKeepOpaque<::RuntimeCall>; - #[frame_support::storage_alias] + #[frame::storage_alias] type Calls = StorageMap< Pallet, Identity, @@ -42,15 +36,14 @@ pub mod v1 { pub struct MigrateToV1(core::marker::PhantomData); impl OnRuntimeUpgrade for MigrateToV1 { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + fn pre_upgrade() -> Result, frame::deps::sp_runtime::TryRuntimeError> { log!(info, "Number of calls to refund and delete: {}", Calls::::iter().count()); Ok(Vec::new()) } fn on_runtime_upgrade() -> Weight { - use sp_runtime::Saturating; - + use frame::traits::ReservableCurrency as _; let current = Pallet::::in_code_storage_version(); let onchain = Pallet::::on_chain_storage_version(); @@ -76,7 +69,7 @@ pub mod v1 { } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + fn post_upgrade(_state: Vec) -> Result<(), frame::try_runtime::TryRuntimeError> { ensure!( Calls::::iter().count() == 0, "there are some dangling calls that need to be destroyed and refunded" diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index cfdd33f7dfcc..762407e15df7 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -20,18 +20,13 @@ #![cfg(test)] use super::*; - use crate as pallet_multisig; -use frame_support::{ - assert_noop, assert_ok, derive_impl, - traits::{ConstU32, ConstU64, Contains}, -}; -use sp_runtime::{BuildStorage, TokenError}; +use frame::{prelude::*, runtime::prelude::*, testing_prelude::*}; type Block = frame_system::mocking::MockBlockU32; -frame_support::construct_runtime!( - pub enum Test { +construct_runtime!( + pub struct Test { System: frame_system, Balances: pallet_balances, Multisig: pallet_multisig, @@ -75,14 +70,14 @@ impl Config for Test { use pallet_balances::Call as BalancesCall; -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)], } .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); + let mut ext = TestState::new(t); ext.execute_with(|| System::set_block_number(1)); ext } diff --git a/substrate/frame/multisig/src/weights.rs b/substrate/frame/multisig/src/weights.rs index ac1c1b23b030..fb263116ea62 100644 --- a/substrate/frame/multisig/src/weights.rs +++ b/substrate/frame/multisig/src/weights.rs @@ -46,9 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - +// TODO update this in frame-weight-template.hbs +use frame::weights_prelude::*; /// Weight functions needed for `pallet_multisig`. pub trait WeightInfo { fn as_multi_threshold_1(z: u32, ) -> Weight; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index e5fb15cdd07c..c7c4e479692a 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -35,7 +35,7 @@ //! The main intended use of this crate is for it to be imported with its preludes: //! //! ``` -//! # use polkadot_sdk_frame as frame; +//! use polkadot_sdk_frame as frame; //! #[frame::pallet] //! pub mod pallet { //! # use polkadot_sdk_frame as frame; @@ -49,18 +49,25 @@ //! pub struct Pallet(_); //! } //! +//! #[cfg(test)] //! pub mod tests { //! # use polkadot_sdk_frame as frame; //! use frame::testing_prelude::*; //! } //! +//! #[cfg(feature = "runtime-benchmarks")] +//! pub mod benchmarking { +//! # use polkadot_sdk_frame as frame; +//! use frame::benchmarking::prelude::*; +//! } +//! //! pub mod runtime { //! # use polkadot_sdk_frame as frame; //! use frame::runtime::prelude::*; //! } //! ``` //! -//! See: [`prelude`], [`testing_prelude`] and [`runtime::prelude`]. +//! See: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`]. //! //! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. //! @@ -92,6 +99,9 @@ pub use frame_support::pallet_macros::{import_section, pallet_section}; /// The logging library of the runtime. Can normally be the classic `log` crate. pub use log; +#[doc(inline)] +pub use frame_support::storage_alias; + /// Macros used within the main [`pallet`] macro. /// /// Note: All of these macros are "stubs" and not really usable outside `#[pallet] mod pallet { .. @@ -137,6 +147,60 @@ pub mod prelude { pub use super::derive::*; } +#[cfg(any(feature = "try-runtime", test))] +pub mod try_runtime { + pub use sp_runtime::TryRuntimeError; +} + +/// Prelude to be included in the `benchmarking.rs` of a pallet. +/// +/// It supports both the `benchmarking::v1::benchmarks` and `benchmarking::v2::benchmark` syntax. +/// +/// ``` +/// use polkadot_sdk_frame::benchmarking::prelude::*; +/// // rest of your code. +/// ``` +/// +/// It already includes `polkadot_sdk_frame::prelude::*` and `polkadot_sdk_frame::testing_prelude`. +#[cfg(any(feature = "runtime-benchmarks", test))] +pub mod benchmarking { + mod shared { + pub use frame_benchmarking::{add_benchmark, v1::account, whitelist, whitelisted_caller}; + // all benchmarking host functions. + pub use frame_benchmarking::benchmarking::*; + } + + #[deprecated(note = "use the syntax in `frame::benchmarking::v2`")] + pub mod v1 { + pub use super::shared::*; + pub use frame_benchmarking::benchmarks; + } + + pub mod prelude { + pub use super::shared::*; + pub use crate::prelude::*; + pub use frame_benchmarking::v2::*; + } +} + +/// Prelude to be included in the `weight.rs` of each pallet. +/// +/// ``` +/// pub use polkadot_sdk_frame::weights_prelude::*; +/// ``` +pub mod weights_prelude { + + pub use core::marker::PhantomData; + pub use frame_support::{ + traits::Get, + weights::{ + constants::{ParityDbWeight, RocksDbWeight}, + Weight, + }, + }; + pub use frame_system; +} + /// The main testing prelude of FRAME. /// /// A test setup typically starts with: @@ -145,9 +209,13 @@ pub mod prelude { /// use polkadot_sdk_frame::testing_prelude::*; /// // rest of your test setup. /// ``` +/// +/// This automatically brings in `polkadot_sdk_frame::prelude::*` and +/// `polkadot_sdk_frame::runtime::prelude::*`. #[cfg(feature = "std")] pub mod testing_prelude { - pub use super::prelude::*; + pub use crate::{prelude::*, runtime::prelude::*}; + /// Testing includes building a runtime, so we bring in all preludes related to runtimes as /// well. pub use super::runtime::testing_prelude::*; @@ -159,6 +227,10 @@ pub mod testing_prelude { }; pub use frame_system::{self, mocking::*}; + + #[deprecated(note = "Use `frame::testing_prelude::TestExternalities` instead.")] + pub use sp_io::TestExternalities; + pub use sp_io::TestExternalities as TestState; } @@ -170,9 +242,13 @@ pub mod runtime { /// A runtime typically starts with: /// /// ``` - /// use polkadot_sdk_frame::{prelude::*, runtime::prelude::*}; + /// use polkadot_sdk_frame::runtime::prelude::*; /// ``` + /// + /// This automatically brings in `polkadot_sdk_frame::prelude::*`. pub mod prelude { + pub use crate::prelude::*; + /// All of the types related to the FRAME runtime executive. pub use frame_executive::*; @@ -322,7 +398,6 @@ pub mod runtime { /// counter part of `runtime::prelude`. #[cfg(feature = "std")] pub mod testing_prelude { - pub use super::prelude::*; pub use sp_core::storage::Storage; pub use sp_runtime::BuildStorage; } @@ -344,12 +419,6 @@ pub mod arithmetic { pub use sp_arithmetic::{traits::*, *}; } -/// Low level primitive types used in FRAME pallets. -pub mod primitives { - pub use sp_core::{H160, H256, H512, U256, U512}; - pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; -} - /// All derive macros used in frame. /// /// This is already part of the [`prelude`]. @@ -364,12 +433,17 @@ pub mod derive { pub use sp_runtime::RuntimeDebug; } -/// Access to all of the dependencies of this crate. In case the re-exports are not enough, this -/// module can be used. +pub mod hashing { + pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; + pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; +} + +/// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, +/// this module can be used. /// -/// Any time one uses this module to access a dependency, you can have a moment to think about -/// whether this item could have been placed in any of the other modules and preludes in this crate. -/// In most cases, hopefully the answer is yes. +/// Note for maintainers: Any time one uses this module to access a dependency, you can have a +/// moment to think about whether this item could have been placed in any of the other modules and +/// preludes in this crate. In most cases, hopefully the answer is yes. pub mod deps { // TODO: It would be great to somehow instruct RA to prefer *not* suggesting auto-imports from // these. For example, we prefer `polkadot_sdk_frame::derive::CloneNoBound` rather than diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 269867e38c51..5e4c1750d0ef 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -886,7 +886,10 @@ pub mod testing_prelude { pub mod pallet_prelude { pub use crate::{ defensive, defensive_assert, - dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays}, + dispatch::{ + DispatchClass, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, Parameter, + Pays, PostDispatchInfo, + }, ensure, inherent::{InherentData, InherentIdentifier, ProvideInherent}, storage, @@ -902,8 +905,9 @@ pub mod pallet_prelude { StorageList, }, traits::{ - BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, - IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet, + BuildGenesisConfig, ConstU32, Contains, EnsureOrigin, Get, GetDefault, + GetStorageVersion, Hooks, IsType, OnRuntimeUpgrade, PalletInfoAccess, StorageInfoTrait, + StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, @@ -915,13 +919,17 @@ pub mod pallet_prelude { pub use scale_info::TypeInfo; pub use sp_inherents::MakeFatalError; pub use sp_runtime::{ - traits::{MaybeSerializeDeserialize, Member, ValidateUnsigned}, + traits::{ + Bounded, DispatchInfoOf, Dispatchable, MaybeSerializeDeserialize, Member, One, + SaturatedConversion, Saturating, TrailingZeroInput, ValidateUnsigned, Zero, + }, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag, TransactionValidity, TransactionValidityError, UnknownTransaction, ValidTransaction, }, - DispatchError, RuntimeDebug, MAX_MODULE_ERROR_ENCODED_SIZE, + DispatchError, DispatchErrorWithPostInfo, DispatchResultWithInfo, RuntimeDebug, TokenError, + MAX_MODULE_ERROR_ENCODED_SIZE, }; pub use sp_weights::Weight; } diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 662b7f1a94bf..9adcdf5a0bb7 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -2267,6 +2267,9 @@ impl Lookup for ChainContext { pub mod pallet_prelude { pub use crate::{ensure_none, ensure_root, ensure_signed, ensure_signed_or_root}; + #[doc(inline)] + pub use super::RawOrigin; + /// Type alias for the `Origin` associated type of system config. pub type OriginFor = ::RuntimeOrigin; From 8eefc004a706329328b57e09a5e19eb2bad2a612 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 9 Oct 2024 14:18:21 +0100 Subject: [PATCH 02/35] pallet-multisig --- Cargo.lock | 7 +---- substrate/frame/proxy/Cargo.toml | 29 +++---------------- substrate/frame/proxy/src/benchmarking.rs | 9 +++--- substrate/frame/proxy/src/lib.rs | 35 ++++++++--------------- substrate/frame/proxy/src/tests.rs | 26 ++++++----------- substrate/frame/proxy/src/weights.rs | 3 +- substrate/frame/src/lib.rs | 3 ++ substrate/frame/support/src/lib.rs | 7 +++-- 8 files changed, 38 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db9e63c66c80..442ab51ddaa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12227,16 +12227,11 @@ dependencies = [ name = "pallet-proxy" version = "28.0.0" dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", "pallet-balances", "pallet-utility", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/proxy/Cargo.toml b/substrate/frame/proxy/Cargo.toml index 40c1c9750614..4f9a3fd97f6e 100644 --- a/substrate/frame/proxy/Cargo.toml +++ b/substrate/frame/proxy/Cargo.toml @@ -18,43 +18,22 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["max-encoded-len"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } pallet-utility = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "pallet-utility/std", "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", + "frame/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "pallet-utility/try-runtime", - "sp-runtime/try-runtime", + "frame/try-runtime", ] diff --git a/substrate/frame/proxy/src/benchmarking.rs b/substrate/frame/proxy/src/benchmarking.rs index 4081af49c243..534019209a3e 100644 --- a/substrate/frame/proxy/src/benchmarking.rs +++ b/substrate/frame/proxy/src/benchmarking.rs @@ -22,9 +22,8 @@ use super::*; use crate::Pallet as Proxy; use alloc::{boxed::Box, vec}; -use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller}; -use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; -use sp_runtime::traits::Bounded; +#[allow(deprecated)] +use frame::benchmarking::v1::*; const SEED: u32 = 0; @@ -250,8 +249,8 @@ benchmarks! { BlockNumberFor::::zero(), 0 )?; - let height = system::Pallet::::block_number(); - let ext_index = system::Pallet::::extrinsic_index().unwrap_or(0); + let height = frame_system::Pallet::::block_number(); + let ext_index = frame_system::Pallet::::extrinsic_index().unwrap_or(0); let pure_account = Pallet::::pure_account(&caller, &T::ProxyType::default(), 0, None); add_proxies::(p, Some(pure_account.clone()))?; diff --git a/substrate/frame/proxy/src/lib.rs b/substrate/frame/proxy/src/lib.rs index 016f2cf225e0..ca76afccc3a0 100644 --- a/substrate/frame/proxy/src/lib.rs +++ b/substrate/frame/proxy/src/lib.rs @@ -34,23 +34,13 @@ mod tests; pub mod weights; extern crate alloc; - use alloc::{boxed::Box, vec}; -use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{ - dispatch::GetDispatchInfo, - ensure, - traits::{Currency, Get, InstanceFilter, IsSubType, IsType, OriginTrait, ReservableCurrency}, - BoundedVec, +use frame::{ + hashing::blake2_256, + prelude::*, + traits::{Currency, ReservableCurrency}, }; -use frame_system::{self as system, ensure_signed, pallet_prelude::BlockNumberFor}; pub use pallet::*; -use scale_info::TypeInfo; -use sp_io::hashing::blake2_256; -use sp_runtime::{ - traits::{Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero}, - DispatchError, DispatchResult, RuntimeDebug, -}; pub use weights::WeightInfo; type CallHashOf = <::CallHasher as Hash>::Output; @@ -96,11 +86,9 @@ pub struct Announcement { height: BlockNumber, } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { - use super::{DispatchResult, *}; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + use super::*; #[pallet::pallet] pub struct Pallet(_); @@ -130,7 +118,7 @@ pub mod pallet { + Member + Ord + PartialOrd - + InstanceFilter<::RuntimeCall> + + frame::traits::InstanceFilter<::RuntimeCall> + Default + MaxEncodedLen; @@ -392,7 +380,7 @@ pub mod pallet { let announcement = Announcement { real: real.clone(), call_hash, - height: system::Pallet::::block_number(), + height: frame_system::Pallet::::block_number(), }; Announcements::::try_mutate(&who, |(ref mut pending, ref mut deposit)| { @@ -503,7 +491,7 @@ pub mod pallet { let def = Self::find_proxy(&real, &delegate, force_proxy_type)?; let call_hash = T::CallHasher::hash_of(&call); - let now = system::Pallet::::block_number(); + let now = frame_system::Pallet::::block_number(); Self::edit_announcements(&delegate, |ann| { ann.real != real || ann.call_hash != call_hash || @@ -639,8 +627,8 @@ impl Pallet { ) -> T::AccountId { let (height, ext_index) = maybe_when.unwrap_or_else(|| { ( - system::Pallet::::block_number(), - system::Pallet::::extrinsic_index().unwrap_or_default(), + frame_system::Pallet::::block_number(), + frame_system::Pallet::::extrinsic_index().unwrap_or_default(), ) }); let entropy = (b"modlpy/proxy____", who, height, ext_index, proxy_type, index) @@ -796,6 +784,7 @@ impl Pallet { real: T::AccountId, call: ::RuntimeCall, ) { + use frame::traits::{InstanceFilter as _, OriginTrait as _}; // This is a freshly authenticated new account, the origin restrictions doesn't apply. let mut origin: T::RuntimeOrigin = frame_system::RawOrigin::Signed(real).into(); origin.add_filter(move |c: &::RuntimeCall| { diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index 3edb96026a82..5baf9bb9e838 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -20,22 +20,14 @@ #![cfg(test)] use super::*; - use crate as proxy; use alloc::{vec, vec::Vec}; -use codec::{Decode, Encode}; -use frame_support::{ - assert_noop, assert_ok, derive_impl, - traits::{ConstU32, ConstU64, Contains}, -}; -use sp_core::H256; -use sp_runtime::{traits::BlakeTwo256, BuildStorage, DispatchError, RuntimeDebug}; +use frame::testing_prelude::*; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( - pub enum Test - { +construct_runtime!( + pub struct Test { System: frame_system, Balances: pallet_balances, Proxy: proxy, @@ -86,7 +78,7 @@ impl Default for ProxyType { Self::Any } } -impl InstanceFilter for ProxyType { +impl frame::traits::InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, @@ -136,20 +128,20 @@ use pallet_utility::{Call as UtilityCall, Event as UtilityEvent}; type SystemError = frame_system::Error; -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 3)], } .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); + let mut ext = TestState::new(t); ext.execute_with(|| System::set_block_number(1)); ext } fn last_events(n: usize) -> Vec { - system::Pallet::::events() + frame_system::Pallet::::events() .into_iter() .rev() .take(n) @@ -286,7 +278,7 @@ fn delayed_requires_pre_announcement() { assert_noop!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 2, 1, None, call.clone()), e); let call_hash = BlakeTwo256::hash_of(&call); assert_ok!(Proxy::announce(RuntimeOrigin::signed(2), 1, call_hash)); - system::Pallet::::set_block_number(2); + frame_system::Pallet::::set_block_number(2); assert_ok!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 2, 1, None, call.clone())); }); } @@ -304,7 +296,7 @@ fn proxy_announced_removes_announcement_and_returns_deposit() { let e = Error::::Unannounced; assert_noop!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone()), e); - system::Pallet::::set_block_number(2); + frame_system::Pallet::::set_block_number(2); assert_ok!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone())); let announcements = Announcements::::get(3); assert_eq!(announcements.0, vec![Announcement { real: 2, call_hash, height: 1 }]); diff --git a/substrate/frame/proxy/src/weights.rs b/substrate/frame/proxy/src/weights.rs index 3093298e3e54..eab2cb4b2683 100644 --- a/substrate/frame/proxy/src/weights.rs +++ b/substrate/frame/proxy/src/weights.rs @@ -46,8 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; +use frame::weights_prelude::*; /// Weight functions needed for `pallet_proxy`. pub trait WeightInfo { diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c7c4e479692a..d856b794cf30 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -145,6 +145,9 @@ pub mod prelude { /// All FRAME-relevant derive macros. #[doc(no_inline)] pub use super::derive::*; + + /// All hashing related things + pub use super::hashing::*; } #[cfg(any(feature = "try-runtime", test))] diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 5e4c1750d0ef..72f5cbaf9269 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -906,8 +906,8 @@ pub mod pallet_prelude { }, traits::{ BuildGenesisConfig, ConstU32, Contains, EnsureOrigin, Get, GetDefault, - GetStorageVersion, Hooks, IsType, OnRuntimeUpgrade, PalletInfoAccess, StorageInfoTrait, - StorageVersion, Task, TypedGet, + GetStorageVersion, Hooks, IsSubType, IsType, OnRuntimeUpgrade, PalletInfoAccess, + StorageInfoTrait, StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, @@ -921,7 +921,8 @@ pub mod pallet_prelude { pub use sp_runtime::{ traits::{ Bounded, DispatchInfoOf, Dispatchable, MaybeSerializeDeserialize, Member, One, - SaturatedConversion, Saturating, TrailingZeroInput, ValidateUnsigned, Zero, + SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, + Zero, }, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, From 78b52f2346745d123f0966f6d7ec841b2b5aa878 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 9 Oct 2024 15:55:24 +0100 Subject: [PATCH 03/35] better docs --- Cargo.lock | 1 + substrate/frame/Cargo.toml | 3 ++ substrate/frame/multisig/src/lib.rs | 1 - substrate/frame/proxy/src/lib.rs | 1 - substrate/frame/src/lib.rs | 70 ++++++++++++++++++++++++----- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8add8313218..3cfa81407e80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15669,6 +15669,7 @@ dependencies = [ "sp-consensus-aura", "sp-consensus-grandpa", "sp-core 28.0.0", + "sp-genesis-builder", "sp-inherents", "sp-io 30.0.0", "sp-offchain", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 41ece6c9a27f..8739837cd4de 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -46,6 +46,7 @@ sp-consensus-aura = { optional = true, workspace = true } sp-consensus-grandpa = { optional = true, workspace = true } sp-inherents = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } +sp-genesis-builder = { optional = true, workspace = true } frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } @@ -77,6 +78,7 @@ runtime = [ "sp-storage", "sp-transaction-pool", "sp-version", + "sp-genesis-builder", "frame-executive", "frame-system-rpc-runtime-api", @@ -98,6 +100,7 @@ std = [ "sp-consensus-aura?/std", "sp-consensus-grandpa?/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents?/std", "sp-io/std", "sp-offchain?/std", diff --git a/substrate/frame/multisig/src/lib.rs b/substrate/frame/multisig/src/lib.rs index 0876600b1091..8f3c1ebe5830 100644 --- a/substrate/frame/multisig/src/lib.rs +++ b/substrate/frame/multisig/src/lib.rs @@ -51,7 +51,6 @@ pub mod weights; extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use frame::{ - hashing::blake2_256, prelude::*, traits::{Currency, ReservableCurrency}, }; diff --git a/substrate/frame/proxy/src/lib.rs b/substrate/frame/proxy/src/lib.rs index ca76afccc3a0..e447625d1cbd 100644 --- a/substrate/frame/proxy/src/lib.rs +++ b/substrate/frame/proxy/src/lib.rs @@ -36,7 +36,6 @@ pub mod weights; extern crate alloc; use alloc::{boxed::Box, vec}; use frame::{ - hashing::blake2_256, prelude::*, traits::{Currency, ReservableCurrency}, }; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index d856b794cf30..c3515e4b9338 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -32,7 +32,14 @@ //! //! ## Usage //! -//! The main intended use of this crate is for it to be imported with its preludes: +//! This crate is organized into 3 stages: +//! +//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`], +//! [`weights_prelude`], [`try_runtime`]. +//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`]. +//! 3. Accessing frame/substrate dependencies directly: [`deps`]. +//! +//! The main intended use of this crate is for it to be used with the former, preludes: //! //! ``` //! use polkadot_sdk_frame as frame; @@ -67,25 +74,67 @@ //! } //! ``` //! -//! See: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`]. +//! See: . //! -//! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. +//! If not in preludes, one can look into the domain-specific modules. Finally, if an import is +//! still not feasible, one can look into [`deps`]. //! -//! ## Documentation //! -//! See [`polkadot_sdk::frame`](../polkadot_sdk_docs/polkadot_sdk/frame_runtime/index.html). +//! ## Naming //! -//! ## Underlying dependencies +//! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. This is due +//! to compatibility matters with `frame-support`. //! -//! This crate is an amalgamation of multiple other crates that are often used together to compose a -//! pallet. It is not necessary to use it, and it may fall short for certain purposes. +//! A typical pallet's `Cargo.toml` using this crate looks like: //! -//! In short, this crate only re-exports types and traits from multiple sources. All of these -//! sources are listed (and re-exported again) in [`deps`]. +//! ```ignore +//! [dependencies] +//! codec = { features = ["max-encoded-len"], workspace = true } +//! scale-info = { features = ["derive"], workspace = true } +//! frame = { workspace = true, features = ["experimental", "runtime"] } +//! +//! [features] +//! default = ["std"] +//! std = [ +//! "codec/std", +//! "scale-info/std", +//! "frame/std", +//! ] +//! runtime-benchmarks = [ +//! "frame/runtime-benchmarks", +//! ] +//! try-runtime = [ +//! "frame/try-runtime", +//! ] +//! ``` +//! +//! ## Documentation +//! +//! See [`polkadot_sdk::frame`](../polkadot_sdk_docs/polkadot_sdk/frame_runtime/index.html). //! //! ## WARNING: Experimental //! //! **This crate and all of its content is experimental, and should not yet be used in production.** +//! +//! ## Maintenance Note +//! +//! > Notes for the maintainers of this crate, describing how the re-exports and preludes should +//! > work. +//! +//! * Preludes should be extensive. The goal of this pallet is to be ONLY used with the preludes. +//! The domain-specific modules are just a backup, aiming to keep things organized. Don't hesitate +//! in adding more items to the main prelude. +//! * When doing so, prefer adding the relevant item to `frame_support::pallet_prelude` and +//! `frame_system::pallet_prelude`. +//! * The only non-module, non-prelude items exported from the top level crate is the `pallet` +//! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. +//! * In most cases, you might want to create a domain-specific module, but also add it to the +//! preludes, such as [`hashing`]. +//! * The only items that should NOT be in preludes are those that have been placed in +//! `frame-support`/`sp-runtime`, but in truth are related to just one pallet. +//! * The currency related traits are kept out of the preludes to encourage a deliberate choice of +//! one over the other. +//! * [`runtime::apis`] should expose all common runtime APIs that all FRAME-based runtimes need. #![cfg_attr(not(feature = "std"), no_std)] #![cfg(feature = "experimental")] @@ -325,6 +374,7 @@ pub mod runtime { pub use sp_block_builder::*; pub use sp_consensus_aura::*; pub use sp_consensus_grandpa::*; + pub use sp_genesis_builder::*; pub use sp_offchain::*; pub use sp_session::runtime_api::*; pub use sp_transaction_pool::runtime_api::*; From d253bc5d2fe280193d5d67a38100f0050ed522cb Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 9 Oct 2024 16:13:25 +0100 Subject: [PATCH 04/35] also improve the minimal template --- Cargo.lock | 2 +- substrate/frame/src/lib.rs | 3 +++ templates/minimal/pallets/template/Cargo.toml | 5 +++-- templates/minimal/pallets/template/src/lib.rs | 5 +++-- templates/minimal/runtime/Cargo.toml | 6 +++--- templates/minimal/runtime/src/lib.rs | 11 +++++------ 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3cfa81407e80..bf7ec8cd8e2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11856,7 +11856,7 @@ name = "pallet-minimal-template" version = "0.0.0" dependencies = [ "parity-scale-codec", - "polkadot-sdk", + "polkadot-sdk-frame", "scale-info", ] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c3515e4b9338..52d16f2f48cb 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -350,6 +350,7 @@ pub mod runtime { // Types often used in the runtime APIs. pub use sp_core::OpaqueMetadata; + pub use sp_genesis_builder::PresetId; pub use sp_inherents::{CheckInherentsResult, InherentData}; pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; } @@ -530,6 +531,8 @@ pub mod deps { pub use sp_storage; #[cfg(feature = "runtime")] pub use sp_version; + #[cfg(feature = "runtime")] + pub use sp_genesis_builder; #[cfg(feature = "runtime-benchmarks")] pub use frame_benchmarking; diff --git a/templates/minimal/pallets/template/Cargo.toml b/templates/minimal/pallets/template/Cargo.toml index 9a02d4daeaac..d6ca6b449cde 100644 --- a/templates/minimal/pallets/template/Cargo.toml +++ b/templates/minimal/pallets/template/Cargo.toml @@ -15,7 +15,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -polkadot-sdk = { workspace = true, default-features = false, features = [ +# TODO: will this work fine when we sync-out this template? maybe the name should `polkadot-sdk-frame` +frame = { workspace = true, default-features = false, features = [ "experimental", "runtime", ] } @@ -23,4 +24,4 @@ polkadot-sdk = { workspace = true, default-features = false, features = [ [features] default = ["std"] -std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] +std = ["codec/std", "frame/std", "scale-info/std"] diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index b8a8614932a6..5c0e8a049fab 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -5,7 +5,8 @@ #![cfg_attr(not(feature = "std"), no_std)] -use polkadot_sdk::polkadot_sdk_frame as frame; +#[allow(unused_imports)] +use frame::prelude::*; // Re-export all pallet parts, this is needed to properly import the pallet into the runtime. pub use pallet::*; @@ -15,7 +16,7 @@ pub mod pallet { use super::*; #[pallet::config] - pub trait Config: polkadot_sdk::frame_system::Config {} + pub trait Config: frame_system::Config {} #[pallet::pallet] pub struct Pallet(_); diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 74a09b9396e5..54b84cca0de7 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -13,7 +13,6 @@ publish = false codec = { workspace = true } scale-info = { workspace = true } polkadot-sdk = { workspace = true, features = [ - "experimental", "pallet-balances", "pallet-sudo", "pallet-timestamp", @@ -35,8 +34,9 @@ polkadot-sdk = { optional = true, workspace = true, features = [ default = ["std"] std = [ "codec/std", - "pallet-minimal-template/std", - "polkadot-sdk/std", "scale-info/std", "serde_json/std", + + "pallet-minimal-template/std", + "polkadot-sdk/std", ] diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 7379e33b6b3e..0dcb0970d0b3 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -30,7 +30,7 @@ use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use polkadot_sdk::{ polkadot_sdk_frame::{ self as frame, - prelude::*, + deps::sp_genesis_builder, runtime::{apis, prelude::*}, }, *, @@ -38,15 +38,14 @@ use polkadot_sdk::{ /// Provides getters for genesis configuration presets. pub mod genesis_config_presets { + use super::*; use crate::{ interface::{Balance, MinimumBalance}, - sp_genesis_builder::PresetId, sp_keyring::AccountKeyring, BalancesConfig, RuntimeGenesisConfig, SudoConfig, }; use alloc::{vec, vec::Vec}; - use polkadot_sdk::{sp_core::Get, sp_genesis_builder}; use serde_json::Value; /// Returns a development genesis config preset. @@ -314,16 +313,16 @@ impl_runtime_apis! { } } - impl sp_genesis_builder::GenesisBuilder for Runtime { + impl apis::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } - fn get_preset(id: &Option) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id, self::genesis_config_presets::get_preset) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { self::genesis_config_presets::preset_names() } } From a4b1fd25b62c6b4f9001510873e8c47d6a7b7e46 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 9 Oct 2024 16:40:13 +0100 Subject: [PATCH 05/35] fix --- Cargo.lock | 2 +- templates/minimal/pallets/template/Cargo.toml | 5 ++--- templates/minimal/pallets/template/src/lib.rs | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf7ec8cd8e2c..3cfa81407e80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11856,7 +11856,7 @@ name = "pallet-minimal-template" version = "0.0.0" dependencies = [ "parity-scale-codec", - "polkadot-sdk-frame", + "polkadot-sdk", "scale-info", ] diff --git a/templates/minimal/pallets/template/Cargo.toml b/templates/minimal/pallets/template/Cargo.toml index d6ca6b449cde..9a02d4daeaac 100644 --- a/templates/minimal/pallets/template/Cargo.toml +++ b/templates/minimal/pallets/template/Cargo.toml @@ -15,8 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -# TODO: will this work fine when we sync-out this template? maybe the name should `polkadot-sdk-frame` -frame = { workspace = true, default-features = false, features = [ +polkadot-sdk = { workspace = true, default-features = false, features = [ "experimental", "runtime", ] } @@ -24,4 +23,4 @@ frame = { workspace = true, default-features = false, features = [ [features] default = ["std"] -std = ["codec/std", "frame/std", "scale-info/std"] +std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index 5c0e8a049fab..2c5fdf1e81b2 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -7,6 +7,7 @@ #[allow(unused_imports)] use frame::prelude::*; +use polkadot_sdk::polkadot_sdk_frame as frame; // Re-export all pallet parts, this is needed to properly import the pallet into the runtime. pub use pallet::*; @@ -16,7 +17,7 @@ pub mod pallet { use super::*; #[pallet::config] - pub trait Config: frame_system::Config {} + pub trait Config: polkadot_sdk::frame_system::Config {} #[pallet::pallet] pub struct Pallet(_); From e0293d1d65d3c30e06a92fdaf01c010cfb649f9f Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:57:52 +0100 Subject: [PATCH 06/35] Update substrate/frame/multisig/src/migrations.rs Co-authored-by: Guillaume Thiolliere --- substrate/frame/multisig/src/migrations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/multisig/src/migrations.rs b/substrate/frame/multisig/src/migrations.rs index cef06d38f563..8d6e77813673 100644 --- a/substrate/frame/multisig/src/migrations.rs +++ b/substrate/frame/multisig/src/migrations.rs @@ -36,7 +36,7 @@ pub mod v1 { pub struct MigrateToV1(core::marker::PhantomData); impl OnRuntimeUpgrade for MigrateToV1 { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, frame::deps::sp_runtime::TryRuntimeError> { + fn pre_upgrade() -> Result, frame::try_runtime::TryRuntimeError> { log!(info, "Number of calls to refund and delete: {}", Calls::::iter().count()); Ok(Vec::new()) From 253ce3fcefc80d8e9644075e9011f1f81f173e65 Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Tue, 15 Oct 2024 17:32:44 +0200 Subject: [PATCH 07/35] Upgrade Proxy and Multisig pallets to Benchmarking V2 (#6018) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sub-task of PR https://github.com/paritytech/polkadot-sdk/pull/5995 ## Integration These changes should **not** require any integration effort. --------- Co-authored-by: Dónal Murray Co-authored-by: Shawn Tabrizi --- substrate/frame/multisig/src/benchmarking.rs | 123 +++++++------ substrate/frame/proxy/src/benchmarking.rs | 179 ++++++++++++------- 2 files changed, 186 insertions(+), 116 deletions(-) diff --git a/substrate/frame/multisig/src/benchmarking.rs b/substrate/frame/multisig/src/benchmarking.rs index 6e71a89c7a89..88f9b16689d5 100644 --- a/substrate/frame/multisig/src/benchmarking.rs +++ b/substrate/frame/multisig/src/benchmarking.rs @@ -20,8 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -#[allow(deprecated)] -use frame::benchmarking::v1::*; +use frame::benchmarking::prelude::*; use crate::Pallet as Multisig; @@ -46,10 +45,13 @@ fn setup_multi( Ok((signatories, Box::new(call))) } -benchmarks! { - as_multi_threshold_1 { - // Transaction Length - let z in 0 .. 10_000; +#[benchmarks] +mod benchmarks { + use super::*; + + // `z`: Transaction Length + #[benchmark] + fn as_multi_threshold_1(z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let max_signatories = T::MaxSignatories::get().into(); let (mut signatories, _) = setup_multi::(max_signatories, z)?; let call: ::RuntimeCall = frame_system::Call::::remark { @@ -61,16 +63,18 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); - }: _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call)) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call)); + // If the benchmark resolves, then the call was dispatched successfully. + Ok(()) } - as_multi_create { - // Signatories, need at least 2 total people - let s in 2 .. T::MaxSignatories::get(); - // Transaction Length - let z in 0 .. 10_000; + // `z`: Transaction Length + // `s`: Signatories, need at least 2 people + #[benchmark] + fn as_multi_create(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -78,16 +82,19 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); - }: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, Weight::zero()) - verify { + + #[extrinsic_call] + as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, Weight::zero()); + assert!(Multisigs::::contains_key(multi_account_id, call_hash)); + + Ok(()) } - as_multi_approve { - // Signatories, need at least 3 people (so we don't complete the multisig) - let s in 3 .. T::MaxSignatories::get(); - // Transaction Length - let z in 0 .. 10_000; + // `z`: Transaction Length + // `s`: Signatories, need at least 3 people (so we don't complete the multisig) + #[benchmark] + fn as_multi_approve(s: Linear<3, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -101,17 +108,20 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); add_to_whitelist(caller_key.into()); - }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::zero()) - verify { + + #[extrinsic_call] + as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::zero()); + let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; assert_eq!(multisig.approvals.len(), 2); + + Ok(()) } - as_multi_complete { - // Signatories, need at least 2 people - let s in 2 .. T::MaxSignatories::get(); - // Transaction Length - let z in 0 .. 10_000; + // `z`: Transaction Length + // `s`: Signatories, need at least 2 people + #[benchmark] + fn as_multi_complete(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -133,16 +143,19 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); add_to_whitelist(caller_key.into()); - }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::MAX) - verify { + + #[extrinsic_call] + as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::MAX); + assert!(!Multisigs::::contains_key(&multi_account_id, call_hash)); + + Ok(()) } - approve_as_multi_create { - // Signatories, need at least 2 people - let s in 2 .. T::MaxSignatories::get(); - // Transaction Length, not a component - let z = 10_000; + // `z`: Transaction Length, not a component + // `s`: Signatories, need at least 2 people + #[benchmark] + fn approve_as_multi_create(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; @@ -150,17 +163,20 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); + // Create the multi - }: approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, Weight::zero()) - verify { + #[extrinsic_call] + approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, Weight::zero()); + assert!(Multisigs::::contains_key(multi_account_id, call_hash)); + + Ok(()) } - approve_as_multi_approve { - // Signatories, need at least 2 people - let s in 2 .. T::MaxSignatories::get(); - // Transaction Length, not a component - let z = 10_000; + // `z`: Transaction Length, not a component + // `s`: Signatories, need at least 2 people + #[benchmark] + fn approve_as_multi_approve(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let mut signatories2 = signatories.clone(); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -181,17 +197,20 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); add_to_whitelist(caller_key.into()); - }: approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, Weight::zero()) - verify { + + #[extrinsic_call] + approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, Weight::zero()); + let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; assert_eq!(multisig.approvals.len(), 2); + + Ok(()) } - cancel_as_multi { - // Signatories, need at least 2 people - let s in 2 .. T::MaxSignatories::get(); - // Transaction Length, not a component - let z = 10_000; + // `z`: Transaction Length, not a component + // `s`: Signatories, need at least 2 people + #[benchmark] + fn cancel_as_multi(s: Linear<2, { T::MaxSignatories::get() } >, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; @@ -204,9 +223,13 @@ benchmarks! { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); - }: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash); + assert!(!Multisigs::::contains_key(multi_account_id, call_hash)); + + Ok(()) } impl_benchmark_test_suite!(Multisig, crate::tests::new_test_ext(), crate::tests::Test); diff --git a/substrate/frame/proxy/src/benchmarking.rs b/substrate/frame/proxy/src/benchmarking.rs index 534019209a3e..4e4501b44c1e 100644 --- a/substrate/frame/proxy/src/benchmarking.rs +++ b/substrate/frame/proxy/src/benchmarking.rs @@ -22,8 +22,7 @@ use super::*; use crate::Pallet as Proxy; use alloc::{boxed::Box, vec}; -#[allow(deprecated)] -use frame::benchmarking::v1::*; +use frame::benchmarking::prelude::*; const SEED: u32 = 0; @@ -79,9 +78,13 @@ fn add_announcements( Ok(()) } -benchmarks! { - proxy { - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); @@ -89,14 +92,19 @@ benchmarks! { let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); - }: _(RawOrigin::Signed(caller), real_lookup, Some(T::ProxyType::default()), Box::new(call)) - verify { - assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()) + + #[extrinsic_call] + _(RawOrigin::Signed(caller), real_lookup, Some(T::ProxyType::default()), Box::new(call)); + + assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()); + + Ok(()) } + - proxy_announced { - let a in 0 .. T::MaxPending::get() - 1; - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn proxy_announced(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("pure", 0, SEED); let delegate: T::AccountId = account("target", p - 1, SEED); @@ -112,14 +120,18 @@ benchmarks! { T::CallHasher::hash_of(&call), )?; add_announcements::(a, Some(delegate.clone()), None)?; - }: _(RawOrigin::Signed(caller), delegate_lookup, real_lookup, Some(T::ProxyType::default()), Box::new(call)) - verify { - assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()) - } + + #[extrinsic_call] + _(RawOrigin::Signed(caller), delegate_lookup, real_lookup, Some(T::ProxyType::default()), Box::new(call)); + + assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()); - remove_announcement { - let a in 0 .. T::MaxPending::get() - 1; - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + Ok(()) + } + + #[benchmark] + fn remove_announcement(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); @@ -133,15 +145,19 @@ benchmarks! { T::CallHasher::hash_of(&call), )?; add_announcements::(a, Some(caller.clone()), None)?; - }: _(RawOrigin::Signed(caller.clone()), real_lookup, T::CallHasher::hash_of(&call)) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), real_lookup, T::CallHasher::hash_of(&call)); + let (announcements, _) = Announcements::::get(&caller); assert_eq!(announcements.len() as u32, a); + + Ok(()) } - reject_announcement { - let a in 0 .. T::MaxPending::get() - 1; - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn reject_announcement(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); let caller_lookup = T::Lookup::unlookup(caller.clone()); @@ -156,15 +172,19 @@ benchmarks! { T::CallHasher::hash_of(&call), )?; add_announcements::(a, Some(caller.clone()), None)?; - }: _(RawOrigin::Signed(real), caller_lookup, T::CallHasher::hash_of(&call)) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(real), caller_lookup, T::CallHasher::hash_of(&call)); + let (announcements, _) = Announcements::::get(&caller); assert_eq!(announcements.len() as u32, a); + + Ok(()) } - announce { - let a in 0 .. T::MaxPending::get() - 1; - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn announce(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); @@ -174,60 +194,82 @@ benchmarks! { add_announcements::(a, Some(caller.clone()), None)?; let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); let call_hash = T::CallHasher::hash_of(&call); - }: _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash); + assert_last_event::(Event::Announced { real, proxy: caller, call_hash }.into()); + + Ok(()) } - add_proxy { - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn add_proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); let real = T::Lookup::unlookup(account("target", T::MaxProxies::get(), SEED)); - }: _( - RawOrigin::Signed(caller.clone()), - real, - T::ProxyType::default(), - BlockNumberFor::::zero() - ) - verify { + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + real, + T::ProxyType::default(), + BlockNumberFor::::zero() + ); + let (proxies, _) = Proxies::::get(caller); assert_eq!(proxies.len() as u32, p + 1); + + Ok(()) } - remove_proxy { - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn remove_proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); let delegate = T::Lookup::unlookup(account("target", 0, SEED)); - }: _( - RawOrigin::Signed(caller.clone()), - delegate, - T::ProxyType::default(), - BlockNumberFor::::zero() - ) - verify { + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + delegate, + T::ProxyType::default(), + BlockNumberFor::::zero() + ); + let (proxies, _) = Proxies::::get(caller); assert_eq!(proxies.len() as u32, p - 1); + + Ok(()) } - remove_proxies { - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn remove_proxies(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller.clone())) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + let (proxies, _) = Proxies::::get(caller); assert_eq!(proxies.len() as u32, 0); + + Ok(()) } - create_pure { - let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; + #[benchmark] + fn create_pure(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); - }: _( - RawOrigin::Signed(caller.clone()), - T::ProxyType::default(), - BlockNumberFor::::zero(), - 0 - ) - verify { + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + T::ProxyType::default(), + BlockNumberFor::::zero(), + 0 + ); + let pure_account = Pallet::::pure_account(&caller, &T::ProxyType::default(), 0, None); assert_last_event::(Event::PureCreated { pure: pure_account, @@ -235,11 +277,12 @@ benchmarks! { proxy_type: T::ProxyType::default(), disambiguation_index: 0, }.into()); - } - kill_pure { - let p in 0 .. (T::MaxProxies::get() - 2); + Ok(()) + } + #[benchmark] + fn kill_pure(p: Linear<0, { T::MaxProxies::get() - 2 }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -255,9 +298,13 @@ benchmarks! { add_proxies::(p, Some(pure_account.clone()))?; ensure!(Proxies::::contains_key(&pure_account), "pure proxy not created"); - }: _(RawOrigin::Signed(pure_account.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(pure_account.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index); + assert!(!Proxies::::contains_key(&pure_account)); + + Ok(()) } impl_benchmark_test_suite!(Proxy, crate::tests::new_test_ext(), crate::tests::Test); From ff36c5378a7e3eb0e12726ad06af6b94f451baff Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 15 Oct 2024 18:12:40 +0100 Subject: [PATCH 08/35] cleanup --- .../frame/democracy/src/migrations/v1.rs | 8 +- substrate/frame/multisig/src/benchmarking.rs | 118 ++++++++++++++---- substrate/frame/multisig/src/lib.rs | 3 +- substrate/frame/proxy/src/benchmarking.rs | 92 +++++++++----- substrate/frame/src/lib.rs | 12 +- substrate/frame/system/src/lib.rs | 3 - 6 files changed, 170 insertions(+), 66 deletions(-) diff --git a/substrate/frame/democracy/src/migrations/v1.rs b/substrate/frame/democracy/src/migrations/v1.rs index 47f8df017f1e..8783a2ac1c94 100644 --- a/substrate/frame/democracy/src/migrations/v1.rs +++ b/substrate/frame/democracy/src/migrations/v1.rs @@ -18,7 +18,13 @@ //! Storage migrations for the preimage pallet. use crate::*; -use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade, BoundedVec}; +use frame_support::{ + // We cannot use the `pallet_prelude` here as the item `Bounded` will become ambiguous. + pallet_prelude::{StorageVersion, ValueQuery}, + storage_alias, + traits::OnRuntimeUpgrade, + BoundedVec, +}; use frame_system::pallet_prelude::BlockNumberFor; use sp_core::H256; diff --git a/substrate/frame/multisig/src/benchmarking.rs b/substrate/frame/multisig/src/benchmarking.rs index 88f9b16689d5..45bf95a75b5d 100644 --- a/substrate/frame/multisig/src/benchmarking.rs +++ b/substrate/frame/multisig/src/benchmarking.rs @@ -54,16 +54,15 @@ mod benchmarks { fn as_multi_threshold_1(z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let max_signatories = T::MaxSignatories::get().into(); let (mut signatories, _) = setup_multi::(max_signatories, z)?; - let call: ::RuntimeCall = frame_system::Call::::remark { - remark: vec![0; z as usize] - }.into(); + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![0; z as usize] }.into(); let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, 1); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); - + #[extrinsic_call] _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call)); @@ -74,7 +73,10 @@ mod benchmarks { // `z`: Transaction Length // `s`: Signatories, need at least 2 people #[benchmark] - fn as_multi_create(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn as_multi_create( + s: Linear<2, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -94,7 +96,10 @@ mod benchmarks { // `z`: Transaction Length // `s`: Signatories, need at least 3 people (so we don't complete the multisig) #[benchmark] - fn as_multi_approve(s: Linear<3, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn as_multi_approve( + s: Linear<3, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -103,16 +108,31 @@ mod benchmarks { // before the call, get the timepoint let timepoint = Multisig::::timepoint(); // Create the multi - Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), Weight::zero())?; + Multisig::::as_multi( + RawOrigin::Signed(caller).into(), + s as u16, + signatories, + None, + call.clone(), + Weight::zero(), + )?; let caller2 = signatories2.remove(0); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); add_to_whitelist(caller_key.into()); - + #[extrinsic_call] - as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::zero()); + as_multi( + RawOrigin::Signed(caller2), + s as u16, + signatories2, + Some(timepoint), + call, + Weight::zero(), + ); - let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; + let multisig = + Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; assert_eq!(multisig.approvals.len(), 2); Ok(()) @@ -121,7 +141,10 @@ mod benchmarks { // `z`: Transaction Length // `s`: Signatories, need at least 2 people #[benchmark] - fn as_multi_complete(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn as_multi_complete( + s: Linear<2, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -130,22 +153,43 @@ mod benchmarks { // before the call, get the timepoint let timepoint = Multisig::::timepoint(); // Create the multi - Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), Weight::zero())?; + Multisig::::as_multi( + RawOrigin::Signed(caller).into(), + s as u16, + signatories, + None, + call.clone(), + Weight::zero(), + )?; // Everyone except the first person approves - for i in 1 .. s - 1 { + for i in 1..s - 1 { let mut signatories_loop = signatories2.clone(); let caller_loop = signatories_loop.remove(i as usize); let o = RawOrigin::Signed(caller_loop).into(); - Multisig::::as_multi(o, s as u16, signatories_loop, Some(timepoint), call.clone(), Weight::zero())?; + Multisig::::as_multi( + o, + s as u16, + signatories_loop, + Some(timepoint), + call.clone(), + Weight::zero(), + )?; } let caller2 = signatories2.remove(0); assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller2); add_to_whitelist(caller_key.into()); - + #[extrinsic_call] - as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, Weight::MAX); + as_multi( + RawOrigin::Signed(caller2), + s as u16, + signatories2, + Some(timepoint), + call, + Weight::MAX, + ); assert!(!Multisigs::::contains_key(&multi_account_id, call_hash)); @@ -155,7 +199,10 @@ mod benchmarks { // `z`: Transaction Length, not a component // `s`: Signatories, need at least 2 people #[benchmark] - fn approve_as_multi_create(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn approve_as_multi_create( + s: Linear<2, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; @@ -163,10 +210,17 @@ mod benchmarks { // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); add_to_whitelist(caller_key.into()); - + // Create the multi #[extrinsic_call] - approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, Weight::zero()); + approve_as_multi( + RawOrigin::Signed(caller), + s as u16, + signatories, + None, + call_hash, + Weight::zero(), + ); assert!(Multisigs::::contains_key(multi_account_id, call_hash)); @@ -176,7 +230,10 @@ mod benchmarks { // `z`: Transaction Length, not a component // `s`: Signatories, need at least 2 people #[benchmark] - fn approve_as_multi_approve(s: Linear<2, { T::MaxSignatories::get() }>, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn approve_as_multi_approve( + s: Linear<2, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let mut signatories2 = signatories.clone(); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -191,7 +248,7 @@ mod benchmarks { signatories, None, call, - Weight::zero() + Weight::zero(), )?; let caller2 = signatories2.remove(0); // Whitelist caller account from further DB operations. @@ -199,9 +256,17 @@ mod benchmarks { add_to_whitelist(caller_key.into()); #[extrinsic_call] - approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, Weight::zero()); - - let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; + approve_as_multi( + RawOrigin::Signed(caller2), + s as u16, + signatories2, + Some(timepoint), + call_hash, + Weight::zero(), + ); + + let multisig = + Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; assert_eq!(multisig.approvals.len(), 2); Ok(()) @@ -210,7 +275,10 @@ mod benchmarks { // `z`: Transaction Length, not a component // `s`: Signatories, need at least 2 people #[benchmark] - fn cancel_as_multi(s: Linear<2, { T::MaxSignatories::get() } >, z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { + fn cancel_as_multi( + s: Linear<2, { T::MaxSignatories::get() }>, + z: Linear<0, 10_000>, + ) -> Result<(), BenchmarkError> { let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; diff --git a/substrate/frame/multisig/src/lib.rs b/substrate/frame/multisig/src/lib.rs index 8f3c1ebe5830..53f5f77f705d 100644 --- a/substrate/frame/multisig/src/lib.rs +++ b/substrate/frame/multisig/src/lib.rs @@ -54,7 +54,8 @@ use frame::{ prelude::*, traits::{Currency, ReservableCurrency}, }; -use weights::WeightInfo; +use frame_system::RawOrigin; +pub use weights::WeightInfo; /// Re-export all pallet items. pub use pallet::*; diff --git a/substrate/frame/proxy/src/benchmarking.rs b/substrate/frame/proxy/src/benchmarking.rs index 4e4501b44c1e..eebb506bf374 100644 --- a/substrate/frame/proxy/src/benchmarking.rs +++ b/substrate/frame/proxy/src/benchmarking.rs @@ -91,8 +91,9 @@ mod benchmarks { // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); - + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![] }.into(); + #[extrinsic_call] _(RawOrigin::Signed(caller), real_lookup, Some(T::ProxyType::default()), Box::new(call)); @@ -100,10 +101,12 @@ mod benchmarks { Ok(()) } - #[benchmark] - fn proxy_announced(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + fn proxy_announced( + a: Linear<0, { T::MaxPending::get() - 1 }>, + p: Linear<1, { T::MaxProxies::get() - 1 }>, + ) -> Result<(), BenchmarkError> { add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("pure", 0, SEED); @@ -113,24 +116,34 @@ mod benchmarks { // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![] }.into(); Proxy::::announce( RawOrigin::Signed(delegate.clone()).into(), real_lookup.clone(), T::CallHasher::hash_of(&call), )?; add_announcements::(a, Some(delegate.clone()), None)?; - + #[extrinsic_call] - _(RawOrigin::Signed(caller), delegate_lookup, real_lookup, Some(T::ProxyType::default()), Box::new(call)); - + _( + RawOrigin::Signed(caller), + delegate_lookup, + real_lookup, + Some(T::ProxyType::default()), + Box::new(call), + ); + assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()); Ok(()) } - + #[benchmark] - fn remove_announcement(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + fn remove_announcement( + a: Linear<0, { T::MaxPending::get() - 1 }>, + p: Linear<1, { T::MaxProxies::get() - 1 }>, + ) -> Result<(), BenchmarkError> { add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); @@ -138,7 +151,8 @@ mod benchmarks { // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![] }.into(); Proxy::::announce( RawOrigin::Signed(caller.clone()).into(), real_lookup.clone(), @@ -156,7 +170,10 @@ mod benchmarks { } #[benchmark] - fn reject_announcement(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + fn reject_announcement( + a: Linear<0, { T::MaxPending::get() - 1 }>, + p: Linear<1, { T::MaxProxies::get() - 1 }>, + ) -> Result<(), BenchmarkError> { add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); @@ -165,14 +182,15 @@ mod benchmarks { // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real.clone()); - let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![] }.into(); Proxy::::announce( RawOrigin::Signed(caller.clone()).into(), real_lookup, T::CallHasher::hash_of(&call), )?; add_announcements::(a, Some(caller.clone()), None)?; - + #[extrinsic_call] _(RawOrigin::Signed(real), caller_lookup, T::CallHasher::hash_of(&call)); @@ -183,7 +201,10 @@ mod benchmarks { } #[benchmark] - fn announce(a: Linear<0, { T::MaxPending::get() - 1 }>, p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { + fn announce( + a: Linear<0, { T::MaxPending::get() - 1 }>, + p: Linear<1, { T::MaxProxies::get() - 1 }>, + ) -> Result<(), BenchmarkError> { add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); @@ -192,9 +213,10 @@ mod benchmarks { let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real.clone()); add_announcements::(a, Some(caller.clone()), None)?; - let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + let call: ::RuntimeCall = + frame_system::Call::::remark { remark: vec![] }.into(); let call_hash = T::CallHasher::hash_of(&call); - + #[extrinsic_call] _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash); @@ -208,13 +230,13 @@ mod benchmarks { add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); let real = T::Lookup::unlookup(account("target", T::MaxProxies::get(), SEED)); - + #[extrinsic_call] _( RawOrigin::Signed(caller.clone()), real, T::ProxyType::default(), - BlockNumberFor::::zero() + BlockNumberFor::::zero(), ); let (proxies, _) = Proxies::::get(caller); @@ -228,13 +250,13 @@ mod benchmarks { add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); let delegate = T::Lookup::unlookup(account("target", 0, SEED)); - + #[extrinsic_call] _( RawOrigin::Signed(caller.clone()), delegate, T::ProxyType::default(), - BlockNumberFor::::zero() + BlockNumberFor::::zero(), ); let (proxies, _) = Proxies::::get(caller); @@ -267,16 +289,19 @@ mod benchmarks { RawOrigin::Signed(caller.clone()), T::ProxyType::default(), BlockNumberFor::::zero(), - 0 + 0, ); let pure_account = Pallet::::pure_account(&caller, &T::ProxyType::default(), 0, None); - assert_last_event::(Event::PureCreated { - pure: pure_account, - who: caller, - proxy_type: T::ProxyType::default(), - disambiguation_index: 0, - }.into()); + assert_last_event::( + Event::PureCreated { + pure: pure_account, + who: caller, + proxy_type: T::ProxyType::default(), + disambiguation_index: 0, + } + .into(), + ); Ok(()) } @@ -290,7 +315,7 @@ mod benchmarks { RawOrigin::Signed(whitelisted_caller()).into(), T::ProxyType::default(), BlockNumberFor::::zero(), - 0 + 0, )?; let height = frame_system::Pallet::::block_number(); let ext_index = frame_system::Pallet::::extrinsic_index().unwrap_or(0); @@ -300,7 +325,14 @@ mod benchmarks { ensure!(Proxies::::contains_key(&pure_account), "pure proxy not created"); #[extrinsic_call] - _(RawOrigin::Signed(pure_account.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index); + _( + RawOrigin::Signed(pure_account.clone()), + caller_lookup, + T::ProxyType::default(), + 0, + height, + ext_index, + ); assert!(!Proxies::::contains_key(&pure_account)); diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 52d16f2f48cb..2d48d9600350 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -74,12 +74,9 @@ //! } //! ``` //! -//! See: . -//! //! If not in preludes, one can look into the domain-specific modules. Finally, if an import is //! still not feasible, one can look into [`deps`]. //! -//! //! ## Naming //! //! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. This is due @@ -218,8 +215,11 @@ pub mod try_runtime { pub mod benchmarking { mod shared { pub use frame_benchmarking::{add_benchmark, v1::account, whitelist, whitelisted_caller}; - // all benchmarking host functions. + //. all benchmarking host functions. pub use frame_benchmarking::benchmarking::*; + // The system origin, which is very often needed in benchmarking code. Might be tricky only + // if the pallet defines its own `#[pallet::origin]` and call it `RawOrigin`. + pub use frame_system::RawOrigin; } #[deprecated(note = "use the syntax in `frame::benchmarking::v2`")] @@ -524,6 +524,8 @@ pub mod deps { #[cfg(feature = "runtime")] pub use sp_consensus_grandpa; #[cfg(feature = "runtime")] + pub use sp_genesis_builder; + #[cfg(feature = "runtime")] pub use sp_inherents; #[cfg(feature = "runtime")] pub use sp_offchain; @@ -531,8 +533,6 @@ pub mod deps { pub use sp_storage; #[cfg(feature = "runtime")] pub use sp_version; - #[cfg(feature = "runtime")] - pub use sp_genesis_builder; #[cfg(feature = "runtime-benchmarks")] pub use frame_benchmarking; diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 282330e04e3e..a5c5f1ed2e47 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -2267,9 +2267,6 @@ impl Lookup for ChainContext { pub mod pallet_prelude { pub use crate::{ensure_none, ensure_root, ensure_signed, ensure_signed_or_root}; - #[doc(inline)] - pub use super::RawOrigin; - /// Type alias for the `Origin` associated type of system config. pub type OriginFor = ::RuntimeOrigin; From 2d8323f40eb51f81fb66c6a0e969454b16514b37 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 15 Oct 2024 18:13:02 +0100 Subject: [PATCH 09/35] possibly how CI will look like --- .github/scripts/cmd/cmd.py | 20 +-- .../frame-umbrella-weight-template.hbs | 120 ++++++++++++++++++ 2 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 substrate/.maintain/frame-umbrella-weight-template.hbs diff --git a/.github/scripts/cmd/cmd.py b/.github/scripts/cmd/cmd.py index 01f36ea375c5..652fed7232fd 100755 --- a/.github/scripts/cmd/cmd.py +++ b/.github/scripts/cmd/cmd.py @@ -29,20 +29,20 @@ subparsers = parser.add_subparsers(help='a command to run', dest='command') """ -BENCH +BENCH """ bench_example = '''**Examples**: - Runs all benchmarks + Runs all benchmarks %(prog)s Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions %(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet - + Runs bench for all pallets for westend runtime and continues even if some benchmarks fail %(prog)s --runtime westend --continue-on-fail - - Does not output anything and cleans up the previous bot's & author command triggering comments in PR + + Does not output anything and cleans up the previous bot's & author command triggering comments in PR %(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean ''' @@ -55,14 +55,14 @@ parser_bench.add_argument('--pallet', help='Pallet(s) space separated', nargs='*', default=[]) """ -FMT +FMT """ parser_fmt = subparsers.add_parser('fmt', help='Formats code (cargo +nightly-VERSION fmt) and configs (taplo format)') for arg, config in common_args.items(): parser_fmt.add_argument(arg, **config) """ -Update UI +Update UI """ parser_ui = subparsers.add_parser('update-ui', help='Updates UI tests') for arg, config in common_args.items(): @@ -161,7 +161,9 @@ def main(): print(f'-- package_dir: {package_dir}') print(f'-- manifest_path: {manifest_path}') output_path = os.path.join(package_dir, "src", "weights.rs") - template = config['template'] + # TODO: we can remove once all pallets in dev runtime are migrated to polkadot-sdk-frame + uses_polkadot_sdk_frame = "true" in os.popen(f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \"{pallet.replace('_', '-')}\") | .dependencies | any(.name == \"polkadot-sdk-frame\")'").read() + template = config['template'] if not uses_polkadot_sdk_frame else "substrate/.maintain/frame-umbrella-weight-template.hbs" else: default_path = f"./{config['path']}/src/weights" xcm_path = f"./{config['path']}/src/weights/xcm" @@ -236,4 +238,4 @@ def main(): print('🚀 Done') if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/substrate/.maintain/frame-umbrella-weight-template.hbs b/substrate/.maintain/frame-umbrella-weight-template.hbs new file mode 100644 index 000000000000..0f26fae1d8f1 --- /dev/null +++ b/substrate/.maintain/frame-umbrella-weight-template.hbs @@ -0,0 +1,120 @@ +{{header}} +//! Autogenerated weights for `{{pallet}}` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` +//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: `{{cmd.db_cache}}` + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame::weights_prelude::*; + +/// Weight functions needed for `{{pallet}}`. +pub trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weights for `{{pallet}}` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +{{#if (eq pallet "frame_system")}} +impl WeightInfo for SubstrateWeight { +{{else}} +impl WeightInfo for SubstrateWeight { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +} From 49a4cc392aef0a5e2bb5f04b39b4fb17399cf9dd Mon Sep 17 00:00:00 2001 From: giuseppere Date: Mon, 21 Oct 2024 16:47:20 +0200 Subject: [PATCH 10/35] run_all_benchmarks.sh: format + use umbrella template when possible --- substrate/scripts/run_all_benchmarks.sh | 109 +++++++++++++----------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/substrate/scripts/run_all_benchmarks.sh b/substrate/scripts/run_all_benchmarks.sh index 6dd7cede319f..209b60530f5a 100755 --- a/substrate/scripts/run_all_benchmarks.sh +++ b/substrate/scripts/run_all_benchmarks.sh @@ -25,39 +25,37 @@ while getopts 'bfp:v' flag; do case "${flag}" in - b) - # Skip build. - skip_build='true' - ;; - f) - # Fail if any sub-command in a pipe fails, not just the last one. - set -o pipefail - # Fail on undeclared variables. - set -u - # Fail if any sub-command fails. - set -e - # Fail on traps. - set -E - ;; - p) - # Start at pallet - start_pallet="${OPTARG}" - ;; - v) - # Echo all executed commands. - set -x - ;; - *) - # Exit early. - echo "Bad options. Check Script." - exit 1 - ;; + b) + # Skip build. + skip_build='true' + ;; + f) + # Fail if any sub-command in a pipe fails, not just the last one. + set -o pipefail + # Fail on undeclared variables. + set -u + # Fail if any sub-command fails. + set -e + # Fail on traps. + set -E + ;; + p) + # Start at pallet + start_pallet="${OPTARG}" + ;; + v) + # Echo all executed commands. + set -x + ;; + *) + # Exit early. + echo "Bad options. Check Script." + exit 1 + ;; esac done - -if [ "$skip_build" != true ] -then +if [ "$skip_build" != true ]; then echo "[+] Compiling Substrate benchmarks..." cargo build --profile=production --locked --features=runtime-benchmarks --bin substrate-node fi @@ -97,33 +95,40 @@ rm -f $ERR_FILE # Benchmark each pallet. for PALLET in "${PALLETS[@]}"; do # If `-p` is used, skip benchmarks until the start pallet. - if [ ! -z "$start_pallet" ] && [ "$start_pallet" != "$PALLET" ] - then + if [ ! -z "$start_pallet" ] && [ "$start_pallet" != "$PALLET" ]; then echo "[+] Skipping ${PALLET}..." continue else unset start_pallet fi - FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')"; + FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')" WEIGHT_FILE="./frame/${FOLDER}/src/weights.rs" - echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE"; + + TEMPLATE_FILE_NAME="frame-weight-template.hbs" + if [ $(cargo metadata --locked --format-version 1 --no-deps | jq --arg pallet "${PALLET//_/-}" -r '.packages[] | select(.name == $pallet) | .dependencies | any(.name == "polkadot-sdk-frame")') = true ]; then + TEMPLATE_FILE_NAME="frame-umbrella-weight-template.hbs" + fi + TEMPLATE_FILE="./.maintain/${TEMPLATE_FILE_NAME}" + + echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE" + echo "$TEMPLATE_FILE" OUTPUT=$( $SUBSTRATE benchmark pallet \ - --chain=dev \ - --steps=50 \ - --repeat=20 \ - --pallet="$PALLET" \ - --extrinsic="*" \ - --wasm-execution=compiled \ - --heap-pages=4096 \ - --output="$WEIGHT_FILE" \ - --header="./HEADER-APACHE2" \ - --template=./.maintain/frame-weight-template.hbs 2>&1 + --chain=dev \ + --steps=50 \ + --repeat=20 \ + --pallet="$PALLET" \ + --extrinsic="*" \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output="$WEIGHT_FILE" \ + --header="./HEADER-APACHE2" \ + --template="$TEMPLATE_FILE" 2>&1 ) if [ $? -ne 0 ]; then - echo "$OUTPUT" >> "$ERR_FILE" + echo "$OUTPUT" >>"$ERR_FILE" echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..." fi done @@ -132,15 +137,15 @@ done echo "[+] Benchmarking block and extrinsic overheads..." OUTPUT=$( $SUBSTRATE benchmark overhead \ - --chain=dev \ - --wasm-execution=compiled \ - --weight-path="./frame/support/src/weights/" \ - --header="./HEADER-APACHE2" \ - --warmup=10 \ - --repeat=100 2>&1 + --chain=dev \ + --wasm-execution=compiled \ + --weight-path="./frame/support/src/weights/" \ + --header="./HEADER-APACHE2" \ + --warmup=10 \ + --repeat=100 2>&1 ) if [ $? -ne 0 ]; then - echo "$OUTPUT" >> "$ERR_FILE" + echo "$OUTPUT" >>"$ERR_FILE" echo "[-] Failed to benchmark the block and extrinsic overheads. Error written to $ERR_FILE; continuing..." fi From 556e8eabd463752ec292490268b648ba2e8fec77 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Mon, 21 Oct 2024 18:07:37 +0200 Subject: [PATCH 11/35] fix Issue #6160 --- substrate/scripts/run_all_benchmarks.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/substrate/scripts/run_all_benchmarks.sh b/substrate/scripts/run_all_benchmarks.sh index 8c05c50e3956..3856f8935321 100755 --- a/substrate/scripts/run_all_benchmarks.sh +++ b/substrate/scripts/run_all_benchmarks.sh @@ -112,18 +112,17 @@ for PALLET in "${PALLETS[@]}"; do TEMPLATE_FILE="./.maintain/${TEMPLATE_FILE_NAME}" # Special handling of custom weight paths. - if [ "$PALLET" == "frame_system_extensions" ] || [ "$PALLET" == "frame-system-extensions" ] - then + if [ "$PALLET" == "frame_system_extensions" ] || [ "$PALLET" == "frame-system-extensions" ]; then WEIGHT_FILE="./frame/system/src/extensions/weights.rs" - elif [ "$PALLET" == "pallet_asset_conversion_tx_payment" ] || [ "$PALLET" == "pallet-asset-conversion-tx-payment" ] - then + elif [ "$PALLET" == "pallet_asset_conversion_tx_payment" ] || [ "$PALLET" == "pallet-asset-conversion-tx-payment" ]; then WEIGHT_FILE="./frame/transaction-payment/asset-conversion-tx-payment/src/weights.rs" - elif [ "$PALLET" == "pallet_asset_tx_payment" ] || [ "$PALLET" == "pallet-asset-tx-payment" ] - then + elif [ "$PALLET" == "pallet_asset_tx_payment" ] || [ "$PALLET" == "pallet-asset-tx-payment" ]; then WEIGHT_FILE="./frame/transaction-payment/asset-tx-payment/src/weights.rs" + elif [ "$PALLET" == "pallet_asset_conversion_ops" ] || [ "$PALLET" == "pallet-asset-conversion-ops" ]; then + WEIGHT_FILE="./frame/asset-conversion/ops/src/weights.rs" fi - echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE"; + echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE" OUTPUT=$( $SUBSTRATE benchmark pallet \ From a6dfbed145d1373c2bfa9bb749c3aad03cd18f2e Mon Sep 17 00:00:00 2001 From: giuseppere Date: Mon, 21 Oct 2024 18:16:03 +0200 Subject: [PATCH 12/35] remove unused code in multisig/benchmarking --- substrate/frame/multisig/src/benchmarking.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrate/frame/multisig/src/benchmarking.rs b/substrate/frame/multisig/src/benchmarking.rs index 45bf95a75b5d..82f5a829553a 100644 --- a/substrate/frame/multisig/src/benchmarking.rs +++ b/substrate/frame/multisig/src/benchmarking.rs @@ -56,8 +56,6 @@ mod benchmarks { let (mut signatories, _) = setup_multi::(max_signatories, z)?; let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![0; z as usize] }.into(); - let call_hash = call.using_encoded(blake2_256); - let multi_account_id = Multisig::::multi_account_id(&signatories, 1); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); From 645f2f437e6b3913a7c7988b600cbaa719b74e3d Mon Sep 17 00:00:00 2001 From: giuseppere Date: Tue, 22 Oct 2024 11:42:04 +0200 Subject: [PATCH 13/35] fix `cmd.py` to use umbrella weights template only in `frame` --- .github/scripts/cmd/cmd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/scripts/cmd/cmd.py b/.github/scripts/cmd/cmd.py index 774181454811..51c44450e793 100755 --- a/.github/scripts/cmd/cmd.py +++ b/.github/scripts/cmd/cmd.py @@ -6,6 +6,7 @@ import argparse import _help import importlib.util +import re _HelpAction = _help._HelpAction @@ -177,7 +178,9 @@ def main(): output_path = os.path.join(package_dir, "src", "weights.rs") # TODO: we can remove once all pallets in dev runtime are migrated to polkadot-sdk-frame uses_polkadot_sdk_frame = "true" in os.popen(f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \"{pallet.replace('_', '-')}\") | .dependencies | any(.name == \"polkadot-sdk-frame\")'").read() - template = config['template'] if not uses_polkadot_sdk_frame else "substrate/.maintain/frame-umbrella-weight-template.hbs" + template = config['template'] + if uses_polkadot_sdk_frame and re.match(r"frame-(:?umbrella-)?weight-template\.hbs", os.path.normpath(template).split(os.path.sep)[-1]): + template = "substrate/.maintain/frame-umbrella-weight-template.hbs" else: default_path = f"./{config['path']}/src/weights" xcm_path = f"./{config['path']}/src/weights/xcm" From 21cd6da9b4dfece0f6e84ce99cdad3e3b518ed0a Mon Sep 17 00:00:00 2001 From: giuseppere Date: Tue, 22 Oct 2024 13:04:20 +0200 Subject: [PATCH 14/35] fix CI: handle empty output from `os.popen` --- .github/scripts/cmd/cmd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/scripts/cmd/cmd.py b/.github/scripts/cmd/cmd.py index 51c44450e793..9da05cac17b9 100755 --- a/.github/scripts/cmd/cmd.py +++ b/.github/scripts/cmd/cmd.py @@ -177,7 +177,11 @@ def main(): print(f'-- manifest_path: {manifest_path}') output_path = os.path.join(package_dir, "src", "weights.rs") # TODO: we can remove once all pallets in dev runtime are migrated to polkadot-sdk-frame - uses_polkadot_sdk_frame = "true" in os.popen(f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \"{pallet.replace('_', '-')}\") | .dependencies | any(.name == \"polkadot-sdk-frame\")'").read() + try: + uses_polkadot_sdk_frame = "true" in os.popen(f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \"{pallet.replace('_', '-')}\") | .dependencies | any(.name == \"polkadot-sdk-frame\")'").read() + # Empty output from the previous os.popen command + except StopIteration: + uses_polkadot_sdk_frame = False template = config['template'] if uses_polkadot_sdk_frame and re.match(r"frame-(:?umbrella-)?weight-template\.hbs", os.path.normpath(template).split(os.path.sep)[-1]): template = "substrate/.maintain/frame-umbrella-weight-template.hbs" From 2c910cb410c1de3ac860993cc7c0f19342311ff0 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Tue, 22 Oct 2024 16:52:29 +0200 Subject: [PATCH 15/35] moving imports from support to umbrella crate --- substrate/frame/src/lib.rs | 15 ++++++++++++--- substrate/frame/support/src/lib.rs | 10 +++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 0211a465d797..7ec857f8dccc 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -45,7 +45,6 @@ //! use polkadot_sdk_frame as frame; //! #[frame::pallet] //! pub mod pallet { -//! # use polkadot_sdk_frame as frame; //! use frame::prelude::*; //! // ^^ using the prelude! //! @@ -121,8 +120,6 @@ //! * Preludes should be extensive. The goal of this pallet is to be ONLY used with the preludes. //! The domain-specific modules are just a backup, aiming to keep things organized. Don't hesitate //! in adding more items to the main prelude. -//! * When doing so, prefer adding the relevant item to `frame_support::pallet_prelude` and -//! `frame_system::pallet_prelude`. //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the @@ -330,9 +327,21 @@ pub mod runtime { ConstU32, ConstU64, ConstU8, }; + /// Check the value contained in an object + pub use frame_support::traits::Contains; + + /// Check if instance is sub type of a given type + pub use frame_support::traits::IsSubType; + + /// For code that must run on runtime upgrades + pub use frame_support::traits::OnRuntimeUpgrade; + /// Used for simple fee calculation. pub use frame_support::weights::{self, FixedFee, NoFee}; + /// Traits for `Dispatchable` objects that can also carry some static information + pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; + /// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`. pub use frame_system::{ EnsureNever, EnsureNone, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 86c86da1c371..31dbb2b4e0f8 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -887,10 +887,7 @@ pub mod testing_prelude { pub mod pallet_prelude { pub use crate::{ defensive, defensive_assert, - dispatch::{ - DispatchClass, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, Parameter, - Pays, PostDispatchInfo, - }, + dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays}, ensure, inherent::{InherentData, InherentIdentifier, ProvideInherent}, storage, @@ -906,9 +903,8 @@ pub mod pallet_prelude { StorageList, }, traits::{ - BuildGenesisConfig, ConstU32, Contains, EnsureOrigin, Get, GetDefault, - GetStorageVersion, Hooks, IsSubType, IsType, OnRuntimeUpgrade, PalletInfoAccess, - StorageInfoTrait, StorageVersion, Task, TypedGet, + BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, + IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, From 6e6f1ace9d4dbc26294426f25523d6f676f25b0a Mon Sep 17 00:00:00 2001 From: giuseppere Date: Tue, 22 Oct 2024 17:04:03 +0200 Subject: [PATCH 16/35] Revert "moving imports from support to umbrella crate" This reverts commit 2c910cb410c1de3ac860993cc7c0f19342311ff0. --- substrate/frame/src/lib.rs | 15 +++------------ substrate/frame/support/src/lib.rs | 10 +++++++--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 7ec857f8dccc..0211a465d797 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -45,6 +45,7 @@ //! use polkadot_sdk_frame as frame; //! #[frame::pallet] //! pub mod pallet { +//! # use polkadot_sdk_frame as frame; //! use frame::prelude::*; //! // ^^ using the prelude! //! @@ -120,6 +121,8 @@ //! * Preludes should be extensive. The goal of this pallet is to be ONLY used with the preludes. //! The domain-specific modules are just a backup, aiming to keep things organized. Don't hesitate //! in adding more items to the main prelude. +//! * When doing so, prefer adding the relevant item to `frame_support::pallet_prelude` and +//! `frame_system::pallet_prelude`. //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the @@ -327,21 +330,9 @@ pub mod runtime { ConstU32, ConstU64, ConstU8, }; - /// Check the value contained in an object - pub use frame_support::traits::Contains; - - /// Check if instance is sub type of a given type - pub use frame_support::traits::IsSubType; - - /// For code that must run on runtime upgrades - pub use frame_support::traits::OnRuntimeUpgrade; - /// Used for simple fee calculation. pub use frame_support::weights::{self, FixedFee, NoFee}; - /// Traits for `Dispatchable` objects that can also carry some static information - pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - /// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`. pub use frame_system::{ EnsureNever, EnsureNone, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 31dbb2b4e0f8..86c86da1c371 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -887,7 +887,10 @@ pub mod testing_prelude { pub mod pallet_prelude { pub use crate::{ defensive, defensive_assert, - dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays}, + dispatch::{ + DispatchClass, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, Parameter, + Pays, PostDispatchInfo, + }, ensure, inherent::{InherentData, InherentIdentifier, ProvideInherent}, storage, @@ -903,8 +906,9 @@ pub mod pallet_prelude { StorageList, }, traits::{ - BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, - IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet, + BuildGenesisConfig, ConstU32, Contains, EnsureOrigin, Get, GetDefault, + GetStorageVersion, Hooks, IsSubType, IsType, OnRuntimeUpgrade, PalletInfoAccess, + StorageInfoTrait, StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, From bd17cf205f6ddc934436eb2a3d68d63fb7e86b02 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Wed, 23 Oct 2024 14:29:08 +0200 Subject: [PATCH 17/35] undo frame support prelude edits + fix imports --- .../pallets/system/src/migration.rs | 1 + substrate/frame/nfts/src/lib.rs | 2 +- substrate/frame/nfts/src/migration.rs | 1 + substrate/frame/src/lib.rs | 16 ++++++++++++++++ substrate/frame/support/src/lib.rs | 19 ++++++------------- templates/minimal/runtime/Cargo.toml | 5 ++--- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bridges/snowbridge/pallets/system/src/migration.rs b/bridges/snowbridge/pallets/system/src/migration.rs index c1519d27fac4..ee94fc091bd1 100644 --- a/bridges/snowbridge/pallets/system/src/migration.rs +++ b/bridges/snowbridge/pallets/system/src/migration.rs @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2023 Snowfork //! Governance API for controlling the Ethereum side of the bridge use super::*; +use frame_support::traits::OnRuntimeUpgrade; use log; #[cfg(feature = "try-runtime")] diff --git a/substrate/frame/nfts/src/lib.rs b/substrate/frame/nfts/src/lib.rs index 331b9a02da5e..4e5493a3c755 100644 --- a/substrate/frame/nfts/src/lib.rs +++ b/substrate/frame/nfts/src/lib.rs @@ -58,7 +58,7 @@ use frame_support::traits::{ }; use frame_system::Config as SystemConfig; use sp_runtime::{ - traits::{IdentifyAccount, StaticLookup, Verify, Zero}, + traits::{IdentifyAccount, Saturating, StaticLookup, Verify, Zero}, RuntimeDebug, }; diff --git a/substrate/frame/nfts/src/migration.rs b/substrate/frame/nfts/src/migration.rs index 23bd8566ddcb..8f82e092262f 100644 --- a/substrate/frame/nfts/src/migration.rs +++ b/substrate/frame/nfts/src/migration.rs @@ -16,6 +16,7 @@ // limitations under the License. use super::*; +use frame_support::traits::OnRuntimeUpgrade; use log; #[cfg(feature = "try-runtime")] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 0211a465d797..ee64e9f719bd 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -184,6 +184,11 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::pallet_prelude::*; + /// Dispatch types from `frame-support`, other fundamental traits + #[doc(no_inline)] + pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; + pub use frame_support::traits::{Contains, IsSubType, OnRuntimeUpgrade}; + /// Pallet prelude of `frame-system`. #[doc(no_inline)] pub use frame_system::pallet_prelude::*; @@ -194,6 +199,17 @@ pub mod prelude { /// All hashing related things pub use super::hashing::*; + + /// Runtime traits + #[doc(no_inline)] + pub use sp_runtime::traits::{ + Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, Saturating, StaticLookup, + TrailingZeroInput, + }; + + /// Other error/result types for runtime + #[doc(no_inline)] + pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; } #[cfg(any(feature = "try-runtime", test))] diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 86c86da1c371..cc805d724857 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -887,10 +887,7 @@ pub mod testing_prelude { pub mod pallet_prelude { pub use crate::{ defensive, defensive_assert, - dispatch::{ - DispatchClass, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, Parameter, - Pays, PostDispatchInfo, - }, + dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays}, ensure, inherent::{InherentData, InherentIdentifier, ProvideInherent}, storage, @@ -906,9 +903,8 @@ pub mod pallet_prelude { StorageList, }, traits::{ - BuildGenesisConfig, ConstU32, Contains, EnsureOrigin, Get, GetDefault, - GetStorageVersion, Hooks, IsSubType, IsType, OnRuntimeUpgrade, PalletInfoAccess, - StorageInfoTrait, StorageVersion, Task, TypedGet, + BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, + IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, @@ -921,18 +917,15 @@ pub mod pallet_prelude { pub use sp_inherents::MakeFatalError; pub use sp_runtime::{ traits::{ - Bounded, CheckedAdd, CheckedConversion, CheckedDiv, CheckedMul, CheckedShl, CheckedShr, - CheckedSub, DispatchInfoOf, Dispatchable, MaybeSerializeDeserialize, Member, One, - SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, - Zero, + CheckedAdd, CheckedConversion, CheckedDiv, CheckedMul, CheckedShl, CheckedShr, + CheckedSub, MaybeSerializeDeserialize, Member, One, ValidateUnsigned, Zero, }, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag, TransactionValidity, TransactionValidityError, UnknownTransaction, ValidTransaction, }, - DispatchError, DispatchErrorWithPostInfo, DispatchResultWithInfo, RuntimeDebug, TokenError, - MAX_MODULE_ERROR_ENCODED_SIZE, + DispatchError, RuntimeDebug, MAX_MODULE_ERROR_ENCODED_SIZE, }; pub use sp_weights::Weight; } diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 54b84cca0de7..b803c74539ef 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -34,9 +34,8 @@ polkadot-sdk = { optional = true, workspace = true, features = [ default = ["std"] std = [ "codec/std", - "scale-info/std", - "serde_json/std", - "pallet-minimal-template/std", "polkadot-sdk/std", + "scale-info/std", + "serde_json/std", ] From 532ee9bd0d5031b7385058b923af087aba0b439a Mon Sep 17 00:00:00 2001 From: giuseppere Date: Wed, 23 Oct 2024 16:28:25 +0200 Subject: [PATCH 18/35] fix and fmt `Cargo.toml` files + remove duplicate import --- substrate/frame/Cargo.toml | 7 +++---- substrate/frame/multisig/Cargo.toml | 5 ++++- substrate/frame/nfts/src/benchmarking.rs | 2 +- substrate/frame/proxy/Cargo.toml | 6 +++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 9cda570177b2..5e28dede6d69 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -68,20 +68,19 @@ pallet-examples = { workspace = true } default = ["runtime", "std"] experimental = ["frame-support/experimental"] runtime = [ + "frame-executive", + "frame-system-rpc-runtime-api", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-session", "sp-storage", "sp-transaction-pool", "sp-version", - "sp-genesis-builder", - - "frame-executive", - "frame-system-rpc-runtime-api", ] std = [ "codec/std", diff --git a/substrate/frame/multisig/Cargo.toml b/substrate/frame/multisig/Cargo.toml index b0f6ad3a55ec..c96be908faef 100644 --- a/substrate/frame/multisig/Cargo.toml +++ b/substrate/frame/multisig/Cargo.toml @@ -30,12 +30,15 @@ pallet-balances = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "scale-info/std", "frame/std", + "log/std", + "scale-info/std", ] runtime-benchmarks = [ "frame/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", ] try-runtime = [ "frame/try-runtime", + "pallet-balances/try-runtime", ] diff --git a/substrate/frame/nfts/src/benchmarking.rs b/substrate/frame/nfts/src/benchmarking.rs index 9dca514c4e4f..bc81096b459d 100644 --- a/substrate/frame/nfts/src/benchmarking.rs +++ b/substrate/frame/nfts/src/benchmarking.rs @@ -30,7 +30,7 @@ use frame_support::{ BoundedVec, }; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin}; -use sp_runtime::traits::{Bounded, One, Saturating}; +use sp_runtime::traits::{Bounded, One}; use crate::Pallet as Nfts; diff --git a/substrate/frame/proxy/Cargo.toml b/substrate/frame/proxy/Cargo.toml index 4f9a3fd97f6e..8897c66419c7 100644 --- a/substrate/frame/proxy/Cargo.toml +++ b/substrate/frame/proxy/Cargo.toml @@ -28,12 +28,16 @@ pallet-utility = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "scale-info/std", "frame/std", + "scale-info/std", ] runtime-benchmarks = [ "frame/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", ] try-runtime = [ "frame/try-runtime", + "pallet-balances/try-runtime", + "pallet-utility/try-runtime", ] From d0120f23e05c6ec702fe50f00950802639c8ed97 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Wed, 23 Oct 2024 16:58:05 +0200 Subject: [PATCH 19/35] Add prdoc --- prdoc/pr_5995.prdoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 prdoc/pr_5995.prdoc diff --git a/prdoc/pr_5995.prdoc b/prdoc/pr_5995.prdoc new file mode 100644 index 000000000000..33ae10017115 --- /dev/null +++ b/prdoc/pr_5995.prdoc @@ -0,0 +1,19 @@ +# 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: Use frame umbrella crate in pallet-proxy and pallet-multisig + +doc: + - audience: Runtime Dev + description: | + Extends the umbrella crate and uses it in pallet-proxy and pallet-multisig. + Migrates benchmarking from v1 to v2 for pallet-proxy and pallet-multisig. + Allows CI to pick the umbrella crate weights template to run benchmarks. + +crates: + - name: pallet-multisig + bump: minor + - name: pallet-proxy + bump: minor + - name: polkadot-sdk + bump: minor From 1e7d1bb038c106d02eeac9e44d8b27d73918c698 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Wed, 23 Oct 2024 18:22:34 +0200 Subject: [PATCH 20/35] docs fix --- substrate/frame/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index ee64e9f719bd..566fc14ffd16 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -34,10 +34,10 @@ //! //! This crate is organized into 3 stages: //! -//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`], -//! [`weights_prelude`], [`try_runtime`]. -//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`]. -//! 3. Accessing frame/substrate dependencies directly: [`deps`]. +//! 1. preludes: \[`prelude`\], \[`testing_prelude`\] and \[`runtime::prelude`\], +//! \[`benchmarking`\], \[`weights_prelude`\], \[`try_runtime`\]. +//! 2. domain-specific modules: \[`traits`\], \[`hashing`\], \[`arithmetic`\] and \[`derive`\]. +//! 3. Accessing frame/substrate dependencies directly: \[`deps`\]. //! //! The main intended use of this crate is for it to be used with the former, preludes: //! @@ -75,7 +75,7 @@ //! ``` //! //! If not in preludes, one can look into the domain-specific modules. Finally, if an import is -//! still not feasible, one can look into [`deps`]. +//! still not feasible, one can look into \[`deps`\]. //! //! ## Naming //! @@ -126,12 +126,12 @@ //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the -//! preludes, such as [`hashing`]. +//! preludes, such as \[`hashing`\]. //! * The only items that should NOT be in preludes are those that have been placed in //! `frame-support`/`sp-runtime`, but in truth are related to just one pallet. //! * The currency related traits are kept out of the preludes to encourage a deliberate choice of //! one over the other. -//! * [`runtime::apis`] should expose all common runtime APIs that all FRAME-based runtimes need. +//! * \[`runtime::apis`\] should expose all common runtime APIs that all FRAME-based runtimes need. #![cfg_attr(not(feature = "std"), no_std)] #![cfg(feature = "experimental")] From cf32fbfadd3ca8868436f37f64be751150cadd4c Mon Sep 17 00:00:00 2001 From: giuseppere Date: Wed, 23 Oct 2024 18:33:36 +0200 Subject: [PATCH 21/35] undo docs change --- substrate/frame/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 566fc14ffd16..ee64e9f719bd 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -34,10 +34,10 @@ //! //! This crate is organized into 3 stages: //! -//! 1. preludes: \[`prelude`\], \[`testing_prelude`\] and \[`runtime::prelude`\], -//! \[`benchmarking`\], \[`weights_prelude`\], \[`try_runtime`\]. -//! 2. domain-specific modules: \[`traits`\], \[`hashing`\], \[`arithmetic`\] and \[`derive`\]. -//! 3. Accessing frame/substrate dependencies directly: \[`deps`\]. +//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`], +//! [`weights_prelude`], [`try_runtime`]. +//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`]. +//! 3. Accessing frame/substrate dependencies directly: [`deps`]. //! //! The main intended use of this crate is for it to be used with the former, preludes: //! @@ -75,7 +75,7 @@ //! ``` //! //! If not in preludes, one can look into the domain-specific modules. Finally, if an import is -//! still not feasible, one can look into \[`deps`\]. +//! still not feasible, one can look into [`deps`]. //! //! ## Naming //! @@ -126,12 +126,12 @@ //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the -//! preludes, such as \[`hashing`\]. +//! preludes, such as [`hashing`]. //! * The only items that should NOT be in preludes are those that have been placed in //! `frame-support`/`sp-runtime`, but in truth are related to just one pallet. //! * The currency related traits are kept out of the preludes to encourage a deliberate choice of //! one over the other. -//! * \[`runtime::apis`\] should expose all common runtime APIs that all FRAME-based runtimes need. +//! * [`runtime::apis`] should expose all common runtime APIs that all FRAME-based runtimes need. #![cfg_attr(not(feature = "std"), no_std)] #![cfg(feature = "experimental")] From d46029526908a15a9d76c738afc92168643cea1b Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 09:36:37 +0200 Subject: [PATCH 22/35] add docs comment + undo format for `run_all_benchmarks.sh` --- .../frame/democracy/src/migrations/v1.rs | 8 +- substrate/frame/multisig/src/benchmarking.rs | 26 ++-- substrate/scripts/run_all_benchmarks.sh | 118 ++++++++++-------- 3 files changed, 77 insertions(+), 75 deletions(-) diff --git a/substrate/frame/democracy/src/migrations/v1.rs b/substrate/frame/democracy/src/migrations/v1.rs index 8783a2ac1c94..47f8df017f1e 100644 --- a/substrate/frame/democracy/src/migrations/v1.rs +++ b/substrate/frame/democracy/src/migrations/v1.rs @@ -18,13 +18,7 @@ //! Storage migrations for the preimage pallet. use crate::*; -use frame_support::{ - // We cannot use the `pallet_prelude` here as the item `Bounded` will become ambiguous. - pallet_prelude::{StorageVersion, ValueQuery}, - storage_alias, - traits::OnRuntimeUpgrade, - BoundedVec, -}; +use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade, BoundedVec}; use frame_system::pallet_prelude::BlockNumberFor; use sp_core::H256; diff --git a/substrate/frame/multisig/src/benchmarking.rs b/substrate/frame/multisig/src/benchmarking.rs index 82f5a829553a..ccaa1ceab66e 100644 --- a/substrate/frame/multisig/src/benchmarking.rs +++ b/substrate/frame/multisig/src/benchmarking.rs @@ -49,7 +49,7 @@ fn setup_multi( mod benchmarks { use super::*; - // `z`: Transaction Length + /// `z`: Transaction Length #[benchmark] fn as_multi_threshold_1(z: Linear<0, 10_000>) -> Result<(), BenchmarkError> { let max_signatories = T::MaxSignatories::get().into(); @@ -68,8 +68,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length - // `s`: Signatories, need at least 2 people + /// `z`: Transaction Length + /// `s`: Signatories, need at least 2 people #[benchmark] fn as_multi_create( s: Linear<2, { T::MaxSignatories::get() }>, @@ -91,8 +91,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length - // `s`: Signatories, need at least 3 people (so we don't complete the multisig) + /// `z`: Transaction Length + /// `s`: Signatories, need at least 3 people (so we don't complete the multisig) #[benchmark] fn as_multi_approve( s: Linear<3, { T::MaxSignatories::get() }>, @@ -136,8 +136,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length - // `s`: Signatories, need at least 2 people + /// `z`: Transaction Length + /// `s`: Signatories, need at least 2 people #[benchmark] fn as_multi_complete( s: Linear<2, { T::MaxSignatories::get() }>, @@ -194,8 +194,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length, not a component - // `s`: Signatories, need at least 2 people + /// `z`: Transaction Length, not a component + /// `s`: Signatories, need at least 2 people #[benchmark] fn approve_as_multi_create( s: Linear<2, { T::MaxSignatories::get() }>, @@ -225,8 +225,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length, not a component - // `s`: Signatories, need at least 2 people + /// `z`: Transaction Length, not a component + /// `s`: Signatories, need at least 2 people #[benchmark] fn approve_as_multi_approve( s: Linear<2, { T::MaxSignatories::get() }>, @@ -270,8 +270,8 @@ mod benchmarks { Ok(()) } - // `z`: Transaction Length, not a component - // `s`: Signatories, need at least 2 people + /// `z`: Transaction Length, not a component + /// `s`: Signatories, need at least 2 people #[benchmark] fn cancel_as_multi( s: Linear<2, { T::MaxSignatories::get() }>, diff --git a/substrate/scripts/run_all_benchmarks.sh b/substrate/scripts/run_all_benchmarks.sh index 3856f8935321..053c230fedb4 100755 --- a/substrate/scripts/run_all_benchmarks.sh +++ b/substrate/scripts/run_all_benchmarks.sh @@ -25,37 +25,39 @@ while getopts 'bfp:v' flag; do case "${flag}" in - b) - # Skip build. - skip_build='true' - ;; - f) - # Fail if any sub-command in a pipe fails, not just the last one. - set -o pipefail - # Fail on undeclared variables. - set -u - # Fail if any sub-command fails. - set -e - # Fail on traps. - set -E - ;; - p) - # Start at pallet - start_pallet="${OPTARG}" - ;; - v) - # Echo all executed commands. - set -x - ;; - *) - # Exit early. - echo "Bad options. Check Script." - exit 1 - ;; + b) + # Skip build. + skip_build='true' + ;; + f) + # Fail if any sub-command in a pipe fails, not just the last one. + set -o pipefail + # Fail on undeclared variables. + set -u + # Fail if any sub-command fails. + set -e + # Fail on traps. + set -E + ;; + p) + # Start at pallet + start_pallet="${OPTARG}" + ;; + v) + # Echo all executed commands. + set -x + ;; + *) + # Exit early. + echo "Bad options. Check Script." + exit 1 + ;; esac done -if [ "$skip_build" != true ]; then + +if [ "$skip_build" != true ] +then echo "[+] Compiling Substrate benchmarks..." cargo build --profile=production --locked --features=runtime-benchmarks --bin substrate-node fi @@ -95,50 +97,56 @@ rm -f $ERR_FILE # Benchmark each pallet. for PALLET in "${PALLETS[@]}"; do # If `-p` is used, skip benchmarks until the start pallet. - if [ ! -z "$start_pallet" ] && [ "$start_pallet" != "$PALLET" ]; then + if [ ! -z "$start_pallet" ] && [ "$start_pallet" != "$PALLET" ] + then echo "[+] Skipping ${PALLET}..." continue else unset start_pallet fi - FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')" + FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')"; WEIGHT_FILE="./frame/${FOLDER}/src/weights.rs" TEMPLATE_FILE_NAME="frame-weight-template.hbs" - if [ $(cargo metadata --locked --format-version 1 --no-deps | jq --arg pallet "${PALLET//_/-}" -r '.packages[] | select(.name == $pallet) | .dependencies | any(.name == "polkadot-sdk-frame")') = true ]; then + if [ $(cargo metadata --locked --format-version 1 --no-deps | jq --arg pallet "${PALLET//_/-}" -r '.packages[] | select(.name == $pallet) | .dependencies | any(.name == "polkadot-sdk-frame")') = true ] + then TEMPLATE_FILE_NAME="frame-umbrella-weight-template.hbs" fi TEMPLATE_FILE="./.maintain/${TEMPLATE_FILE_NAME}" # Special handling of custom weight paths. - if [ "$PALLET" == "frame_system_extensions" ] || [ "$PALLET" == "frame-system-extensions" ]; then + if [ "$PALLET" == "frame_system_extensions" ] || [ "$PALLET" == "frame-system-extensions" ] + then WEIGHT_FILE="./frame/system/src/extensions/weights.rs" - elif [ "$PALLET" == "pallet_asset_conversion_tx_payment" ] || [ "$PALLET" == "pallet-asset-conversion-tx-payment" ]; then + elif [ "$PALLET" == "pallet_asset_conversion_tx_payment" ] || [ "$PALLET" == "pallet-asset-conversion-tx-payment" ] + then WEIGHT_FILE="./frame/transaction-payment/asset-conversion-tx-payment/src/weights.rs" - elif [ "$PALLET" == "pallet_asset_tx_payment" ] || [ "$PALLET" == "pallet-asset-tx-payment" ]; then + elif [ "$PALLET" == "pallet_asset_tx_payment" ] || [ "$PALLET" == "pallet-asset-tx-payment" ] + then WEIGHT_FILE="./frame/transaction-payment/asset-tx-payment/src/weights.rs" - elif [ "$PALLET" == "pallet_asset_conversion_ops" ] || [ "$PALLET" == "pallet-asset-conversion-ops" ]; then + elif [ "$PALLET" == "pallet_asset_conversion_ops" ] || [ "$PALLET" == "pallet-asset-conversion-ops" ] + then WEIGHT_FILE="./frame/asset-conversion/ops/src/weights.rs" fi - echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE" + echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE"; OUTPUT=$( $SUBSTRATE benchmark pallet \ - --chain=dev \ - --steps=50 \ - --repeat=20 \ - --pallet="$PALLET" \ - --extrinsic="*" \ - --wasm-execution=compiled \ - --heap-pages=4096 \ - --output="$WEIGHT_FILE" \ - --header="./HEADER-APACHE2" \ - --template="$TEMPLATE_FILE" 2>&1 + --chain=dev \ + --steps=50 \ + --repeat=20 \ + --pallet="$PALLET" \ + --extrinsic="*" \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output="$WEIGHT_FILE" \ + --header="./HEADER-APACHE2" \ + --template="$TEMPLATE_FILE" 2>&1 ) if [ $? -ne 0 ]; then - echo "$OUTPUT" >>"$ERR_FILE" + echo "$OUTPUT" >> "$ERR_FILE" echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..." fi done @@ -147,15 +155,15 @@ done echo "[+] Benchmarking block and extrinsic overheads..." OUTPUT=$( $SUBSTRATE benchmark overhead \ - --chain=dev \ - --wasm-execution=compiled \ - --weight-path="./frame/support/src/weights/" \ - --header="./HEADER-APACHE2" \ - --warmup=10 \ - --repeat=100 2>&1 + --chain=dev \ + --wasm-execution=compiled \ + --weight-path="./frame/support/src/weights/" \ + --header="./HEADER-APACHE2" \ + --warmup=10 \ + --repeat=100 2>&1 ) if [ $? -ne 0 ]; then - echo "$OUTPUT" >>"$ERR_FILE" + echo "$OUTPUT" >> "$ERR_FILE" echo "[-] Failed to benchmark the block and extrinsic overheads. Error written to $ERR_FILE; continuing..." fi @@ -175,4 +183,4 @@ if [ -f "$ERR_FILE" ]; then else echo "[+] All benchmarks passed." exit 0 -fi +fi \ No newline at end of file From ca35eed003c955db97fefb60a94f6507d0a59bbd Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 24 Oct 2024 09:40:03 +0200 Subject: [PATCH 23/35] Update substrate/frame/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index ee64e9f719bd..0e26e99b6e6a 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -238,7 +238,7 @@ pub mod benchmarking { pub use frame_system::RawOrigin; } - #[deprecated(note = "use the syntax in `frame::benchmarking::v2`")] + #[deprecated(note = "'The V1 benchmarking syntax is deprecated. Please use the V2 syntax. This warning may become a hard error any time after April 2025. For more info, see: https://github.com/paritytech/polkadot-sdk/pull/5995")] pub mod v1 { pub use super::shared::*; pub use frame_benchmarking::benchmarks; From 393d9987a65b88c09f4cad1f5019dac05ce9bf36 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 09:55:31 +0200 Subject: [PATCH 24/35] comment nit --- substrate/frame/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 2bc5c605aeb0..ef973486e59f 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -231,7 +231,7 @@ pub mod try_runtime { pub mod benchmarking { mod shared { pub use frame_benchmarking::{add_benchmark, v1::account, whitelist, whitelisted_caller}; - //. all benchmarking host functions. + // all benchmarking functions. pub use frame_benchmarking::benchmarking::*; // The system origin, which is very often needed in benchmarking code. Might be tricky only // if the pallet defines its own `#[pallet::origin]` and call it `RawOrigin`. From 2f5eea937a894856e7f7c894d9207efc10fdad64 Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 24 Oct 2024 11:35:38 +0200 Subject: [PATCH 25/35] Update prdoc/pr_5995.prdoc Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- prdoc/pr_5995.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5995.prdoc b/prdoc/pr_5995.prdoc index 33ae10017115..4023a2e6cc07 100644 --- a/prdoc/pr_5995.prdoc +++ b/prdoc/pr_5995.prdoc @@ -6,7 +6,7 @@ title: Use frame umbrella crate in pallet-proxy and pallet-multisig doc: - audience: Runtime Dev description: | - Extends the umbrella crate and uses it in pallet-proxy and pallet-multisig. + Extends the FRAME umbrella crate and uses it in pallet-proxy and pallet-multisig. Migrates benchmarking from v1 to v2 for pallet-proxy and pallet-multisig. Allows CI to pick the umbrella crate weights template to run benchmarks. From b85d64439f204b23817549a7829304b47b342637 Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 24 Oct 2024 11:35:52 +0200 Subject: [PATCH 26/35] Update substrate/frame/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/frame/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index ef973486e59f..46a101016dec 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -259,7 +259,6 @@ pub mod benchmarking { /// pub use polkadot_sdk_frame::weights_prelude::*; /// ``` pub mod weights_prelude { - pub use core::marker::PhantomData; pub use frame_support::{ traits::Get, From 9e771eed6ff7e9e1b5714e576fde8e108270ef5c Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 24 Oct 2024 11:36:05 +0200 Subject: [PATCH 27/35] Update prdoc/pr_5995.prdoc Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- prdoc/pr_5995.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5995.prdoc b/prdoc/pr_5995.prdoc index 4023a2e6cc07..74dc57a9f9b6 100644 --- a/prdoc/pr_5995.prdoc +++ b/prdoc/pr_5995.prdoc @@ -15,5 +15,5 @@ crates: bump: minor - name: pallet-proxy bump: minor - - name: polkadot-sdk + - name: polkadot-sdk-frame bump: minor From 66d7396a38426946ea10ff621744a2e33bf8984c Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 24 Oct 2024 11:36:18 +0200 Subject: [PATCH 28/35] Update prdoc/pr_5995.prdoc Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- prdoc/pr_5995.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5995.prdoc b/prdoc/pr_5995.prdoc index 74dc57a9f9b6..ad8aa6d1675d 100644 --- a/prdoc/pr_5995.prdoc +++ b/prdoc/pr_5995.prdoc @@ -16,4 +16,4 @@ crates: - name: pallet-proxy bump: minor - name: polkadot-sdk-frame - bump: minor + bump: major From 88265e59c283c83335e81f8115378efe174fb9a1 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 11:40:31 +0200 Subject: [PATCH 29/35] undo snowbridge changes --- bridges/snowbridge/pallets/inbound-queue/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridges/snowbridge/pallets/inbound-queue/src/lib.rs b/bridges/snowbridge/pallets/inbound-queue/src/lib.rs index 77d1c709966b..423b92b9fae0 100644 --- a/bridges/snowbridge/pallets/inbound-queue/src/lib.rs +++ b/bridges/snowbridge/pallets/inbound-queue/src/lib.rs @@ -59,7 +59,7 @@ use xcm_executor::traits::TransactAsset; use snowbridge_core::{ inbound::{Message, VerificationError, Verifier}, sibling_sovereign_account, BasicOperatingMode, Channel, ChannelId, ParaId, PricingParameters, - StaticLookup as SnowBridgeStaticLookup, + StaticLookup, }; use snowbridge_router_primitives::inbound::{ ConvertMessage, ConvertMessageError, VersionedMessage, @@ -118,7 +118,7 @@ pub mod pallet { >; /// Lookup a channel descriptor - type ChannelLookup: SnowBridgeStaticLookup; + type ChannelLookup: StaticLookup; /// Lookup pricing parameters type PricingParameters: Get>>; From dc2973d0074a6a41f840b042cb204f310cb9a04d Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 17:38:25 +0200 Subject: [PATCH 30/35] expand frame docs --- substrate/frame/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 46a101016dec..c67f0b474ef6 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -36,7 +36,7 @@ //! //! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`], //! [`weights_prelude`], [`try_runtime`]. -//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`]. +//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`](mod@derive). //! 3. Accessing frame/substrate dependencies directly: [`deps`]. //! //! The main intended use of this crate is for it to be used with the former, preludes: @@ -77,6 +77,14 @@ //! If not in preludes, one can look into the domain-specific modules. Finally, if an import is //! still not feasible, one can look into [`deps`]. //! +//! This crate also uses a `runtime` feature to include all of the types and tools needed to build +//! FRAME-based runtimes, which otherwise are ignored. You can enable it with `--features runtime`. +//! +//! Notice that the preludes overlap since they have imports in common. More in detail: +//! - [`testing_prelude`] brings in frame [`prelude`] and [`runtime::prelude`]; +//! - [`runtime::prelude`] brings in frame [`prelude`]; +//! - [`benchmarking`] brings in frame [`prelude`]. +//! //! ## Naming //! //! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. This is due @@ -121,8 +129,6 @@ //! * Preludes should be extensive. The goal of this pallet is to be ONLY used with the preludes. //! The domain-specific modules are just a backup, aiming to keep things organized. Don't hesitate //! in adding more items to the main prelude. -//! * When doing so, prefer adding the relevant item to `frame_support::pallet_prelude` and -//! `frame_system::pallet_prelude`. //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the From 8cd8c73064a7b2d25df7b5d36c0516ede9687849 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 17:52:26 +0200 Subject: [PATCH 31/35] remove broken links from docs --- substrate/frame/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c67f0b474ef6..9fb15663c41b 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -34,8 +34,8 @@ //! //! This crate is organized into 3 stages: //! -//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], [`benchmarking`], -//! [`weights_prelude`], [`try_runtime`]. +//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], `benchmarking`, +//! [`weights_prelude`], `try_runtime`. //! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`](mod@derive). //! 3. Accessing frame/substrate dependencies directly: [`deps`]. //! @@ -83,7 +83,7 @@ //! Notice that the preludes overlap since they have imports in common. More in detail: //! - [`testing_prelude`] brings in frame [`prelude`] and [`runtime::prelude`]; //! - [`runtime::prelude`] brings in frame [`prelude`]; -//! - [`benchmarking`] brings in frame [`prelude`]. +//! - `benchmarking` brings in frame [`prelude`]. //! //! ## Naming //! From 5918bef5c71113c5bf8b3c7b135ea8cf50672953 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 19:18:06 +0200 Subject: [PATCH 32/35] fix docs + add storage value to minimal template --- substrate/frame/src/lib.rs | 20 +++++++++---------- templates/minimal/pallets/template/src/lib.rs | 4 +++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 9fb15663c41b..c092054697b4 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -34,10 +34,10 @@ //! //! This crate is organized into 3 stages: //! -//! 1. preludes: [`prelude`], [`testing_prelude`] and [`runtime::prelude`], `benchmarking`, -//! [`weights_prelude`], `try_runtime`. -//! 2. domain-specific modules: [`traits`], [`hashing`], [`arithmetic`] and [`derive`](mod@derive). -//! 3. Accessing frame/substrate dependencies directly: [`deps`]. +//! 1. preludes: `prelude`, `testing_prelude` and `runtime::prelude`, `benchmarking`, +//! `weights_prelude`, `try_runtime`. +//! 2. domain-specific modules: `traits`, `hashing`, `arithmetic` and `derive`. +//! 3. Accessing frame/substrate dependencies directly: `deps`. //! //! The main intended use of this crate is for it to be used with the former, preludes: //! @@ -75,15 +75,15 @@ //! ``` //! //! If not in preludes, one can look into the domain-specific modules. Finally, if an import is -//! still not feasible, one can look into [`deps`]. +//! still not feasible, one can look into `deps`. //! //! This crate also uses a `runtime` feature to include all of the types and tools needed to build //! FRAME-based runtimes, which otherwise are ignored. You can enable it with `--features runtime`. //! //! Notice that the preludes overlap since they have imports in common. More in detail: -//! - [`testing_prelude`] brings in frame [`prelude`] and [`runtime::prelude`]; -//! - [`runtime::prelude`] brings in frame [`prelude`]; -//! - `benchmarking` brings in frame [`prelude`]. +//! - `testing_prelude` brings in frame `prelude` and `runtime::prelude`; +//! - `runtime::prelude` brings in frame `prelude`; +//! - `benchmarking` brings in frame `prelude`. //! //! ## Naming //! @@ -132,12 +132,12 @@ //! * The only non-module, non-prelude items exported from the top level crate is the `pallet` //! macro, such that we can have the `#[frame::pallet] mod pallet { .. }` syntax working. //! * In most cases, you might want to create a domain-specific module, but also add it to the -//! preludes, such as [`hashing`]. +//! preludes, such as `hashing`. //! * The only items that should NOT be in preludes are those that have been placed in //! `frame-support`/`sp-runtime`, but in truth are related to just one pallet. //! * The currency related traits are kept out of the preludes to encourage a deliberate choice of //! one over the other. -//! * [`runtime::apis`] should expose all common runtime APIs that all FRAME-based runtimes need. +//! * `runtime::apis` should expose all common runtime APIs that all FRAME-based runtimes need. #![cfg_attr(not(feature = "std"), no_std)] #![cfg(feature = "experimental")] diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index 2c5fdf1e81b2..722b606079f9 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -5,7 +5,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[allow(unused_imports)] use frame::prelude::*; use polkadot_sdk::polkadot_sdk_frame as frame; @@ -21,4 +20,7 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); + + #[pallet::storage] + pub type Value = StorageValue; } From 325d62e73709c68e4233bde3ce958055d5e7f3ad Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 24 Oct 2024 19:19:40 +0200 Subject: [PATCH 33/35] prdoc add missing pallet --- prdoc/pr_5995.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5995.prdoc b/prdoc/pr_5995.prdoc index ad8aa6d1675d..fdd754057bd1 100644 --- a/prdoc/pr_5995.prdoc +++ b/prdoc/pr_5995.prdoc @@ -17,3 +17,5 @@ crates: bump: minor - name: polkadot-sdk-frame bump: major + - name: pallet-migrations + bump: patch From 48050fd5c66c3c587c4fc7ecaa1fdbf1b5670827 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Fri, 25 Oct 2024 12:51:26 +0200 Subject: [PATCH 34/35] docs nit --- substrate/frame/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c092054697b4..e674727f6317 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -78,7 +78,17 @@ //! still not feasible, one can look into `deps`. //! //! This crate also uses a `runtime` feature to include all of the types and tools needed to build -//! FRAME-based runtimes, which otherwise are ignored. You can enable it with `--features runtime`. +//! FRAME-based runtimes. So, if you want to build a runtime with this, import it as +//! +//! ``` +//! polkadot-sdk-frame = { version = "foo", features = ["runtime"] } +//! ``` +//! +//! If you just want to build a pallet instead, import it as +//! +//! ``` +//! polkadot-sdk-frame = { version = "foo" } +//! ``` //! //! Notice that the preludes overlap since they have imports in common. More in detail: //! - `testing_prelude` brings in frame `prelude` and `runtime::prelude`; From d9f132b20b584c56c286b962d5695442f44279f6 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:48:30 +0100 Subject: [PATCH 35/35] Apply suggestions from code review --- substrate/frame/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index e674727f6317..a8d2c0b3fc56 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -80,13 +80,13 @@ //! This crate also uses a `runtime` feature to include all of the types and tools needed to build //! FRAME-based runtimes. So, if you want to build a runtime with this, import it as //! -//! ``` +//! ```text //! polkadot-sdk-frame = { version = "foo", features = ["runtime"] } //! ``` //! //! If you just want to build a pallet instead, import it as //! -//! ``` +//! ```text //! polkadot-sdk-frame = { version = "foo" } //! ``` //!