mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 11:51:12 +00:00
Reduce the execution time of some tests (#10377)
* Reduce the execution time of some tests * Fix * Fix build * fmt
This commit is contained in:
@@ -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},
|
||||
@@ -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;
|
||||
@@ -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! {
|
||||
@@ -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];
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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>);
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2020-2021 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.
|
||||
|
||||
//! Mock file for staking fuzzing.
|
||||
|
||||
use frame_support::parameter_types;
|
||||
|
||||
type AccountId = u64;
|
||||
type AccountIndex = u32;
|
||||
type BlockNumber = u64;
|
||||
type Balance = u64;
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Staking: pallet_staking::{Pallet, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
|
||||
Indices: pallet_indices::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
|
||||
}
|
||||
);
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
type Call = Call;
|
||||
type Hash = sp_core::H256;
|
||||
type Hashing = ::sp_runtime::traits::BlakeTwo256;
|
||||
type AccountId = AccountId;
|
||||
type Lookup = Indices;
|
||||
type Header = sp_runtime::testing::Header;
|
||||
type Event = Event;
|
||||
type BlockHashCount = ();
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: Balance = 10;
|
||||
}
|
||||
impl pallet_balances::Config for Test {
|
||||
type MaxLocks = ();
|
||||
type MaxReserves = ();
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type Balance = Balance;
|
||||
type Event = Event;
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl pallet_indices::Config for Test {
|
||||
type AccountIndex = AccountIndex;
|
||||
type Event = Event;
|
||||
type Currency = Balances;
|
||||
type Deposit = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = 5;
|
||||
}
|
||||
impl pallet_timestamp::Config for Test {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl pallet_session::historical::Config for Test {
|
||||
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
|
||||
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
|
||||
}
|
||||
|
||||
sp_runtime::impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub foo: sp_runtime::testing::UintAuthorityId,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TestSessionHandler;
|
||||
impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
|
||||
const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[];
|
||||
|
||||
fn on_genesis_session<Ks: sp_runtime::traits::OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
|
||||
|
||||
fn on_new_session<Ks: sp_runtime::traits::OpaqueKeys>(
|
||||
_: bool,
|
||||
_: &[(AccountId, Ks)],
|
||||
_: &[(AccountId, Ks)],
|
||||
) {}
|
||||
|
||||
fn on_disabled(_: u32) {}
|
||||
}
|
||||
|
||||
impl pallet_session::Config for Test {
|
||||
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
|
||||
type Keys = SessionKeys;
|
||||
type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>;
|
||||
type NextSessionRotation = pallet_session::PeriodicSessions<(), ()>;
|
||||
type SessionHandler = TestSessionHandler;
|
||||
type Event = Event;
|
||||
type ValidatorId = AccountId;
|
||||
type ValidatorIdOf = pallet_staking::StashOf<Test>;
|
||||
type DisabledValidatorsThreshold = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
pallet_staking_reward_curve::build! {
|
||||
const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!(
|
||||
min_inflation: 0_025_000,
|
||||
max_inflation: 0_100_000,
|
||||
ideal_stake: 0_500_000,
|
||||
falloff: 0_050_000,
|
||||
max_piece_count: 40,
|
||||
test_precision: 0_005_000,
|
||||
);
|
||||
}
|
||||
parameter_types! {
|
||||
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
|
||||
pub const MaxNominatorRewardedPerValidator: u32 = 64;
|
||||
pub const MaxIterations: u32 = 20;
|
||||
}
|
||||
|
||||
pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;
|
||||
|
||||
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
|
||||
where
|
||||
Call: From<C>,
|
||||
{
|
||||
type OverarchingCall = Call;
|
||||
type Extrinsic = Extrinsic;
|
||||
}
|
||||
|
||||
pub struct MockElectionProvider;
|
||||
impl frame_election_provider_support::ElectionProvider<AccountId, BlockNumber>
|
||||
for MockElectionProvider
|
||||
{
|
||||
type Error = ();
|
||||
type DataProvider = pallet_staking::Module<Test>;
|
||||
|
||||
fn elect() -> Result<
|
||||
(sp_npos_elections::Supports<AccountId>, frame_support::weights::Weight),
|
||||
Self::Error
|
||||
> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_staking::Config for Test {
|
||||
type Currency = Balances;
|
||||
type UnixTime = pallet_timestamp::Pallet<Self>;
|
||||
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
|
||||
type RewardRemainder = ();
|
||||
type Event = Event;
|
||||
type Slash = ();
|
||||
type Reward = ();
|
||||
type SessionsPerEra = ();
|
||||
type SlashDeferDuration = ();
|
||||
type SlashCancelOrigin = frame_system::EnsureRoot<Self::AccountId>;
|
||||
type BondingDuration = ();
|
||||
type SessionInterface = Self;
|
||||
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
|
||||
type NextNewSession = Session;
|
||||
type ElectionLookahead = ();
|
||||
type Call = Call;
|
||||
type MaxIterations = MaxIterations;
|
||||
type MinSolutionScoreBump = ();
|
||||
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
||||
type UnsignedPriority = ();
|
||||
type OffchainSolutionWeightLimit = ();
|
||||
type WeightInfo = ();
|
||||
type ElectionProvider = MockElectionProvider;
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
@@ -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));
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -301,7 +301,7 @@ mod pallet;
|
||||
|
||||
use codec::{Decode, Encode, HasCompact};
|
||||
use frame_support::{
|
||||
traits::{Currency, Get},
|
||||
traits::{ConstU32, Currency, Get},
|
||||
weights::Weight,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
@@ -807,3 +807,23 @@ where
|
||||
R::is_known_offence(offenders, time_slot)
|
||||
}
|
||||
}
|
||||
|
||||
/// Configurations of the benchmarking of the pallet.
|
||||
pub trait BenchmarkingConfig {
|
||||
/// The maximum number of validators to use.
|
||||
type MaxValidators: Get<u32>;
|
||||
/// The maximum number of nominators to use.
|
||||
type MaxNominators: Get<u32>;
|
||||
}
|
||||
|
||||
/// A mock benchmarking config for pallet-staking.
|
||||
///
|
||||
/// Should only be used for testing.
|
||||
#[cfg(feature = "std")]
|
||||
pub struct TestBenchmarkingConfig;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl BenchmarkingConfig for TestBenchmarkingConfig {
|
||||
type MaxValidators = ConstU32<100>;
|
||||
type MaxNominators = ConstU32<100>;
|
||||
}
|
||||
|
||||
@@ -272,9 +272,10 @@ impl crate::pallet::pallet::Config for Test {
|
||||
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
||||
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
|
||||
type GenesisElectionProvider = Self::ElectionProvider;
|
||||
type WeightInfo = ();
|
||||
// NOTE: consider a macro and use `UseNominatorsMap<Self>` as well.
|
||||
type SortedListProvider = BagsList;
|
||||
type BenchmarkingConfig = TestBenchmarkingConfig;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test
|
||||
|
||||
@@ -50,6 +50,8 @@ const STAKING_ID: LockIdentifier = *b"staking ";
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use crate::BenchmarkingConfig;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
@@ -151,6 +153,9 @@ pub mod pallet {
|
||||
/// the bags-list is not desired, [`impls::UseNominatorsMap`] is likely the desired option.
|
||||
type SortedListProvider: SortedListProvider<Self::AccountId>;
|
||||
|
||||
/// Some parameters of the benchmarking.
|
||||
type BenchmarkingConfig: BenchmarkingConfig;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user