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

Decouple Staking and Election - Part 2.1: Unleash Multi Phase #8113

Merged
72 commits merged into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
d998b12
Base features and traits.
kianenigma Jan 15, 2021
5aea9cc
pallet and unsigned phase
kianenigma Jan 15, 2021
632e107
Undo bad formattings.
kianenigma Jan 15, 2021
c52e65d
Master.into()
kianenigma Jan 18, 2021
b4fc5e1
some formatting cleanup.
kianenigma Jan 18, 2021
cc26881
Small self-cleanup.
kianenigma Jan 18, 2021
67a9fae
Master.into()
kianenigma Jan 27, 2021
75eca3f
Make it all build
kianenigma Jan 27, 2021
8daec3a
self-review
kianenigma Jan 27, 2021
49613ed
Some doc tests.
kianenigma Jan 27, 2021
35f1faf
Some changes from other PR
kianenigma Jan 27, 2021
e01cacc
Fix session test
kianenigma Jan 27, 2021
6278150
Merge branch 'master' into kiz-election-provider-2-two-phase-unsigned
shawntabrizi Feb 4, 2021
4c516cb
Update Cargo.lock
shawntabrizi Feb 4, 2021
8c8d1e6
Update frame/election-provider-multi-phase/src/lib.rs
kianenigma Feb 11, 2021
4b58c91
Some review comments
kianenigma Feb 11, 2021
f4029aa
Merge branch 'kiz-election-provider-2-two-phase-unsigned' of github.c…
kianenigma Feb 11, 2021
f16ac88
Master.into()
kianenigma Feb 11, 2021
528917e
Rename + make encode/decode
kianenigma Feb 12, 2021
1a5794a
Do an assert as well, just in case.
kianenigma Feb 12, 2021
01e63ed
Fix build
kianenigma Feb 12, 2021
4ccecdf
Update frame/election-provider-multi-phase/src/unsigned.rs
kianenigma Feb 12, 2021
83a789e
Las comment
kianenigma Feb 12, 2021
adb3618
Merge branch 'kiz-election-provider-2-two-phase-unsigned' of github.c…
kianenigma Feb 12, 2021
7c71df0
fix staking fuzzer.
kianenigma Feb 12, 2021
12b1640
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Feb 12, 2021
6397d4a
Add one last layer of feasibility check as well.
kianenigma Feb 12, 2021
80d3c31
Merge branch 'kiz-election-provider-2-two-phase-unsigned' of github.c…
kianenigma Feb 12, 2021
7d6f6ad
Last fixes to benchmarks
kianenigma Feb 12, 2021
2e28437
Some more docs.
kianenigma Feb 12, 2021
5fda744
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Feb 12, 2021
1ce6c8e
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Feb 12, 2021
f63c5b8
Some nits
kianenigma Feb 12, 2021
8029c01
Merge branch 'kiz-election-provider-2-two-phase-unsigned' of github.c…
kianenigma Feb 12, 2021
5973b61
It all works
kianenigma Feb 13, 2021
0882c62
Master.into()
kianenigma Mar 8, 2021
e137035
Some self cleanup
kianenigma Mar 9, 2021
428c4c9
Master.into()
kianenigma Mar 12, 2021
a16b964
Update frame/staking/src/lib.rs
kianenigma Mar 12, 2021
6d506a4
remove most todos.
kianenigma Mar 12, 2021
75accd3
Merge branch 'kiz-election-provider-21-enable-multi-phase' of github.…
kianenigma Mar 12, 2021
df3fb9a
Round of self-review.
kianenigma Mar 12, 2021
e76af15
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 12, 2021
530ab32
Fix migration
kianenigma Mar 13, 2021
9a61b20
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 14, 2021
c92be7e
clean macro
kianenigma Mar 14, 2021
794f0ed
Master.into()
kianenigma Mar 16, 2021
789b35c
Revert wrong merge
kianenigma Mar 16, 2021
5732f01
Holy master.into()
kianenigma Mar 16, 2021
964771c
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 16, 2021
37b666d
remove fuzzer stuff.
kianenigma Mar 16, 2021
ec487a4
Self review
kianenigma Mar 16, 2021
943fc9d
Update frame/staking/src/lib.rs
kianenigma Mar 16, 2021
7963165
review comments
kianenigma Mar 16, 2021
8cbc2bb
ccccrbvlhcjehndjkuknhvijigbrjgdjellvhttutb
kianenigma Mar 16, 2021
a7ec248
add logs
kianenigma Mar 17, 2021
79b6b45
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 18, 2021
8e23866
Master.into()
kianenigma Mar 18, 2021
1a80518
Add tests to demonstrate the capacity of the snapshot.
kianenigma Mar 18, 2021
228b0d3
Replace upgrade
kianenigma Mar 18, 2021
9f6fdab
Last touches
kianenigma Mar 19, 2021
ecdf259
Merge remote-tracking branch 'origin/master' into kiz-election-provid…
Mar 19, 2021
db58d4b
Fix benchmakrs
kianenigma Mar 19, 2021
2824957
Merge branch 'kiz-election-provider-21-enable-multi-phase' of github.…
kianenigma Mar 19, 2021
92e2619
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Mar 19, 2021
9f74fbb
Merge remote-tracking branch 'origin/master' into kiz-election-provid…
Mar 19, 2021
75a7a76
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Mar 19, 2021
dfe6ef9
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 19, 2021
20e8c7c
remove unused stuff
kianenigma Mar 19, 2021
408af31
Merge branch 'kiz-election-provider-21-enable-multi-phase' of github.…
kianenigma Mar 19, 2021
f2f1293
Fix tests.
kianenigma Mar 19, 2021
b47ff14
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Mar 20, 2021
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
24 changes: 1 addition & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ members = [
"frame/session/benchmarking",
"frame/society",
"frame/staking",
"frame/staking/fuzzer",
"frame/staking/reward-curve",
"frame/sudo",
"frame/support",
Expand Down
20 changes: 2 additions & 18 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
pub const MaxIterations: u32 = 10;
// 0.05%. The higher the value, the more strict solution acceptance becomes.
pub MinSolutionScoreBump: Perbill = Perbill::from_rational(5u32, 10_000);
pub OffchainSolutionWeightLimit: Weight = RuntimeBlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic.expect("Normal extrinsics have a weight limit configured; qed")
.saturating_sub(BlockExecutionWeight::get());
}

impl pallet_staking::Config for Runtime {
Expand All @@ -499,14 +491,6 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type MaxIterations = MaxIterations;
type MinSolutionScoreBump = MinSolutionScoreBump;
type UnsignedPriority = StakingUnsignedPriority;
// The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
// a single extrinsic.
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type ElectionProvider = ElectionProviderMultiPhase;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
}
Expand Down Expand Up @@ -536,7 +520,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type Currency = Balances;
type SignedPhase = SignedPhase;
type UnsignedPhase = UnsignedPhase;
type SolutionImprovementThreshold = MinSolutionScoreBump;
type SolutionImprovementThreshold = SolutionImprovementThreshold;
type MinerMaxIterations = MinerMaxIterations;
type MinerMaxWeight = MinerMaxWeight;
type MinerTxPriority = MultiPhaseUnsignedPriority;
Expand Down Expand Up @@ -1095,7 +1079,7 @@ construct_runtime!(
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Module, Call, Storage, Event<T>, ValidateUnsigned},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
Democracy: pallet_democracy::{Module, Call, Storage, Config, Event<T>},
Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
Expand Down
6 changes: 0 additions & 6 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,6 @@ impl pallet_staking::Config for Test {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = ();
}
Expand Down
3 changes: 1 addition & 2 deletions frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ mod tests {
roll_to(25);
assert!(MultiPhase::current_phase().is_unsigned());

// mine seq_phragmen solution with 2 iters.
assert_eq!(
MultiPhase::mine_check_and_submit().unwrap_err(),
MinerError::PreDispatchChecksFailed,
Expand Down Expand Up @@ -844,7 +843,7 @@ mod tests {
}

#[test]
fn ocw_only_runs_when_signed_open_now() {
fn ocw_only_runs_when_unsigned_open_now() {
let (mut ext, pool) = ExtBuilder::default().build_offchainify(0);
ext.execute_with(|| {
roll_to(25);
Expand Down
4 changes: 3 additions & 1 deletion frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ use frame_support::weights::Weight;

/// Re-export some type as they are used in the interface.
pub use sp_arithmetic::PerThing;
pub use sp_npos_elections::{Assignment, ExtendedBalance, PerThing128, Supports, VoteWeight};
pub use sp_npos_elections::{
Assignment, ExtendedBalance, PerThing128, Supports, Support, VoteWeight
};

/// Types that are used by the data provider trait.
pub mod data_provider {
Expand Down
8 changes: 1 addition & 7 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ frame_support::construct_runtime!(
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned},
Offences: pallet_offences::{Module, Call, Storage, Event},
Expand Down Expand Up @@ -214,12 +214,6 @@ impl pallet_staking::Config for Test {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = ();
}
Expand Down
4 changes: 1 addition & 3 deletions frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use pallet_session::historical::{Config as HistoricalConfig, IdentificationTuple
use pallet_session::{Config as SessionConfig, SessionManager};
use pallet_staking::{
Module as Staking, Config as StakingConfig, RewardDestination, ValidatorPrefs,
Exposure, IndividualExposure, ElectionStatus, MAX_NOMINATIONS, Event as StakingEvent
Exposure, IndividualExposure, MAX_NOMINATIONS, Event as StakingEvent
};

const SEED: u32 = 0;
Expand Down Expand Up @@ -386,8 +386,6 @@ benchmarks! {
let o = 10;
let n = 100;

Staking::<T>::put_election_status(ElectionStatus::Closed);

let mut deferred_offences = vec![];
let offenders = make_offenders::<T>(o, n)?.0;
let offence_details = offenders.into_iter()
Expand Down
8 changes: 1 addition & 7 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type ElectionLookahead = ();
type Call = Call;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = ();
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = ();
}
Expand Down Expand Up @@ -222,7 +216,7 @@ frame_support::construct_runtime!(
{
System: system::{Module, Call, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
Offences: pallet_offences::{Module, Call, Storage, Event},
Expand Down
8 changes: 1 addition & 7 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ frame_support::construct_runtime!(
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
}
);
Expand Down Expand Up @@ -177,13 +177,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type ElectionLookahead = ();
type Call = Call;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = UnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = ();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ static_assertions = "1.1.0"
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" }
# TWO_PHASE_NOTE:: ideally we should be able to get rid of this.
Copy link
Member

Choose a reason for hiding this comment

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

We didnt get rid of anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need to generate the static solution type here at compile time sp_npos_election::generate_compact_solution!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and will be fixed here: #8368

sp-npos-elections = { version = "3.0.0", default-features = false, path = "../../primitives/npos-elections" }
sp-io ={ version = "3.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" }
Expand All @@ -27,8 +26,9 @@ frame-system = { version = "3.0.0", default-features = false, path = "../system"
pallet-session = { version = "3.0.0", default-features = false, features = ["historical"], path = "../session" }
pallet-authorship = { version = "3.0.0", default-features = false, path = "../authorship" }
sp-application-crypto = { version = "3.0.0", default-features = false, path = "../../primitives/application-crypto" }
log = { version = "0.4.14", default-features = false }
frame-election-provider-support = { version = "3.0.0", default-features = false, path = "../election-provider-support" }
log = { version = "0.4.14", default-features = false }
paste = "1.0"

# Optional imports for benchmarking
frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true }
Expand Down
2 changes: 0 additions & 2 deletions frame/staking/fuzzer/.gitignore

This file was deleted.

Loading