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

Commit

Permalink
Add Control to Growth of the Staking Pallet (#8920)
Browse files Browse the repository at this point in the history
* start count

* track count

* add max limit

* min bonds for participating

* respect min bond when unbonding

* revert a bit of u32

* fix merge

* more merge fixes

* update to `Current*`

* add helper functions

* Update frame/staking/src/lib.rs

Co-authored-by: Kian Paimani <[email protected]>

* fix

* minbond as storage

* checkpoint

* chill_other

* better bond tracking

* MinBond to MinNominatorBond

* better doc

* use helper function

* oops

* simple hard limits to validators / nominators.

* better doc

* update storage version

* fix tests

* enable migrations

* min bond tests

* chill other tests

* tests for max cap

* check `None` on cap too

* benchmarks

* Update frame/staking/src/lib.rs

* Update frame/staking/src/lib.rs

Co-authored-by: Zeke Mostov <[email protected]>

* Update frame/staking/src/lib.rs

Co-authored-by: Zeke Mostov <[email protected]>

* Update frame/staking/src/tests.rs

Co-authored-by: Zeke Mostov <[email protected]>

* fix benchmark

* cargo run --release --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

* nits

* fix reap_stash benchmark

* remove lower bound to min bond

Co-authored-by: kianenigma <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: Parity Bot <[email protected]>
Co-authored-by: Zeke Mostov <[email protected]>
  • Loading branch information
5 people committed Jun 17, 2021
1 parent c7ca5cb commit c22d612
Show file tree
Hide file tree
Showing 6 changed files with 750 additions and 306 deletions.
53 changes: 44 additions & 9 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use frame_benchmarking::{
const SEED: u32 = 0;
const MAX_SPANS: u32 = 100;
const MAX_VALIDATORS: u32 = 1000;
const MAX_NOMINATORS: u32 = 1000;
const MAX_SLASHES: u32 = 1000;

// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
Expand Down Expand Up @@ -463,12 +464,18 @@ benchmarks! {
reap_stash {
let s in 1 .. MAX_SPANS;
let (stash, controller) = create_stash_controller::<T>(0, 100, Default::default())?;
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), ValidatorPrefs::default())?;
add_slashing_spans::<T>(&stash, s);
T::Currency::make_free_balance_be(&stash, T::Currency::minimum_balance());
whitelist_account!(controller);

assert!(Bonded::<T>::contains_key(&stash));
assert!(Validators::<T>::contains_key(&stash));

}: _(RawOrigin::Signed(controller), stash.clone(), s)
verify {
assert!(!Bonded::<T>::contains_key(&stash));
assert!(!Validators::<T>::contains_key(&stash));
}

new_era {
Expand Down Expand Up @@ -563,9 +570,9 @@ benchmarks! {

get_npos_voters {
// number of validator intention.
let v in 200 .. 400;
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
// number of nominator intention.
let n in 200 .. 400;
let n in (MAX_NOMINATORS / 2) .. MAX_NOMINATORS;
// total number of slashing spans. Assigned to validators randomly.
let s in 1 .. 20;

Expand All @@ -584,15 +591,42 @@ benchmarks! {

get_npos_targets {
// number of validator intention.
let v in 200 .. 400;
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
// number of nominator intention.
let n = 500;
let n = MAX_NOMINATORS;

let _ = create_validators_with_nominators_for_era::<T>(v, n, T::MAX_NOMINATIONS as usize, false, None)?;
}: {
let targets = <Staking<T>>::get_npos_targets();
assert_eq!(targets.len() as u32, v);
}

update_staking_limits {
// This function always does the same thing... just write to 4 storage items.
}: _(
RawOrigin::Root,
BalanceOf::<T>::max_value(),
BalanceOf::<T>::max_value(),
Some(u32::max_value()),
Some(u32::max_value())
) verify {
assert_eq!(MinNominatorBond::<T>::get(), BalanceOf::<T>::max_value());
assert_eq!(MinValidatorBond::<T>::get(), BalanceOf::<T>::max_value());
assert_eq!(MaxNominatorsCount::<T>::get(), Some(u32::max_value()));
assert_eq!(MaxValidatorsCount::<T>::get(), Some(u32::max_value()));
}

chill_other {
let (_, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), ValidatorPrefs::default())?;
Staking::<T>::update_staking_limits(
RawOrigin::Root.into(), BalanceOf::<T>::max_value(), BalanceOf::<T>::max_value(), None, None,
)?;
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), controller.clone())
verify {
assert!(!Validators::<T>::contains_key(controller));
}
}

#[cfg(test)]
Expand All @@ -603,7 +637,7 @@ mod tests {

#[test]
fn create_validators_with_nominators_for_era_works() {
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
let v = 10;
let n = 100;

Expand All @@ -625,7 +659,7 @@ mod tests {

#[test]
fn create_validator_with_nominators_works() {
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
let n = 10;

let (validator_stash, nominators) = create_validator_with_nominators::<Test>(
Expand All @@ -649,7 +683,7 @@ mod tests {

#[test]
fn add_slashing_spans_works() {
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
let n = 10;

let (validator_stash, _nominators) = create_validator_with_nominators::<Test>(
Expand Down Expand Up @@ -680,7 +714,7 @@ mod tests {

#[test]
fn test_payout_all() {
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
let v = 10;
let n = 100;

Expand All @@ -700,6 +734,7 @@ mod tests {

impl_benchmark_test_suite!(
Staking,
crate::mock::ExtBuilder::default().has_stakers(true).build(),
crate::mock::ExtBuilder::default().has_stakers(true),
crate::mock::Test,
exec_name = build_and_execute
);
Loading

0 comments on commit c22d612

Please sign in to comment.