Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions bridges/modules/shift-session-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -37,13 +37,17 @@ decl_storage! {
}
}

impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Pallet<T> {
impl<T: Config> pallet_session::SessionManager<T::ValidatorId, T::MaxValidatorsCount>
for Pallet<T>
{
fn end_session(_: sp_staking::SessionIndex) {}
fn start_session(_: sp_staking::SessionIndex) {}
fn new_session(session_index: sp_staking::SessionIndex) -> Option<Vec<T::ValidatorId>> {
fn new_session(
session_index: sp_staking::SessionIndex,
) -> Option<WeakBoundedVec<T::ValidatorId, T::MaxValidatorsCount>> {
// 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
Expand All @@ -66,7 +70,7 @@ impl<T: Config> Pallet<T> {
fn select_validators(
session_index: sp_staking::SessionIndex,
available_validators: &[T::ValidatorId],
) -> Vec<T::ValidatorId> {
) -> WeakBoundedVec<T::ValidatorId, T::MaxValidatorsCount> {
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;
Expand All @@ -80,7 +84,10 @@ impl<T: Config> Pallet<T> {
_ => available_validators[offset..end].to_vec(),
};

session_validators
WeakBoundedVec::force_from(
session_validators,
Some("select_validators: too many validators"),
)
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -171,17 +182,21 @@ mod tests {
impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID];

fn on_genesis_session<Ks: sp_runtime::traits::OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
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_new_session<Ks: sp_runtime::traits::OpaqueKeys>(
_: bool,
_: &[(AccountId, Ks)],
_: &[(AccountId, Ks)],
) {
}

fn on_disabled(_: u32) {}
}

fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<TestRuntime>()
.unwrap();
let mut t = frame_system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();

let keys = vec![
(1, 1, UintAuthorityId(1)),
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 35 additions & 11 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ impl pallet_babe::Config for Runtime {

type WeightInfo = ();

type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = MaxValidatorsCount;
type MaxReportersCount = MaxReportersCount;
}

parameter_types! {
Expand Down Expand Up @@ -361,10 +362,12 @@ impl pallet_session::Config for Runtime {
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
type MaxValidatorsCount = MaxValidatorsCount;
type MaxKeysEncodingSize = MaxKeysEncodingSize;
}

impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentification = pallet_staking::Exposure<AccountId, Balance, MaxIndividualExposures>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}

Expand Down Expand Up @@ -434,6 +437,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
>;
type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo<Self>;
type VoterSnapshotPerBlock = VoterSnapshotPerBlock;
type MaxTargets = MaxValidatorsCount;
}

parameter_types! {
Expand Down Expand Up @@ -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 = <NposCompactSolution24 as sp_npos_elections::NposSolution>::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);
}

Expand All @@ -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 =
<NposCompactSolution24 as sp_npos_elections::NposSolution>::LIMIT as u32;
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVote;
Expand All @@ -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<Runtime>;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -784,10 +805,11 @@ impl pallet_offences::Config for Runtime {
type Event = Event;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type MaxReportersCount = MaxReportersCount;
}

impl pallet_authority_discovery::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = MaxValidatorsCount;
}

parameter_types! {
Expand All @@ -804,9 +826,10 @@ impl pallet_im_online::Config for Runtime {
type ReportUnresponsiveness = Offences;
type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
type MaxKeys = MaxKeys;
type MaxKeys = MaxValidatorsCount;
type MaxPeerInHeartbeats = MaxPeerInHeartbeats;
type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize;
type MaxReportersCount = MaxReportersCount;
}

impl pallet_grandpa::Config for Runtime {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn sample_size_is_sensible() {
fn payout_weight_portion() {
use pallet_staking::WeightInfo;
let payout_weight = <Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
MaxNominatorRewardedPerValidator::get(),
MaxRewardableIndividualExposures::get(),
) as f64;
let block_weight = BlockWeights::get().max_block as f64;

Expand Down
6 changes: 2 additions & 4 deletions runtime/kusama/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
// 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)
Expand All @@ -120,7 +119,7 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
// 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)
Expand Down Expand Up @@ -386,13 +385,12 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.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)
Expand Down
Loading