diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9f0b701f20be..d0d72ee6ab5a 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1516,6 +1516,7 @@ impl pallet_nomination_pools::Config for Runtime { type PalletId = PoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; type AdminOrigin = EitherOf, StakingAdmin>; + type BlockNumberProvider = System; } parameter_types! { diff --git a/prdoc/pr_6715.prdoc b/prdoc/pr_6715.prdoc new file mode 100644 index 000000000000..89cc2be5d4d9 --- /dev/null +++ b/prdoc/pr_6715.prdoc @@ -0,0 +1,13 @@ +# 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: Update Nomination Pool Pallet to Support Block Number Provider + +doc: + - audience: Runtime Dev + description: | + This PR makes the block number provider used in the nomination pool pallet configurable. Before this PR, nomination pool pallet always used the system block number, + with this PR some runtime can opt to use the relay chain block number instead. +crates: +- name: pallet-nomination-pools + bump: major \ No newline at end of file diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index bff263548087..68264a1ed47b 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -963,6 +963,7 @@ impl pallet_nomination_pools::Config for Runtime { EnsureRoot, pallet_collective::EnsureProportionAtLeast, >; + type BlockNumberProvider = System; } parameter_types! { diff --git a/substrate/frame/delegated-staking/src/mock.rs b/substrate/frame/delegated-staking/src/mock.rs index 811d5739f4e9..2d4f40b75017 100644 --- a/substrate/frame/delegated-staking/src/mock.rs +++ b/substrate/frame/delegated-staking/src/mock.rs @@ -160,6 +160,7 @@ impl pallet_nomination_pools::Config for Runtime { type StakeAdapter = pallet_nomination_pools::adapter::DelegateStake; type AdminOrigin = frame_system::EnsureRoot; + type BlockNumberProvider = System; } frame_support::construct_runtime!( diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index eaab848c1694..0cff17f49778 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -272,6 +272,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = MaxUnbonding; type MaxPointsToBalance = frame_support::traits::ConstU8<10>; type AdminOrigin = frame_system::EnsureRoot; + type BlockNumberProvider = System; } parameter_types! { diff --git a/substrate/frame/nomination-pools/benchmarking/src/mock.rs b/substrate/frame/nomination-pools/benchmarking/src/mock.rs index 15d9e2c56031..27da1bec72f6 100644 --- a/substrate/frame/nomination-pools/benchmarking/src/mock.rs +++ b/substrate/frame/nomination-pools/benchmarking/src/mock.rs @@ -139,6 +139,7 @@ impl pallet_nomination_pools::Config for Runtime { type PalletId = PoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; type AdminOrigin = frame_system::EnsureRoot; + type BlockNumberProvider = System; } parameter_types! { diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index dc82bf3a37c6..27e3e0b54b82 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -368,7 +368,6 @@ use frame_support::{ }, DefaultNoBound, PalletError, }; -use frame_system::pallet_prelude::BlockNumberFor; use scale_info::TypeInfo; use sp_core::U256; use sp_runtime::{ @@ -406,6 +405,7 @@ pub mod migration; pub mod weights; pub use pallet::*; +use sp_runtime::traits::BlockNumberProvider; pub use weights::WeightInfo; /// The balance type used by the currency system. @@ -416,6 +416,9 @@ pub type PoolId = u32; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; +pub type BlockNumberFor = + <::BlockNumberProvider as BlockNumberProvider>::BlockNumber; + pub const POINTS_TO_BALANCE_INIT_RATIO: u32 = 1; /// Possible operations on the configuration values of this pallet. @@ -779,7 +782,7 @@ impl Commission { } else { // throttling if blocks passed is less than `min_delay`. let blocks_surpassed = - >::block_number().saturating_sub(f); + T::BlockNumberProvider::current_block_number().saturating_sub(f); blocks_surpassed < t.min_delay } }, @@ -892,7 +895,7 @@ impl Commission { /// Updates a commission's `throttle_from` field to the current block. fn register_update(&mut self) { - self.throttle_from = Some(>::block_number()); + self.throttle_from = Some(T::BlockNumberProvider::current_block_number()); } /// Checks whether a change rate is less restrictive than the current change rate, if any. @@ -1565,7 +1568,9 @@ impl Get for TotalUnbondingPools { pub mod pallet { use super::*; use frame_support::traits::StorageVersion; - use frame_system::{ensure_signed, pallet_prelude::*}; + use frame_system::pallet_prelude::{ + ensure_root, ensure_signed, BlockNumberFor as SystemBlockNumberFor, OriginFor, + }; use sp_runtime::Perbill; /// The in-code storage version. @@ -1650,6 +1655,9 @@ pub mod pallet { /// The origin that can manage pool configurations. type AdminOrigin: EnsureOrigin; + + /// Provider for the block number. Normally this is the `frame_system` pallet. + type BlockNumberProvider: BlockNumberProvider; } /// The sum of funds across all pools. @@ -3092,9 +3100,9 @@ pub mod pallet { } #[pallet::hooks] - impl Hooks> for Pallet { + impl Hooks> for Pallet { #[cfg(feature = "try-runtime")] - fn try_state(_n: BlockNumberFor) -> Result<(), TryRuntimeError> { + fn try_state(_n: SystemBlockNumberFor) -> Result<(), TryRuntimeError> { Self::do_try_state(u8::MAX) } diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index cc942039760c..d92c603f4cc8 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -302,6 +302,7 @@ impl pools::Config for Runtime { type MaxUnbonding = MaxUnbonding; type MaxPointsToBalance = frame_support::traits::ConstU8<10>; type AdminOrigin = EnsureSignedBy; + type BlockNumberProvider = System; } type Block = frame_system::mocking::MockBlock; diff --git a/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs b/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs index d1bc4ef8ff28..ca1f6205d61d 100644 --- a/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs +++ b/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs @@ -265,6 +265,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; type AdminOrigin = EnsureRoot; + type BlockNumberProvider = System; } parameter_types! { diff --git a/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs b/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs index d913c5fe6948..2efde35fd6fe 100644 --- a/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs +++ b/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs @@ -145,6 +145,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; type AdminOrigin = frame_system::EnsureRoot; + type BlockNumberProvider = System; } type Block = frame_system::mocking::MockBlock;