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

Deprecate RewardDestination::Controller #2380

Merged
merged 49 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4369870
use `DeprecatedController`, payout same as stash
Nov 17, 2023
a5537d6
add update_payee call
Nov 17, 2023
016d225
add migration test
Nov 17, 2023
446fe8f
get ci working
Nov 17, 2023
46a5062
rm unused payout_stakers_dead_controller
Nov 17, 2023
7dcef6d
stop using `DeprecatedController` variant
Nov 17, 2023
039d618
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 17, 2023
0119204
fix benchmarks
Nov 17, 2023
2e14496
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 17, 2023
18638c2
tidy up comments
Nov 17, 2023
2b98d99
annotate with deprecated
Nov 17, 2023
096ac39
revert to `Controller`
Nov 17, 2023
7c07d93
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 17, 2023
8edebd5
add update_payee benchamrk
Nov 17, 2023
7d8021c
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 17, 2023
af75c2f
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 17, 2023
5614c1c
replace weight call
Nov 17, 2023
797f68c
allow deprecatef in bench
Nov 17, 2023
ce4fdd3
fmt
Nov 17, 2023
e34d97b
add runtime weight
Nov 17, 2023
5caba0c
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 17, 2023
d652e2e
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 18, 2023
f0e3759
add error
Nov 19, 2023
34d7fd9
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 19, 2023
11de5a5
Update substrate/frame/staking/src/pallet/mod.rs
Nov 19, 2023
fef57b3
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 19, 2023
aaf5233
Update substrate/frame/staking/src/pallet/mod.rs
Nov 20, 2023
a83b9bd
rm controller_deprecated
Nov 20, 2023
30a6b5c
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 20, 2023
45e048f
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 20, 2023
4bb35d3
add deprecation removal date
Nov 21, 2023
0f95d05
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 21, 2023
06799f2
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 21, 2023
98860f0
keep Controller payout until post-migration
Nov 21, 2023
2c5cd1f
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 21, 2023
c94ab24
revert
Nov 21, 2023
78d5e38
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 21, 2023
89a1ed1
return error on not controllererror
Nov 21, 2023
c0299b8
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 21, 2023
e9fe18a
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 21, 2023
02f5f55
use deprecated!
Nov 21, 2023
5363cc3
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 21, 2023
cec0430
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 21, 2023
a39745f
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Nov 21, 2023
c8f1d01
Merge branch 'master' into rb-deprecate-set-payee-controller
Nov 22, 2023
90d4ee1
polishes
Nov 22, 2023
568c676
Merge branch 'rb-deprecate-set-payee-controller' of https://github.co…
Nov 22, 2023
a1fdb2c
rm getter
Nov 22, 2023
ee44468
don't use default
Nov 22, 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
42 changes: 0 additions & 42 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,48 +442,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Staking::CurrentEra` (r:1 w:0)
/// Proof: `Staking::CurrentEra` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:1 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasValidatorReward` (r:1 w:0)
/// Proof: `Staking::ErasValidatorReward` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:65 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Ledger` (r:1 w:1)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:1 w:1)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:0)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(67), added: 2542, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:66 w:66)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Staking::ClaimedRewards` (r:1 w:1)
/// Proof: `Staking::ClaimedRewards` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::ErasStakersPaged` (r:1 w:0)
/// Proof: `Staking::ErasStakersPaged` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::ErasRewardPoints` (r:1 w:0)
/// Proof: `Staking::ErasRewardPoints` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::ErasValidatorPrefs` (r:1 w:0)
/// Proof: `Staking::ErasValidatorPrefs` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Staking::Payee` (r:65 w:0)
/// Proof: `Staking::Payee` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 64]`.
fn payout_stakers_dead_controller(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `6895 + n * (156 ±0)`
// Estimated: `9802 + n * (2603 ±0)`
// Minimum execution time: 114_338_000 picoseconds.
Weight::from_parts(138_518_124, 0)
.saturating_add(Weight::from_parts(0, 9802))
// Standard Error: 53_621
.saturating_add(Weight::from_parts(25_676_781, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(14))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes(5))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 2603).saturating_mul(n.into()))
}
/// Storage: `Staking::Bonded` (r:65 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Ledger` (r:65 w:65)
Expand Down
38 changes: 2 additions & 36 deletions substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ benchmarks! {
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Staked);
whitelist_account!(controller);
}: _(RawOrigin::Signed(controller), RewardDestination::Controller)
}: _(RawOrigin::Signed(controller.clone()), RewardDestination::Account(controller.clone()))
verify {
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Controller);
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Account(controller));
}

