mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 08:11:02 +00:00
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:
Generated
+2
-1
@@ -5490,6 +5490,7 @@ dependencies = [
|
|||||||
"pallet-session",
|
"pallet-session",
|
||||||
"pallet-timestamp",
|
"pallet-timestamp",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
|
"rand 0.7.3",
|
||||||
"serde",
|
"serde",
|
||||||
"sp-consensus-aura",
|
"sp-consensus-aura",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
@@ -12187,7 +12188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
|
checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"rand 0.7.3",
|
"rand 0.6.5",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ targets = ['x86_64-unknown-linux-gnu']
|
|||||||
log = { version = "0.4.0", default-features = false }
|
log = { version = "0.4.0", default-features = false }
|
||||||
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
|
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
|
||||||
serde = { version = "1.0.119", default-features = false }
|
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-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-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" }
|
sp-staking = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "polkadot-v0.9.10" }
|
||||||
@@ -46,6 +47,7 @@ runtime-benchmarks = [
|
|||||||
std = [
|
std = [
|
||||||
'codec/std',
|
'codec/std',
|
||||||
'log/std',
|
'log/std',
|
||||||
|
'rand/std',
|
||||||
'sp-runtime/std',
|
'sp-runtime/std',
|
||||||
'sp-staking/std',
|
'sp-staking/std',
|
||||||
'sp-std/std',
|
'sp-std/std',
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ use frame_system::{RawOrigin, EventRecord};
|
|||||||
use frame_support::{
|
use frame_support::{
|
||||||
assert_ok,
|
assert_ok,
|
||||||
traits::{Currency, Get, EnsureOrigin},
|
traits::{Currency, Get, EnsureOrigin},
|
||||||
|
codec::Decode
|
||||||
};
|
};
|
||||||
use pallet_authorship::EventHandler;
|
use pallet_authorship::EventHandler;
|
||||||
use pallet_session::SessionManager;
|
use pallet_session::{self as session, SessionManager};
|
||||||
|
|
||||||
pub type BalanceOf<T> =
|
pub type BalanceOf<T> =
|
||||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
<<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);
|
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) {
|
fn register_candidates<T: Config>(count: u32) {
|
||||||
let candidates = (0..count).map(|c| account("candidate", c, SEED)).collect::<Vec<_>>();
|
let candidates = (0..count).map(|c| account("candidate", c, SEED)).collect::<Vec<_>>();
|
||||||
assert!(<CandidacyBond<T>>::get() > 0u32.into(), "Bond cannot be zero!");
|
assert!(<CandidacyBond<T>>::get() > 0u32.into(), "Bond cannot be zero!");
|
||||||
|
|
||||||
for who in candidates {
|
for who in candidates {
|
||||||
T::Currency::make_free_balance_be(&who, <CandidacyBond<T>>::get() * 2u32.into());
|
T::Currency::make_free_balance_be(&who, <CandidacyBond<T>>::get() * 2u32.into());
|
||||||
<CollatorSelection<T>>::register_as_candidate(RawOrigin::Signed(who).into()).unwrap();
|
<CollatorSelection<T>>::register_as_candidate(RawOrigin::Signed(who).into()).unwrap();
|
||||||
@@ -61,7 +105,7 @@ fn register_candidates<T: Config>(count: u32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
benchmarks! {
|
benchmarks! {
|
||||||
where_clause { where T: pallet_authorship::Config }
|
where_clause { where T: pallet_authorship::Config + session::Config }
|
||||||
|
|
||||||
set_invulnerables {
|
set_invulnerables {
|
||||||
let b in 1 .. T::MaxInvulnerables::get();
|
let b in 1 .. T::MaxInvulnerables::get();
|
||||||
@@ -107,12 +151,20 @@ benchmarks! {
|
|||||||
|
|
||||||
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
|
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
|
||||||
<DesiredCandidates<T>>::put(c + 1);
|
<DesiredCandidates<T>>::put(c + 1);
|
||||||
|
|
||||||
|
register_validators::<T>(c);
|
||||||
register_candidates::<T>(c);
|
register_candidates::<T>(c);
|
||||||
|
|
||||||
let caller: T::AccountId = whitelisted_caller();
|
let caller: T::AccountId = whitelisted_caller();
|
||||||
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
|
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
|
||||||
T::Currency::make_free_balance_be(&caller, bond.clone());
|
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()))
|
}: _(RawOrigin::Signed(caller.clone()))
|
||||||
verify {
|
verify {
|
||||||
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
|
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
|
||||||
@@ -120,9 +172,11 @@ benchmarks! {
|
|||||||
|
|
||||||
// worse case is the last candidate leaving.
|
// worse case is the last candidate leaving.
|
||||||
leave_intent {
|
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());
|
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
|
||||||
<DesiredCandidates<T>>::put(c);
|
<DesiredCandidates<T>>::put(c);
|
||||||
|
|
||||||
|
register_validators::<T>(c);
|
||||||
register_candidates::<T>(c);
|
register_candidates::<T>(c);
|
||||||
|
|
||||||
let leaving = <Candidates<T>>::get().last().unwrap().who.clone();
|
let leaving = <Candidates<T>>::get().last().unwrap().who.clone();
|
||||||
@@ -160,6 +214,8 @@ benchmarks! {
|
|||||||
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
|
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
|
||||||
<DesiredCandidates<T>>::put(c);
|
<DesiredCandidates<T>>::put(c);
|
||||||
frame_system::Pallet::<T>::set_block_number(0u32.into());
|
frame_system::Pallet::<T>::set_block_number(0u32.into());
|
||||||
|
|
||||||
|
register_validators::<T>(c);
|
||||||
register_candidates::<T>(c);
|
register_candidates::<T>(c);
|
||||||
|
|
||||||
let new_block: T::BlockNumber = 1800u32.into();
|
let new_block: T::BlockNumber = 1800u32.into();
|
||||||
@@ -171,19 +227,32 @@ benchmarks! {
|
|||||||
for i in 0..c {
|
for i in 0..c {
|
||||||
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), zero_block);
|
<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();
|
let pre_length = <Candidates<T>>::get().len();
|
||||||
|
|
||||||
frame_system::Pallet::<T>::set_block_number(new_block);
|
frame_system::Pallet::<T>::set_block_number(new_block);
|
||||||
|
|
||||||
assert!(<Candidates<T>>::get().len() == c as usize);
|
assert!(<Candidates<T>>::get().len() == c as usize);
|
||||||
|
|
||||||
}: {
|
}: {
|
||||||
<CollatorSelection<T> as SessionManager<_>>::new_session(0)
|
<CollatorSelection<T> as SessionManager<_>>::new_session(0)
|
||||||
} verify {
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ pub mod pallet {
|
|||||||
/// This does not take into account the invulnerables.
|
/// This does not take into account the invulnerables.
|
||||||
type MinCandidates: Get<u32>;
|
type MinCandidates: Get<u32>;
|
||||||
|
|
||||||
|
|
||||||
/// Maximum number of invulnerables.
|
/// Maximum number of invulnerables.
|
||||||
///
|
///
|
||||||
/// Used only for benchmarking.
|
/// Used only for benchmarking.
|
||||||
@@ -156,7 +155,6 @@ pub mod pallet {
|
|||||||
/// Validate a user is registered
|
/// Validate a user is registered
|
||||||
type ValidatorRegistration: ValidatorRegistration<Self::ValidatorId>;
|
type ValidatorRegistration: ValidatorRegistration<Self::ValidatorId>;
|
||||||
|
|
||||||
|
|
||||||
/// The weight information of this pallet.
|
/// The weight information of this pallet.
|
||||||
type WeightInfo: WeightInfo;
|
type WeightInfo: WeightInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-2
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
steps=50
|
steps=50
|
||||||
repeat=20
|
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
|
statemineChain=statemine-dev
|
||||||
statemintChain=statemint-dev
|
statemintChain=statemint-dev
|
||||||
|
westmintChain=westmint-dev
|
||||||
|
|
||||||
pallets=(
|
pallets=(
|
||||||
pallet_assets
|
pallet_assets
|
||||||
pallet_balances
|
pallet_balances
|
||||||
@@ -15,6 +20,7 @@ pallets=(
|
|||||||
pallet_session
|
pallet_session
|
||||||
pallet_timestamp
|
pallet_timestamp
|
||||||
pallet_utility
|
pallet_utility
|
||||||
|
pallet_uniques
|
||||||
)
|
)
|
||||||
|
|
||||||
for p in ${pallets[@]}
|
for p in ${pallets[@]}
|
||||||
@@ -28,6 +34,7 @@ do
|
|||||||
--steps=$steps \
|
--steps=$steps \
|
||||||
--repeat=$repeat \
|
--repeat=$repeat \
|
||||||
--raw \
|
--raw \
|
||||||
|
--header=./file_header.txt \
|
||||||
--output=$statemineOutput
|
--output=$statemineOutput
|
||||||
|
|
||||||
./target/release/polkadot-collator benchmark \
|
./target/release/polkadot-collator benchmark \
|
||||||
@@ -39,6 +46,18 @@ do
|
|||||||
--steps=$steps \
|
--steps=$steps \
|
||||||
--repeat=$repeat \
|
--repeat=$repeat \
|
||||||
--raw \
|
--raw \
|
||||||
|
--header=./file_header.txt \
|
||||||
--output=$statemintOutput
|
--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
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user