Skip to content
Snippets Groups Projects
Commit 7793796b authored by Georges's avatar Georges Committed by GitHub
Browse files

Adding `Fallback` on election failure (#5093)


* Adding `Fallback` on election failure
Use the newly introduced `BoundedOnChainSequentialPhragmen`
and `UnboundedOnChainSequentialPhragmen`

* Adding `BoundedOnchainExecution`
after changes in substrate

* Introducing `ExecutionConfig`
from `frame_election_provider_support::onchain`

* `OnChainSequentialPhragmen` > `OnChainSeqPhragmen`
Renaming to have a shorter name

* `BoundedOnchainExecution` -> `BoundedExecution`
And `UnboundedOnchainExecution` -> `UnboundedExecution`

* `Fallback` back to `NoFallback`
`UnboundedExecution` for `GovernanceFallback`

* Update runtime/test-runtime/src/lib.rs

* update lockfile for {"substrate"}

Co-authored-by: default avatarKian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: parity-processbot <>
parent cbd6570c
No related merge requests found
This diff is collapsed.
......@@ -16,7 +16,10 @@
//! Code for elections.
use frame_election_provider_support::SortedListProvider;
use frame_election_provider_support::{
onchain::{ExecutionConfig, UnboundedExecution},
ElectionDataProvider, SequentialPhragmen, SortedListProvider,
};
use sp_std::{boxed::Box, marker::PhantomData};
/// Implements the weight types for the elections module and a specific
......@@ -64,9 +67,20 @@ impl pallet_election_provider_multi_phase::BenchmarkingConfig for BenchmarkConfi
/// The accuracy type used for genesis election provider;
pub type OnOnChainAccuracy = sp_runtime::Perbill;
/// Election Configuration parameters
pub struct OnChainSeqPhragmen<T: frame_system::Config, S>(PhantomData<(T, S)>);
impl<
T: frame_system::Config,
S: ElectionDataProvider<AccountId = T::AccountId, BlockNumber = T::BlockNumber>,
> ExecutionConfig for OnChainSeqPhragmen<T, S>
{
type System = T;
type Solver = SequentialPhragmen<T::AccountId, OnOnChainAccuracy>;
type DataProvider = S;
}
/// The election provider of the genesis
pub type GenesisElectionOf<T> =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<T>;
pub type GenesisElectionOf<T, S> = UnboundedExecution<OnChainSeqPhragmen<T, S>>;
/// Implementation of `frame_election_provider_support::SortedListProvider` that updates the
/// bags-list but uses [`pallet_staking::Nominators`] for `iter`. This is meant to be a transitionary
......
......@@ -29,8 +29,9 @@ use primitives::v2::{
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
};
use runtime_common::{
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
prod_or_fast, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
auctions, claims, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
impls::DealWithFees, paras_registrar, prod_or_fast, slots, BlockHashCount, BlockLength,
CurrencyToVote, SlowAdjustingFeeUpdate,
};
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};
......@@ -45,6 +46,9 @@ use runtime_parachains::{
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_election_provider_support::{
generate_solution_type, onchain::UnboundedExecution, NposSolution, SequentialPhragmen,
};
use frame_support::{
construct_runtime, parameter_types,
traits::{
......@@ -413,7 +417,7 @@ parameter_types! {
pub const MaxElectableTargets: u16 = u16::MAX;
}
frame_election_provider_support::generate_solution_type!(
generate_solution_type!(
#[compact]
pub struct NposCompactSolution24::<
VoterIndex = u32,
......@@ -445,9 +449,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type DataProvider = Staking;
type Solution = NposCompactSolution24;
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
type GovernanceFallback =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type Solver = frame_election_provider_support::SequentialPhragmen<
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
type Solver = SequentialPhragmen<
AccountId,
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
(),
......@@ -546,7 +549,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
// 24
pub const MaxNominations: u32 = <NposCompactSolution24 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub const MaxNominations: u32 = <NposCompactSolution24 as NposSolution>::LIMIT as u32;
}
type SlashCancelOrigin = EnsureOneOf<
......@@ -554,18 +557,13 @@ type SlashCancelOrigin = EnsureOneOf<
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>,
>;
impl frame_election_provider_support::onchain::Config for Runtime {
type Accuracy = runtime_common::elections::OnOnChainAccuracy;
type DataProvider = Staking;
}
impl pallet_staking::Config for Runtime {
type MaxNominations = MaxNominations;
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVote;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
type RewardRemainder = Treasury;
type Event = Event;
type Slash = Treasury;
......
......@@ -22,8 +22,9 @@
use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
prod_or_fast, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
auctions, claims, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
impls::DealWithFees, paras_registrar, prod_or_fast, slots, BlockHashCount, BlockLength,
CurrencyToVote, SlowAdjustingFeeUpdate,
};
use runtime_parachains::{
......@@ -37,6 +38,9 @@ use runtime_parachains::{
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_election_provider_support::{
generate_solution_type, onchain::UnboundedExecution, SequentialPhragmen,
};
use frame_support::{
construct_runtime, parameter_types,
traits::{
......@@ -456,7 +460,7 @@ parameter_types! {
pub const MaxElectableTargets: u16 = u16::MAX;
}
frame_election_provider_support::generate_solution_type!(
generate_solution_type!(
#[compact]
pub struct NposCompactSolution16::<
VoterIndex = u32,
......@@ -488,9 +492,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type DataProvider = Staking;
type Solution = NposCompactSolution16;
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
type GovernanceFallback =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type Solver = frame_election_provider_support::SequentialPhragmen<
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
type Solver = SequentialPhragmen<
AccountId,
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
(),
......@@ -551,11 +554,6 @@ type SlashCancelOrigin = EnsureOneOf<
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
>;
impl frame_election_provider_support::onchain::Config for Runtime {
type Accuracy = runtime_common::elections::OnOnChainAccuracy;
type DataProvider = Staking;
}
impl pallet_staking::Config for Runtime {
type MaxNominations = MaxNominations;
type Currency = Balances;
......@@ -576,7 +574,7 @@ impl pallet_staking::Config for Runtime {
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
type VoterList = BagsList;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
......
......@@ -318,11 +318,6 @@ parameter_types! {
pub const MaxAuthorities: u32 = 100_000;
}
impl frame_election_provider_support::onchain::Config for Runtime {
type Accuracy = runtime_common::elections::OnOnChainAccuracy;
type DataProvider = Staking;
}
impl pallet_staking::Config for Runtime {
type MaxNominations = frame_support::pallet_prelude::ConstU32<16>;
type Currency = Balances;
......@@ -342,10 +337,14 @@ impl pallet_staking::Config for Runtime {
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type ElectionProvider = frame_election_provider_support::onchain::UnboundedExecution<
runtime_common::elections::OnChainSeqPhragmen<Self, Staking>,
>;
type GenesisElectionProvider = frame_election_provider_support::onchain::UnboundedExecution<
runtime_common::elections::OnChainSeqPhragmen<Self, Staking>,
>;
// Use the nominator map to iter voter AND no-ops for all SortedListProvider hooks. The migration
// to bags-list is a no-op, but the storage version will be updated.
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Runtime>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
......
......@@ -22,6 +22,7 @@
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_election_provider_support::{onchain::UnboundedExecution, SequentialPhragmen};
use frame_support::{
construct_runtime, parameter_types,
traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade},
......@@ -42,8 +43,9 @@ use primitives::v2::{
ValidatorIndex, ValidatorSignature,
};
use runtime_common::{
assigned_slots, auctions, crowdloan, impl_runtime_weights, impls::ToAuthor, paras_registrar,
paras_sudo_wrapper, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
assigned_slots, auctions, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
impls::ToAuthor, paras_registrar, paras_sudo_wrapper, slots, BlockHashCount, BlockLength,
CurrencyToVote, SlowAdjustingFeeUpdate,
};
use runtime_parachains::{
configuration as parachains_configuration, disputes as parachains_disputes,
......@@ -390,9 +392,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type DataProvider = Staking;
type Solution = NposCompactSolution16;
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
type GovernanceFallback =
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type Solver = frame_election_provider_support::SequentialPhragmen<
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
type Solver = SequentialPhragmen<
AccountId,
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
(),
......@@ -440,11 +441,6 @@ parameter_types! {
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
}
impl frame_election_provider_support::onchain::Config for Runtime {
type Accuracy = runtime_common::elections::OnOnChainAccuracy;
type DataProvider = Staking;
}
impl pallet_staking::Config for Runtime {
type MaxNominations = MaxNominations;
type Currency = Balances;
......@@ -465,7 +461,7 @@ impl pallet_staking::Config for Runtime {
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
type VoterList = BagsList;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment