Skip to content

Commit 13d1ff9

Browse files
kianenigmaRoss BulatBustaNitKiChjangruseinov
authored andcommitted
Fast Unstake Pallet (paritytech#12129)
* add failing test for itamar * an ugly example of fast unstake * Revert "add failing test for itamar" This reverts commit bdd1399. * fast unstake wip * clean it up a bit * some comments * on_idle logic * fix * comment * new working version, checks all pass, looking good * some notes * add mock boilerplate * more boilerplate * simplify the weight stuff * ExtBuilder for pools * fmt * rm bags-list, simplify setup_works * mock + tests boilerplate * make some benchmarks work * mock boilerplate * tests boilerplate * run_to_block works * add Error enums * add test * note * make UnstakeRequest fields pub * some tests * fix origin * fmt * add fast_unstake_events_since_last_call * text * rewrite some benchmes and fix them -- the outcome is still strange * Fix weights * cleanup * Update frame/election-provider-support/solution-type/src/single_page.rs * fix build * Fix pools tests * iterate teset + mock * test unfinished * cleanup and add some tests * add test successful_multi_queue * comment * rm Head check * add TODO * complete successful_multi_queue * + test early_exit * fix a lot of things above the beautiful atlantic ocean 🌊 * seemingly it is finished now * Fix build * ".git/.scripts/fmt.sh" 1 * Fix slashing amount as well * better docs * abstract types * rm use * import * Update frame/nomination-pools/benchmarking/src/lib.rs Co-authored-by: Nitwit <[email protected]> * Update frame/fast-unstake/src/types.rs Co-authored-by: Nitwit <[email protected]> * Fix build * fmt * Update frame/fast-unstake/src/lib.rs Co-authored-by: Keith Yeung <[email protected]> * make bounded * feedback from code review with Ankan * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/lib.rs Co-authored-by: Roman Useinov <[email protected]> * Update frame/fast-unstake/src/mock.rs * update to master * some final review comments * fmt * fix clippy * remove unused * ".git/.scripts/fmt.sh" 1 * make it all build again * fmt * undo fishy change Co-authored-by: Ross Bulat <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Nitwit <[email protected]> Co-authored-by: Keith Yeung <[email protected]> Co-authored-by: Roman Useinov <[email protected]>
1 parent dfae062 commit 13d1ff9

File tree

21 files changed

+2650
-29
lines changed

21 files changed

+2650
-29
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ members = [
9090
"frame/contracts/rpc/runtime-api",
9191
"frame/conviction-voting",
9292
"frame/democracy",
93+
"frame/fast-unstake",
9394
"frame/try-runtime",
9495
"frame/election-provider-multi-phase",
9596
"frame/election-provider-support",

bin/node/runtime/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "..
6868
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
6969
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
7070
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
71+
pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" }
7172
pallet-gilt = { version = "4.0.0-dev", default-features = false, path = "../../../frame/gilt" }
7273
pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" }
7374
pallet-im-online = { version = "4.0.0-dev", default-features = false, path = "../../../frame/im-online" }
@@ -142,6 +143,7 @@ std = [
142143
"pallet-conviction-voting/std",
143144
"pallet-democracy/std",
144145
"pallet-elections-phragmen/std",
146+
"pallet-fast-unstake/std",
145147
"frame-executive/std",
146148
"pallet-gilt/std",
147149
"pallet-grandpa/std",
@@ -220,6 +222,7 @@ runtime-benchmarks = [
220222
"pallet-election-provider-multi-phase/runtime-benchmarks",
221223
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
222224
"pallet-elections-phragmen/runtime-benchmarks",
225+
"pallet-fast-unstake/runtime-benchmarks",
223226
"pallet-gilt/runtime-benchmarks",
224227
"pallet-grandpa/runtime-benchmarks",
225228
"pallet-identity/runtime-benchmarks",
@@ -272,6 +275,7 @@ try-runtime = [
272275
"pallet-democracy/try-runtime",
273276
"pallet-election-provider-multi-phase/try-runtime",
274277
"pallet-elections-phragmen/try-runtime",
278+
"pallet-fast-unstake/try-runtime",
275279
"pallet-gilt/try-runtime",
276280
"pallet-grandpa/try-runtime",
277281
"pallet-im-online/try-runtime",

bin/node/runtime/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ impl pallet_staking::Config for Runtime {
579579
type BenchmarkingConfig = StakingBenchmarkingConfig;
580580
}
581581

582+
impl pallet_fast_unstake::Config for Runtime {
583+
type RuntimeEvent = RuntimeEvent;
584+
type SlashPerEra = ConstU128<{ DOLLARS }>;
585+
type ControlOrigin = frame_system::EnsureRoot<AccountId>;
586+
type WeightInfo = ();
587+
}
588+
582589
parameter_types! {
583590
// phase durations. 1/4 of the last session for each.
584591
pub const SignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
@@ -1655,6 +1662,7 @@ construct_runtime!(
16551662
NominationPools: pallet_nomination_pools,
16561663
RankedPolls: pallet_referenda::<Instance2>,
16571664
RankedCollective: pallet_ranked_collective,
1665+
FastUnstake: pallet_fast_unstake,
16581666
}
16591667
);
16601668

@@ -1741,6 +1749,7 @@ mod benches {
17411749
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
17421750
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
17431751
[pallet_elections_phragmen, Elections]
1752+
[pallet_fast_unstake, FastUnstake]
17441753
[pallet_gilt, Gilt]
17451754
[pallet_grandpa, Grandpa]
17461755
[pallet_identity, Identity]

frame/election-provider-multi-phase/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ impl<T: Config> ElectionProvider for NoFallback<T> {
318318
type DataProvider = T::DataProvider;
319319
type Error = &'static str;
320320

321+
fn ongoing() -> bool {
322+
false
323+
}
324+
321325
fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
322326
// Do nothing, this will enable the emergency phase.
323327
Err("NoFallback.")
@@ -1598,6 +1602,13 @@ impl<T: Config> ElectionProvider for Pallet<T> {
15981602
type Error = ElectionError<T>;
15991603
type DataProvider = T::DataProvider;
16001604

1605+
fn ongoing() -> bool {
1606+
match Self::current_phase() {
1607+
Phase::Off => false,
1608+
_ => true,
1609+
}
1610+
}
1611+
16011612
fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
16021613
match Self::do_elect() {
16031614
Ok(supports) => {

frame/election-provider-multi-phase/src/mock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ impl ElectionProvider for MockFallback {
303303
type Error = &'static str;
304304
type DataProvider = StakingMock;
305305

306+
fn ongoing() -> bool {
307+
false
308+
}
309+
306310
fn elect() -> Result<Supports<AccountId>, Self::Error> {
307311
Self::elect_with_bounds(Bounded::max_value(), Bounded::max_value())
308312
}

frame/election-provider-support/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
//! type BlockNumber = BlockNumber;
137137
//! type Error = &'static str;
138138
//! type DataProvider = T::DataProvider;
139-
//!
139+
//! fn ongoing() -> bool { false }
140140
//! fn elect() -> Result<Supports<AccountId>, Self::Error> {
141141
//! Self::DataProvider::electable_targets(None)
142142
//! .map_err(|_| "failed to elect")
@@ -370,6 +370,9 @@ pub trait ElectionProvider {
370370
BlockNumber = Self::BlockNumber,
371371
>;
372372

373+
/// Indicate if this election provider is currently ongoing an asynchronous election or not.
374+
fn ongoing() -> bool;
375+
373376
/// Elect a new set of winners, without specifying any bounds on the amount of data fetched from
374377
/// [`Self::DataProvider`]. An implementation could nonetheless impose its own custom limits.
375378
///
@@ -420,6 +423,10 @@ where
420423
fn elect() -> Result<Supports<AccountId>, Self::Error> {
421424
Err("<NoElection as ElectionProvider> cannot do anything.")
422425
}
426+
427+
fn ongoing() -> bool {
428+
false
429+
}
423430
}
424431

425432
/// A utility trait for something to implement `ElectionDataProvider` in a sensible way.

frame/election-provider-support/src/onchain.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ impl<T: Config> ElectionProvider for UnboundedExecution<T> {
138138
type Error = Error;
139139
type DataProvider = T::DataProvider;
140140

141+
fn ongoing() -> bool {
142+
false
143+
}
144+
141145
fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
142146
// This should not be called if not in `std` mode (and therefore neither in genesis nor in
143147
// testing)
@@ -167,6 +171,10 @@ impl<T: BoundedConfig> ElectionProvider for BoundedExecution<T> {
167171
type Error = Error;
168172
type DataProvider = T::DataProvider;
169173

174+
fn ongoing() -> bool {
175+
false
176+
}
177+
170178
fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
171179
elect_with::<T>(Some(T::VotersBound::get() as usize), Some(T::TargetsBound::get() as usize))
172180
}

frame/fast-unstake/Cargo.toml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[package]
2+
name = "pallet-fast-unstake"
3+
version = "4.0.0-dev"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2021"
6+
license = "Unlicense"
7+
homepage = "https://substrate.io"
8+
repository = "https://github.com/paritytech/substrate/"
9+
description = "FRAME fast unstake pallet"
10+
readme = "README.md"
11+
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
14+
15+
[dependencies]
16+
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
17+
log = { version = "0.4.17", default-features = false }
18+
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
19+
20+
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
21+
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
22+
23+
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
24+
sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" }
25+
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
26+
sp-staking = { default-features = false, path = "../../primitives/staking" }
27+
28+
pallet-balances = { default-features = false, path = "../balances" }
29+
pallet-timestamp = { default-features = false, path = "../timestamp" }
30+
pallet-staking = { default-features = false, path = "../staking" }
31+
pallet-nomination-pools = { default-features = false, path = "../nomination-pools" }
32+
frame-election-provider-support = { default-features = false, path = "../election-provider-support" }
33+
34+
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
35+
36+
[dev-dependencies]
37+
pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" }
38+
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
39+
substrate-test-utils = { version = "4.0.0-dev", path = "../../test-utils" }
40+
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
41+
42+
[features]
43+
default = ["std"]
44+
std = [
45+
"codec/std",
46+
"log/std",
47+
"scale-info/std",
48+
49+
"frame-support/std",
50+
"frame-system/std",
51+
52+
"sp-io/std",
53+
"sp-staking/std",
54+
"sp-runtime/std",
55+
"sp-std/std",
56+
57+
"pallet-staking/std",
58+
"pallet-nomination-pools/std",
59+
"pallet-balances/std",
60+
"pallet-timestamp/std",
61+
"frame-election-provider-support/std",
62+
63+
"frame-benchmarking/std",
64+
]
65+
runtime-benchmarks = [
66+
"frame-benchmarking/runtime-benchmarks",
67+
"frame-system/runtime-benchmarks",
68+
"pallet-staking/runtime-benchmarks",
69+
]
70+
try-runtime = ["frame-support/try-runtime"]

0 commit comments

Comments
 (0)