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

Fast Unstake Pallet #12129

Merged
merged 99 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
bdd1399
add failing test for itamar
kianenigma Jul 31, 2022
14486b6
an ugly example of fast unstake
kianenigma Jul 31, 2022
960c067
Revert "add failing test for itamar"
kianenigma Jul 31, 2022
85fb600
fast unstake wip
kianenigma Aug 2, 2022
1c10497
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Aug 19, 2022
87a712e
clean it up a bit
kianenigma Aug 19, 2022
0449aab
some comments
Aug 22, 2022
be76057
on_idle logic
Aug 22, 2022
6afd4ac
fix
Aug 22, 2022
91f047a
comment
Aug 22, 2022
548b5cc
new working version, checks all pass, looking good
kianenigma Aug 22, 2022
1de37da
merged
kianenigma Aug 22, 2022
815a0e8
some notes
kianenigma Aug 22, 2022
3747b54
add mock boilerplate
Aug 23, 2022
17fda17
more boilerplate
Aug 23, 2022
078ad67
simplify the weight stuff
kianenigma Aug 23, 2022
554d706
Merge remote-tracking branch 'origin/kiz-fast-unstake' into rb-fast-u…
Aug 23, 2022
18e8fa3
ExtBuilder for pools
Aug 23, 2022
c232118
fmt
Aug 23, 2022
427d2c9
rm bags-list, simplify setup_works
Aug 23, 2022
4cbe28a
mock + tests boilerplate
Aug 23, 2022
c5df0a7
make some benchmarks work
kianenigma Aug 23, 2022
7f784d5
mock boilerplate
Aug 23, 2022
754f189
tests boilerplate
Aug 23, 2022
cefc48f
Merge remote-tracking branch 'origin/kiz-fast-unstake' into rb-fast-u…
Aug 23, 2022
0c69897
run_to_block works
Aug 23, 2022
bbd0be6
add Error enums
Aug 23, 2022
b350f15
add test
Aug 23, 2022
fd6e4ad
note
Aug 23, 2022
ac10d8e
make UnstakeRequest fields pub
Aug 24, 2022
96fc5f5
some tests
Aug 24, 2022
12fff9d
fix origin
Aug 24, 2022
f46ed2f
fmt
Aug 24, 2022
40ec631
add fast_unstake_events_since_last_call
Aug 26, 2022
1ba1194
text
Aug 26, 2022
ca45c78
rewrite some benchmes and fix them -- the outcome is still strange
kianenigma Aug 28, 2022
956ac7c
Fix weights
kianenigma Aug 28, 2022
db7cfec
cleanup
kianenigma Aug 28, 2022
db921e0
Update frame/election-provider-support/solution-type/src/single_page.rs
kianenigma Aug 28, 2022
f5ae199
fix build
kianenigma Aug 29, 2022
29994aa
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Aug 29, 2022
80b5e5f
Fix pools tests
kianenigma Aug 29, 2022
5453097
Merge branch 'kiz-fast-unstake' into rb-fast-unstake
Aug 29, 2022
9fa95e9
iterate teset + mock
Aug 29, 2022
1bc7835
test unfinished
Aug 29, 2022
818dabc
cleanup and add some tests
kianenigma Aug 29, 2022
239f45f
add test successful_multi_queue
Aug 30, 2022
141798d
comment
Aug 30, 2022
2777d23
rm Head check
Aug 30, 2022
642fb02
add TODO
Aug 30, 2022
f34d43e
complete successful_multi_queue
Aug 30, 2022
058dfe5
+ test early_exit
Aug 30, 2022
1c64074
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 6, 2022
a830f4b
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Sep 6, 2022
5d78bf6
fix a lot of things above the beautiful atlantic ocean 🌊
kianenigma Sep 7, 2022
ce81494
seemingly it is finished now
kianenigma Sep 8, 2022
dc93db9
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 8, 2022
fe19157
Fix build
kianenigma Sep 8, 2022
61d041b
".git/.scripts/fmt.sh" 1
Sep 8, 2022
c3e292c
Fix slashing amount as well
kianenigma Sep 9, 2022
eaf57d5
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Sep 9, 2022
c925741
better docs
kianenigma Sep 9, 2022
bb1261d
abstract types
Sep 11, 2022
aed73b6
rm use
Sep 11, 2022
1f32054
import
Sep 11, 2022
c067da3
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 12, 2022
b08f8e2
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 13, 2022
5bb83ac
Update frame/nomination-pools/benchmarking/src/lib.rs
kianenigma Sep 13, 2022
2325c23
Update frame/fast-unstake/src/types.rs
kianenigma Sep 13, 2022
01b3605
Fix build
kianenigma Sep 13, 2022
8b616e2
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Sep 13, 2022
0621f96
fmt
kianenigma Sep 13, 2022
1f0fb09
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 13, 2022
de11f0f
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 15, 2022
69128f9
make bounded
kianenigma Sep 15, 2022
0818920
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Sep 15, 2022
b6e51f3
feedback from code review with Ankan
kianenigma Sep 15, 2022
2720ab0
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
002fb1c
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
8cbcfd8
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
88dc2e5
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
40b8afe
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
cc30c6b
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
9987751
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
c807a95
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
daf38eb
Update frame/fast-unstake/src/lib.rs
kianenigma Sep 16, 2022
31a3948
Update frame/fast-unstake/src/mock.rs
kianenigma Sep 16, 2022
151f43f
Merge branch 'master' of github.com:paritytech/substrate into kiz-fas…
kianenigma Sep 20, 2022
10b9c45
update to master
kianenigma Sep 20, 2022
f37f466
some final review comments
kianenigma Sep 20, 2022
d6238ca
Merge branch 'kiz-fast-unstake' of github.com:paritytech/substrate in…
kianenigma Sep 20, 2022
ea92142
fmt
kianenigma Sep 20, 2022
eae079f
fix clippy
kianenigma Sep 20, 2022
5a8048a
remove unused
kianenigma Sep 20, 2022
524da81
".git/.scripts/fmt.sh" 1
Sep 20, 2022
c4e6bfe
master.into()
kianenigma Sep 23, 2022
4d45cd0
make it all build again
kianenigma Sep 23, 2022
f145c60
fmt
kianenigma Sep 23, 2022
91d31b4
undo fishy change
kianenigma Sep 23, 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: 26 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ members = [
"frame/contracts/rpc/runtime-api",
"frame/conviction-voting",
"frame/democracy",
"frame/fast-unstake",
"frame/try-runtime",
"frame/election-provider-multi-phase",
"frame/election-provider-support",
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "..
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" }
pallet-gilt = { version = "4.0.0-dev", default-features = false, path = "../../../frame/gilt" }
pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" }
pallet-im-online = { version = "4.0.0-dev", default-features = false, path = "../../../frame/im-online" }
Expand Down Expand Up @@ -136,6 +137,7 @@ std = [
"pallet-conviction-voting/std",
"pallet-democracy/std",
"pallet-elections-phragmen/std",
"pallet-fast-unstake/std",
"frame-executive/std",
"pallet-gilt/std",
"pallet-grandpa/std",
Expand Down Expand Up @@ -212,6 +214,7 @@ runtime-benchmarks = [
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-gilt/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
Expand Down Expand Up @@ -265,6 +268,7 @@ try-runtime = [
"pallet-democracy/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-gilt/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-im-online/try-runtime",
Expand Down
11 changes: 10 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ impl pallet_staking::Config for Runtime {
type BenchmarkingConfig = StakingBenchmarkingConfig;
}

impl pallet_fast_unstake::Config for Runtime {
type Event = Event;
type SlashPerEra = ConstU128<{ DOLLARS }>;
type ControlOrigin = frame_system::EnsureRoot<AccountId>;
type WeightInfo = ();
}

parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
Expand Down Expand Up @@ -1409,7 +1416,7 @@ impl pallet_assets::Config for Runtime {
type Balance = u128;
type AssetId = u32;
type Currency = Balances;
type ForceOrigin = EnsureRoot<AccountId>;
type ForceOrigin = EnsureSigned<AccountId>;
type AssetDeposit = AssetDeposit;
type AssetAccountDeposit = ConstU128<DOLLARS>;
type MetadataDepositBase = MetadataDepositBase;
Expand Down Expand Up @@ -1647,6 +1654,7 @@ construct_runtime!(
NominationPools: pallet_nomination_pools,
RankedPolls: pallet_referenda::<Instance2>,
RankedCollective: pallet_ranked_collective,
FastUnstake: pallet_fast_unstake,
}
);

Expand Down Expand Up @@ -1732,6 +1740,7 @@ mod benches {
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
[pallet_elections_phragmen, Elections]
[pallet_fast_unstake, FastUnstake]
[pallet_gilt, Gilt]
[pallet_grandpa, Grandpa]
[pallet_identity, Identity]
Expand Down
11 changes: 11 additions & 0 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ impl<T: Config> ElectionProvider for NoFallback<T> {
type DataProvider = T::DataProvider;
type Error = &'static str;

fn ongoing() -> bool {
false
}

fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
// Do nothing, this will enable the emergency phase.
Err("NoFallback.")
Expand Down Expand Up @@ -1597,6 +1601,13 @@ impl<T: Config> ElectionProvider for Pallet<T> {
type Error = ElectionError<T>;
type DataProvider = T::DataProvider;

fn ongoing() -> bool {
match Self::current_phase() {
Phase::Off => false,
_ => true,
}
}

fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
match Self::do_elect() {
Ok(supports) => {
Expand Down
4 changes: 4 additions & 0 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ impl ElectionProvider for MockFallback {
type Error = &'static str;
type DataProvider = StakingMock;

fn ongoing() -> bool {
false
}

fn elect() -> Result<Supports<AccountId>, Self::Error> {
Self::elect_with_bounds(Bounded::max_value(), Bounded::max_value())
}
Expand Down
9 changes: 8 additions & 1 deletion frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
//! type BlockNumber = BlockNumber;
//! type Error = &'static str;
//! type DataProvider = T::DataProvider;
//!
//! fn ongoing() -> bool { false }
//! fn elect() -> Result<Supports<AccountId>, Self::Error> {
//! Self::DataProvider::electable_targets(None)
//! .map_err(|_| "failed to elect")
Expand Down Expand Up @@ -370,6 +370,9 @@ pub trait ElectionProvider {
BlockNumber = Self::BlockNumber,
>;

/// Indicate if this election provider is currently ongoing an asynchronous election or not.
fn ongoing() -> bool;

/// Elect a new set of winners, without specifying any bounds on the amount of data fetched from
/// [`Self::DataProvider`]. An implementation could nonetheless impose its own custom limits.
///
Expand Down Expand Up @@ -420,6 +423,10 @@ where
fn elect() -> Result<Supports<AccountId>, Self::Error> {
Err("<NoElection as ElectionProvider> cannot do anything.")
}

fn ongoing() -> bool {
false
}
}

/// A utility trait for something to implement `ElectionDataProvider` in a sensible way.
Expand Down
8 changes: 8 additions & 0 deletions frame/election-provider-support/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ impl<T: Config> ElectionProvider for UnboundedExecution<T> {
type Error = Error;
type DataProvider = T::DataProvider;

fn ongoing() -> bool {
false
}

fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
// This should not be called if not in `std` mode (and therefore neither in genesis nor in
// testing)
Expand Down Expand Up @@ -167,6 +171,10 @@ impl<T: BoundedConfig> ElectionProvider for BoundedExecution<T> {
type Error = Error;
type DataProvider = T::DataProvider;

fn ongoing() -> bool {
false
}

fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
elect_with::<T>(Some(T::VotersBound::get() as usize), Some(T::TargetsBound::get() as usize))
}
Expand Down
70 changes: 70 additions & 0 deletions frame/fast-unstake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[package]
name = "pallet-fast-unstake"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "Unlicense"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME fast unstake pallet"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }

frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }

sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
sp-staking = { default-features = false, path = "../../primitives/staking" }

pallet-balances = { default-features = false, path = "../balances" }
pallet-timestamp = { default-features = false, path = "../timestamp" }
pallet-staking = { default-features = false, path = "../staking" }
pallet-nomination-pools = { default-features = false, path = "../nomination-pools" }
frame-election-provider-support = { default-features = false, path = "../election-provider-support" }

frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }

[dev-dependencies]
pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" }
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
substrate-test-utils = { version = "4.0.0-dev", path = "../../test-utils" }
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }

[features]
default = ["std"]
std = [
"codec/std",
"log/std",
"scale-info/std",

"frame-support/std",
"frame-system/std",

"sp-io/std",
"sp-staking/std",
"sp-runtime/std",
"sp-std/std",

"pallet-staking/std",
"pallet-nomination-pools/std",
"pallet-balances/std",
"pallet-timestamp/std",
"frame-election-provider-support/std",

"frame-benchmarking/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
Loading