Skip to content

Commit

Permalink
Delay nominator revocations and exits (#610)
Browse files Browse the repository at this point in the history
* init

* save

* save

* save

* log::trace -> log::warn, drop errors, and fix compile errors

* commit migrationss design will revert for simpler impl

* minimal migration impl instead

* delay leave nominators with all unit tests passing

* delayed revoke_nomination with all tests passing

* unit tests

* split BondDuration into 4 constants and update runtimes

* try green

* green

* rm revoke nomination TS test because it expects revocation to be immediate and it is now delayed and there is no leave candidates TS test to show how to delay

* add types to moonbeam types bundle and update test instead of commenting it out

* fix

* fix

* try fix TS test

* try again

* every byte counts

* x

* y

* z

* update weights

* ready for review

* rm unused errors

* more accurate weight returned in on runtime upgrade

* fix weight, one read to check if migration has run before

* Update pallets/parachain-staking/src/lib.rs
  • Loading branch information
4meta5 authored Jul 22, 2021
1 parent 6c45864 commit 5086f00
Show file tree
Hide file tree
Showing 18 changed files with 1,118 additions and 640 deletions.
54 changes: 53 additions & 1 deletion Cargo.lock

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

19 changes: 18 additions & 1 deletion moonbeam-types-bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ export const moonbeamDefinitions = {
nominations: "Vec<Bond>",
total: "Balance",
},
NominatorStatus: {
_enum: ["Active", { Leaving: "RoundIndex" }],
},
Nominator2: {
nominations: "Vec<Bond>",
revocations: "Vec<AccountId>",
total: "Balance",
scheduled_revocations_count: "u32",
scheduled_revocations_total: "Balance",
status: "NominatorStatus",
},
Bond: {
owner: "AccountId",
amount: "Balance",
Expand Down Expand Up @@ -680,7 +691,7 @@ export const moonbeamDefinitions = {
state: "CollatorStatus",
},
NominatorAdded: {
_enum: ["AddedToBottom", { AddedToTop: "Balance" }],
_enum: [{ AddedToTop: "Balance" }, "AddedToBottom"],
},
CollatorSnapshot: {
bond: "Balance",
Expand Down Expand Up @@ -716,6 +727,12 @@ export const moonbeamDefinitions = {
s: "H256",
v: "U8",
},
ExitQ: {
candidates: "Vec<AccountId>",
nominators_leaving: "Vec<AccountId>",
candidate_schedule: "Vec<(AccountId, RoundIndex)>",
nominator_schedule: "Vec<(AccountId, Option<AccountId>, RoundIndex)>",
},
},
},
],
Expand Down
15 changes: 8 additions & 7 deletions pallets/parachain-staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
[package]
name = "parachain-staking"
version = "2.1.0"
version = "2.1.1"
authors = ["PureStake"]
edition = "2018"
description = "parachain staking pallet for collator selection and reward distribution"

[dependencies]
nimbus-primitives = { git = "https://github.com/purestake/cumulus", branch = "joshy-np098", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
log = "0.4"
nimbus-primitives = { git = "https://github.com/purestake/cumulus", branch = "joshy-np098", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
substrate-fixed = { default-features = false, git = "https://github.com/encointer/substrate-fixed" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
similar-asserts = "1.1.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }

[features]
default = ["std"]
std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"nimbus-primitives/std",
"pallet-balances/std",
"parity-scale-codec/std",
Expand Down
6 changes: 6 additions & 0 deletions pallets/parachain-staking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# DPoS Pallet for Parachain Staking

## Formatting Rules

- dependencies in alphabetical order in the `Cargo.toml` and at the top of each file
- prefer explicit imports to glob import syntax i.e. prefer `use::crate::{Ex1, Ex2, ..};` to `use super::*;`
13 changes: 8 additions & 5 deletions pallets/parachain-staking/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ benchmarks! {
}
}: _(RawOrigin::Signed(caller.clone()), nomination_count)
verify {
assert!(!Pallet::<T>::is_nominator(&caller));
assert!(Pallet::<T>::nominator_state2(&caller).unwrap().is_leaving());
}

revoke_nomination {
Expand All @@ -363,9 +363,12 @@ benchmarks! {
0u32,
0u32
)?;
}: _(RawOrigin::Signed(caller.clone()), collator)
}: _(RawOrigin::Signed(caller.clone()), collator.clone())
verify {
assert!(!Pallet::<T>::is_nominator(&caller));
assert_eq!(
Pallet::<T>::nominator_state2(&caller).unwrap().revocations.0[0],
collator
);
}

nominator_bond_more {
Expand Down Expand Up @@ -520,7 +523,7 @@ benchmarks! {
// PREPARE RUN_TO_BLOCK LOOP
let before_running_round_index = Pallet::<T>::round().current;
let round_length: T::BlockNumber = Pallet::<T>::round().length.into();
let reward_delay = <<T as Config>::BondDuration as Get<u32>>::get() + 2u32;
let reward_delay = <<T as Config>::RewardPaymentDelay as Get<u32>>::get() + 2u32;
let mut now = <frame_system::Pallet<T>>::block_number();
let mut counter = 0usize;
let end = Pallet::<T>::round().first + (round_length * reward_delay.into());
Expand Down Expand Up @@ -581,7 +584,7 @@ benchmarks! {

#[cfg(test)]
mod tests {
use super::*;
use crate::benchmarks::*;
use crate::mock::Test;
use frame_support::assert_ok;
use sp_io::TestExternalities;
Expand Down
Loading

0 comments on commit 5086f00

Please sign in to comment.