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

Staking: Add deprecate_controller_batch AdminOrigin call #2589

Merged
merged 95 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
b7df147
add deprecate_controller_batch call
Dec 3, 2023
bb8658d
fix name
Dec 3, 2023
ce1b7d7
ledger controller to None
Dec 3, 2023
566ecd9
MaxControllersInBatch to 10
Dec 3, 2023
eea28dc
init deprecate_controller_batch_works test
Dec 3, 2023
37bf26d
add benchmark boilerplate
Dec 3, 2023
acb3ebe
amend mocks
Dec 3, 2023
af012b6
amend mocks
Dec 3, 2023
68a75bb
benchmark tidy up
Dec 3, 2023
4df272b
start test at account 1001
Dec 3, 2023
759f3f4
some benchmark fixes
Dec 3, 2023
f72e1e3
benchmarks
Dec 3, 2023
d75a2d0
use create_unique_stash_controller
Dec 3, 2023
e8b2898
fmt
Dec 3, 2023
8f4fe14
fixes
Dec 3, 2023
186966b
fixes
Dec 3, 2023
77b90ca
introduce i
Dec 3, 2023
41df014
comments, use BoundedVec
Dec 3, 2023
3b3f760
fmt
Dec 3, 2023
85a2b7d
fix
Dec 3, 2023
24738d3
tidy up benchmarl
Dec 3, 2023
e364610
more fixes
Dec 3, 2023
c984419
fix
Dec 3, 2023
1253894
amend runtime MaxControllersInBatch
Dec 3, 2023
99ab57d
rename
Dec 4, 2023
734722a
".git/.scripts/commands/fmt/fmt.sh"
Dec 4, 2023
ce6462e
add type
Dec 4, 2023
3fb3f7e
Merge branch 'rb-depreciate-controller-batch' of https://github.com/p…
Dec 4, 2023
5d9f1be
test
Dec 4, 2023
3263180
use u32
Dec 4, 2023
16faf72
uncomment
Dec 4, 2023
5dcac5a
try using parameter_types!
Dec 4, 2023
6b6363f
Revert "try using parameter_types!"
Dec 4, 2023
85567a9
fix test-runtime
Dec 4, 2023
6c56e6c
fix
Dec 4, 2023
6543b95
".git/.scripts/commands/fmt/fmt.sh"
Dec 4, 2023
9070a80
test
Dec 4, 2023
ee5b86a
use u32
Dec 4, 2023
58f1fd0
uncomment
Dec 4, 2023
791c737
try using parameter_types!
Dec 4, 2023
d4bac69
Revert "try using parameter_types!"
Dec 4, 2023
b693da0
fix test-runtime
Dec 4, 2023
e03c74d
fix
Dec 4, 2023
4972615
Merge branch 'rb-depreciate-controller-batch' of https://github.com/p…
Dec 4, 2023
0c1795a
add weights
Dec 4, 2023
23343d4
increase westend MaxControllersInDeprecationBatch
Dec 4, 2023
07b51b8
+ westend weights
Dec 4, 2023
c91c912
weights for max controllers
Dec 4, 2023
8c082e8
Merge branch 'master' into rb-depreciate-controller-batch
Dec 4, 2023
01d9fd0
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Dec 4, 2023
866f388
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Dec 4, 2023
c3e482c
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Dec 4, 2023
b7163b7
Merge branch 'master' into rb-depreciate-controller-batch
Dec 4, 2023
423a5fb
Merge branch 'master' into rb-depreciate-controller-batch
Dec 4, 2023
cc807b3
add PostInfo
Dec 5, 2023
637d4ea
fmt
Dec 5, 2023
6a9a6e3
test full weight scenario
Dec 5, 2023
e156276
Merge branch 'rb-depreciate-controller-batch' of https://github.com/p…
Dec 5, 2023
376e5e8
add deprecate_controller_batch_works_half_weight
Dec 5, 2023
954835b
tidy up
Dec 5, 2023
9247185
more tidy up
Dec 5, 2023
b3527d8
Merge branch 'master' into rb-depreciate-controller-batch
Dec 5, 2023
32ecfa5
remove comments
Dec 5, 2023
fb7732e
tidy up benchmark
Dec 5, 2023
278373c
Merge branch 'master' into rb-depreciate-controller-batch
Dec 5, 2023
c37c70d
rm clone
Dec 5, 2023
40b7096
Merge branch 'rb-depreciate-controller-batch' of https://github.com/p…
Dec 5, 2023
f207395
address feedback
Dec 6, 2023
87cf4c2
feedback
Dec 6, 2023
ba6e84a
add DeprecationOrigin
Dec 6, 2023
cdaf683
Merge branch 'master' into rb-depreciate-controller-batch
Dec 6, 2023
224861c
comment
Dec 6, 2023
65b7072
fixes
Dec 6, 2023
2a47ee8
fix
Dec 6, 2023
4ef7c13
add DeprecationOrigin to mocks
Dec 6, 2023
3f8846d
fix
Dec 6, 2023
efb8032
remove duplicate
Dec 6, 2023
d2f49fe
AdminOrigin gains StakingAdmin
Dec 6, 2023
eef8360
rm DeprecationOrigin
Dec 6, 2023
04833df
rm DeprecationOrigin
Dec 6, 2023
509c324
Merge branch 'master' into rb-depreciate-controller-batch
Dec 6, 2023
569067d
Merge branch 'master' into rb-depreciate-controller-batch
Dec 6, 2023
3fef4c4
Merge branch 'master' into rb-depreciate-controller-batch
Dec 7, 2023
a67b6cf
Merge branch 'master' into rb-depreciate-controller-batch
Dec 7, 2023
d9d0539
Merge branch 'master' into rb-depreciate-controller-batch
Dec 7, 2023
34bcd0b
Merge branch 'master' into rb-depreciate-controller-batch
Dec 8, 2023
6800e33
Merge branch 'master' into rb-depreciate-controller-batch
Dec 9, 2023
0d71005
skip deprecation if still Controller payee
Dec 10, 2023
84daf1b
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Dec 10, 2023
5b5dc1a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Dec 10, 2023
b381830
Merge branch 'master' into rb-depreciate-controller-batch
Dec 11, 2023
ec42467
Merge branch 'master' into rb-depreciate-controller-batch
Dec 11, 2023
bbcefc3
Update substrate/frame/staking/src/pallet/mod.rs
Dec 12, 2023
6536fba
Merge branch 'master' into rb-depreciate-controller-batch
Dec 12, 2023
9aa3af1
fix rustdoc
Dec 12, 2023
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/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl pallet_staking::Config for Runtime {
type TargetList = pallet_staking::UseValidatorsMap<Runtime>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<MAX_QUOTA_NOMINATIONS>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<5900>;
type HistoryDepth = frame_support::traits::ConstU32<84>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type EventListeners = ();
Expand Down
4 changes: 3 additions & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ parameter_types! {
pub const MaxNominators: u32 = 64;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub const MaxControllersInDeprecationBatch: u32 = 751;
}

impl pallet_staking::Config for Runtime {
Expand All @@ -686,7 +687,7 @@ impl pallet_staking::Config for Runtime {
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
type AdminOrigin = EnsureRoot<AccountId>;
type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxExposurePageSize = MaxExposurePageSize;
Expand All @@ -699,6 +700,7 @@ impl pallet_staking::Config for Runtime {
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type EventListeners = NominationPools;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
Expand Down
214 changes: 118 additions & 96 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominators: u32 = 64;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxControllersInDeprecationBatch: u32 = 5900;
pub OffchainRepeat: BlockNumber = 5;
pub HistoryDepth: u32 = 84;
}
Expand Down Expand Up @@ -674,6 +675,7 @@ impl pallet_staking::Config for Runtime {
// This a placeholder, to be introduced in the next PR as an instance of bags-list
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type HistoryDepth = HistoryDepth;
type EventListeners = NominationPools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl pallet_staking::Config for Test {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl pallet_staking::Config for Test {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl pallet_staking::Config for Runtime {
type NominationsQuota = pallet_staking::FixedNominationsQuota<MAX_QUOTA_NOMINATIONS>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = HistoryDepth;
type EventListeners = ();
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl pallet_staking::Config for Runtime {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl pallet_staking::Config for Test {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
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 @@ -119,6 +119,7 @@ impl pallet_staking::Config for Runtime {
type VoterList = VoterList;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type MaxUnlockingChunks = ConstU32<32>;
type HistoryDepth = ConstU32<84>;
type EventListeners = Pools;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nomination-pools/test-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl pallet_staking::Config for Runtime {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type EventListeners = Pools;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl pallet_staking::Config for Test {
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/root-offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl pallet_staking::Config for Test {
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type HistoryDepth = ConstU32<84>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type EventListeners = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type HistoryDepth = ConstU32<84>;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
Expand Down
34 changes: 34 additions & 0 deletions substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use codec::Decode;
use frame_election_provider_support::{bounds::DataProviderBounds, SortedListProvider};
use frame_support::{
pallet_prelude::*,
storage::bounded_vec::BoundedVec,
traits::{Currency, Get, Imbalance, UnfilteredDispatchable},
};
use sp_runtime::{
Expand Down Expand Up @@ -525,6 +526,39 @@ benchmarks! {
assert_eq!(Invulnerables::<T>::get().len(), v as usize);
}

deprecate_controller_batch {
// We pass a dynamic number of controllers to the benchmark, up to
// `MaxControllersInDeprecationBatch`.
let i in 0 .. T::MaxControllersInDeprecationBatch::get();

let mut controllers: Vec<_> = vec![];
let mut stashes: Vec<_> = vec![];
for n in 0..i as u32 {
let (stash, controller) = create_unique_stash_controller::<T>(
n,
100,
RewardDestination::Staked,
false
)?;
controllers.push(controller);
stashes.push(stash);
}
let bounded_controllers: BoundedVec<_, T::MaxControllersInDeprecationBatch> =
BoundedVec::try_from(controllers.clone()).unwrap();
}: _(RawOrigin::Root, bounded_controllers)
verify {
for n in 0..i as u32 {
let stash = &stashes[n as usize];
let controller = &controllers[n as usize];
// Ledger no longer keyed by controller.
assert_eq!(Ledger::<T>::get(controller), None);
// Bonded now maps to the stash.
assert_eq!(Bonded::<T>::get(stash), Some(stash.clone()));
// Ledger is now keyed by stash.
assert_eq!(Ledger::<T>::get(stash).unwrap().stash, *stash);
}
}

force_unstake {
// Slashing Spans
let s in 0 .. MAX_SPANS;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ parameter_types! {
pub static SlashDeferDuration: EraIndex = 0;
pub static Period: BlockNumber = 5;
pub static Offset: BlockNumber = 0;
pub static MaxControllersInDeprecationBatch: u32 = 5900;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
Expand Down Expand Up @@ -316,6 +317,7 @@ impl crate::pallet::pallet::Config for Test {
type NominationsQuota = WeightedNominationsQuota<16>;
type MaxUnlockingChunks = MaxUnlockingChunks;
type HistoryDepth = HistoryDepth;
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type EventListeners = EventListenerMock;
type BenchmarkingConfig = TestBenchmarkingConfig;
type WeightInfo = ();
Expand Down
56 changes: 53 additions & 3 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ pub mod pallet {
#[pallet::constant]
type MaxUnlockingChunks: Get<u32>;

/// The maximum amount of controller accounts that can be deprecated in one call.
type MaxControllersInDeprecationBatch: Get<u32>;
Ank4n marked this conversation as resolved.
Show resolved Hide resolved

/// Something that listens to staking updates and performs actions based on the data it
/// receives.
///
Expand Down Expand Up @@ -1323,18 +1326,17 @@ pub mod pallet {
pub fn set_controller(origin: OriginFor<T>) -> DispatchResult {
let stash = ensure_signed(origin)?;

// the bonded map and ledger are mutated directly as this extrinsic is related to a
// The bonded map and ledger are mutated directly as this extrinsic is related to a
// (temporary) passive migration.
Self::ledger(StakingAccount::Stash(stash.clone())).map(|ledger| {
let controller = ledger.controller()
.defensive_proof("Ledger's controller field didn't exist. The controller should have been fetched using StakingLedger.")
.ok_or(Error::<T>::NotController)?;

if controller == stash {
// stash is already its own controller.
// Stash is already its own controller.
return Err(Error::<T>::AlreadyPaired.into())
}
// update bond and ledger.
<Ledger<T>>::remove(controller);
<Bonded<T>>::insert(&stash, &stash);
<Ledger<T>>::insert(&stash, ledger);
Expand Down Expand Up @@ -1920,6 +1922,54 @@ pub mod pallet {

Ok(Pays::No.into())
}

/// Updates a batch of controller accounts to their corresponding stash account if they are
/// not the same. Ignores any controller accounts that do not exist, and does not operate if
/// the stash and controller are already the same.
///
/// Effects will be felt instantly (as soon as this function is completed successfully).
///
/// The dispatch origin must be `T::AdminOrigin`.
#[pallet::call_index(28)]
#[pallet::weight(T::WeightInfo::deprecate_controller_batch(controllers.len() as u32))]
pub fn deprecate_controller_batch(
origin: OriginFor<T>,
controllers: BoundedVec<T::AccountId, T::MaxControllersInDeprecationBatch>,
) -> DispatchResultWithPostInfo {
T::AdminOrigin::ensure_origin(origin)?;

// Ignore controllers that do not exist or are already the same as stash.
let filtered_batch_with_ledger: Vec<_> = controllers
.iter()
.filter_map(|controller| {
let ledger = Self::ledger(StakingAccount::Controller(controller.clone()));
ledger.ok().map_or(None, |ledger| {
// If the controller `RewardDestination` is still the deprecated
// `Controller` variant, skip deprecating this account.
let payee_deprecated = Payee::<T>::get(&ledger.stash) == {
#[allow(deprecated)]
RewardDestination::Controller
};

if ledger.stash != *controller && !payee_deprecated {
Some((controller.clone(), ledger))
} else {
None
}
})
})
.collect();

// Update unique pairs.
for (controller, ledger) in filtered_batch_with_ledger {
let stash = ledger.stash.clone();

<Bonded<T>>::insert(&stash, &stash);
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
<Ledger<T>>::remove(controller);
<Ledger<T>>::insert(stash, ledger);
}
Ok(Some(T::WeightInfo::deprecate_controller_batch(controllers.len() as u32)).into())
Ank4n marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
Loading
Loading