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

Move Staking Weights to T::WeightInfo #7007

Merged
22 commits merged into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
81 changes: 56 additions & 25 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,37 @@ benchmarks! {
let validator = create_validator_with_nominators::<T>(n, T::MaxNominatorRewardedPerValidator::get() as u32, true)?;

let current_era = CurrentEra::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));

let caller = whitelisted_caller();
let balance_before = T::Currency::free_balance(&validator);
}: _(RawOrigin::Signed(caller), validator.clone(), current_era)
verify {
// Validator has been paid!
let balance_after = T::Currency::free_balance(&validator);
assert!(balance_before < balance_after);
assert!(
balance_before < balance_after,
"Balance of stash {:?} should have increased after payout.", validator,
);
}

payout_stakers_alive_controller {
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
let n in 1 .. T::MaxNominatorRewardedPerValidator::get() as u32;
let validator = create_validator_with_nominators::<T>(n, T::MaxNominatorRewardedPerValidator::get() as u32, false)?;

let current_era = CurrentEra::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));

let caller = whitelisted_caller();
let balance_before = T::Currency::free_balance(&validator);
}: payout_stakers(RawOrigin::Signed(caller), validator.clone(), current_era)
verify {
// Validator has been paid!
let balance_after = T::Currency::free_balance(&validator);
assert!(balance_before < balance_after);
assert!(
balance_before < balance_after,
"Balance of stash {:?} should have increased after payout.", validator,
);
}

rebond {
Expand Down Expand Up @@ -426,18 +436,17 @@ benchmarks! {
}
}

