Benchmark Staking and Session Pallet (#5183)

* starting bench

* More

* more

* Payout Validator

* Give each validator exactly n nominators

* Update with test

* Try to add accounts to chain spec

* Undo changes to chainspec

* Payout nominator

* Rebond and Reap Stash

* Set history depth

* fix smelly code

* cancel deferred slash

* new_era bench

* do_slash benchmark

* Add features

* undo extrinsic move

* lower

* Update new era

* Update benchmarking.rs

* whitespace

* Apply suggestions from code review

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* fixes

* nit

* Refactor tests, initial code

* Move session benchmarks to avoid cyclic deps

* Update lib.rs

* Fix warnings

* Move impl

* Update to do random nominator allocation

* add feature to benchmark pallet

* Remove extra stuff

* Update based on feedback

* Less intrusive

* Remove `transfer_idle_users`

* remove again

* unused dep

* test feature flag

* Update to latest substrate

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-03-17 15:12:04 +02:00
committed by GitHub
parent d146cc3ae3
commit 9c06d8c6f4
17 changed files with 961 additions and 333 deletions
@@ -0,0 +1,57 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Benchmarks for the Session Pallet.
// This is separated into its own crate due to cyclic dependency issues.
#![cfg_attr(not(feature = "std"), no_std)]
use sp_std::prelude::*;
use sp_std::vec;
use frame_system::RawOrigin;
use frame_benchmarking::benchmarks;
use pallet_session::*;
use pallet_session::Module as Session;
use pallet_staking::{
MAX_NOMINATIONS,
benchmarking::create_validator_with_nominators,
};
pub struct Module<T: Trait>(pallet_session::Module<T>);
pub trait Trait: pallet_session::Trait + pallet_staking::Trait {}
benchmarks! {
_ { }
set_keys {
let n in 1 .. MAX_NOMINATIONS as u32;
let validator = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(validator), keys, proof)
purge_keys {
let n in 1 .. MAX_NOMINATIONS as u32;
let validator = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
Session::<T>::set_keys(RawOrigin::Signed(validator.clone()).into(), keys, proof)?;
}: _(RawOrigin::Signed(validator))
}