pallet-staking: Add extrinsic force_apply_min_commission (#10786)

* pallet-staking: Add extrinsic `force_apply_min_commission`

* Add benchmarks

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Bound iteration by  max_validator_count

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Only apply to 1 validator

* Update doc comments

* Uncomment tests

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Accept signed origins

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Remove contains_key check

* Add test for try_mutate_exists

* Impove try_mutate_exists docs

* Delete redundant try_mutate_exists tests;

* Delete residual from removed test

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Return an error when the stash does not exist

* Update try_mutate_exist doc wording

* Update frame/staking/src/pallet/mod.rs

* Apply suggestions from code review

Co-authored-by: Parity Bot <admin@parity.io>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Zeke Mostov
2022-02-10 13:22:26 -08:00
committed by GitHub
parent 20b2bba1cd
commit 83eed8018b
10 changed files with 225 additions and 110 deletions
+22
View File
@@ -1616,6 +1616,28 @@ pub mod pallet {
Self::chill_stash(&stash);
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::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(())
}
}
}