Fix Benchmarks for Statemine-V4 release (#639)

* register validators

* register_as_candidate & leave_intent fixed

* new_session benchmark fixed

* intent_leave_modified

* clean up

* clean up

* benchmark script updated

* update cargo.lock

* done

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Ignacio Palacios
2021-10-04 11:54:58 +02:00
committed by GitHub
parent 18cae2f496
commit 288a98d3d2
5 changed files with 101 additions and 12 deletions
Generated
+2 -1
View File
@@ -5490,6 +5490,7 @@ dependencies = [
"pallet-session",
"pallet-timestamp",
"parity-scale-codec",
"rand 0.7.3",
"serde",
"sp-consensus-aura",
"sp-core",
@@ -12187,7 +12188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
dependencies = [
"cfg-if 0.1.10",
"rand 0.7.3",
"rand 0.6.5",
"static_assertions",
]
+2
View File
@@ -16,6 +16,7 @@ targets = ['x86_64-unknown-linux-gnu']
log = { version = "0.4.0", default-features = false }
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
serde = { version = "1.0.119", default-features = false }
rand = { version = "0.7.2", default-features = false }
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "polkadot-v0.9.10" }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "polkadot-v0.9.10" }
sp-staking = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "polkadot-v0.9.10" }
@@ -46,6 +47,7 @@ runtime-benchmarks = [
std = [
'codec/std',
'log/std',
'rand/std',
'sp-runtime/std',
'sp-staking/std',
'sp-std/std',
+76 -7
View File
@@ -25,9 +25,10 @@ use frame_system::{RawOrigin, EventRecord};
use frame_support::{
assert_ok,
traits::{Currency, Get, EnsureOrigin},
codec::Decode
};
use pallet_authorship::EventHandler;
use pallet_session::SessionManager;
use pallet_session::{self as session, SessionManager};
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
@@ -51,9 +52,52 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
assert_eq!(event, &system_event);
}
fn create_funded_user<T: Config>(
string: &'static str,
n: u32,
balance_factor: u32,
) -> T::AccountId {
let user = account(string, n, SEED);
let balance = T::Currency::minimum_balance() * balance_factor.into();
let _ = T::Currency::make_free_balance_be(&user, balance);
user
}
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};
let keys = {
let mut keys = [0u8; 128];
if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);
rng.fill_bytes(&mut keys);
}
keys
};
Decode::decode(&mut &keys[..]).unwrap()
}
fn validator<T: Config + session::Config>(c: u32)-> (T::AccountId, <T as session::Config>::Keys) {
(create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))
}
fn register_validators<T: Config + session::Config>(count: u32) {
let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();
for (who, keys) in validators {
<session::Module<T>>::set_keys(
RawOrigin::Signed(who).into(), keys, vec![]
).unwrap();
}
}
fn register_candidates<T: Config>(count: u32) {
let candidates = (0..count).map(|c| account("candidate", c, SEED)).collect::<Vec<_>>();
assert!(<CandidacyBond<T>>::get() > 0u32.into(), "Bond cannot be zero!");
for who in candidates {
T::Currency::make_free_balance_be(&who, <CandidacyBond<T>>::get() * 2u32.into());
<CollatorSelection<T>>::register_as_candidate(RawOrigin::Signed(who).into()).unwrap();
@@ -61,7 +105,7 @@ fn register_candidates<T: Config>(count: u32) {
}
benchmarks! {
where_clause { where T: pallet_authorship::Config }
where_clause { where T: pallet_authorship::Config + session::Config }
set_invulnerables {
let b in 1 .. T::MaxInvulnerables::get();
@@ -107,12 +151,20 @@ benchmarks! {
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c + 1);
register_validators::<T>(c);
register_candidates::<T>(c);
let caller: T::AccountId = whitelisted_caller();
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
T::Currency::make_free_balance_be(&caller, bond.clone());
<session::Module<T>>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys::<T>(c + 1),
vec![]
).unwrap();
}: _(RawOrigin::Signed(caller.clone()))
verify {
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
@@ -120,9 +172,11 @@ benchmarks! {
// worse case is the last candidate leaving.
leave_intent {
let c in 1 .. T::MaxCandidates::get();
let c in (T::MinCandidates::get() + 1) .. T::MaxCandidates::get();
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c);
register_validators::<T>(c);
register_candidates::<T>(c);
let leaving = <Candidates<T>>::get().last().unwrap().who.clone();
@@ -160,6 +214,8 @@ benchmarks! {
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c);
frame_system::Pallet::<T>::set_block_number(0u32.into());
register_validators::<T>(c);
register_candidates::<T>(c);
let new_block: T::BlockNumber = 1800u32.into();
@@ -171,19 +227,32 @@ benchmarks! {
for i in 0..c {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), zero_block);
}
for i in 0..non_removals {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
if non_removals > 0 {
for i in 0..non_removals {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
}
} else {
for i in 0..c {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
}
}
let pre_length = <Candidates<T>>::get().len();
frame_system::Pallet::<T>::set_block_number(new_block);
assert!(<Candidates<T>>::get().len() == c as usize);
}: {
<CollatorSelection<T> as SessionManager<_>>::new_session(0)
} verify {
assert!(<Candidates<T>>::get().len() < pre_length);
if c > r && non_removals >= T::MinCandidates::get() {
assert!(<Candidates<T>>::get().len() < pre_length);
} else if c > r && non_removals < T::MinCandidates::get() {
assert!(<Candidates<T>>::get().len() == T::MinCandidates::get() as usize);
} else {
assert!(<Candidates<T>>::get().len() == pre_length);
}
}
}
-2
View File
@@ -136,7 +136,6 @@ pub mod pallet {
/// This does not take into account the invulnerables.
type MinCandidates: Get<u32>;
/// Maximum number of invulnerables.
///
/// Used only for benchmarking.
@@ -156,7 +155,6 @@ pub mod pallet {
/// Validate a user is registered
type ValidatorRegistration: ValidatorRegistration<Self::ValidatorId>;
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
+21 -2
View File
@@ -2,10 +2,15 @@
steps=50
repeat=20
statemineOutput=./polkadot-parachains/statemine-runtime/src/weights
statemintOutput=./polkadot-parachains/statemint-runtime/src/weights
statemineOutput=./polkadot-parachains/statemine/src/weights
statemintOutput=./polkadot-parachains/statemint/src/weights
westmintOutput=./polkadot-parachains/westmint/src/weights
statemineChain=statemine-dev
statemintChain=statemint-dev
westmintChain=westmint-dev
pallets=(
pallet_assets
pallet_balances
@@ -15,6 +20,7 @@ pallets=(
pallet_session
pallet_timestamp
pallet_utility
pallet_uniques
)
for p in ${pallets[@]}
@@ -28,6 +34,7 @@ do
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$statemineOutput
./target/release/polkadot-collator benchmark \
@@ -39,6 +46,18 @@ do
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$statemintOutput
./target/release/polkadot-collator benchmark \
--chain=$westmintChain \
--execution=wasm \
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$westmintOutput
done