mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 10:18:02 +00:00
048a9c2744
Partially Addresses #2500 Adds a `deprecate_controller_batch` call to the staking pallet that is callable by `Root` and `StakingAdmin`. To be used for controller account deprecation and removed thereafter. Adds `MaxControllersDeprecationBatch` pallet constant that defines max possible deprecations per call. - [x] Add `deprecate_controller_batch` call, and `MaxControllersInDeprecationBatch` constant. - [x] Add tests, benchmark, weights. Tests that weight is only consumed if unique pair. - [x] Adds `StakingAdmin` origin to staking's `AdminOrigin` type in westend runtime. - [x] Determined that worst case 5,900 deprecations does fit into `maxBlock` `proofSize` and `refTime` in both normal and operational thresholds, meaning we can deprecate all controllers for each network in one call. ## Block Weights By querying `consts.system.blockWeights` we can see that the `deprecate_controller_batch` weights fit within the `normal` threshold on Polkadot. #### `controller_deprecation_batch` where i = 5900: #### Ref time: 69,933,325,300 #### Proof size: 21,040,390 ### Polkadot ``` // consts.query.blockWeights maxBlock: { refTime: 2,000,000,000,000 proofSize: 18,446,744,073,709,551,615 } normal: { maxExtrinsic: { refTime: 1,479,873,955,000 proofSize: 13,650,590,614,545,068,195 } maxTotal: { refTime: 1,500,000,000,000 proofSize: 13,835,058,055,282,163,711 } } ``` ### Kusama ``` // consts.query.blockWeights maxBlock: { refTime: 2,000,000,000,000 proofSize: 18,446,744,073,709,551,615 } normal: { maxExtrinsic: { refTime: 1,479,875,294,000 proofSize: 13,650,590,614,545,068,195 } maxTotal: { refTime: 1,500,000,000,000 proofSize: 13,835,058,055,282,163,711 } } ``` --------- Co-authored-by: command-bot <> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
198 lines
6.2 KiB
Rust
198 lines
6.2 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 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 session benchmarking.
|
|
|
|
#![cfg(test)]
|
|
|
|
use frame_election_provider_support::{
|
|
bounds::{ElectionBounds, ElectionBoundsBuilder},
|
|
onchain, SequentialPhragmen,
|
|
};
|
|
use frame_support::{
|
|
derive_impl, parameter_types,
|
|
traits::{ConstU32, ConstU64},
|
|
};
|
|
use sp_runtime::{traits::IdentityLookup, BuildStorage};
|
|
|
|
type AccountId = u64;
|
|
type Nonce = u32;
|
|
type Balance = u64;
|
|
|
|
type Block = frame_system::mocking::MockBlock<Test>;
|
|
|
|
frame_support::construct_runtime!(
|
|
pub enum Test
|
|
{
|
|
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
|
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
|
Staking: pallet_staking::{Pallet, Call, Config<T>, Storage, Event<T>},
|
|
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
|
|
}
|
|
);
|
|
|
|
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
|
impl frame_system::Config for Test {
|
|
type BaseCallFilter = frame_support::traits::Everything;
|
|
type BlockWeights = ();
|
|
type BlockLength = ();
|
|
type DbWeight = ();
|
|
type RuntimeOrigin = RuntimeOrigin;
|
|
type Nonce = Nonce;
|
|
type RuntimeCall = RuntimeCall;
|
|
type Hash = sp_core::H256;
|
|
type Hashing = ::sp_runtime::traits::BlakeTwo256;
|
|
type AccountId = AccountId;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Block = Block;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type BlockHashCount = ();
|
|
type Version = ();
|
|
type PalletInfo = PalletInfo;
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
type SS58Prefix = ();
|
|
type OnSetCode = ();
|
|
type MaxConsumers = ConstU32<16>;
|
|
}
|
|
|
|
impl pallet_balances::Config for Test {
|
|
type MaxLocks = ();
|
|
type MaxReserves = ();
|
|
type ReserveIdentifier = [u8; 8];
|
|
type Balance = Balance;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type DustRemoval = ();
|
|
type ExistentialDeposit = ConstU64<10>;
|
|
type AccountStore = System;
|
|
type WeightInfo = ();
|
|
type FreezeIdentifier = ();
|
|
type MaxFreezes = ();
|
|
type RuntimeHoldReason = ();
|
|
type RuntimeFreezeReason = ();
|
|
type MaxHolds = ();
|
|
}
|
|
|
|
impl pallet_timestamp::Config for Test {
|
|
type Moment = u64;
|
|
type OnTimestampSet = ();
|
|
type MinimumPeriod = ConstU64<5>;
|
|
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 RuntimeEvent = RuntimeEvent;
|
|
type ValidatorId = AccountId;
|
|
type ValidatorIdOf = pallet_staking::StashOf<Test>;
|
|
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 static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
|
|
}
|
|
|
|
pub struct OnChainSeqPhragmen;
|
|
impl onchain::Config for OnChainSeqPhragmen {
|
|
type System = Test;
|
|
type Solver = SequentialPhragmen<AccountId, sp_runtime::Perbill>;
|
|
type DataProvider = Staking;
|
|
type WeightInfo = ();
|
|
type MaxWinners = ConstU32<100>;
|
|
type Bounds = ElectionsBounds;
|
|
}
|
|
|
|
impl pallet_staking::Config for Test {
|
|
type Currency = Balances;
|
|
type CurrencyBalance = <Self as pallet_balances::Config>::Balance;
|
|
type UnixTime = pallet_timestamp::Pallet<Self>;
|
|
type CurrencyToVote = ();
|
|
type RewardRemainder = ();
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type Slash = ();
|
|
type Reward = ();
|
|
type SessionsPerEra = ();
|
|
type SlashDeferDuration = ();
|
|
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
|
|
type BondingDuration = ();
|
|
type SessionInterface = Self;
|
|
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
|
|
type NextNewSession = Session;
|
|
type MaxExposurePageSize = ConstU32<64>;
|
|
type OffendingValidatorsThreshold = ();
|
|
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
|
|
type GenesisElectionProvider = Self::ElectionProvider;
|
|
type MaxUnlockingChunks = ConstU32<32>;
|
|
type MaxControllersInDeprecationBatch = ConstU32<100>;
|
|
type HistoryDepth = ConstU32<84>;
|
|
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
|
|
type TargetList = pallet_staking::UseValidatorsMap<Self>;
|
|
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
|
|
type EventListeners = ();
|
|
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
impl crate::Config for Test {}
|
|
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
|
sp_io::TestExternalities::new(t)
|
|
}
|