// This benchmark create `v` validators intent, `n` nominators intent, each nominator nominate
// MAX_NOMINATIONS in the set of the first `w` validators.
// It builds a solution with `w` winners composed of nominated validators randomly nominated,
// `a` assignment with MAX_NOMINATIONS.
// This benchmark create `v` validators intent, `n` nominators intent, in total creating `e`
// edges.
submit_solution_initial {
// number of validator intent
let v in 1000 .. 2000;
// number of nominator intent
let n in 1000 .. 2000;
// number of assignments. Basically, number of active nominators.
let a in 200 .. 500;
// number of winners, also ValidatorCount
// number of validator intention. This will be equal to `ElectionSize::validators`.
let v in 200 .. 400;
// number of nominator intention. This will be equal to `ElectionSize::nominators`.
let n in 500 .. 1000;
// number of assignments. Basically, number of active nominators. This will be equal to
// `compact.len()`.
let a in 200 .. 400;
// number of winners, also ValidatorCount. This will be equal to `winner.len()`.
let w in 16 .. 100;

ensure!(w as usize >= MAX_NOMINATIONS, "doesn't support lower value");
Expand Down Expand Up @@ -466,6 +475,13 @@ benchmarks! {
size
) = offchain_election::prepare_submission::<T>(assignments, winners, false).unwrap();

assert_eq!(
winners.len(), compact.unique_targets().len(),
"unique targets ({}) and winners ({}) count not same. This solution is not valid.",
compact.unique_targets().len(),
winners.len(),
);

// needed for the solution to be accepted
<EraElectionStatus<T>>::put(ElectionStatus::Open(T::BlockNumber::from(1u32)));

Expand All @@ -492,14 +508,15 @@ benchmarks! {
}

// same as submit_solution_initial but we place a very weak solution on chian first.
#[extra]
submit_solution_better {
// number of validator intent
let v in 1000 .. 2000;
// number of nominator intent
let n in 1000 .. 2000;
// number of validator intention.
let v in 200 .. 400;
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
// number of nominator intention.
let n in 500 .. 1000;
// number of assignments. Basically, number of active nominators.
let a in 200 .. 500;
// number of winners, also ValidatorCount
let a in 200 .. 400;
// number of winners, also ValidatorCount.
let w in 16 .. 100;

ensure!(w as usize >= MAX_NOMINATIONS, "doesn't support lower value");
Expand Down Expand Up @@ -530,6 +547,13 @@ benchmarks! {
size
) = offchain_election::prepare_submission::<T>(assignments, winners, false).unwrap();

assert_eq!(
winners.len(), compact.unique_targets().len(),
"unique targets ({}) and winners ({}) count not same. This solution is not valid.",
compact.unique_targets().len(),
winners.len(),
);

// needed for the solution to be accepted
<EraElectionStatus<T>>::put(ElectionStatus::Open(T::BlockNumber::from(1u32)));

Expand Down Expand Up @@ -576,11 +600,12 @@ benchmarks! {
}

// This will be early rejected based on the score.
#[extra]
submit_solution_weaker {
// number of validator intent
let v in 1000 .. 2000;
// number of nominator intent
let n in 1000 .. 2000;
// number of validator intention.
let v in 200 .. 400;
// number of nominator intention.
let n in 500 .. 1000;

create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;

Expand All @@ -599,6 +624,12 @@ benchmarks! {
// submit a seq-phragmen with all the good stuff on chain.
{
let (winners, compact, score, size) = get_seq_phragmen_solution::<T>(true);
assert_eq!(
winners.len(), compact.unique_targets().len(),
"unique targets ({}) and winners ({}) count not same. This solution is not valid.",
compact.unique_targets().len(),
winners.len(),
);
assert!(
<Staking<T>>::submit_election_solution(
RawOrigin::Signed(caller.clone()).into(),
Expand Down
215 changes: 215 additions & 0 deletions frame/staking/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@

// This file is part of Substrate.

// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Default weights of pallet-staking.
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6

#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

impl crate::WeightInfo for () {
// WARNING! Some components were not used: ["u"]
fn bond() -> Weight {
(65788000 as Weight)
.saturating_add(DbWeight::get().reads(6 as Weight))
.saturating_add(DbWeight::get().writes(5 as Weight))
}
// WARNING! Some components were not used: ["u"]
fn bond_extra() -> Weight {
(53598000 as Weight)
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
// WARNING! Some components were not used: ["u"]
fn unbond() -> Weight {
(48977000 as Weight)
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn withdraw_unbonded_update(s: u32, ) -> Weight {
(49008000 as Weight)
.saturating_add((30000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn withdraw_unbonded_kill(s: u32, ) -> Weight {
(69924000 as Weight)
.saturating_add((1554000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(7 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
}
// WARNING! Some components were not used: ["u"]
fn validate() -> Weight {
(15848000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn nominate(n: u32, ) -> Weight {
(20625000 as Weight)
.saturating_add((357000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
// WARNING! Some components were not used: ["u"]
fn chill() -> Weight {
(17159000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
// WARNING! Some components were not used: ["u"]
fn set_payee() -> Weight {
(10970000 as Weight)
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
// WARNING! Some components were not used: ["u"]
fn set_controller() -> Weight {
(23826000 as Weight)
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
// WARNING! Some components were not used: ["c"]
fn set_validator_count() -> Weight {
(1962000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
// WARNING! Some components were not used: ["i"]
fn force_no_eras() -> Weight {
(2000000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
// WARNING! Some components were not used: ["i"]
fn force_new_era() -> Weight {
(2000000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
// WARNING! Some components were not used: ["i"]
fn force_new_era_always() -> Weight {
(2000000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn set_invulnerables(v: u32, ) -> Weight {
(1955000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(v as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn force_unstake(s: u32, ) -> Weight {
(38402000 as Weight)
.saturating_add((1711000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
}
fn cancel_deferred_slash(s: u32, ) -> Weight {
(410638000 as Weight)
.saturating_add((710000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn payout_stakers(n: u32, ) -> Weight {
(31790000 as Weight)
.saturating_add((40680000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight)))
.saturating_add(DbWeight::get().writes(1 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(n as Weight)))
}
fn payout_stakers_alive_controller(n: u32, ) -> Weight {
(0 as Weight)
.saturating_add((55362000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight)))
.saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight)))
}
fn rebond(l: u32, ) -> Weight {
(35025000 as Weight)
.saturating_add((28000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn set_history_depth(e: u32, ) -> Weight {
(0 as Weight)
.saturating_add((43889000 as Weight).saturating_mul(e as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(4 as Weight))
.saturating_add(DbWeight::get().writes((7 as Weight).saturating_mul(e as Weight)))
}
fn reap_stash(s: u32, ) -> Weight {
(69698000 as Weight)
.saturating_add((1680000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
}
fn new_era(v: u32, n: u32, ) -> Weight {
(0 as Weight)
.saturating_add((462131000 as Weight).saturating_mul(v as Weight))
.saturating_add((75480000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads(10 as Weight))
.saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(v as Weight)))
.saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight)))
.saturating_add(DbWeight::get().writes(8 as Weight))
.saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight)))
}
// WARNING! Some components were not used: ["l"]
fn do_slash() -> Weight {
(47783000 as Weight)
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn payout_all(v: u32, n: u32, ) -> Weight {
(0 as Weight)
.saturating_add((1841741000 as Weight).saturating_mul(v as Weight))
.saturating_add((181891000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads((15 as Weight).saturating_mul(v as Weight)))
.saturating_add(DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight)))
.saturating_add(DbWeight::get().writes((8 as Weight).saturating_mul(v as Weight)))
.saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight)))
}
fn submit_solution_initial(v: u32, n: u32, a: u32, w: u32, ) -> Weight {
(0 as Weight)
.saturating_add((762000 as Weight).saturating_mul(v as Weight))
.saturating_add((868000 as Weight).saturating_mul(n as Weight))
.saturating_add((66802000 as Weight).saturating_mul(a as Weight))
.saturating_add((6474000 as Weight).saturating_mul(w as Weight))
.saturating_add(DbWeight::get().reads(6 as Weight))
.saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight)))
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight)))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight {
(0 as Weight)
.saturating_add((784000 as Weight).saturating_mul(v as Weight))
.saturating_add((640000 as Weight).saturating_mul(n as Weight))
.saturating_add((68830000 as Weight).saturating_mul(a as Weight))
.saturating_add((8181000 as Weight).saturating_mul(w as Weight))
.saturating_add(DbWeight::get().reads(6 as Weight))
.saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight)))
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight)))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn submit_solution_weaker(v: u32, n: u32, ) -> Weight {
(11244000 as Weight)
.saturating_add((28000 as Weight).saturating_mul(v as Weight))
.saturating_add((12000 as Weight).saturating_mul(n as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
}
}
Loading