Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds multi-block election types and refactors current pallets to support new interfaces and types #6034

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
3f6bf3f
init: adds EPM-MB, multipaged types and primitives
gpestana Oct 13, 2024
8a682b8
refactors staking pallet with new paginated types
gpestana Oct 13, 2024
94ff073
refactors election-multiphase pallet with new paginated types
gpestana Oct 13, 2024
1527bd6
nits for dependent pallets and runtimes
gpestana Oct 13, 2024
5cb1de1
adds ElectionProvider::ongoing to trait and impls
gpestana Oct 14, 2024
50d9698
Merge branch 'master' into gpestana/epm-mb
Ank4n Oct 15, 2024
43eec4b
clean up sp-staking
gpestana Oct 18, 2024
11dd785
clean up and rustdoc for epm-support
gpestana Oct 18, 2024
d446ed0
Merge branch 'gpestana/epm-mb' of github.com:paritytech/polkadot-sdk …
gpestana Oct 18, 2024
5c17573
nits onchain election provider
gpestana Oct 18, 2024
ee7bdd4
EPM nits and rustdoc improvements
gpestana Oct 18, 2024
f30b548
clean up and rustdocs for EPM core and sub pallets
gpestana Oct 18, 2024
e7bf7dc
rustdocs and nits
gpestana Oct 18, 2024
f810692
Merge branch 'master' into gpestana/epm-mb
gpestana Oct 18, 2024
bf67a3e
adds prdoc
gpestana Oct 18, 2024
345840d
fixes prdoc
gpestana Oct 18, 2024
52dcee9
removes from all pallets
gpestana Oct 18, 2024
6d506e2
Adds new tests for verifier pallet
gpestana Oct 18, 2024
430532a
implements hold logic in signed pallet; finishes implementing bail call
gpestana Oct 19, 2024
068e0fd
finishes signed pallet
gpestana Oct 21, 2024
5ca0bab
Merge branch 'master' into gpestana/epm-mb-merge
gpestana Oct 22, 2024
385500d
updates inherent call in unsigned phase to new interfaces
gpestana Oct 22, 2024
b4019bb
licence header nit
gpestana Oct 22, 2024
9f30e2d
Merge branch 'master' into gpestana/epm-mb
gpestana Oct 23, 2024
82abba1
removes epm-mb
gpestana Oct 24, 2024
1034653
nit fix in bags list remote tests
gpestana Oct 24, 2024
7248960
nit fix prdoc
gpestana Oct 24, 2024
18813c9
Merge branch 'master' into gpestana/epm-mb
gpestana Oct 25, 2024
a92d44a
Addresses PR reviews (removes all paged types/configs from epm and nits)
gpestana Oct 25, 2024
3d1a330
improve memory efficiency of try into bounded supports; tests
gpestana Oct 25, 2024
1757c91
a few nits in the staking pallet; handles exposures better (do not le…
gpestana Oct 28, 2024
7022467
updates electable stashes to allow for multiple adds across pages
gpestana Nov 1, 2024
b49684e
Adds staking pallet rustdocs; nits
gpestana Nov 1, 2024
7851c6e
Refactors the snapshot cursors of staking pallet and adds more tests
gpestana Nov 5, 2024
3ff9914
Adds e2e tests to staking pallet
gpestana Nov 7, 2024
bc7b200
adds exposure collection checks to multi page election tests
gpestana Nov 7, 2024
2e71ab2
EPM-MB: Supports only single page target snapshot (#6414)
gpestana Nov 8, 2024
e9854fc
Adds try-state checks for election prep metadata and tests
gpestana Nov 8, 2024
9f4b6a3
more tests
gpestana Nov 11, 2024
612886f
Merge branch 'master' into gpestana/epm-mb
gpestana Nov 12, 2024
fb31d1b
".git/.scripts/commands/fmt/fmt.sh"
Nov 12, 2024
01e09c6
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
b4c900c
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
628ae67
Update prdoc/pr_6034.prdoc
gpestana Nov 12, 2024
d05a002
Update substrate/frame/staking/src/lib.rs
gpestana Nov 12, 2024
07796d9
Update substrate/frame/staking/src/lib.rs
gpestana Nov 12, 2024
23b9c21
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
2570c23
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
808e2ba
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
2092d2c
Update substrate/frame/election-provider-multi-phase/src/unsigned.rs
gpestana Nov 12, 2024
f2fe960
Update substrate/frame/election-provider-support/src/onchain.rs
gpestana Nov 12, 2024
bca81c2
Update substrate/frame/election-provider-support/src/lib.rs
gpestana Nov 12, 2024
df729a0
addresses PR review comments
gpestana Nov 12, 2024
0774cc4
Merge branch 'master' into gpestana/epm-mb
gpestana Nov 12, 2024
51329d7
ensures only collected electable stashes have exposures collectede
gpestana Nov 12, 2024
64d3ab3
comment nits
gpestana Nov 12, 2024
2082723
adds type alias to ensure bounds are in order
gpestana Nov 12, 2024
d720e5a
integrity test
gpestana Nov 12, 2024
a88361a
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
ea5aa9e
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 12, 2024
d140b1f
removes the lockable election provider and other nits
gpestana Nov 12, 2024
d64068b
Merge branch 'gpestana/epm-mb' of github.com:paritytech/polkadot-sdk …
gpestana Nov 12, 2024
1a2ddfc
removes unecessary last_page_empty_slots
gpestana Nov 13, 2024
2117056
docs and tests for exposures.split_others
gpestana Nov 14, 2024
e568248
Merge branch 'master' into gpestana/epm-mb
gpestana Nov 14, 2024
83c7288
nits and removes sp-std dependency from staking primitives
gpestana Nov 14, 2024
6705e0f
Update substrate/frame/election-provider-multi-phase/src/lib.rs
gpestana Nov 14, 2024
4e13e4f
Update prdoc/pr_6034.prdoc
gpestana Nov 14, 2024
825984b
fixes epm test case
gpestana Nov 14, 2024
93d6bda
removes TryIntoBoundedSupports trait and impl coversion directly in S…
gpestana Nov 14, 2024
69b38e5
Adds max backers per winner bounds check in the phragmen implementati…
gpestana Nov 14, 2024
f6be182
Merge branch 'master' into gpestana/epm-mb
gpestana Nov 22, 2024
442a64e
Merge branch 'master' into gpestana/epm-mb
gpestana Dec 3, 2024
e43e885
addresses PR comments
gpestana Dec 3, 2024
676db53
Revert "Adds max backers per winner bounds check in the phragmen impl…
gpestana Dec 3, 2024
fe8b9ae
adds max backers per winner trimming test
gpestana Dec 3, 2024
84eea26
Ensures max backers per winner bounds are met in Staking miner (#6771)
gpestana Dec 5, 2024
4788579
fixes overflowing tests
gpestana Dec 9, 2024
b792a6d
adds benchs and nits
gpestana Dec 11, 2024
61ef83e
Merge branch 'master' into gpestana/epm-mb
gpestana Dec 11, 2024
5ce51ea
pr review refactors and improvements
gpestana Dec 11, 2024
39e5c3d
improves add_electables and tests
gpestana Dec 11, 2024
65cf87f
improves add_electables
gpestana Dec 11, 2024
7d33c5c
remove unecessary cloning
gpestana Dec 12, 2024
d7817e0
migrations
gpestana Dec 17, 2024
0edb158
Merge branch 'master' into gpestana/epm-mb
gpestana Dec 17, 2024
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
4,644 changes: 2,543 additions & 2,101 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ parameter_types! {
ElectionBoundsBuilder::default().voters_count(MaxElectingVoters::get().into()).build();
// Maximum winners that can be chosen as active validators
pub const MaxActiveValidators: u32 = 1000;

// One page only, fill the whole page with the `MaxActiveValidators`.
pub const MaxWinnersPerPage: u32 = MaxActiveValidators::get();
// Unbonded, thus the max backers per winner maps to the max electing voters limit.
pub const MaxBackersPerWinner: u32 = MaxElectingVoters::get();
}

frame_election_provider_support::generate_solution_type!(
Expand All @@ -601,8 +604,9 @@ impl onchain::Config for OnChainSeqPhragmen {
type Solver = SequentialPhragmen<AccountId, OnChainAccuracy>;
type DataProvider = Staking;
type WeightInfo = weights::frame_election_provider_support::WeightInfo<Runtime>;
type MaxWinners = MaxActiveValidators;
type Bounds = ElectionBounds;
type MaxBackersPerWinner = MaxBackersPerWinner;
type MaxWinnersPerPage = MaxWinnersPerPage;
}

impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
Expand All @@ -615,7 +619,8 @@ impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
as
frame_election_provider_support::ElectionDataProvider
>::MaxVotesPerVoter;
type MaxWinners = MaxActiveValidators;
type MaxWinnersPerPage = MaxWinnersPerPage;
type MaxBackersPerWinner = MaxBackersPerWinner;

// The unsigned submissions have to respect the weight of the submit_unsigned call, thus their
// weight estimate function is wired to this call's weight.
Expand Down Expand Up @@ -649,6 +654,9 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type BetterSignedThreshold = ();
type OffchainRepeat = OffchainRepeat;
type MinerTxPriority = NposSolutionPriority;
type Pages = ConstU32<1>;
type MaxWinnersPerPage = MaxWinnersPerPage;
type MaxBackersPerWinner = MaxBackersPerWinner;
type DataProvider = Staking;
#[cfg(any(feature = "fast-runtime", feature = "runtime-benchmarks"))]
type Fallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand All @@ -657,7 +665,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
AccountId,
BlockNumber,
Staking,
MaxActiveValidators,
MaxWinnersPerPage,
MaxBackersPerWinner,
)>;
type GovernanceFallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
type Solver = SequentialPhragmen<
Expand All @@ -668,7 +677,6 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type BenchmarkingConfig = polkadot_runtime_common::elections::BenchmarkConfig;
type ForceOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo<Self>;
type MaxWinners = MaxActiveValidators;
type ElectionBounds = ElectionBounds;
}

Expand Down Expand Up @@ -748,6 +756,7 @@ impl pallet_staking::Config for Runtime {
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type VoterList = VoterList;
type TargetList = UseValidatorsMap<Self>;
type MaxValidatorSet = MaxActiveValidators;
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type HistoryDepth = frame_support::traits::ConstU32<84>;
Expand Down
25 changes: 25 additions & 0 deletions prdoc/pr_6034.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
title: Adds multi-block election types and refactors current single logic to support it

doc:
- audience: Runtime Dev
description: |
This PR adds election types and structs required to run a multi-block election. In addition,
it modifies EPM, staking pallet and all dependent pallets and logic to use the multi-block types.

crates:
- name: frame-election-provider-support
bump: major
- name: pallet-election-provider-multi-phase
bump: major
- name: pallet-staking
bump: major
- name: pallet-fast-unstake
bump: minor
- name: pallet-delegated-staking
bump: minor
- name: sp-npos-elections
bump: major
- name: sp-staking
bump: major
- name: pallet-bags-list-remote-tests
bump: minor
8 changes: 6 additions & 2 deletions substrate/frame/bags-list/remote-tests/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use frame_election_provider_support::{
};
use frame_support::traits::PalletInfoAccess;
use remote_externalities::{Builder, Mode, OnlineConfig};
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
use sp_runtime::{
traits::{Block as BlockT, Zero},
DeserializeOwned,
};

/// Execute create a snapshot from pallet-staking.
pub async fn execute<Runtime, Block>(voter_limit: Option<usize>, currency_unit: u64, ws_url: String)
Expand Down Expand Up @@ -70,8 +73,9 @@ where
Some(v) => DataProviderBounds { count: Some(CountBound(v as u32)), size: None },
};

// single page voter snapshot, thus page index == 0.
let voters =
<pallet_staking::Pallet<Runtime> as ElectionDataProvider>::electing_voters(bounds)
<pallet_staking::Pallet<Runtime> as ElectionDataProvider>::electing_voters(bounds, Zero::zero())
.unwrap();

let mut voters_nominator_only = voters
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ impl onchain::Config for OnChainSeqPhragmen {
type Solver = SequentialPhragmen<Balance, sp_runtime::Perbill>;
type DataProvider = Staking;
type WeightInfo = ();
type MaxWinners = ConstU32<100>;
type MaxWinnersPerPage = ConstU32<100>;
type MaxBackersPerWinner = ConstU32<100>;
type Bounds = ElectionsBoundsOnChain;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ mod benchmarks {
) -> Result<(), BenchmarkError> {
// We don't directly need the data-provider to be populated, but it is just easy to use it.
set_up_data_provider::<T>(v, t);
// Default bounds are unbounded.
let targets = T::DataProvider::electable_targets(DataProviderBounds::default())?;
let voters = T::DataProvider::electing_voters(DataProviderBounds::default())?;
// default bounds are unbounded.
let targets =
T::DataProvider::electable_targets(DataProviderBounds::default(), Zero::zero())?;
let voters = T::DataProvider::electing_voters(DataProviderBounds::default(), Zero::zero())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can introduce a function unbounded to DataProviderBounds to make code more readable.


let desired_targets = T::DataProvider::desired_targets()?;
assert!(Snapshot::<T>::get().is_none());

Expand Down Expand Up @@ -343,7 +345,7 @@ mod benchmarks {

#[block]
{
result = <Pallet<T> as ElectionProvider>::elect();
result = <Pallet<T> as ElectionProvider>::elect(Zero::zero());
}

assert!(result.is_ok());
Expand Down
Loading
Loading