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

Recursive election provider as fallback #9648

Merged
14 commits merged into from
Sep 12, 2021
29 changes: 19 additions & 10 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use frame_system::{
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use pallet_contracts::weights::WeightInfo;
use pallet_election_provider_multi_phase::FallbackStrategy;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
Expand Down Expand Up @@ -487,6 +486,11 @@ parameter_types! {
}

use frame_election_provider_support::onchain;
impl onchain::Config for Runtime {
type Accuracy = Perbill;
type DataProvider = Staking;
}

impl pallet_staking::Config for Runtime {
const MAX_NOMINATIONS: u32 = MAX_NOMINATIONS;
type Currency = Balances;
Expand All @@ -510,9 +514,7 @@ impl pallet_staking::Config for Runtime {
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::OnChainSequentialPhragmen<
pallet_election_provider_multi_phase::OnChainConfig<Self>,
>;
type GenesisElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
}

Expand All @@ -527,9 +529,6 @@ parameter_types! {
pub const SignedDepositBase: Balance = 1 * DOLLARS;
pub const SignedDepositByte: Balance = 1 * CENTS;

// fallback: no on-chain fallback.
pub const Fallback: FallbackStrategy = FallbackStrategy::Nothing;

pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000);

// miner configs
Expand Down Expand Up @@ -591,10 +590,9 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type SlashHandler = (); // burn slashes
type RewardHandler = (); // nothing to do upon rewards
type DataProvider = Staking;
type OnChainAccuracy = Perbill;
type Solution = NposSolution16;
type Fallback = Fallback;
type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight<Runtime>;
type Fallback = pallet_election_provider_multi_phase::NoFallback<Self>;
type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight<Self>;
type ForceOrigin = EnsureRootOrHalfCouncil;
type BenchmarkingConfig = BenchmarkConfig;
}
Expand Down Expand Up @@ -1672,6 +1670,7 @@ impl_runtime_apis! {
mod tests {
use super::*;
use frame_system::offchain::CreateSignedTransaction;
use sp_runtime::UpperOf;

#[test]
fn validate_transaction_submitter_bounds() {
Expand All @@ -1684,6 +1683,16 @@ mod tests {
is_submit_signed_transaction::<Runtime>();
}

#[test]
fn perbill_as_onchain_accuracy() {
type OnChainAccuracy = <Runtime as onchain::Config>::Accuracy;
let maximum_chain_accuracy: Vec<UpperOf<OnChainAccuracy>> = (0..MAX_NOMINATIONS)
.map(|_| <UpperOf<OnChainAccuracy>>::from(OnChainAccuracy::one().deconstruct()))
.collect();
let _: UpperOf<OnChainAccuracy> =
maximum_chain_accuracy.iter().fold(0, |acc, x| acc.checked_add(*x).unwrap());
}

#[test]
fn call_size() {
assert!(
Expand Down
Loading