diff --git a/bridges/modules/shift-session-manager/src/lib.rs b/bridges/modules/shift-session-manager/src/lib.rs index 3635e6223d7f..2ff6a1397460 100644 --- a/bridges/modules/shift-session-manager/src/lib.rs +++ b/bridges/modules/shift-session-manager/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::{decl_module, decl_storage}; +use frame_support::{decl_module, decl_storage, WeakBoundedVec}; use sp_std::prelude::*; /// The module configuration trait. @@ -37,13 +37,17 @@ decl_storage! { } } -impl pallet_session::SessionManager for Pallet { +impl pallet_session::SessionManager + for Pallet +{ fn end_session(_: sp_staking::SessionIndex) {} fn start_session(_: sp_staking::SessionIndex) {} - fn new_session(session_index: sp_staking::SessionIndex) -> Option> { + fn new_session( + session_index: sp_staking::SessionIndex, + ) -> Option> { // we don't want to add even more fields to genesis config => just return None if session_index == 0 || session_index == 1 { - return None; + return None } // the idea that on first call (i.e. when session 1 ends) we're reading current @@ -66,7 +70,7 @@ impl Pallet { fn select_validators( session_index: sp_staking::SessionIndex, available_validators: &[T::ValidatorId], - ) -> Vec { + ) -> WeakBoundedVec { let available_validators_count = available_validators.len(); let count = sp_std::cmp::max(1, 2 * available_validators_count / 3); let offset = session_index as usize % available_validators_count; @@ -80,7 +84,10 @@ impl Pallet { _ => available_validators[offset..end].to_vec(), }; - session_validators + WeakBoundedVec::force_from( + session_validators, + Some("select_validators: too many validators"), + ) } } @@ -90,13 +97,17 @@ mod tests { #![allow(clippy::from_over_into)] use super::*; - use frame_support::sp_io::TestExternalities; - use frame_support::sp_runtime::{ - testing::{Header, UintAuthorityId}, - traits::{BlakeTwo256, ConvertInto, IdentityLookup}, - Perbill, RuntimeAppPublic, + use frame_support::{ + parameter_types, + sp_io::TestExternalities, + sp_runtime::{ + testing::{Header, UintAuthorityId}, + traits::{BlakeTwo256, ConvertInto, IdentityLookup}, + Perbill, RuntimeAppPublic, + }, + weights::Weight, + BasicExternalities, }; - use frame_support::{parameter_types, weights::Weight, BasicExternalities}; use sp_core::H256; type AccountId = u64; @@ -171,17 +182,21 @@ mod tests { impl pallet_session::SessionHandler for TestSessionHandler { const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID]; - fn on_genesis_session(_validators: &[(AccountId, Ks)]) {} + fn on_genesis_session(_validators: &[(AccountId, Ks)]) { + } - fn on_new_session(_: bool, _: &[(AccountId, Ks)], _: &[(AccountId, Ks)]) {} + fn on_new_session( + _: bool, + _: &[(AccountId, Ks)], + _: &[(AccountId, Ks)], + ) { + } fn on_disabled(_: u32) {} } fn new_test_ext() -> TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); let keys = vec![ (1, 1, UintAuthorityId(1)), diff --git a/runtime/common/src/elections.rs b/runtime/common/src/elections.rs index ae0ec401f63a..0972053413e4 100644 --- a/runtime/common/src/elections.rs +++ b/runtime/common/src/elections.rs @@ -56,7 +56,6 @@ impl pallet_election_provider_multi_phase::BenchmarkingConfig for BenchmarkConfi const DESIRED_TARGETS: [u32; 2] = [200, 400]; const SNAPSHOT_MAXIMUM_VOTERS: u32 = 1000; const MINER_MAXIMUM_VOTERS: u32 = 1000; - const MAXIMUM_TARGETS: u32 = 300; } /// The accuracy type used for genesis election provider; diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 4afe8488f93d..7c7c5bdc796a 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -266,7 +266,8 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -361,10 +362,12 @@ impl pallet_session::Config for Runtime { type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; type WeightInfo = weights::pallet_session::WeightInfo; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxKeysEncodingSize = MaxKeysEncodingSize; } impl pallet_session::historical::Config for Runtime { - type FullIdentification = pallet_staking::Exposure; + type FullIdentification = pallet_staking::Exposure; type FullIdentificationOf = pallet_staking::ExposureOf; } @@ -434,6 +437,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime { >; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type VoterSnapshotPerBlock = VoterSnapshotPerBlock; + type MaxTargets = MaxValidatorsCount; } parameter_types! { @@ -516,7 +520,17 @@ parameter_types! { pub const BondingDuration: pallet_staking::EraIndex = 28; // 27 eras in which slashes can be cancelled (slightly less than 7 days). pub const SlashDeferDuration: pallet_staking::EraIndex = 27; - pub const MaxNominatorRewardedPerValidator: u32 = 256; + pub const MaxRewardableIndividualExposures: u32 = 256; + pub const MaxIndividualExposures: u32 = 10_000; + pub const MaxNominations: u32 = ::LIMIT as u32; + pub const MaxUnappliedSlashes: u32 = 1_000; + pub const MaxInvulnerablesCount: u32 = 10; + pub const MaxHistoryDepth: u32 = 10_000; + pub const MaxReportersCount: u32 = 1_000; + pub const MaxPriorSlashingSpans: u32 = 1_000; + pub const MaxValidatorsCount: u32 = 4_000; + pub const MaxKeysEncodingSize: u32 = 1_000; + pub const MaxUnlockingChunks: u32 = 32; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); } @@ -529,11 +543,11 @@ type SlashCancelOrigin = EnsureOneOf< impl frame_election_provider_support::onchain::Config for Runtime { type Accuracy = runtime_common::elections::OnOnChainAccuracy; type DataProvider = Staking; + type MaxNominations = MaxNominations; + type MaxTargets = MaxValidatorsCount; } impl pallet_staking::Config for Runtime { - const MAX_NOMINATIONS: u32 = - ::LIMIT as u32; type Currency = Balances; type UnixTime = Timestamp; type CurrencyToVote = CurrencyToVote; @@ -551,7 +565,16 @@ impl pallet_staking::Config for Runtime { type SessionInterface = Self; type EraPayout = EraPayout; type NextNewSession = Session; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type MaxRewardableIndividualExposures = MaxRewardableIndividualExposures; + type MaxIndividualExposures = MaxIndividualExposures; + type MaxNominations = MaxNominations; + type MaxUnappliedSlashes = MaxUnappliedSlashes; + type MaxInvulnerablesCount = MaxInvulnerablesCount; + type MaxHistoryDepth = MaxHistoryDepth; + type MaxReportersCount = MaxReportersCount; + type MaxPriorSlashingSpans = MaxPriorSlashingSpans; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxUnlockingChunks = MaxUnlockingChunks; type OffendingValidatorsThreshold = OffendingValidatorsThreshold; // Use the nominators map to iter voters, but also keep bags-list up-to-date. type SortedListProvider = runtime_common::elections::UseNominatorsAndUpdateBagsList; @@ -728,8 +751,6 @@ parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 200 * CENTS; pub const MaxApprovals: u32 = 100; - pub const MaxAuthorities: u32 = 100_000; - pub const MaxKeys: u32 = 10_000; pub const MaxPeerInHeartbeats: u32 = 10_000; pub const MaxPeerDataEncodingSize: u32 = 1_000; } @@ -784,10 +805,11 @@ impl pallet_offences::Config for Runtime { type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; + type MaxReportersCount = MaxReportersCount; } impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; } parameter_types! { @@ -804,9 +826,10 @@ impl pallet_im_online::Config for Runtime { type ReportUnresponsiveness = Offences; type UnsignedPriority = ImOnlineUnsignedPriority; type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; + type MaxKeys = MaxValidatorsCount; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; + type MaxReportersCount = MaxReportersCount; } impl pallet_grandpa::Config for Runtime { @@ -830,7 +853,8 @@ impl pallet_grandpa::Config for Runtime { >; type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } /// Submits transaction with the node's public and signature type. Adheres to the signed extension diff --git a/runtime/kusama/src/tests.rs b/runtime/kusama/src/tests.rs index d2c1c725e3a9..e3a59607de99 100644 --- a/runtime/kusama/src/tests.rs +++ b/runtime/kusama/src/tests.rs @@ -49,7 +49,7 @@ fn sample_size_is_sensible() { fn payout_weight_portion() { use pallet_staking::WeightInfo; let payout_weight = ::WeightInfo::payout_stakers_alive_staked( - MaxNominatorRewardedPerValidator::get(), + MaxRewardableIndividualExposures::get(), ) as f64; let block_weight = BlockWeights::get().max_block as f64; diff --git a/runtime/kusama/src/weights/pallet_staking.rs b/runtime/kusama/src/weights/pallet_staking.rs index 5f385be7167e..7092e73a742b 100644 --- a/runtime/kusama/src/weights/pallet_staking.rs +++ b/runtime/kusama/src/weights/pallet_staking.rs @@ -111,7 +111,6 @@ impl pallet_staking::WeightInfo for WeightInfo { // Storage: Staking Ledger (r:1 w:0) // Storage: Staking MinValidatorBond (r:1 w:0) // Storage: Staking Validators (r:1 w:1) - // Storage: Staking MaxValidatorsCount (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) // Storage: BagsList ListNodes (r:2 w:2) @@ -120,7 +119,7 @@ impl pallet_staking::WeightInfo for WeightInfo { // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { (63_555_000 as Weight) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -386,13 +385,12 @@ impl pallet_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking MinValidatorBond (r:0 w:1) - // Storage: Staking MaxValidatorsCount (r:0 w:1) // Storage: Staking ChillThreshold (r:0 w:1) // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_limits() -> Weight { (5_996_000 as Weight) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking ChillThreshold (r:1 w:0) diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 88e8820c5803..51e2e31abc19 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -297,7 +297,8 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -388,10 +389,12 @@ impl pallet_session::Config for Runtime { type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; type WeightInfo = weights::pallet_session::WeightInfo; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxKeysEncodingSize = MaxKeysEncodingSize; } impl pallet_session::historical::Config for Runtime { - type FullIdentification = pallet_staking::Exposure; + type FullIdentification = pallet_staking::Exposure; type FullIdentificationOf = pallet_staking::ExposureOf; } @@ -463,6 +466,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime { >; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type VoterSnapshotPerBlock = VoterSnapshotPerBlock; + type MaxTargets = MaxValidatorsCount; } parameter_types! { @@ -499,7 +503,17 @@ parameter_types! { pub const BondingDuration: pallet_staking::EraIndex = 28; pub const SlashDeferDuration: pallet_staking::EraIndex = 27; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; - pub const MaxNominatorRewardedPerValidator: u32 = 256; + pub const MaxRewardableIndividualExposures: u32 = 256; + pub const MaxIndividualExposures: u32 = 10_000; + pub const MaxNominations: u32 = ::LIMIT as u32; + pub const MaxUnappliedSlashes: u32 = 1_000; + pub const MaxInvulnerablesCount: u32 = 10; + pub const MaxHistoryDepth: u32 = 10_000; + pub const MaxReportersCount: u32 = 1_000; + pub const MaxPriorSlashingSpans: u32 = 1_000; + pub const MaxValidatorsCount: u32 = 4_000; + pub const MaxKeysEncodingSize: u32 = 1_000; + pub const MaxUnlockingChunks: u32 = 32; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); } @@ -512,11 +526,11 @@ type SlashCancelOrigin = EnsureOneOf< impl frame_election_provider_support::onchain::Config for Runtime { type Accuracy = runtime_common::elections::OnOnChainAccuracy; type DataProvider = Staking; + type MaxTargets = MaxValidatorsCount; + type MaxNominations = MaxNominations; } impl pallet_staking::Config for Runtime { - const MAX_NOMINATIONS: u32 = - ::LIMIT as u32; type Currency = Balances; type UnixTime = Timestamp; type CurrencyToVote = CurrencyToVote; @@ -531,7 +545,16 @@ impl pallet_staking::Config for Runtime { type SlashCancelOrigin = SlashCancelOrigin; type SessionInterface = Self; type EraPayout = pallet_staking::ConvertCurve; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type MaxRewardableIndividualExposures = MaxRewardableIndividualExposures; + type MaxIndividualExposures = MaxIndividualExposures; + type MaxNominations = MaxNominations; + type MaxUnappliedSlashes = MaxUnappliedSlashes; + type MaxInvulnerablesCount = MaxInvulnerablesCount; + type MaxHistoryDepth = MaxHistoryDepth; + type MaxReportersCount = MaxReportersCount; + type MaxPriorSlashingSpans = MaxPriorSlashingSpans; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxUnlockingChunks = MaxUnlockingChunks; type OffendingValidatorsThreshold = OffendingValidatorsThreshold; type NextNewSession = Session; type ElectionProvider = ElectionProviderMultiPhase; @@ -751,8 +774,6 @@ parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const MaxApprovals: u32 = 100; - pub const MaxAuthorities: u32 = 100_000; - pub const MaxKeys: u32 = 10_000; pub const MaxPeerInHeartbeats: u32 = 10_000; pub const MaxPeerDataEncodingSize: u32 = 1_000; } @@ -807,10 +828,11 @@ impl pallet_offences::Config for Runtime { type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; + type MaxReportersCount = MaxReportersCount; } impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; } parameter_types! { @@ -827,9 +849,10 @@ impl pallet_im_online::Config for Runtime { type ReportUnresponsiveness = Offences; type UnsignedPriority = ImOnlineUnsignedPriority; type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; + type MaxKeys = MaxValidatorsCount; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; + type MaxReportersCount = MaxReportersCount; } impl pallet_grandpa::Config for Runtime { @@ -853,7 +876,8 @@ impl pallet_grandpa::Config for Runtime { >; type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } /// Submits a transaction with the node's public and signature type. Adheres to the signed extension @@ -1876,7 +1900,7 @@ mod test_fees { use pallet_staking::WeightInfo; let payout_weight = ::WeightInfo::payout_stakers_alive_staked( - MaxNominatorRewardedPerValidator::get(), + MaxRewardableIndividualExposures::get(), ) as f64; let block_weight = BlockWeights::get().max_block as f64; diff --git a/runtime/polkadot/src/weights/pallet_staking.rs b/runtime/polkadot/src/weights/pallet_staking.rs index 2e30aabcbf09..f67a33b0c8b4 100644 --- a/runtime/polkadot/src/weights/pallet_staking.rs +++ b/runtime/polkadot/src/weights/pallet_staking.rs @@ -105,13 +105,12 @@ impl pallet_staking::WeightInfo for WeightInfo { // Storage: Staking Ledger (r:1 w:0) // Storage: Staking MinValidatorBond (r:1 w:0) // Storage: Staking Validators (r:1 w:1) - // Storage: Staking MaxValidatorsCount (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { (36_901_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -364,13 +363,12 @@ impl pallet_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking MinValidatorBond (r:0 w:1) - // Storage: Staking MaxValidatorsCount (r:0 w:1) // Storage: Staking ChillThreshold (r:0 w:1) // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_limits() -> Weight { (5_680_000 as Weight) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking ChillThreshold (r:1 w:0) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index d4f3ce524087..aa64f733e9fa 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -382,9 +382,9 @@ parameter_types! { parameter_types! { pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); - pub const MaxKeys: u32 = 10_000; pub const MaxPeerInHeartbeats: u32 = 10_000; pub const MaxPeerDataEncodingSize: u32 = 1_000; + pub const MaxReportersCount: u32 = 1_000; } impl pallet_im_online::Config for Runtime { @@ -395,9 +395,10 @@ impl pallet_im_online::Config for Runtime { type ReportUnresponsiveness = Offences; type UnsignedPriority = ImOnlineUnsignedPriority; type WeightInfo = (); - type MaxKeys = MaxKeys; + type MaxKeys = MaxValidatorsCount; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -428,17 +429,17 @@ where parameter_types! { pub const MaxRetries: u32 = 3; - pub const MaxAuthorities: u32 = 100_000; } impl pallet_offences::Config for Runtime { type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = (); + type MaxReportersCount = MaxReportersCount; } impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; } parameter_types! { @@ -456,6 +457,8 @@ parameter_types! { /// This value increases the priority of `Operational` transactions by adding /// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`. pub const OperationalFeeMultiplier: u8 = 5; + pub const MaxValidatorsCount: u32 = 4_000; + pub const MaxKeysEncodingSize: u32 = 1_000; } impl pallet_transaction_payment::Config for Runtime { @@ -483,6 +486,8 @@ impl pallet_session::Config for Runtime { type SessionManager = pallet_session::historical::NoteHistoricalRoot; type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxKeysEncodingSize = MaxKeysEncodingSize; type WeightInfo = (); } @@ -517,7 +522,8 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -557,7 +563,8 @@ impl pallet_grandpa::Config for Runtime { >; type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -1083,8 +1090,9 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::CancelProxy => - matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })), + ProxyType::CancelProxy => { + matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })) + }, ProxyType::Auction => matches!( c, Call::Auctions { .. } | diff --git a/runtime/rococo/src/validator_manager.rs b/runtime/rococo/src/validator_manager.rs index 763d12c73f5c..8892a3689fb4 100644 --- a/runtime/rococo/src/validator_manager.rs +++ b/runtime/rococo/src/validator_manager.rs @@ -16,7 +16,9 @@ //! A pallet for managing validators on Rococo. -use frame_support::{decl_error, decl_event, decl_module, decl_storage, traits::EnsureOrigin}; +use frame_support::{ + decl_error, decl_event, decl_module, decl_storage, traits::EnsureOrigin, WeakBoundedVec, +}; use sp_staking::SessionIndex; use sp_std::vec::Vec; @@ -93,14 +95,19 @@ decl_module! { impl Module {} -impl pallet_session::SessionManager for Module { - fn new_session(new_index: SessionIndex) -> Option> { +impl pallet_session::SessionManager + for Module +{ + fn new_session( + new_index: SessionIndex, + ) -> Option> { if new_index <= 1 { return None } let mut validators = Session::::validators(); + // It's crucial to remove validators first and then add for the WeakBoundedVec not to overflow ValidatorsToRetire::::take().iter().for_each(|v| { if let Some(pos) = validators.iter().position(|r| r == v) { validators.swap_remove(pos); @@ -109,7 +116,12 @@ impl pallet_session::SessionManager for Module { ValidatorsToAdd::::take().into_iter().for_each(|v| { if !validators.contains(&v) { - validators.push(v); + if validators.try_push(v).is_err() { + log::error!( + target: "Validator Managers", + "new_session: Too many validators to add, will be truncated" + ); + }; } }); @@ -121,17 +133,22 @@ impl pallet_session::SessionManager for Module { fn start_session(_start_index: SessionIndex) {} } -impl pallet_session::historical::SessionManager for Module { - fn new_session(new_index: SessionIndex) -> Option> { - >::new_session(new_index) - .map(|r| r.into_iter().map(|v| (v, Default::default())).collect()) +impl + pallet_session::historical::SessionManager + for Module +{ + fn new_session( + new_index: SessionIndex, + ) -> Option> { + >::new_session(new_index) + .map(|r| r.map_collect(|v| (v, Default::default()))) } fn start_session(start_index: SessionIndex) { - >::start_session(start_index) + >::start_session(start_index) } fn end_session(end_index: SessionIndex) { - >::end_session(end_index) + >::end_session(end_index) } } diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 773c50920c52..a2b86b954694 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -188,7 +188,8 @@ impl pallet_babe::Config for Runtime { type HandleEquivocation = (); type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -282,11 +283,13 @@ impl pallet_session::Config for Runtime { type SessionManager = Staking; type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxKeysEncodingSize = MaxKeysEncodingSize; type WeightInfo = (); } impl pallet_session::historical::Config for Runtime { - type FullIdentification = pallet_staking::Exposure; + type FullIdentification = pallet_staking::Exposure; type FullIdentificationOf = pallet_staking::ExposureOf; } @@ -309,18 +312,28 @@ parameter_types! { // 27 eras in which slashes can be cancelled (a bit less than 7 days). pub storage SlashDeferDuration: pallet_staking::EraIndex = 27; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; - pub storage MaxNominatorRewardedPerValidator: u32 = 64; + pub storage MaxRewardableIndividualExposures: u32 = 64; + pub const MaxIndividualExposures: u32 = 1_000; pub storage OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); - pub const MaxAuthorities: u32 = 100_000; + pub const MaxNominations: u32 = 16; + pub const MaxUnappliedSlashes: u32 = 1_000; + pub const MaxInvulnerablesCount: u32 = 10; + pub const MaxHistoryDepth: u32 = 10_000; + pub const MaxReportersCount: u32 = 1_000; + pub const MaxPriorSlashingSpans: u32 = 1_000; + pub const MaxValidatorsCount: u32 = 4_000; + pub const MaxUnlockingChunks: u32 = 32; + pub const MaxKeysEncodingSize: u32 = 1_000; } impl frame_election_provider_support::onchain::Config for Runtime { type Accuracy = runtime_common::elections::OnOnChainAccuracy; type DataProvider = Staking; + type MaxNominations = MaxNominations; + type MaxTargets = MaxValidatorsCount; } impl pallet_staking::Config for Runtime { - const MAX_NOMINATIONS: u32 = 16; type Currency = Balances; type UnixTime = Timestamp; type CurrencyToVote = frame_support::traits::U128CurrencyToVote; @@ -335,7 +348,16 @@ impl pallet_staking::Config for Runtime { type SlashCancelOrigin = frame_system::EnsureNever<()>; type SessionInterface = Self; type EraPayout = pallet_staking::ConvertCurve; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type MaxRewardableIndividualExposures = MaxRewardableIndividualExposures; + type MaxIndividualExposures = MaxIndividualExposures; + type MaxNominations = MaxNominations; + type MaxUnappliedSlashes = MaxUnappliedSlashes; + type MaxInvulnerablesCount = MaxInvulnerablesCount; + type MaxHistoryDepth = MaxHistoryDepth; + type MaxReportersCount = MaxReportersCount; + type MaxPriorSlashingSpans = MaxPriorSlashingSpans; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxUnlockingChunks = MaxUnlockingChunks; type OffendingValidatorsThreshold = OffendingValidatorsThreshold; type NextNewSession = Session; type ElectionProvider = @@ -365,7 +387,8 @@ impl pallet_grandpa::Config for Runtime { type HandleEquivocation = (); type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } impl frame_system::offchain::CreateSignedTransaction for Runtime @@ -416,10 +439,11 @@ impl pallet_offences::Config for Runtime { type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; + type MaxReportersCount = MaxReportersCount; } impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; } parameter_types! { diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 646a4a18f351..627a92d06dfb 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -228,7 +228,8 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } parameter_types! { @@ -323,10 +324,12 @@ impl pallet_session::Config for Runtime { type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; type WeightInfo = weights::pallet_session::WeightInfo; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxKeysEncodingSize = MaxKeysEncodingSize; } impl pallet_session::historical::Config for Runtime { - type FullIdentification = pallet_staking::Exposure; + type FullIdentification = pallet_staking::Exposure; type FullIdentificationOf = pallet_staking::ExposureOf; } @@ -392,6 +395,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime { type ForceOrigin = EnsureRoot; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type VoterSnapshotPerBlock = VoterSnapshotPerBlock; + type MaxTargets = MaxValidatorsCount; } parameter_types! { @@ -424,18 +428,28 @@ parameter_types! { // 27 eras in which slashes can be cancelled (slightly less than 7 days). pub const SlashDeferDuration: pallet_staking::EraIndex = 27; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; - pub const MaxNominatorRewardedPerValidator: u32 = 64; + pub const MaxRewardableIndividualExposures: u32 = 64; + pub const MaxIndividualExposures: u32 = 1_000; + pub const MaxNominations: u32 = ::LIMIT as u32; + pub const MaxUnappliedSlashes: u32 = 1_000; + pub const MaxInvulnerablesCount: u32 = 10; + pub const MaxHistoryDepth: u32 = 10_000; + pub const MaxReportersCount: u32 = 1_000; + pub const MaxPriorSlashingSpans: u32 = 1_000; + pub const MaxValidatorsCount: u32 = 4_000; + pub const MaxKeysEncodingSize: u32 = 1_000; + pub const MaxUnlockingChunks: u32 = 32; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); } impl frame_election_provider_support::onchain::Config for Runtime { type Accuracy = runtime_common::elections::OnOnChainAccuracy; type DataProvider = Staking; + type MaxNominations = MaxNominations; + type MaxTargets = MaxValidatorsCount; } impl pallet_staking::Config for Runtime { - const MAX_NOMINATIONS: u32 = - ::LIMIT as u32; type Currency = Balances; type UnixTime = Timestamp; type CurrencyToVote = CurrencyToVote; @@ -450,7 +464,16 @@ impl pallet_staking::Config for Runtime { type SlashCancelOrigin = EnsureRoot; type SessionInterface = Self; type EraPayout = pallet_staking::ConvertCurve; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type MaxRewardableIndividualExposures = MaxRewardableIndividualExposures; + type MaxIndividualExposures = MaxIndividualExposures; + type MaxNominations = MaxNominations; + type MaxUnappliedSlashes = MaxUnappliedSlashes; + type MaxInvulnerablesCount = MaxInvulnerablesCount; + type MaxHistoryDepth = MaxHistoryDepth; + type MaxReportersCount = MaxReportersCount; + type MaxPriorSlashingSpans = MaxPriorSlashingSpans; + type MaxValidatorsCount = MaxValidatorsCount; + type MaxUnlockingChunks = MaxUnlockingChunks; type OffendingValidatorsThreshold = OffendingValidatorsThreshold; type NextNewSession = Session; type ElectionProvider = ElectionProviderMultiPhase; @@ -470,23 +493,22 @@ parameter_types! { // One cent: $10,000 / MB pub const PreimageByteDeposit: Balance = 10 * MILLICENTS; pub const InstantAllowed: bool = true; - pub const MaxAuthorities: u32 = 100_000; } impl pallet_offences::Config for Runtime { type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; + type MaxReportersCount = MaxReportersCount; } impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; } parameter_types! { pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2; pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); - pub const MaxKeys: u32 = 10_000; pub const MaxPeerInHeartbeats: u32 = 10_000; pub const MaxPeerDataEncodingSize: u32 = 1_000; } @@ -499,9 +521,10 @@ impl pallet_im_online::Config for Runtime { type ReportUnresponsiveness = Offences; type UnsignedPriority = ImOnlineUnsignedPriority; type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; + type MaxKeys = MaxValidatorsCount; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; + type MaxReportersCount = MaxReportersCount; } impl pallet_grandpa::Config for Runtime { @@ -525,7 +548,8 @@ impl pallet_grandpa::Config for Runtime { >; type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = MaxValidatorsCount; + type MaxReportersCount = MaxReportersCount; } /// Submits a transaction with the node's public and signature type. Adheres to the signed extension diff --git a/runtime/westend/src/weights/pallet_staking.rs b/runtime/westend/src/weights/pallet_staking.rs index 7392df46e267..e5485030f42e 100644 --- a/runtime/westend/src/weights/pallet_staking.rs +++ b/runtime/westend/src/weights/pallet_staking.rs @@ -111,7 +111,6 @@ impl pallet_staking::WeightInfo for WeightInfo { // Storage: Staking Ledger (r:1 w:0) // Storage: Staking MinValidatorBond (r:1 w:0) // Storage: Staking Validators (r:1 w:1) - // Storage: Staking MaxValidatorsCount (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) // Storage: BagsList ListNodes (r:2 w:2) @@ -120,7 +119,7 @@ impl pallet_staking::WeightInfo for WeightInfo { // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { (65_171_000 as Weight) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -386,13 +385,12 @@ impl pallet_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking MinValidatorBond (r:0 w:1) - // Storage: Staking MaxValidatorsCount (r:0 w:1) // Storage: Staking ChillThreshold (r:0 w:1) // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_limits() -> Weight { (5_641_000 as Weight) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking ChillThreshold (r:1 w:0)