diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 935b62c23388e..360ae57497668 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1534,6 +1534,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 0000000000000..d7b55509f3f26 --- /dev/null +++ b/prdoc/pr_6715.prdoc @@ -0,0 +1,14 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Update Nomination Pool Pallet to Support Block Number Provider + +doc: + - audience: Runtime Dev + description: | + This PR makes the block number provider in the Society pallet configurable so that runtimes can choose between using the system block number or an alternative source like the relay chain’s block number. + If you want to keep the existing behavior, simply set the provider to System. For scenarios that require a different notion of block number—such as using a relay chain number you can select another provider, + ensuring flexibility in how the nomination pools pallet references the current block. +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 220929fdfd838..ba1441b722fd1 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -990,6 +990,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 a4546e57dab5e..42b876d049ac3 100644 --- a/substrate/frame/delegated-staking/src/mock.rs +++ b/substrate/frame/delegated-staking/src/mock.rs @@ -161,6 +161,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 3a64964361870..8118dfa2045cb 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 @@ -277,6 +277,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 7c09cf22ad51e..39ff6fb7a09e9 100644 --- a/substrate/frame/nomination-pools/benchmarking/src/mock.rs +++ b/substrate/frame/nomination-pools/benchmarking/src/mock.rs @@ -140,6 +140,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 dc82bf3a37c6e..27e3e0b54b82f 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 f4552389a267a..88ef82a156200 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -477,6 +477,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 7aa8019b9c42c..77a57e5a815b1 100644 --- a/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs +++ b/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs @@ -269,6 +269,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; type AdminOrigin = EnsureRoot; + type BlockNumberProvider = System; } parameter_types! {