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

Commit

Permalink
Partial Unbonding for Nomination Pools (#11212)
Browse files Browse the repository at this point in the history
* first draft of partial unbonding for pools

* remove option

* Add some more tests and fix issues

* Fix all tests

* simplify some tests

* Update frame/nomination-pools/src/mock.rs

* remove clone

* rename to delegator_unbonding_eras

* Update frame/nomination-pools/src/tests.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/nomination-pools/src/tests.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/nomination-pools/src/tests.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* remove pub

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* undo

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* leftovers

* fix invariant

* Fix the depositor assumption

* round of self-review

* little bit more cleanup

* Update frame/nomination-pools/src/mock.rs

* Apply suggestions from code review

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Fix interpretation of MinCreateBond

* controvesial refactor

* rename

* make everything build

* add TODO about killing the reward account

* Update frame/nomination-pools/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/nomination-pools/src/lib.rs

* last self-review

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
  • Loading branch information
kianenigma and emostov authored Apr 20, 2022
1 parent 844f42f commit 781fb6e
Show file tree
Hide file tree
Showing 9 changed files with 945 additions and 332 deletions.
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ impl pallet_nomination_pools::Config for Runtime {
type StakingInterface = pallet_staking::Pallet<Self>;
type PostUnbondingPoolsWindow = PostUnbondPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = ConstU32<8>;
type PalletId = NominationPoolsPalletId;
}

Expand Down
1 change: 1 addition & 0 deletions frame/nomination-pools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pallet-balances = { version = "4.0.0-dev", path = "../balances" }
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }

[features]
runtime-benchmarks = []
default = ["std"]
std = [
"codec/std",
Expand Down
2 changes: 1 addition & 1 deletion frame/nomination-pools/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../..
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
pallet-bags-list = { version = "4.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../bags-list" }
pallet-staking = { version = "4.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../staking" }
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../" }
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../", features = ["runtime-benchmarks"] }

# Substrate Primitives
sp-runtime = { version = "6.0.0", default-features = false, path = "../../../primitives/runtime" }
Expand Down
19 changes: 13 additions & 6 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ frame_benchmarking::benchmarks! {
.map_err(|_| "balance expected to be a u128")
.unwrap();
let scenario = ListScenario::<T>::new(origin_weight, false)?;

let amount = origin_weight - scenario.dest_weight.clone();

let scenario = scenario.add_joiner(amount);
let delegator_id = scenario.origin1_delegator.unwrap().clone();
let all_points = Delegators::<T>::get(&delegator_id).unwrap().points;
whitelist_account!(delegator_id);
}: _(Origin::Signed(delegator_id.clone()), delegator_id.clone())
}: _(Origin::Signed(delegator_id.clone()), delegator_id.clone(), all_points)
verify {
let bonded_after = T::StakingInterface::active_stake(&scenario.origin1).unwrap();
// We at least went down to the destination bag
Expand All @@ -304,7 +304,14 @@ frame_benchmarking::benchmarks! {
&delegator_id
)
.unwrap();
assert_eq!(delegator.unbonding_era, Some(0 + T::StakingInterface::bonding_duration()));
assert_eq!(
delegator.unbonding_eras.keys().cloned().collect::<Vec<_>>(),
vec![0 + T::StakingInterface::bonding_duration()]
);
assert_eq!(
delegator.unbonding_eras.values().cloned().collect::<Vec<_>>(),
vec![all_points]
);
}

pool_withdraw_unbonded {
Expand All @@ -329,7 +336,7 @@ frame_benchmarking::benchmarks! {
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);

// Unbond the new delegator
Pools::<T>::unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();

// Sanity check that unbond worked
assert_eq!(
Expand Down Expand Up @@ -374,7 +381,7 @@ frame_benchmarking::benchmarks! {

// Unbond the new delegator
pallet_staking::CurrentEra::<T>::put(0);
Pools::<T>::unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();

// Sanity check that unbond worked
assert_eq!(
Expand Down Expand Up @@ -423,7 +430,7 @@ frame_benchmarking::benchmarks! {
// up when unbonding.
let reward_account = Pools::<T>::create_reward_account(1);
assert!(frame_system::Account::<T>::contains_key(&reward_account));
Pools::<T>::unbond(Origin::Signed(depositor.clone()).into(), depositor.clone()).unwrap();
Pools::<T>::fully_unbond(Origin::Signed(depositor.clone()).into(), depositor.clone()).unwrap();

// Sanity check that unbond worked
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl pallet_nomination_pools::Config for Runtime {
type StakingInterface = Staking;
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = ConstU32<8>;
type PalletId = PoolsPalletId;
}

Expand Down
Loading

0 comments on commit 781fb6e

Please sign in to comment.