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

Commit

Permalink
Reduce the execution time of some tests (#10377)
Browse files Browse the repository at this point in the history
* Reduce the execution time of some tests

* Fix

* Fix build

* fmt
  • Loading branch information
kianenigma authored Nov 28, 2021
1 parent de6033a commit 3fdb445
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 229 deletions.
17 changes: 12 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types,
traits::{
Currency, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
ConstU32, Currency, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter,
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
Expand Down Expand Up @@ -515,6 +515,12 @@ impl onchain::Config for Runtime {
type DataProvider = Staking;
}

pub struct StakingBenchmarkingConfig;
impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxNominators = ConstU32<1000>;
type MaxValidators = ConstU32<1000>;
}

impl pallet_staking::Config for Runtime {
const MAX_NOMINATIONS: u32 = MAX_NOMINATIONS;
type Currency = Balances;
Expand Down Expand Up @@ -544,6 +550,7 @@ impl pallet_staking::Config for Runtime {
// Note that the aforementioned does not scale to a very large number of nominators.
type SortedListProvider = BagsList;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
type BenchmarkingConfig = StakingBenchmarkingConfig;
}

parameter_types! {
Expand Down Expand Up @@ -591,8 +598,8 @@ pub const MAX_NOMINATIONS: u32 = <NposSolution16 as sp_npos_elections::NposSolut
/// The numbers configured here could always be more than the the maximum limits of staking pallet
/// to ensure election snapshot will not run out of memory. For now, we set them to smaller values
/// since the staking is bounded and the weight pipeline takes hours for this single pallet.
pub struct BenchmarkConfig;
impl pallet_election_provider_multi_phase::BenchmarkingConfig for BenchmarkConfig {
pub struct ElectionProviderBenchmarkConfig;
impl pallet_election_provider_multi_phase::BenchmarkingConfig for ElectionProviderBenchmarkConfig {
const VOTERS: [u32; 2] = [1000, 2000];
const TARGETS: [u32; 2] = [500, 1000];
const ACTIVE_VOTERS: [u32; 2] = [500, 800];
Expand Down Expand Up @@ -657,7 +664,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
>;
type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight<Self>;
type ForceOrigin = EnsureRootOrHalfCouncil;
type BenchmarkingConfig = BenchmarkConfig;
type BenchmarkingConfig = ElectionProviderBenchmarkConfig;
type VoterSnapshotPerBlock = VoterSnapshotPerBlock;
}

Expand Down
3 changes: 2 additions & 1 deletion frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ impl pallet_staking::Config for Test {
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type WeightInfo = ();
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
}

impl pallet_offences::Config for Test {
Expand Down
10 changes: 0 additions & 10 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,6 @@ pub trait BenchmarkingConfig {
const MAXIMUM_TARGETS: u32;
}

impl BenchmarkingConfig for () {
const VOTERS: [u32; 2] = [4000, 6000];
const TARGETS: [u32; 2] = [1000, 1600];
const ACTIVE_VOTERS: [u32; 2] = [1000, 3000];
const DESIRED_TARGETS: [u32; 2] = [400, 800];
const SNAPSHOT_MAXIMUM_VOTERS: u32 = 10_000;
const MINER_MAXIMUM_VOTERS: u32 = 10_000;
const MAXIMUM_TARGETS: u32 = 2_000;
}

/// A fallback implementation that transitions the pallet to the emergency phase.
pub struct NoFallback<T>(sp_std::marker::PhantomData<T>);

Expand Down
15 changes: 14 additions & 1 deletion frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ parameter_types! {
pub static Balancing: Option<(usize, ExtendedBalance)> = Some((0, 0));
}

pub struct TestBenchmarkingConfig;
impl BenchmarkingConfig for TestBenchmarkingConfig {
const VOTERS: [u32; 2] = [400, 600];
const ACTIVE_VOTERS: [u32; 2] = [100, 300];
const TARGETS: [u32; 2] = [200, 400];
const DESIRED_TARGETS: [u32; 2] = [100, 180];

const SNAPSHOT_MAXIMUM_VOTERS: u32 = 1000;
const MINER_MAXIMUM_VOTERS: u32 = 1000;

const MAXIMUM_TARGETS: u32 = 200;
}

impl crate::Config for Runtime {
type Event = Event;
type Currency = Balances;
Expand All @@ -398,7 +411,7 @@ impl crate::Config for Runtime {
type RewardHandler = ();
type DataProvider = StakingMock;
type WeightInfo = DualMockWeightInfo;
type BenchmarkingConfig = ();
type BenchmarkingConfig = TestBenchmarkingConfig;
type Fallback = MockFallback;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type Solution = TestNposSolution;
Expand Down
1 change: 1 addition & 0 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
}

Expand Down
202 changes: 0 additions & 202 deletions frame/staking/fuzzer/src/mock.rs

This file was deleted.

17 changes: 9 additions & 8 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ use frame_system::RawOrigin;

const SEED: u32 = 0;
const MAX_SPANS: u32 = 100;
const MAX_VALIDATORS: u32 = 1000;
const MAX_NOMINATORS: u32 = 1000;
const MAX_SLASHES: u32 = 1000;

type MaxValidators<T> = <<T as Config>::BenchmarkingConfig as BenchmarkingConfig>::MaxValidators;
type MaxNominators<T> = <<T as Config>::BenchmarkingConfig as BenchmarkingConfig>::MaxNominators;

// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
// read and write operations.
fn add_slashing_spans<T: Config>(who: &T::AccountId, spans: u32) {
Expand Down Expand Up @@ -481,7 +482,7 @@ benchmarks! {
}

set_validator_count {
let validator_count = MAX_VALIDATORS;
let validator_count = MaxValidators::<T>::get();
}: _(RawOrigin::Root, validator_count)
verify {
assert_eq!(ValidatorCount::<T>::get(), validator_count);
Expand All @@ -498,7 +499,7 @@ benchmarks! {

// Worst case scenario, the list of invulnerables is very long.
set_invulnerables {
let v in 0 .. MAX_VALIDATORS;
let v in 0 .. MaxValidators::<T>::get();
let mut invulnerables = Vec::new();
for i in 0 .. v {
invulnerables.push(account("invulnerable", i, SEED));
Expand Down Expand Up @@ -804,9 +805,9 @@ benchmarks! {

get_npos_voters {
// number of validator intention.
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
let v in (MaxValidators::<T>::get() / 2) .. MaxValidators::<T>::get();
// number of nominator intention.
let n in (MAX_NOMINATORS / 2) .. MAX_NOMINATORS;
let n in (MaxNominators::<T>::get() / 2) .. MaxNominators::<T>::get();
// total number of slashing spans. Assigned to validators randomly.
let s in 1 .. 20;

Expand All @@ -829,9 +830,9 @@ benchmarks! {

get_npos_targets {
// number of validator intention.
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
let v in (MaxValidators::<T>::get() / 2) .. MaxValidators::<T>::get();
// number of nominator intention.
let n = MAX_NOMINATORS;
let n = MaxNominators::<T>::get();

let _ = create_validators_with_nominators_for_era::<T>(
v, n, T::MAX_NOMINATIONS as usize, false, None
Expand Down
Loading

0 comments on commit 3fdb445

Please sign in to comment.