mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 19:11:04 +00:00
Deprecate RewardDestination::Controller (#2380)
Deprecates `RewardDestination::Controller` variant. - [x] `RewardDestination::Controller` annotated with `#[deprecated]`. - [x] `Controller` variant is now handled the same way as `Stash` in `payout_stakers`. - [x] `set_payee` errors if `RewardDestination::Controller` is provided. - [x] Added `update_payee` call to lazily migrate `RewardDestination::Controller` `Payee` storage entries to `RewardDestination::Account(controller)` . - [x] `payout_stakers_dead_controller` has been removed from benches & weights - was not used. - [x] Tests no longer use `RewardDestination::Controller`. --------- Co-authored-by: command-bot <> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> Co-authored-by: georgepisaltu <52418509+georgepisaltu@users.noreply.github.com>
This commit is contained in:
@@ -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;
|
||||
@@ -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()))))
|
||||
|
||||
@@ -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]
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user