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

Commit 781fb6e

Browse files
kianenigmaemostov
andauthored
Partial Unbonding for Nomination Pools (#11212)
* 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>
1 parent 844f42f commit 781fb6e

File tree

9 files changed

+945
-332
lines changed

9 files changed

+945
-332
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ impl pallet_nomination_pools::Config for Runtime {
731731
type StakingInterface = pallet_staking::Pallet<Self>;
732732
type PostUnbondingPoolsWindow = PostUnbondPoolsWindow;
733733
type MaxMetadataLen = ConstU32<256>;
734+
type MaxUnbonding = ConstU32<8>;
734735
type PalletId = NominationPoolsPalletId;
735736
}
736737

frame/nomination-pools/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pallet-balances = { version = "4.0.0-dev", path = "../balances" }
3030
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
3131

3232
[features]
33+
runtime-benchmarks = []
3334
default = ["std"]
3435
std = [
3536
"codec/std",

frame/nomination-pools/benchmarking/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../..
2424
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
2525
pallet-bags-list = { version = "4.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../bags-list" }
2626
pallet-staking = { version = "4.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../staking" }
27-
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../" }
27+
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../", features = ["runtime-benchmarks"] }
2828

2929
# Substrate Primitives
3030
sp-runtime = { version = "6.0.0", default-features = false, path = "../../../primitives/runtime" }

frame/nomination-pools/benchmarking/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ frame_benchmarking::benchmarks! {
289289
.map_err(|_| "balance expected to be a u128")
290290
.unwrap();
291291
let scenario = ListScenario::<T>::new(origin_weight, false)?;
292-
293292
let amount = origin_weight - scenario.dest_weight.clone();
294293

295294
let scenario = scenario.add_joiner(amount);
296295
let delegator_id = scenario.origin1_delegator.unwrap().clone();
296+
let all_points = Delegators::<T>::get(&delegator_id).unwrap().points;
297297
whitelist_account!(delegator_id);
298-
}: _(Origin::Signed(delegator_id.clone()), delegator_id.clone())
298+
}: _(Origin::Signed(delegator_id.clone()), delegator_id.clone(), all_points)
299299
verify {
300300
let bonded_after = T::StakingInterface::active_stake(&scenario.origin1).unwrap();
301301
// We at least went down to the destination bag
@@ -304,7 +304,14 @@ frame_benchmarking::benchmarks! {
304304
&delegator_id
305305
)
306306
.unwrap();
307-
assert_eq!(delegator.unbonding_era, Some(0 + T::StakingInterface::bonding_duration()));
307+
assert_eq!(
308+
delegator.unbonding_eras.keys().cloned().collect::<Vec<_>>(),
309+
vec![0 + T::StakingInterface::bonding_duration()]
310+
);
311+
assert_eq!(
312+
delegator.unbonding_eras.values().cloned().collect::<Vec<_>>(),
313+
vec![all_points]
314+
);
308315
}
309316

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

331338
// Unbond the new delegator
332-
Pools::<T>::unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
339+
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
333340

334341
// Sanity check that unbond worked
335342
assert_eq!(
@@ -374,7 +381,7 @@ frame_benchmarking::benchmarks! {
374381

375382
// Unbond the new delegator
376383
pallet_staking::CurrentEra::<T>::put(0);
377-
Pools::<T>::unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
384+
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
378385

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

428435
// Sanity check that unbond worked
429436
assert_eq!(

frame/nomination-pools/benchmarking/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl pallet_nomination_pools::Config for Runtime {
155155
type StakingInterface = Staking;
156156
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
157157
type MaxMetadataLen = ConstU32<256>;
158+
type MaxUnbonding = ConstU32<8>;
158159
type PalletId = PoolsPalletId;
159160
}
160161

0 commit comments

Comments
 (0)