Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pallet nomination pool to support Block Number Provider #6715

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ impl pallet_nomination_pools::Config for Runtime {
type PalletId = PoolsPalletId;
type MaxPointsToBalance = MaxPointsToBalance;
type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
14 changes: 14 additions & 0 deletions prdoc/prdoc/pr_6715.prdoc
Original file line number Diff line number Diff line change
@@ -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 nomination pool pallet use the relay chain as a block provider for a parachain on a regular schedule.
dharjeezy marked this conversation as resolved.
Show resolved Hide resolved
To migrate existing nomination pool implementations, simply add `type BlockNumberProvider = System` to have the same behavior as before.

crates:
- name: pallet-nomination-pools
bump: minor
gui1117 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ impl pallet_nomination_pools::Config for Runtime {
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl pallet_nomination_pools::Config for Runtime {
type StakeAdapter =
pallet_nomination_pools::adapter::DelegateStake<Self, Staking, DelegatedStaking>;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type BlockNumberProvider = System;
}

frame_support::construct_runtime!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::AccountId>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl pallet_nomination_pools::Config for Runtime {
type PalletId = PoolsPalletId;
type MaxPointsToBalance = MaxPointsToBalance;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
20 changes: 14 additions & 6 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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.
Expand All @@ -416,6 +416,9 @@ pub type PoolId = u32;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

pub type BlockNumberFor<T> =
<<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;

pub const POINTS_TO_BALANCE_INIT_RATIO: u32 = 1;

/// Possible operations on the configuration values of this pallet.
Expand Down Expand Up @@ -779,7 +782,7 @@ impl<T: Config> Commission<T> {
} else {
// throttling if blocks passed is less than `min_delay`.
let blocks_surpassed =
<frame_system::Pallet<T>>::block_number().saturating_sub(f);
T::BlockNumberProvider::current_block_number().saturating_sub(f);
blocks_surpassed < t.min_delay
}
},
Expand Down Expand Up @@ -892,7 +895,7 @@ impl<T: Config> Commission<T> {

/// Updates a commission's `throttle_from` field to the current block.
fn register_update(&mut self) {
self.throttle_from = Some(<frame_system::Pallet<T>>::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.
Expand Down Expand Up @@ -1565,7 +1568,7 @@ impl<T: Config> Get<u32> for TotalUnbondingPools<T> {
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, OriginFor};
use sp_runtime::Perbill;

/// The in-code storage version.
Expand Down Expand Up @@ -1650,6 +1653,9 @@ pub mod pallet {

/// The origin that can manage pool configurations.
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Provider for the block number. Normally this is the `frame_system` pallet.
type BlockNumberProvider: BlockNumberProvider;
}

/// The sum of funds across all pools.
Expand Down Expand Up @@ -3092,9 +3098,11 @@ pub mod pallet {
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
impl<T: Config> Hooks<frame_system::pallet_prelude::BlockNumberFor<T>> for Pallet<T> {
dharjeezy marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "try-runtime")]
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
fn try_state(
_n: frame_system::pallet_prelude::BlockNumberFor<T>,
) -> Result<(), TryRuntimeError> {
Self::do_try_state(u8::MAX)
}

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl pools::Config for Runtime {
type MaxUnbonding = MaxUnbonding;
type MaxPointsToBalance = frame_support::traits::ConstU8<10>;
type AdminOrigin = EnsureSignedBy<Admin, AccountId>;
type BlockNumberProvider = System;
}

type Block = frame_system::mocking::MockBlock<Runtime>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl pallet_nomination_pools::Config for Runtime {
type MaxPointsToBalance = ConstU8<10>;
type PalletId = PoolsPalletId;
type AdminOrigin = EnsureRoot<AccountId>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl pallet_nomination_pools::Config for Runtime {
type MaxPointsToBalance = ConstU8<10>;
type PalletId = PoolsPalletId;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type BlockNumberProvider = System;
}

type Block = frame_system::mocking::MockBlock<Runtime>;
Expand Down
Loading