mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
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: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Generated
+166
-163
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
//! Code for elections.
|
//! 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};
|
use sp_std::{boxed::Box, marker::PhantomData};
|
||||||
|
|
||||||
/// Implements the weight types for the elections module and a specific
|
/// 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;
|
/// The accuracy type used for genesis election provider;
|
||||||
pub type OnOnChainAccuracy = sp_runtime::Perbill;
|
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
|
/// The election provider of the genesis
|
||||||
pub type GenesisElectionOf<T> =
|
pub type GenesisElectionOf<T, S> = UnboundedExecution<OnChainSeqPhragmen<T, S>>;
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<T>;
|
|
||||||
|
|
||||||
/// Implementation of `frame_election_provider_support::SortedListProvider` that updates the
|
/// 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
|
/// 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,
|
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
||||||
};
|
};
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
|
auctions, claims, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
|
||||||
prod_or_fast, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
|
impls::DealWithFees, paras_registrar, prod_or_fast, slots, BlockHashCount, BlockLength,
|
||||||
|
CurrencyToVote, SlowAdjustingFeeUpdate,
|
||||||
};
|
};
|
||||||
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};
|
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 authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||||
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||||
|
use frame_election_provider_support::{
|
||||||
|
generate_solution_type, onchain::UnboundedExecution, NposSolution, SequentialPhragmen,
|
||||||
|
};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
construct_runtime, parameter_types,
|
construct_runtime, parameter_types,
|
||||||
traits::{
|
traits::{
|
||||||
@@ -413,7 +417,7 @@ parameter_types! {
|
|||||||
pub const MaxElectableTargets: u16 = u16::MAX;
|
pub const MaxElectableTargets: u16 = u16::MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_election_provider_support::generate_solution_type!(
|
generate_solution_type!(
|
||||||
#[compact]
|
#[compact]
|
||||||
pub struct NposCompactSolution24::<
|
pub struct NposCompactSolution24::<
|
||||||
VoterIndex = u32,
|
VoterIndex = u32,
|
||||||
@@ -445,9 +449,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
|
|||||||
type DataProvider = Staking;
|
type DataProvider = Staking;
|
||||||
type Solution = NposCompactSolution24;
|
type Solution = NposCompactSolution24;
|
||||||
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
||||||
type GovernanceFallback =
|
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
|
type Solver = SequentialPhragmen<
|
||||||
type Solver = frame_election_provider_support::SequentialPhragmen<
|
|
||||||
AccountId,
|
AccountId,
|
||||||
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
|
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
|
||||||
(),
|
(),
|
||||||
@@ -546,7 +549,7 @@ parameter_types! {
|
|||||||
pub const MaxNominatorRewardedPerValidator: u32 = 256;
|
pub const MaxNominatorRewardedPerValidator: u32 = 256;
|
||||||
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
|
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
|
||||||
// 24
|
// 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<
|
type SlashCancelOrigin = EnsureOneOf<
|
||||||
@@ -554,18 +557,13 @@ type SlashCancelOrigin = EnsureOneOf<
|
|||||||
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>,
|
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 {
|
impl pallet_staking::Config for Runtime {
|
||||||
type MaxNominations = MaxNominations;
|
type MaxNominations = MaxNominations;
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
type UnixTime = Timestamp;
|
type UnixTime = Timestamp;
|
||||||
type CurrencyToVote = CurrencyToVote;
|
type CurrencyToVote = CurrencyToVote;
|
||||||
type ElectionProvider = ElectionProviderMultiPhase;
|
type ElectionProvider = ElectionProviderMultiPhase;
|
||||||
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
|
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
|
||||||
type RewardRemainder = Treasury;
|
type RewardRemainder = Treasury;
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
type Slash = Treasury;
|
type Slash = Treasury;
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
|
|
||||||
use pallet_transaction_payment::CurrencyAdapter;
|
use pallet_transaction_payment::CurrencyAdapter;
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
|
auctions, claims, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
|
||||||
prod_or_fast, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
|
impls::DealWithFees, paras_registrar, prod_or_fast, slots, BlockHashCount, BlockLength,
|
||||||
|
CurrencyToVote, SlowAdjustingFeeUpdate,
|
||||||
};
|
};
|
||||||
|
|
||||||
use runtime_parachains::{
|
use runtime_parachains::{
|
||||||
@@ -37,6 +38,9 @@ use runtime_parachains::{
|
|||||||
|
|
||||||
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||||
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||||
|
use frame_election_provider_support::{
|
||||||
|
generate_solution_type, onchain::UnboundedExecution, SequentialPhragmen,
|
||||||
|
};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
construct_runtime, parameter_types,
|
construct_runtime, parameter_types,
|
||||||
traits::{
|
traits::{
|
||||||
@@ -456,7 +460,7 @@ parameter_types! {
|
|||||||
pub const MaxElectableTargets: u16 = u16::MAX;
|
pub const MaxElectableTargets: u16 = u16::MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_election_provider_support::generate_solution_type!(
|
generate_solution_type!(
|
||||||
#[compact]
|
#[compact]
|
||||||
pub struct NposCompactSolution16::<
|
pub struct NposCompactSolution16::<
|
||||||
VoterIndex = u32,
|
VoterIndex = u32,
|
||||||
@@ -488,9 +492,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
|
|||||||
type DataProvider = Staking;
|
type DataProvider = Staking;
|
||||||
type Solution = NposCompactSolution16;
|
type Solution = NposCompactSolution16;
|
||||||
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
||||||
type GovernanceFallback =
|
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
|
type Solver = SequentialPhragmen<
|
||||||
type Solver = frame_election_provider_support::SequentialPhragmen<
|
|
||||||
AccountId,
|
AccountId,
|
||||||
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
|
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
|
||||||
(),
|
(),
|
||||||
@@ -551,11 +554,6 @@ type SlashCancelOrigin = EnsureOneOf<
|
|||||||
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
|
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 {
|
impl pallet_staking::Config for Runtime {
|
||||||
type MaxNominations = MaxNominations;
|
type MaxNominations = MaxNominations;
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
@@ -576,7 +574,7 @@ impl pallet_staking::Config for Runtime {
|
|||||||
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
||||||
type NextNewSession = Session;
|
type NextNewSession = Session;
|
||||||
type ElectionProvider = ElectionProviderMultiPhase;
|
type ElectionProvider = ElectionProviderMultiPhase;
|
||||||
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
|
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
|
||||||
type VoterList = BagsList;
|
type VoterList = BagsList;
|
||||||
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
||||||
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
||||||
|
|||||||
@@ -318,11 +318,6 @@ parameter_types! {
|
|||||||
pub const MaxAuthorities: u32 = 100_000;
|
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 {
|
impl pallet_staking::Config for Runtime {
|
||||||
type MaxNominations = frame_support::pallet_prelude::ConstU32<16>;
|
type MaxNominations = frame_support::pallet_prelude::ConstU32<16>;
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
@@ -342,10 +337,14 @@ impl pallet_staking::Config for Runtime {
|
|||||||
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
||||||
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
||||||
type NextNewSession = Session;
|
type NextNewSession = Session;
|
||||||
type ElectionProvider =
|
type ElectionProvider = frame_election_provider_support::onchain::UnboundedExecution<
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
|
runtime_common::elections::OnChainSeqPhragmen<Self, Staking>,
|
||||||
type GenesisElectionProvider =
|
>;
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
|
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 VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Runtime>;
|
||||||
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
||||||
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||||
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||||
|
use frame_election_provider_support::{onchain::UnboundedExecution, SequentialPhragmen};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
construct_runtime, parameter_types,
|
construct_runtime, parameter_types,
|
||||||
traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade},
|
traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade},
|
||||||
@@ -42,8 +43,9 @@ use primitives::v2::{
|
|||||||
ValidatorIndex, ValidatorSignature,
|
ValidatorIndex, ValidatorSignature,
|
||||||
};
|
};
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
assigned_slots, auctions, crowdloan, impl_runtime_weights, impls::ToAuthor, paras_registrar,
|
assigned_slots, auctions, crowdloan, elections::OnChainSeqPhragmen, impl_runtime_weights,
|
||||||
paras_sudo_wrapper, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
|
impls::ToAuthor, paras_registrar, paras_sudo_wrapper, slots, BlockHashCount, BlockLength,
|
||||||
|
CurrencyToVote, SlowAdjustingFeeUpdate,
|
||||||
};
|
};
|
||||||
use runtime_parachains::{
|
use runtime_parachains::{
|
||||||
configuration as parachains_configuration, disputes as parachains_disputes,
|
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 DataProvider = Staking;
|
||||||
type Solution = NposCompactSolution16;
|
type Solution = NposCompactSolution16;
|
||||||
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
|
||||||
type GovernanceFallback =
|
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen<Self, Staking>>;
|
||||||
frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
|
type Solver = SequentialPhragmen<
|
||||||
type Solver = frame_election_provider_support::SequentialPhragmen<
|
|
||||||
AccountId,
|
AccountId,
|
||||||
pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
|
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;
|
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 {
|
impl pallet_staking::Config for Runtime {
|
||||||
type MaxNominations = MaxNominations;
|
type MaxNominations = MaxNominations;
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
@@ -465,7 +461,7 @@ impl pallet_staking::Config for Runtime {
|
|||||||
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
|
||||||
type NextNewSession = Session;
|
type NextNewSession = Session;
|
||||||
type ElectionProvider = ElectionProviderMultiPhase;
|
type ElectionProvider = ElectionProviderMultiPhase;
|
||||||
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self>;
|
type GenesisElectionProvider = runtime_common::elections::GenesisElectionOf<Self, Staking>;
|
||||||
type VoterList = BagsList;
|
type VoterList = BagsList;
|
||||||
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
||||||
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user