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

[AHM] Multi-block staking election pallet #7282

Merged
merged 187 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from 125 commits
Commits
Show all changes
187 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
89069a9
Master.into()
kianenigma Jan 15, 2025
6255f64
Master.into()
kianenigma Jan 15, 2025
de4f1da
fix
kianenigma Jan 15, 2025
06d3308
fmt
kianenigma Jan 15, 2025
5426e88
Update substrate/frame/election-provider-multi-phase/src/lib.rs
kianenigma Jan 15, 2025
c228dc4
fix lock file
kianenigma Jan 15, 2025
ddeb1ae
Merge branch 'gpestana/epm-mb' of github.com:paritytech/polkadot-sdk …
kianenigma Jan 15, 2025
de93ecd
onchain backup sorting, testing chain in kitchensink
kianenigma Jan 15, 2025
5d64293
fix migration
kianenigma Jan 15, 2025
9464dc5
Merge branch 'master' of github.com:paritytech/polkadot-sdk into gpes…
kianenigma Jan 15, 2025
01adfe6
greenish CI now
kianenigma Jan 16, 2025
eedd03a
fmt
kianenigma Jan 16, 2025
33a37e6
fix unused import
kianenigma Jan 16, 2025
7df54f1
fix some benchmarks too
kianenigma Jan 16, 2025
1b5ddc6
better doc
kianenigma Jan 16, 2025
c5efc26
fix tests and a bug
kianenigma Jan 16, 2025
3ab3a17
Merge branch 'master' into gpestana/epm-mb
kianenigma Jan 16, 2025
4d690b7
more testing
kianenigma Jan 17, 2025
e9180f6
Master.into()
kianenigma Jan 17, 2025
d348cb0
Update substrate/primitives/staking/src/lib.rs
kianenigma Jan 17, 2025
7ce460c
rename and fix
kianenigma Jan 17, 2025
bb685d1
Upstream.into()
kianenigma Jan 17, 2025
7f438db
fix
kianenigma Jan 17, 2025
90807e2
add tests
kianenigma Jan 17, 2025
fbc8733
add original pallet, almost compiles
kianenigma Jan 17, 2025
377b32b
pallet compiles and all tests pass again
kianenigma Jan 20, 2025
b56e739
refactor events
kianenigma Jan 20, 2025
28487af
clean up main pallet a bit
kianenigma Jan 20, 2025
68bc3cd
migrate signed to fungibles
kianenigma Jan 20, 2025
8186246
cleanip signed phase a bit more
kianenigma Jan 20, 2025
b5b21ff
integrate try-runtime
kianenigma Jan 21, 2025
0f81eba
fix up signed phase, lgtm
kianenigma Jan 21, 2025
e09da9b
integrate into the runtime
kianenigma Jan 21, 2025
dbea5a8
make multi page election graceful, onchain supports multi page, bette…
kianenigma Jan 23, 2025
340c563
node biuld
kianenigma Jan 23, 2025
fa9ef69
add a few comments for niklas
kianenigma Jan 23, 2025
0e2446c
add a few comments for niklas
kianenigma Jan 23, 2025
e10e8bf
add a few comments for niklas
kianenigma Jan 23, 2025
31f4245
works continously now
kianenigma Jan 23, 2025
b9aa881
stateless data provider so that EPM and EPMB can work together
kianenigma Jan 27, 2025
e02a7ce
staking benchmarks are mostly green
kianenigma Jan 27, 2025
cd52ab2
master.into()
kianenigma Jan 28, 2025
deb7daa
tests pass again
kianenigma Jan 28, 2025
72841b7
refactor into MinerConfig
kianenigma Jan 29, 2025
a8445bd
move dev_accounts to pallet-staking, simplify onchain large chain-spe…
kianenigma Jan 29, 2025
398382d
rename to validators
kianenigma Feb 3, 2025
322969d
Merge branch 'master' into kiz-multi-block-eletion
Ank4n Feb 4, 2025
c04e473
add benchmarking and weight, we need a lot more work to fix the weights
kianenigma Feb 9, 2025
8f06783
Merge branch 'kiz-multi-block-eletion' of github.com:paritytech/polka…
kianenigma Feb 9, 2025
bb1f89a
make the timing good for testing
kianenigma Feb 10, 2025
0fa010d
Bound some storage items for pallet `staking` and clean up deprecated…
re-gius Feb 10, 2025
7eaf90c
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma Feb 10, 2025
d7f1cdc
pass some tests
kianenigma Feb 10, 2025
14d536d
update all license headers
kianenigma Feb 10, 2025
c72a9c1
Update from kianenigma running command 'prdoc'
github-actions[bot] Feb 10, 2025
4191232
Update from kianenigma running command 'fmt'
github-actions[bot] Feb 10, 2025
35fd8af
Merge branch 'kiz-multi-block-eletion' of github.com:paritytech/polka…
kianenigma Feb 10, 2025
10fbd75
update PRdoc
kianenigma Feb 10, 2025
dfc2f18
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma Feb 10, 2025
a7d2233
some clippy and CI issues
kianenigma Feb 10, 2025
38d4971
gen umbrella + versions
kianenigma Feb 10, 2025
1e04da7
bring back umbrella version
kianenigma Feb 10, 2025
821fcff
make tests temporarily pass to merge the PR
kianenigma Feb 11, 2025
824f0a7
fix
kianenigma Feb 11, 2025
5168936
CI happy?
kianenigma Feb 12, 2025
a6739cf
allow unused
kianenigma Feb 12, 2025
6fd02ea
Merge branch 'master' into kiz-multi-block-eletion
kianenigma Feb 12, 2025
722bf1a
Update prdoc/pr_7282.prdoc
kianenigma Feb 12, 2025
b95fda3
fix unused stuff
kianenigma Feb 12, 2025
00c0828
Merge branch 'kiz-multi-block-eletion' of github.com:paritytech/polka…
kianenigma Feb 12, 2025
ccfea6a
Update prdoc/pr_7282.prdoc
kianenigma Feb 12, 2025
39d2b76
fix PRdoc again
kianenigma Feb 12, 2025
2cd7e37
fix some old prdocs
kianenigma Feb 12, 2025
cd90534
clippy and UI fixes
kianenigma Feb 12, 2025
48add5d
fix all docs
kianenigma Feb 12, 2025
a1dd41a
fix more docs and warnings
kianenigma Feb 12, 2025
5d33179
fix unused fn
kianenigma Feb 12, 2025
7dcb6fd
fix a subset of quick benches
kianenigma Feb 12, 2025
447c81f
fix phragmen benches
kianenigma Feb 12, 2025
1e4ffc3
last CI issues?
kianenigma Feb 12, 2025
8ae2184
Merge branch 'master' into kiz-multi-block-eletion
kianenigma Feb 13, 2025
469046a
make benchmarks faster, quick solver and fix some tests in substrate …
kianenigma Feb 13, 2025
9cad263
Merge branch 'kiz-multi-block-eletion' of github.com:paritytech/polka…
kianenigma Feb 13, 2025
2d5bea3
fix build
kianenigma Feb 13, 2025
0d6c7ff
exclude EPMB benchmarks from the quick-bench job for now
kianenigma Feb 13, 2025
607a101
fix a lot of random tests
kianenigma Feb 13, 2025
bd21793
fix genesis config tests
kianenigma Feb 13, 2025
4dc1ec4
fixing more CI tests...
kianenigma Feb 13, 2025
f0b9503
new weights
kianenigma Feb 13, 2025
9a0ed54
fix test compilation
kianenigma Feb 13, 2025
97300a6
license + fix one more test
kianenigma Feb 13, 2025
3d4c733
:wq
kianenigma Feb 13, 2025
908fa00
license
kianenigma Feb 13, 2025
6769acb
Update from kianenigma running command 'prdoc --force'
github-actions[bot] Feb 14, 2025
2aca247
prdco
kianenigma Feb 14, 2025
ffb9746
remove problematic test
kianenigma Feb 14, 2025
f35de68
revert lock file?
kianenigma Feb 14, 2025
02b438c
fix infinite loop in paras benchmarking
kianenigma Feb 14, 2025
fbb815a
remove one more problematic benchmark for now
kianenigma Feb 14, 2025
2632619
Merge branch 'master' into kiz-multi-block-eletion
kianenigma Feb 14, 2025
979a0f3
Merge branch 'master' into kiz-multi-block-eletion
kianenigma Feb 14, 2025
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,561 changes: 2,459 additions & 2,102 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ members = [
"substrate/frame/core-fellowship",
"substrate/frame/delegated-staking",
"substrate/frame/democracy",
"substrate/frame/election-provider-multi-block",
"substrate/frame/election-provider-multi-phase",
"substrate/frame/election-provider-multi-phase/test-staking-e2e",
"substrate/frame/election-provider-support",
Expand Down
2 changes: 1 addition & 1 deletion cumulus/bin/pov-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ sc-executor.workspace = true
sp-core.workspace = true
sp-io.workspace = true
sp-maybe-compressed-blob.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } |
RuntimeCall::Uniques { .. }
RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. }
)
},
ProxyType::AssetOwner => matches!(
Expand Down
7 changes: 5 additions & 2 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use polkadot_runtime_common::{
use polkadot_runtime_parachains::reward_points::RewardValidatorsWithEraPoints;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_beefy::ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use sp_core::{ConstU32, OpaqueMetadata};
use sp_core::{ConstBool, ConstU32, OpaqueMetadata};
use sp_mmr_primitives as mmr;
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -359,7 +359,9 @@ impl onchain::Config for OnChainSeqPhragmen {
type DataProvider = Staking;
type WeightInfo = ();
type Bounds = ElectionBoundsOnChain;
type MaxWinners = OnChainMaxWinners;
type MaxWinnersPerPage = OnChainMaxWinners;
type MaxBackersPerWinner = ConstU32<{ u32::MAX }>;
type Sort = ConstBool<true>;
}

/// Upper limit on the number of NPOS nominations.
Expand Down Expand Up @@ -398,6 +400,7 @@ impl pallet_staking::Config for Runtime {
type EventListeners = ();
type WeightInfo = ();
type DisablingStrategy = pallet_staking::UpToLimitWithReEnablingDisablingStrategy;
type MaxValidatorSet = MaxAuthorities;
}

parameter_types! {
Expand Down
25 changes: 17 additions & 8 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
};
use sp_core::{ConstU8, OpaqueMetadata, RuntimeDebug, H256};
use sp_core::{ConstBool, ConstU8, OpaqueMetadata, RuntimeDebug, H256};
use sp_runtime::{
generic, impl_opaque_keys,
traits::{
Expand Down 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 @@ -597,12 +600,14 @@ frame_election_provider_support::generate_solution_type!(

pub struct OnChainSeqPhragmen;
impl onchain::Config for OnChainSeqPhragmen {
type Sort = ConstBool<true>;
type System = Runtime;
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 +620,8 @@ impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
as
frame_election_provider_support::ElectionDataProvider
>::MaxVotesPerVoter;
type MaxWinners = MaxActiveValidators;
type MaxBackersPerWinner = MaxBackersPerWinner;
type MaxWinners = MaxWinnersPerPage;

// 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 +655,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type BetterSignedThreshold = ();
type OffchainRepeat = OffchainRepeat;
type MinerTxPriority = NposSolutionPriority;
type MaxWinners = 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 @@ -750,6 +758,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 Expand Up @@ -1144,8 +1153,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
Expand Down Expand Up @@ -1846,6 +1854,7 @@ pub mod migrations {
parachains_shared::migration::MigrateToV1<Runtime>,
parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
pallet_staking::migrations::v16::MigrateV15ToV16<Runtime>,
pallet_staking::migrations::v17::MigrateV16ToV17<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
10 changes: 10 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ use core::marker::PhantomData;
/// Weight functions for `pallet_staking`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
// TODO CI-FAIL: run CI bench bot
fn on_initialize_noop() -> Weight {
Default::default()
}
fn do_elect_paged(_v: u32,) -> Weight {
Default::default()
}
fn clear_election_metadata() -> Weight {
Default::default()
}
/// Storage: `Staking::Bonded` (r:1 w:1)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Ledger` (r:1 w:1)
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
3 changes: 3 additions & 0 deletions substrate/bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ try-runtime = [
"polkadot-sdk/try-runtime",
"substrate-cli-test-utils/try-runtime",
]
staking-playground = [
"kitchensink-runtime/staking-playground",
]

[[bench]]
name = "transaction_pool"
Expand Down
68 changes: 52 additions & 16 deletions substrate/bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ fn configure_accounts(
)>,
initial_nominators: Vec<AccountId>,
endowed_accounts: Option<Vec<AccountId>>,
stash: Balance,
) -> (
Vec<(
AccountId,
Expand Down Expand Up @@ -305,21 +304,31 @@ fn configure_accounts(
}
});

// stakers: all validators and nominators.
use rand::Rng;
let mut rng = rand::thread_rng();
let mut rng2 = rand::thread_rng();
// stakers: all validators and nominators.
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.0.clone(), stash, StakerStatus::Validator))
.map(|x| {
(
x.0.clone(),
x.0.clone(),
rng.gen_range(ENDOWMENT / 100..ENDOWMENT / 2),
StakerStatus::Validator,
)
})
.chain(initial_nominators.iter().map(|x| {
use rand::{seq::SliceRandom, Rng};
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
let count = rng.gen::<usize>() % limit;
let count = (rng2.gen::<usize>() % limit).max(1);
let nominations = initial_authorities
.as_slice()
.choose_multiple(&mut rng, count)
.choose_multiple(&mut rng2, count)
.into_iter()
.map(|choice| choice.0.clone())
.collect::<Vec<_>>();
let stash = rng2.gen_range(ENDOWMENT / 100..ENDOWMENT / 2);
(x.clone(), x.clone(), stash, StakerStatus::Nominator(nominations))
}))
.collect::<Vec<_>>();
Expand All @@ -346,7 +355,8 @@ pub fn testnet_genesis(
endowed_accounts: Option<Vec<AccountId>>,
) -> serde_json::Value {
let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) =
configure_accounts(initial_authorities, initial_nominators, endowed_accounts, STASH);
configure_accounts(initial_authorities, initial_nominators, endowed_accounts);
const MAX_COLLECTIVE_SIZE: usize = 50;

serde_json::json!({
"balances": {
Expand All @@ -372,24 +382,24 @@ pub fn testnet_genesis(
.collect::<Vec<_>>(),
},
"staking": {
"validatorCount": initial_authorities.len() as u32,
"minimumValidatorCount": initial_authorities.len() as u32,
"validatorCount": std::option_env!("VAL_COUNT").map(|v| v.parse::<u32>().unwrap()).unwrap_or((initial_authorities.len()/2usize) as u32),
"minimumValidatorCount": 10,
"invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
"slashRewardFraction": Perbill::from_percent(10),
"stakers": stakers.clone(),
},
"elections": {
"members": endowed_accounts
.iter()
.take((num_endowed_accounts + 1) / 2)
.take(((num_endowed_accounts + 1) / 2).min(MAX_COLLECTIVE_SIZE))
.cloned()
.map(|member| (member, STASH))
.collect::<Vec<_>>(),
},
"technicalCommittee": {
"members": endowed_accounts
.iter()
.take((num_endowed_accounts + 1) / 2)
.take(((num_endowed_accounts + 1) / 2).min(MAX_COLLECTIVE_SIZE))
.cloned()
.collect::<Vec<_>>(),
},
Expand All @@ -410,12 +420,38 @@ pub fn testnet_genesis(
}

fn development_config_genesis_json() -> serde_json::Value {
testnet_genesis(
vec![authority_keys_from_seed("Alice")],
vec![],
Sr25519Keyring::Alice.to_account_id(),
None,
)
if cfg!(feature = "staking-playground") {
let random_authorities_count = std::option_env!("AUTHORITIES")
.map(|s| s.parse::<u32>().unwrap())
.unwrap_or(100);
let random_nominators_count = std::option_env!("NOMINATORS")
.map(|s| s.parse::<u32>().unwrap())
.unwrap_or(3000);
let mut random_authorities = (0..random_authorities_count)
.map(|i| authority_keys_from_seed(&format!("Random{}", i)))
.collect::<Vec<_>>();
let random_nominators = (0..random_nominators_count)
.map(|i| {
get_public_from_string_or_panic::<sr25519::Public>(&format!("Random{}", i)).into()
})
.collect::<Vec<_>>();
// Alice should also always be an authority.
random_authorities.push(authority_keys_from_seed("Alice"));

testnet_genesis(
random_authorities,
random_nominators,
Sr25519Keyring::Alice.to_account_id(),
None,
)
} else {
testnet_genesis(
vec![authority_keys_from_seed("Alice")],
vec![],
Sr25519Keyring::Alice.to_account_id(),
None,
)
}
}

fn props() -> Properties {
Expand Down
6 changes: 6 additions & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ experimental = [
"pallet-example-tasks/experimental",
]
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
# Test temp feature to allow this chain to be used for swift testing of staking elections. should
# only be run by --dev chain. It will create a large staking election process as per the constants
# in `chain_spec.rs`, but `Alice` will be the only authority that is communicated to the node and
# ergo block production works fine with --dev and is independent of staking election. See ` pub
# struct AliceAsOnlyValidator`.
staking-playground = []
4 changes: 4 additions & 0 deletions substrate/bin/node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ pub mod time {

// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// Attempting to do so will brick block production.
#[cfg(not(feature = "staking-playground"))]
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
#[cfg(feature = "staking-playground")]
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 2 * MINUTES;
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;

Expand Down
Loading