Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
238 changes: 106 additions & 132 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs

Large diffs are not rendered by default.

54 changes: 16 additions & 38 deletions substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,28 @@ benchmarks! {
}

set_payee {
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, RewardDestination::Staked)?;
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));
}

update_payee {
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, RewardDestination::Staked)?;
Payee::<T>::insert(&stash, {
#[allow(deprecated)]
RewardDestination::Controller
});
whitelist_account!(controller);
}: _(RawOrigin::Signed(controller.clone()), controller.clone())
verify {
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Account(controller));
}

set_controller {
let (stash, ctlr) = create_unique_stash_controller::<T>(9000, 100, Default::default(), false)?;
let (stash, ctlr) = create_unique_stash_controller::<T>(9000, 100, RewardDestination::Staked, false)?;
// ensure `ctlr` is the currently stored controller.
assert!(!Ledger::<T>::contains_key(&stash));
assert!(Ledger::<T>::contains_key(&ctlr));
Expand Down Expand Up @@ -551,40 +563,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
6 changes: 4 additions & 2 deletions substrate/frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@
//! [`Payee`] storage item (see
//! [`set_payee`](Call::set_payee)), to be one of the following:
//!
//! - Controller account, (obviously) not increasing the staked value.
//! - Stash account, not increasing the staked value.
//! - Stash account, also increasing the staked value.
//! - Any other account, sent as free balance.
//!
//! ### Additional Fund Management Operations
//!
Expand Down Expand Up @@ -404,7 +404,9 @@ pub enum RewardDestination<AccountId> {
Staked,
/// Pay into the stash account, not increasing the amount at stake.
Stash,
/// Pay into the controller account.
#[deprecated(
note = "`Controller` will be removed after January 2024. Use `Account(controller)` instead. This variant now behaves the same as `Stash` variant."
)]
Controller,
/// Pay into a specified account.
Account(AccountId),
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
13 changes: 10 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,8 @@ 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(),
RewardDestination::Stash =>
T::Currency::deposit_into_existing(stash, amount).ok(),
RewardDestination::Staked => Self::ledger(Stash(stash.clone()))
.and_then(|mut ledger| {
ledger.active += amount;
Expand All @@ -357,6 +356,14 @@ impl<T: Config> Pallet<T> {
RewardDestination::Account(dest_account) =>
Some(T::Currency::deposit_creating(&dest_account, amount)),
RewardDestination::None => None,
#[allow(deprecated)]
RewardDestination::Controller => Self::bonded(stash)
.map(|controller| {
defensive!("Paying out controller as reward destination which is deprecated and should be migrated");
// This should never happen once payees with a `Controller` variant have been migrated.
// But if it does, just pay the controller account.
T::Currency::deposit_creating(&controller, amount)
}),
};
maybe_imbalance
.map(|imbalance| (imbalance, Self::payee(StakingAccount::Stash(stash.clone()))))
Expand Down
45 changes: 43 additions & 2 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ pub mod pallet {
CommissionTooLow,
/// Some bound is not met.
BoundNotMet,
/// Used when attempting to use deprecated controller account logic.
ControllerDeprecated,
}

#[pallet::hooks]
Expand Down Expand Up @@ -1283,10 +1285,19 @@ 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!(
(payee != {
#[allow(deprecated)]
RewardDestination::Controller
}),
Error::<T>::ControllerDeprecated
);

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

Ok(())
}
Expand Down Expand Up @@ -1872,6 +1883,36 @@ 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::update_payee())]
pub fn update_payee(
origin: OriginFor<T>,
controller: T::AccountId,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
let ledger = Self::ledger(StakingAccount::Controller(controller.clone()))?;

ensure!(
(Payee::<T>::get(&ledger.stash) == {
#[allow(deprecated)]
RewardDestination::Controller
}),
Error::<T>::NotController
);

let _ = ledger
.set_payee(RewardDestination::Account(controller))
.defensive_proof("ledger should have been previously retrieved from storage.")?;

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

Expand Down
Loading