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
@@ -266,6 +266,8 @@ pub trait StorageMap<K: FullEncode, V: FullCodec> {
) -> R;
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
fn try_mutate_exists<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Option<V>) -> Result<R, E>>(
key: KeyArg,
f: F,
@@ -608,6 +610,8 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
F: FnOnce(&mut Option<V>) -> R;
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
fn try_mutate_exists<KArg1, KArg2, R, E, F>(k1: KArg1, k2: KArg2, f: F) -> Result<R, E>
where
KArg1: EncodeLike<K1>,
@@ -735,6 +739,8 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
F: FnOnce(&mut Option<V>) -> R;
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
fn try_mutate_exists<KArg, R, E, F>(key: KArg, f: F) -> Result<R, E>
where
KArg: EncodeLikeTuple<K::KArg> + TupleToEncodedIter,
@@ -190,6 +190,8 @@ where
}
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
pub fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<Key> + Clone,
@@ -264,6 +264,8 @@ where
}
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
pub fn try_mutate_exists<KArg1, KArg2, R, E, F>(k1: KArg1, k2: KArg2, f: F) -> Result<R, E>
where
KArg1: EncodeLike<Key1>,
@@ -174,6 +174,8 @@ where
}
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
pub fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<Key>,
@@ -217,6 +217,8 @@ where
}
/// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`.
/// `f` will always be called with an option representing if the storage item exists (`Some<V>`)
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
pub fn try_mutate_exists<KArg, R, E, F>(key: KArg, f: F) -> Result<R, E>
where
KArg: EncodeLikeTuple<Key::KArg> + TupleToEncodedIter,