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

Bound Election and Staking by MaxActiveValidators #12436

Merged
merged 73 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6f10773
bounding election provider with kian
Ank4n Sep 29, 2022
0afb48c
multi phase implement bounded election provider
Ank4n Sep 30, 2022
ce7aff8
election provider blanket implementation
Ank4n Sep 30, 2022
72fdf00
staking compiles
Ank4n Oct 2, 2022
65f5e00
fix test for election provider support
Ank4n Oct 2, 2022
49feb66
fmt
Ank4n Oct 2, 2022
129ce83
fixing epmp tests, does not compile yet
Ank4n Oct 3, 2022
c6d1360
fix epmp tests
Ank4n Oct 5, 2022
e8012d2
fix staking tests
Ank4n Oct 5, 2022
eb57530
fmt
Ank4n Oct 5, 2022
defea25
fix runtime tests
Ank4n Oct 5, 2022
f4dc053
fmt
Ank4n Oct 5, 2022
40765c8
remove outdated wip tags
Ank4n Oct 5, 2022
4084fa8
add enum error
Ank4n Oct 5, 2022
3a4058b
sort and truncate supports
Ank4n Oct 5, 2022
f47d8c8
comment
Ank4n Oct 5, 2022
a96fb72
error when unsupported number of election winners
Ank4n Oct 5, 2022
c32c534
compiling wip after kian's suggestions
Ank4n Oct 6, 2022
53aba74
fix TODOs
Ank4n Oct 6, 2022
d4e5367
remove,fix tags
Ank4n Oct 6, 2022
7a7f1af
ensure validator count does not exceed maxwinners
Ank4n Oct 6, 2022
74485d3
clean up
Ank4n Oct 6, 2022
476a78f
some more clean up and todos
Ank4n Oct 6, 2022
8db0f9e
handle too many winners
Ank4n Oct 6, 2022
ac9d7c2
rename parameter for mock
Ank4n Oct 6, 2022
c555de5
todo
Ank4n Oct 7, 2022
a77c874
add sort and truncate rule if there are too many winners
Ank4n Oct 7, 2022
ba494e5
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 7, 2022
d162039
fmt
Ank4n Oct 7, 2022
7101179
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 7, 2022
e2fd857
fail, not swallow emergency result bound not met
Ank4n Oct 8, 2022
3a0f9ef
remove too many winners resolution as it can be guaranteed to be bounded
Ank4n Oct 8, 2022
7c7190c
fix benchmark
Ank4n Oct 9, 2022
8b06725
give MaxWinners more contextual name
Ank4n Oct 10, 2022
c3a973e
make ready solution generic over T
Ank4n Oct 10, 2022
1a58b93
kian feedback
Ank4n Oct 10, 2022
6fa5b0e
fix stuff
kianenigma Oct 10, 2022
ffce12c
Kian's way of solvign this
kianenigma Oct 11, 2022
548ebfa
comment fix
Ank4n Oct 11, 2022
bcfd80b
fix compile
Ank4n Oct 11, 2022
3c8a1ef
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 11, 2022
2673de6
remove use of BoundedExecution
Ank4n Oct 11, 2022
d4c5c1b
fmt
Ank4n Oct 11, 2022
de0b4d0
comment out failing integrity test
Ank4n Oct 11, 2022
8c7ec50
cap validator count increment to max winners
Ank4n Oct 11, 2022
63bd882
dont panic
Ank4n Oct 12, 2022
d348b92
add test for bad data provider
Ank4n Oct 13, 2022
34967a2
Update frame/staking/src/pallet/impls.rs
Ank4n Oct 13, 2022
b68c381
fix namespace conflict and add test for onchain max winners less than…
Ank4n Oct 13, 2022
fddcf54
defensive unwrap
Ank4n Oct 13, 2022
b5a913e
early convert to bounded vec
Ank4n Oct 13, 2022
be0eb91
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 13, 2022
920442e
fix syntax
Ank4n Oct 13, 2022
e68a851
fmt
Ank4n Oct 13, 2022
69da441
fix doc
Ank4n Oct 13, 2022
f0be8d8
fix rustdoc
Ank4n Oct 13, 2022
c5e494a
fmt
Ank4n Oct 13, 2022
2d60cb0
fix maxwinner count for benchmarking
Ank4n Oct 13, 2022
a3d7ec0
add instant election for noelection
Ank4n Oct 14, 2022
1e3e239
fmt
Ank4n Oct 14, 2022
2c43b04
fix compile
Ank4n Oct 14, 2022
bc14e48
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 14, 2022
99e38b3
pr feedbacks
Ank4n Oct 18, 2022
fcd317e
always error at validator count exceeding max winners
Ank4n Oct 18, 2022
5516ffa
add useful error message
Ank4n Oct 18, 2022
a576237
pr comments
Ank4n Oct 18, 2022
70ae6dd
import fix
Ank4n Oct 18, 2022
f6b6ae6
add checked_desired_targets
Ank4n Oct 18, 2022
7d3a566
fmt
Ank4n Oct 18, 2022
2f710e2
Merge remote-tracking branch 'origin/master' into ankan/bound-multi-p…
Oct 18, 2022
700edba
Merge branch 'master' into ankan/bound-multi-phase-ep
Ank4n Nov 7, 2022
3e64985
fmt
Ank4n Nov 7, 2022
a8234ca
fix rust doc
Ank4n Nov 7, 2022
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
26 changes: 16 additions & 10 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl pallet_staking::Config for Runtime {
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type VoterList = VoterList;
// This a placeholder, to be introduced in the next PR as an instance of bags-list
type TargetList = pallet_staking::UseValidatorsMap<Self>;
Expand Down Expand Up @@ -627,7 +627,14 @@ frame_election_provider_support::generate_solution_type!(

parameter_types! {
pub MaxNominations: u32 = <NposSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub MaxElectingVoters: u32 = 10_000;
pub MaxElectingVoters: u32 = 40_000;
pub MaxElectableTargets: u16 = 10_000;
// OnChain values are lower.
pub MaxOnChainElectingVoters: u32 = 5000;
pub MaxOnChainElectableTargets: u16 = 1250;
// The maximum winners that can be elected by the Election pallet which is equivalent to the
// maximum active validators the staking pallet can have.
pub MaxActiveValidators: u32 = 1000;
}

/// The numbers configured here could always be more than the the maximum limits of staking pallet
Expand Down Expand Up @@ -678,11 +685,9 @@ impl onchain::Config for OnChainSeqPhragmen {
>;
type DataProvider = <Runtime as pallet_election_provider_multi_phase::Config>::DataProvider;
type WeightInfo = frame_election_provider_support::weights::SubstrateWeight<Runtime>;
}

impl onchain::BoundedConfig for OnChainSeqPhragmen {
type VotersBound = MaxElectingVoters;
type TargetsBound = ConstU32<2_000>;
type MaxWinners = <Runtime as pallet_election_provider_multi_phase::Config>::MaxWinners;
type VotersBound = MaxOnChainElectingVoters;
type TargetsBound = MaxOnChainElectableTargets;
}

impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
Expand Down Expand Up @@ -725,11 +730,12 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type SlashHandler = (); // burn slashes
type RewardHandler = (); // nothing to do upon rewards
type DataProvider = Staking;
type Fallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type GovernanceFallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type Fallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GovernanceFallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
type Solver = SequentialPhragmen<AccountId, SolutionAccuracyOf<Self>, OffchainRandomBalancing>;
type ForceOrigin = EnsureRootOrHalfCouncil;
type MaxElectableTargets = ConstU16<{ u16::MAX }>;
type MaxElectableTargets = MaxElectableTargets;
type MaxWinners = MaxActiveValidators;
type MaxElectingVoters = MaxElectingVoters;
type BenchmarkingConfig = ElectionProviderBenchmarkConfig;
type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight<Self>;
Expand Down
5 changes: 4 additions & 1 deletion frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ impl onchain::Config for OnChainSeqPhragmen {
type Solver = SequentialPhragmen<DummyValidatorId, Perbill>;
type DataProvider = Staking;
type WeightInfo = ();
type MaxWinners = ConstU32<100>;
type VotersBound = ConstU32<{ u32::MAX }>;
type TargetsBound = ConstU32<{ u32::MAX }>;
}

impl pallet_staking::Config for Test {
Expand All @@ -199,7 +202,7 @@ impl pallet_staking::Config for Test {
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
Expand Down
8 changes: 2 additions & 6 deletions frame/election-provider-multi-phase/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@ frame_benchmarking::benchmarks! {
let receiver = account("receiver", 0, SEED);
let initial_balance = T::Currency::minimum_balance() * 10u32.into();
T::Currency::make_free_balance_be(&receiver, initial_balance);
let ready = ReadySolution {
supports: vec![],
score: Default::default(),
compute: Default::default()
};
let ready = Default::default();
let deposit: BalanceOf<T> = 10u32.into();

let reward: BalanceOf<T> = T::SignedRewardBase::get();
Expand Down Expand Up @@ -403,7 +399,7 @@ frame_benchmarking::benchmarks! {
assert_eq!(raw_solution.solution.voter_count() as u32, a);
assert_eq!(raw_solution.solution.unique_targets().len() as u32, d);
}: {
assert_ok!(<MultiPhase<T>>::feasibility_check(raw_solution, ElectionCompute::Unsigned));
assert!(<MultiPhase<T>>::feasibility_check(raw_solution, ElectionCompute::Unsigned).is_ok());
}

// NOTE: this weight is not used anywhere, but the fact that it should succeed when execution in
Expand Down
Loading