Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Deprecates the chill_other extrinsic in staking #14187

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ benchmarks! {
assert!(T::VoterList::contains(&stash));

whitelist_account!(controller);
}: _(RawOrigin::Signed(controller))
}: _(RawOrigin::Signed(controller), None)
verify {
assert!(!T::VoterList::contains(&stash));
}
Expand Down Expand Up @@ -897,7 +897,7 @@ benchmarks! {
)?;

let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), controller)
}: chill(RawOrigin::Signed(caller), Some(controller))
verify {
assert!(!T::VoterList::contains(&stash));
}
Expand Down
4 changes: 3 additions & 1 deletion frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,9 @@ impl<T: Config> StakingInterface for Pallet<T> {
// defensive-only: any account bonded via this interface has the stash set as the
// controller, but we have to be sure. Same comment anywhere else that we read this.
let ctrl = Self::bonded(who).ok_or(Error::<T>::NotStash)?;
Self::chill(RawOrigin::Signed(ctrl).into())
Self::chill(RawOrigin::Signed(ctrl).into(), None)
.map_err(|with_post| with_post.error)
.map(|_| ())
}

fn withdraw_unbonded(
Expand Down
129 changes: 61 additions & 68 deletions frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ pub mod pallet {
// Only check limits if they are not already a validator.
if !Validators::<T>::contains_key(stash) {
// If this error is reached, we need to adjust the `MinValidatorBond` and start
// calling `chill_other`. Until then, we explicitly block new validators to protect
// calling `chill`. Until then, we explicitly block new validators to protect
// the runtime.
if let Some(max_validators) = MaxValidatorsCount::<T>::get() {
ensure!(
Expand Down Expand Up @@ -1129,7 +1129,7 @@ pub mod pallet {
// Only check limits if they are not already a nominator.
if !Nominators::<T>::contains_key(stash) {
// If this error is reached, we need to adjust the `MinNominatorBond` and start
// calling `chill_other`. Until then, we explicitly block new nominators to protect
// calling `chill`. Until then, we explicitly block new nominators to protect
// the runtime.
if let Some(max_nominators) = MaxNominatorsCount::<T>::get() {
ensure!(
Expand Down Expand Up @@ -1172,25 +1172,6 @@ pub mod pallet {
Ok(())
}

/// Declare no desire to either validate or nominate.
///
/// Effects will be felt at the beginning of the next era.
///
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
///
/// ## Complexity
/// - Independent of the arguments. Insignificant complexity.
/// - Contains one read.
/// - Writes are limited to the `origin` account key.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::chill())]
pub fn chill(origin: OriginFor<T>) -> DispatchResult {
let controller = ensure_signed(origin)?;
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
Self::chill_stash(&ledger.stash);
Ok(())
}

/// (Re-)set the payment target for a controller.
///
/// Effects will be felt instantly (as soon as this function is completed successfully).
Expand Down Expand Up @@ -1634,6 +1615,42 @@ pub mod pallet {
config_op_exp!(MinCommission<T>, min_commission);
Ok(())
}

/// Force a validator to have at least the minimum commission. This will not affect a
/// validator who already has a commission greater than or equal to the minimum. Any account
/// can call this.
#[pallet::call_index(24)]
#[pallet::weight(T::WeightInfo::force_apply_min_commission())]
pub fn force_apply_min_commission(
origin: OriginFor<T>,
validator_stash: T::AccountId,
) -> DispatchResult {
ensure_signed(origin)?;
let min_commission = MinCommission::<T>::get();
Validators::<T>::try_mutate_exists(validator_stash, |maybe_prefs| {
maybe_prefs
.as_mut()
.map(|prefs| {
(prefs.commission < min_commission)
.then(|| prefs.commission = min_commission)
})
.ok_or(Error::<T>::NotStash)
})?;
Ok(())
}

/// Sets the minimum amount of commission that each validators must maintain.
///
/// This call has lower privilege requirements than `set_staking_config` and can be called
/// by the `T::AdminOrigin`. Root can always call this.
#[pallet::call_index(25)]
#[pallet::weight(T::WeightInfo::set_min_commission())]
pub fn set_min_commission(origin: OriginFor<T>, new: Perbill) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
MinCommission::<T>::put(new);
Ok(())
}

/// Declare a `controller` to stop participating as either a validator or nominator.
///
/// Effects will be felt at the beginning of the next era.
Expand All @@ -1660,13 +1677,13 @@ pub mod pallet {
///
/// This can be helpful if bond requirements are updated, and we need to remove old users
/// who do not satisfy these requirements.
#[pallet::call_index(23)]
#[pallet::call_index(26)]
#[pallet::weight(T::WeightInfo::chill_other())]
pub fn chill_other(origin: OriginFor<T>, controller: T::AccountId) -> DispatchResult {
// Anyone can call this function.
pub fn chill(
origin: OriginFor<T>,
controller: Option<T::AccountId>,
) -> DispatchResultWithPostInfo {
let caller = ensure_signed(origin)?;
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let stash = ledger.stash;

// In order for one user to chill another user, the following conditions must be met:
//
Expand All @@ -1683,13 +1700,16 @@ pub mod pallet {
// threshold bond required.
//
// Otherwise, if caller is the same as the controller, this is just like `chill`.
let used_weight = if let Some(controller) = controller {
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let stash = ledger.stash;

// caller controlls the controller.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems comment is not correct. I believe this condition is to check if Nominator Preference is undecodeable?

if Nominators::<T>::contains_key(&stash) && Nominators::<T>::get(&stash).is_none() {
Self::chill_stash(&stash);
return Ok(Some(T::WeightInfo::chill()).into())
}

if Nominators::<T>::contains_key(&stash) && Nominators::<T>::get(&stash).is_none() {
Self::chill_stash(&stash);
return Ok(())
}

if caller != controller {
let threshold = ChillThreshold::<T>::get().ok_or(Error::<T>::CannotChillOther)?;
let min_active_bond = if Nominators::<T>::contains_key(&stash) {
let max_nominator_count =
Expand All @@ -1714,45 +1734,18 @@ pub mod pallet {
};

ensure!(ledger.active < min_active_bond, Error::<T>::CannotChillOther);
}

Self::chill_stash(&stash);
Ok(())
}
Self::chill_stash(&stash);
T::WeightInfo::chill_other()
} else {
let ledger = Self::ledger(&caller).ok_or(Error::<T>::NotController)?;
let stash = ledger.stash;

/// Force a validator to have at least the minimum commission. This will not affect a
/// validator who already has a commission greater than or equal to the minimum. Any account
/// can call this.
#[pallet::call_index(24)]
#[pallet::weight(T::WeightInfo::force_apply_min_commission())]
pub fn force_apply_min_commission(
origin: OriginFor<T>,
validator_stash: T::AccountId,
) -> DispatchResult {
ensure_signed(origin)?;
let min_commission = MinCommission::<T>::get();
Validators::<T>::try_mutate_exists(validator_stash, |maybe_prefs| {
maybe_prefs
.as_mut()
.map(|prefs| {
(prefs.commission < min_commission)
.then(|| prefs.commission = min_commission)
})
.ok_or(Error::<T>::NotStash)
})?;
Ok(())
}
Self::chill_stash(&stash);
T::WeightInfo::chill()
};

/// Sets the minimum amount of commission that each validators must maintain.
///
/// This call has lower privilege requirements than `set_staking_config` and can be called
/// by the `T::AdminOrigin`. Root can always call this.
#[pallet::call_index(25)]
#[pallet::weight(T::WeightInfo::set_min_commission())]
pub fn set_min_commission(origin: OriginFor<T>, new: Perbill) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
MinCommission::<T>::put(new);
Ok(())
Ok(Some(used_weight).into())
}
}
}
Expand Down
Loading