set_controller {
Expand Down Expand Up @@ -551,40 +551,6 @@ benchmarks! {
assert_eq!(UnappliedSlashes::<T>::get(&era).len(), (MAX_SLASHES - s) as usize);
}

payout_stakers_dead_controller {
let n in 0 .. T::MaxExposurePageSize::get() as u32;
let (validator, nominators) = create_validator_with_nominators::<T>(
n,
T::MaxExposurePageSize::get() as u32,
true,
true,
RewardDestination::Controller,
)?;

let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));

let caller = whitelisted_caller();
let validator_controller = <Bonded<T>>::get(&validator).unwrap();
let balance_before = T::Currency::free_balance(&validator_controller);
for (_, controller) in &nominators {
let balance = T::Currency::free_balance(controller);
ensure!(balance.is_zero(), "Controller has balance, but should be dead.");
}
}: payout_stakers_by_page(RawOrigin::Signed(caller), validator, current_era, 0)
verify {
let balance_after = T::Currency::free_balance(&validator_controller);
ensure!(
balance_before < balance_after,
"Balance of validator controller should have increased after payout.",
);
for (_, controller) in &nominators {
let balance = T::Currency::free_balance(controller);
ensure!(!balance.is_zero(), "Payout not given to controller.");
}
}

payout_stakers_alive_staked {
let n in 0 .. T::MaxExposurePageSize::get() as u32;
let (validator, nominators) = create_validator_with_nominators::<T>(
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ pub enum RewardDestination<AccountId> {
Staked,
/// Pay into the stash account, not increasing the amount at stake.
Stash,
/// Pay into the controller account.
Controller,
// Controller accounts are deprecated. This variant now behaves the same as `Stash` variant".
DeprecatedController,
/// Pay into a specified account.
Account(AccountId),
/// Receive no reward.
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ pub(crate) fn current_era() -> EraIndex {

pub(crate) fn bond(who: AccountId, val: Balance) {
let _ = Balances::make_free_balance_be(&who, val);
assert_ok!(Staking::bond(RuntimeOrigin::signed(who), val, RewardDestination::Controller));
assert_ok!(Staking::bond(RuntimeOrigin::signed(who), val, RewardDestination::Stash));
}

pub(crate) fn bond_validator(who: AccountId, val: Balance) {
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@ impl<T: Config> Pallet<T> {

let dest = Self::payee(StakingAccount::Stash(stash.clone()));
let maybe_imbalance = match dest {
RewardDestination::Controller => Self::bonded(stash)
.map(|controller| T::Currency::deposit_creating(&controller, amount)),
RewardDestination::Stash => T::Currency::deposit_into_existing(stash, amount).ok(),
// Note: Controller accounts are being deprecated and will no longer point to a separate
// account. `Controller` variant now points to the `stash`.
RewardDestination::Stash | RewardDestination::DeprecatedController =>
T::Currency::deposit_into_existing(stash, amount).ok(),
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
RewardDestination::Staked => Self::ledger(Stash(stash.clone()))
.and_then(|mut ledger| {
ledger.active += amount;
Expand Down
42 changes: 39 additions & 3 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,20 @@ pub mod pallet {
payee: RewardDestination<T::AccountId>,
) -> DispatchResult {
let controller = ensure_signed(origin)?;
let ledger = Self::ledger(Controller(controller))?;
let ledger = Self::ledger(Controller(controller.clone()))?;

// Ensure that the `DeprecatedController` variant is not assigned. Controller accounts
// are being deprecated and the `DeprecatedController` variant is being phased out via
// the `update_payee` call.
let payee_final = if payee == RewardDestination::DeprecatedController {
RewardDestination::Account(controller)
} else {
payee
};

let _ = ledger
.set_payee(payee)
.defensive_proof("ledger was retrieved from storage, thus its bonded; qed.");
.set_payee(payee_final)
.defensive_proof("ledger was retrieved from storage, thus its bonded; qed.")?;

Ok(())
}
Expand Down Expand Up @@ -1872,6 +1882,32 @@ pub mod pallet {
ensure_signed(origin)?;
Self::do_payout_stakers_by_page(validator_stash, era, page)
}

/// Migrates an account's `RewardDestination::Controller` to
/// `RewardDestination::Account(controller)`.
///
/// Effects will be felt instantly (as soon as this function is completed successfully).
///
/// This will waive the transaction fee if the `payee` is successfully migrated.
#[pallet::call_index(27)]
#[pallet::weight(T::WeightInfo::set_payee())]
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
pub fn update_payee(
origin: OriginFor<T>,
controller: T::AccountId,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
let ledger = Self::ledger(StakingAccount::Controller(controller.clone()))?;

if Payee::<T>::get(&ledger.stash) != RewardDestination::DeprecatedController {
return Ok(Pays::Yes.into())
}

let _ = ledger
.set_payee(RewardDestination::Account(controller))
.defensive_proof("ledger was retrieved from storage, thus its bonded; qed.")?;
rossbulat marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Loading
Loading