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

[Substrate Companion] Part 1: add TargetList for validator ranking #5930

Merged
merged 14 commits into from
Sep 18, 2022
33 changes: 27 additions & 6 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use static_assertions::const_assert;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
use pallet_staking::UseValidatorsMap;
#[cfg(feature = "std")]
pub use pallet_staking::StakerStatus;
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -510,7 +511,8 @@ parameter_types! {
pub const BagThresholds: &'static [u64] = &bag_thresholds::THRESHOLDS;
}

impl pallet_bags_list::Config for Runtime {
type VoterBagsListInstance = pallet_bags_list::Instance1;
impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
type Event = Event;
type ScoreProvider = Staking;
type WeightInfo = weights::pallet_bags_list::WeightInfo<Runtime>;
Expand Down Expand Up @@ -620,13 +622,32 @@ impl pallet_staking::Config for Runtime {
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type VoterList = VoterList;
type VoterList = VoterBagsList;
type TargetList = UseValidatorsMap<Self>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type OnStakerSlash = NominationPools;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}

const OLD_PALLET_NAME: &'static str = "VoterList";
pub struct StakingMigrationV11;
ruseinov marked this conversation as resolved.
Show resolved Hide resolved
impl frame_support::traits::OnRuntimeUpgrade for StakingMigrationV11 {
fn on_runtime_upgrade() -> Weight {
pallet_staking::migrations::v11::migrate::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::pre_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::post_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 2000 * CENTS;
Expand Down Expand Up @@ -1053,7 +1074,7 @@ impl InstanceFilter<Call> for ProxyType {
Call::Crowdloan(..) |
Call::Slots(..) |
Call::Auctions(..) | // Specifically omitting the entire XCM Pallet
Call::VoterList(..) |
Call::VoterBagsList(..) |
Call::NominationPools(..)
),
ProxyType::Governance => matches!(
Expand Down Expand Up @@ -1385,7 +1406,7 @@ construct_runtime! {
Gilt: pallet_gilt::{Pallet, Call, Storage, Event<T>, Config} = 38,

// Provides a semi-sorted list of nominators for staking.
VoterList: pallet_bags_list::{Pallet, Call, Storage, Event<T>} = 39,
VoterBagsList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 39,

// nomination pools: extension to staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 41,
Expand Down Expand Up @@ -1446,7 +1467,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
StakingMigrationV11,
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand Down Expand Up @@ -1475,7 +1496,7 @@ mod benches {
[runtime_parachains::ump, Ump]
// Substrate
[pallet_balances, Balances]
[pallet_bags_list, VoterList]
[pallet_bags_list, VoterBagsList]
[frame_benchmarking::baseline, Baseline::<Runtime>]
[pallet_bounties, Bounties]
[pallet_child_bounties, ChildBounties]
Expand Down
37 changes: 30 additions & 7 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use static_assertions::const_assert;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
use pallet_staking::UseValidatorsMap;
#[cfg(feature = "std")]
pub use pallet_staking::StakerStatus;
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -182,7 +183,7 @@ impl Contains<Call> for BaseFilter {
Call::Registrar(_) |
Call::Auctions(_) |
Call::Crowdloan(_) |
Call::VoterList(_) |
Call::VoterBagsList(_) |
Call::XcmPallet(_) |
Call::NominationPools(_) => true,
// All pallets are allowed, but exhaustive match is defensive
Expand Down Expand Up @@ -547,7 +548,8 @@ parameter_types! {
pub const BagThresholds: &'static [u64] = &bag_thresholds::THRESHOLDS;
}

impl pallet_bags_list::Config for Runtime {
type VoterBagsListInstance = pallet_bags_list::Instance1;
impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
type Event = Event;
type ScoreProvider = Staking;
type WeightInfo = weights::pallet_bags_list::WeightInfo<Runtime>;
Expand Down Expand Up @@ -611,13 +613,33 @@ impl pallet_staking::Config for Runtime {
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type VoterList = VoterList;
type VoterList = VoterBagsList;
type TargetList = UseValidatorsMap<Self>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type OnStakerSlash = NominationPools;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}

const OLD_PALLET_NAME: &'static str = "VoterList";
pub struct StakingMigrationV11;
impl frame_support::traits::OnRuntimeUpgrade for StakingMigrationV11 {
fn on_runtime_upgrade() -> Weight {
pallet_staking::migrations::v11::migrate::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::pre_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)

}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::post_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}
}

parameter_types! {
// Minimum 4 CENTS/byte
pub const BasicDeposit: Balance = deposit(1, 258);
Expand Down Expand Up @@ -1185,7 +1207,7 @@ impl InstanceFilter<Call> for ProxyType {
Call::Crowdloan(..) |
Call::Slots(..) |
Call::Auctions(..) | // Specifically omitting the entire XCM Pallet
Call::VoterList(..) |
Call::VoterBagsList(..) |
Call::NominationPools(..)
),
ProxyType::Governance => matches!(
Expand Down Expand Up @@ -1509,7 +1531,7 @@ construct_runtime! {
ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Pallet, Call, Storage, Event<T>, ValidateUnsigned} = 36,

// Provides a semi-sorted list of nominators for staking.
VoterList: pallet_bags_list::{Pallet, Call, Storage, Event<T>} = 37,
VoterBagsList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 37,

// nomination pools: extension to staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 39,
Expand Down Expand Up @@ -1571,8 +1593,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
InitiateNominationPools,
(InitiateNominationPools, StakingMigrationV11),
>;

/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

Expand All @@ -1598,7 +1621,7 @@ mod benches {
[runtime_parachains::paras_inherent, ParaInherent]
[runtime_parachains::ump, Ump]
// Substrate
[pallet_bags_list, VoterList]
[pallet_bags_list, VoterBagsList]
[pallet_balances, Balances]
[frame_benchmarking::baseline, Baseline::<Runtime>]
[pallet_bounties, Bounties]
Expand Down
33 changes: 27 additions & 6 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use sp_version::RuntimeVersion;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
use pallet_staking::UseValidatorsMap;
#[cfg(feature = "std")]
pub use pallet_staking::StakerStatus;
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -455,7 +456,8 @@ parameter_types! {
pub const BagThresholds: &'static [u64] = &bag_thresholds::THRESHOLDS;
}

impl pallet_bags_list::Config for Runtime {
type VoterBagsListInstance = pallet_bags_list::Instance1;
impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
type Event = Event;
type ScoreProvider = Staking;
type WeightInfo = weights::pallet_bags_list::WeightInfo<Runtime>;
Expand Down Expand Up @@ -509,13 +511,32 @@ impl pallet_staking::Config for Runtime {
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type VoterList = VoterList;
type VoterList = VoterBagsList;
type TargetList = UseValidatorsMap<Self>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type OnStakerSlash = NominationPools;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}

const OLD_PALLET_NAME: &'static str = "VoterList";
pub struct StakingMigrationV11;
impl frame_support::traits::OnRuntimeUpgrade for StakingMigrationV11 {
fn on_runtime_upgrade() -> Weight {
pallet_staking::migrations::v11::migrate::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::pre_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v11::post_upgrade::<Runtime, VoterBagsList, &'static str>(OLD_PALLET_NAME)
}
}

parameter_types! {
pub const MaxAuthorities: u32 = 100_000;
}
Expand Down Expand Up @@ -803,7 +824,7 @@ impl InstanceFilter<Call> for ProxyType {
Call::Crowdloan(..) |
Call::Slots(..) |
Call::Auctions(..) | // Specifically omitting the entire XCM Pallet
Call::VoterList(..) |
Call::VoterBagsList(..) |
Call::NominationPools(..)
),
ProxyType::Staking => {
Expand Down Expand Up @@ -1097,7 +1118,7 @@ construct_runtime! {
ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Pallet, Call, Storage, Event<T>, ValidateUnsigned} = 24,

// Provides a semi-sorted list of nominators for staking.
VoterList: pallet_bags_list::{Pallet, Call, Storage, Event<T>} = 25,
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
VoterBagsList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 25,

// Nomination pools for staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 29,
Expand Down Expand Up @@ -1160,7 +1181,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
StakingMigrationV11,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand All @@ -1187,7 +1208,7 @@ mod benches {
[runtime_parachains::paras_inherent, ParaInherent]
[runtime_parachains::ump, Ump]
// Substrate
[pallet_bags_list, VoterList]
[pallet_bags_list, VoterBagsList]
[pallet_balances, Balances]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[frame_election_provider_support, ElectionProviderBench::<Runtime>]
Expand Down