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

Remove staking controller account logic from pallets & runtimes #5449

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn genesis() -> Storage {
minimum_validator_count: 1,
stakers: validators::initial_authorities()
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, pallet_staking::StakerStatus::Validator))
.map(|x| (x.0.clone(), STASH, pallet_staking::StakerStatus::Validator))
.collect(),
invulnerables: validators::initial_authorities().iter().map(|x| x.0.clone()).collect(),
force_era: pallet_staking::Forcing::ForceNone,
Expand Down
4 changes: 2 additions & 2 deletions polkadot/runtime/common/src/try_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
let mut unstaked_err = 0;
let mut unstaked_slashed = 0;

let all_stakers = Ledger::<T>::iter().map(|(ctrl, l)| (ctrl, l.stash)).collect::<BTreeSet<_>>();
let all_stakers = Ledger::<T>::iter().map(|(_, l)| l.stash).collect::<BTreeSet<_>>();
let mut all_exposed = BTreeSet::new();
ErasStakers::<T>::iter().for_each(|(_, val, expo)| {
all_exposed.insert(val);
Expand All @@ -43,7 +43,7 @@ where

let eligible = all_stakers
.iter()
.filter_map(|(ctrl, stash)| all_exposed.contains(stash).then_some(ctrl))
.filter(|stash| all_exposed.contains(stash))
.collect::<Vec<_>>();

log::info!(
Expand Down
1 change: 0 additions & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ 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 = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = ();
Expand Down
2 changes: 0 additions & 2 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ parameter_types! {
// of nominators.
pub const MaxNominators: u32 = 64;
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 @@ -751,7 +750,6 @@ 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 = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = (NominationPools, DelegatedStaking);
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
Expand Down
50 changes: 0 additions & 50 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,36 +318,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Staking::Ledger` (r:1 w:0)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:1 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Payee` (r:1 w:1)
/// Proof: `Staking::Payee` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`)
fn update_payee() -> Weight {
// Proof Size summary in bytes:
// Measured: `932`
// Estimated: `4556`
// Minimum execution time: 23_428_000 picoseconds.
Weight::from_parts(24_080_000, 0)
.saturating_add(Weight::from_parts(0, 4556))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Staking::Bonded` (r:1 w:1)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Ledger` (r:2 w:2)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
fn set_controller() -> Weight {
// Proof Size summary in bytes:
// Measured: `865`
// Estimated: `8122`
// Minimum execution time: 21_159_000 picoseconds.
Weight::from_parts(21_706_000, 0)
.saturating_add(Weight::from_parts(0, 8122))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Staking::ValidatorCount` (r:0 w:1)
/// Proof: `Staking::ValidatorCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
fn set_validator_count() -> Weight {
Expand Down Expand Up @@ -406,26 +376,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(Weight::from_parts(11_785, 0).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Staking::Ledger` (r:1502 w:1502)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:751 w:751)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Payee` (r:751 w:0)
/// Proof: `Staking::Payee` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`)
/// The range of component `i` is `[0, 751]`.
fn deprecate_controller_batch(i: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `680 + i * (227 ±0)`
// Estimated: `990 + i * (7132 ±0)`
// Minimum execution time: 4_321_000 picoseconds.
Weight::from_parts(4_407_000, 0)
.saturating_add(Weight::from_parts(0, 990))
// Standard Error: 37_239
.saturating_add(Weight::from_parts(21_300_598, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(i.into())))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(i.into())))
.saturating_add(Weight::from_parts(0, 7132).saturating_mul(i.into()))
}
/// Storage: `Staking::SlashingSpans` (r:1 w:1)
/// Proof: `Staking::SlashingSpans` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::Bonded` (r:1 w:1)
Expand Down
36 changes: 36 additions & 0 deletions prdoc/pr_5449.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
title: Remove staking controller account logic from codebase.

doc:
- audience: Runtime Dev
description:
Removes controller account logic from the pallets and runtimes.

crates:
- name: pallet-staking
bump: minor
- name: pallet-babe
bump: patch
- name: pallet-fast-unstake
bump: minor
- name: pallet-grandpa
bump: patch
- name: pallet-beefy
bump: patch
- name: pallet-delegated-staking
bump: patch
- name: pallet-nomination-pools-benchmarking
bump: patch
- name: pallet-offences-benchmarking
bump: patch
- name: pallet-session-benchmarking
bump: patch
- name: pallet-root-offences
bump: patch
- name: pallet-nomination-pools
bump: patch
- name: sp-staking
bump: patch
- name: polkadot-runtime-common
bump: patch
- name: westend-runtime
bump: patch
6 changes: 3 additions & 3 deletions substrate/bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ fn configure_accounts(
)>,
Vec<AccountId>,
usize,
Vec<(AccountId, AccountId, Balance, StakerStatus<AccountId>)>,
Vec<(AccountId, Balance, StakerStatus<AccountId>)>,
) {
let mut endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
vec![
Expand Down Expand Up @@ -338,7 +338,7 @@ fn configure_accounts(
let mut rng = rand::thread_rng();
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.0.clone(), stash, StakerStatus::Validator))
.map(|x| (x.0.clone(), stash, StakerStatus::Validator))
.chain(initial_nominators.iter().map(|x| {
use rand::{seq::SliceRandom, Rng};
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
Expand All @@ -349,7 +349,7 @@ fn configure_accounts(
.into_iter()
.map(|choice| choice.0.clone())
.collect::<Vec<_>>();
(x.clone(), x.clone(), stash, StakerStatus::Nominator(nominations))
(x.clone(), stash, StakerStatus::Nominator(nominations))
}))
.collect::<Vec<_>>();

Expand Down
2 changes: 0 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ parameter_types! {
pub const SlashDeferDuration: sp_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominators: u32 = 64;
pub const MaxControllersInDeprecationBatch: u32 = 5900;
pub OffchainRepeat: BlockNumber = 5;
pub HistoryDepth: u32 = 84;
}
Expand Down Expand Up @@ -694,7 +693,6 @@ 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
6 changes: 3 additions & 3 deletions substrate/bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pub fn config_endowed(extra_endowed: Vec<AccountId>) -> RuntimeGenesisConfig {
},
staking: StakingConfig {
stakers: vec![
(dave(), dave(), 111 * DOLLARS, StakerStatus::Validator),
(eve(), eve(), 100 * DOLLARS, StakerStatus::Validator),
(ferdie(), ferdie(), 100 * DOLLARS, StakerStatus::Validator),
(dave(), 111 * DOLLARS, StakerStatus::Validator),
(eve(), 100 * DOLLARS, StakerStatus::Validator),
(ferdie(), 100 * DOLLARS, StakerStatus::Validator),
],
validator_count: 3,
minimum_validator_count: 0,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes

// controllers are same as stash
let stakers: Vec<_> = (0..authorities.len())
.map(|i| (i as u64, i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
.map(|i| (i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
.collect();

let staking_config = pallet_staking::GenesisConfig::<Test> {
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ impl ExtBuilder {
.assimilate_storage(&mut t)
.unwrap();

// controllers are same as stash
let stakers: Vec<_> = (0..self.authorities.len())
.map(|i| (i as u64, i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
.map(|i| (i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
.collect();

let staking_config = pallet_staking::GenesisConfig::<Test> {
Expand Down
3 changes: 0 additions & 3 deletions substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,16 @@ impl ExtBuilder {

let stakers = vec![
(
GENESIS_VALIDATOR,
GENESIS_VALIDATOR,
1000,
sp_staking::StakerStatus::<AccountId>::Validator,
),
(
GENESIS_NOMINATOR_ONE,
GENESIS_NOMINATOR_ONE,
100,
sp_staking::StakerStatus::<AccountId>::Nominator(vec![1]),
),
(
GENESIS_NOMINATOR_TWO,
GENESIS_NOMINATOR_TWO,
200,
sp_staking::StakerStatus::<AccountId>::Nominator(vec![1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,27 +381,27 @@ pub struct StakingExtBuilder {
min_validator_bond: Balance,
status: BTreeMap<AccountId, StakerStatus<AccountId>>,
stakes: BTreeMap<AccountId, Balance>,
stakers: Vec<(AccountId, AccountId, Balance, StakerStatus<AccountId>)>,
stakers: Vec<(AccountId, Balance, StakerStatus<AccountId>)>,
}

impl Default for StakingExtBuilder {
fn default() -> Self {
let stakers = vec![
// (stash, ctrl, stake, status)
// (stash, stake, status)
// these two will be elected in the default test where we elect 2.
(11, 11, 1000, StakerStatus::<AccountId>::Validator),
(21, 21, 1000, StakerStatus::<AccountId>::Validator),
(11, 1000, StakerStatus::<AccountId>::Validator),
(21, 1000, StakerStatus::<AccountId>::Validator),
// loser validators if validator_count() is default.
(31, 31, 500, StakerStatus::<AccountId>::Validator),
(41, 41, 1500, StakerStatus::<AccountId>::Validator),
(51, 51, 1500, StakerStatus::<AccountId>::Validator),
(61, 61, 1500, StakerStatus::<AccountId>::Validator),
(71, 71, 1500, StakerStatus::<AccountId>::Validator),
(81, 81, 1500, StakerStatus::<AccountId>::Validator),
(91, 91, 1500, StakerStatus::<AccountId>::Validator),
(101, 101, 500, StakerStatus::<AccountId>::Validator),
(31, 500, StakerStatus::<AccountId>::Validator),
(41, 1500, StakerStatus::<AccountId>::Validator),
(51, 1500, StakerStatus::<AccountId>::Validator),
(61, 1500, StakerStatus::<AccountId>::Validator),
(71, 1500, StakerStatus::<AccountId>::Validator),
(81, 1500, StakerStatus::<AccountId>::Validator),
(91, 1500, StakerStatus::<AccountId>::Validator),
(101, 500, StakerStatus::<AccountId>::Validator),
// an idle validator
(201, 201, 1000, StakerStatus::<AccountId>::Idle),
(201, 1000, StakerStatus::<AccountId>::Idle),
];

Self {
Expand Down Expand Up @@ -479,18 +479,6 @@ impl Default for BalancesExtBuilder {
(2, 20),
(3, 300),
(4, 400),
// controllers (still used in some tests. Soon to be deprecated).
(10, 100),
(20, 100),
(30, 100),
(40, 100),
(50, 100),
(60, 100),
(70, 100),
(80, 100),
(90, 100),
(100, 100),
(200, 100),
// stashes
(11, 1000),
(21, 2000),
Expand Down Expand Up @@ -541,15 +529,15 @@ impl ExtBuilder {

let mut stakers = self.staking_builder.stakers.clone();
self.staking_builder.status.clone().into_iter().for_each(|(stash, status)| {
let (_, _, _, ref mut prev_status) = stakers
let (_, _, ref mut prev_status) = stakers
.iter_mut()
.find(|s| s.0 == stash)
.expect("set_status staker should exist; qed");
*prev_status = status;
});
// replaced any of the stakes if needed.
self.staking_builder.stakes.clone().into_iter().for_each(|(stash, stake)| {
let (_, _, ref mut prev_stake, _) = stakers
let (_, ref mut prev_stake, _) = stakers
.iter_mut()
.find(|s| s.0 == stash)
.expect("set_stake staker should exits; qed.");
Expand Down
14 changes: 6 additions & 8 deletions substrate/frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ pub mod pallet {
#[pallet::error]
#[cfg_attr(test, derive(PartialEq))]
pub enum Error<T> {
/// The provided Controller account was not found.
/// The provided stash account was not found.
///
/// This means that the given account is not bonded.
NotController,
NotStash,
/// The bonded account has already been queued.
AlreadyQueued,
/// The bonded account has active unlocking chunks.
Expand Down Expand Up @@ -331,11 +331,10 @@ pub mod pallet {
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::register_fast_unstake())]
pub fn register_fast_unstake(origin: OriginFor<T>) -> DispatchResult {
let ctrl = ensure_signed(origin)?;
let signed = ensure_signed(origin)?;

ensure!(ErasToCheckPerBlock::<T>::get() != 0, Error::<T>::CallNotAllowed);
let stash_account =
T::Staking::stash_by_ctrl(&ctrl).map_err(|_| Error::<T>::NotController)?;
let stash_account = T::Staking::stash(&signed).map_err(|_| Error::<T>::NotStash)?;
ensure!(!Queue::<T>::contains_key(&stash_account), Error::<T>::AlreadyQueued);
ensure!(!Self::is_head(&stash_account), Error::<T>::AlreadyHead);
ensure!(!T::Staking::is_unbonding(&stash_account)?, Error::<T>::NotFullyBonded);
Expand Down Expand Up @@ -372,12 +371,11 @@ pub mod pallet {
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::deregister())]
pub fn deregister(origin: OriginFor<T>) -> DispatchResult {
let ctrl = ensure_signed(origin)?;
let signed = ensure_signed(origin)?;

ensure!(ErasToCheckPerBlock::<T>::get() != 0, Error::<T>::CallNotAllowed);

let stash_account =
T::Staking::stash_by_ctrl(&ctrl).map_err(|_| Error::<T>::NotController)?;
let stash_account = T::Staking::stash(&signed).map_err(|_| Error::<T>::NotStash)?;
ensure!(Queue::<T>::contains_key(&stash_account), Error::<T>::NotQueued);
ensure!(!Self::is_head(&stash_account), Error::<T>::AlreadyHead);
let deposit = Queue::<T>::take(stash_account.clone());
Expand Down
Loading
Loading