Skip to content

Commit 323eecd

Browse files
kianenigmaggwpezshawntabriziParity Bot
authored
Allow nomination pools to chill + fix dismantle scenario (paritytech#11426)
* make pool roles optional * undo lock file changes? * add migration * add the ability for pools to chill themselves * boilerplate of tests * somewhat stable, but I think I found another bug as well * Fix it all * Add more more sophisticated test + capture one more bug. * Update frame/staking/src/lib.rs * reduce the diff a little bit * add some test for the slashing bug * cleanup * fix lock file? * Fix * fmt * Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/nomination-pools/src/mock.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix build * fix some fishy tests.. * add one last integrity check for MinCreateBond * remove bad assertion -- needs to be dealt with later * nits * fix tests and add benchmarks for chill * remove stuff * fix benchmarks * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/nomination-pools/src/weights.rs --template=./.maintain/frame-weight-template.hbs * remove defensive Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Parity Bot <admin@parity.io>
1 parent 4c41a7b commit 323eecd

File tree

18 files changed

+1427
-628
lines changed

18 files changed

+1427
-628
lines changed

Cargo.lock

Lines changed: 24 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
@@ -115,6 +115,7 @@ members = [
115115
"frame/proxy",
116116
"frame/nomination-pools",
117117
"frame/nomination-pools/benchmarking",
118+
"frame/nomination-pools/test-staking",
118119
"frame/randomness-collective-flip",
119120
"frame/ranked-collective",
120121
"frame/recovery",

bin/node/cli/src/chain_spec.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ use hex_literal::hex;
2323
use node_runtime::{
2424
constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig,
2525
BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig,
26-
ImOnlineConfig, IndicesConfig, MaxNominations, SessionConfig, SessionKeys, SocietyConfig,
27-
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
26+
ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig, SessionConfig,
27+
SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
28+
TechnicalCommitteeConfig,
2829
};
2930
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
3031
use sc_chain_spec::ChainSpecExtension;
@@ -365,7 +366,11 @@ pub fn testnet_genesis(
365366
transaction_payment: Default::default(),
366367
alliance: Default::default(),
367368
alliance_motion: Default::default(),
368-
nomination_pools: Default::default(),
369+
nomination_pools: NominationPoolsConfig {
370+
min_create_bond: 10 * DOLLARS,
371+
min_join_bond: 1 * DOLLARS,
372+
..Default::default()
373+
},
369374
}
370375
}
371376

frame/nomination-pools/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../primit
2323
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
2424
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" }
2525
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
26+
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
2627
log = { version = "0.4.0", default-features = false }
2728

2829
[dev-dependencies]
2930
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
30-
sp-io = { version = "6.0.0", path = "../../primitives/io" }
3131
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
3232

3333
[features]
@@ -41,6 +41,7 @@ std = [
4141
"frame-system/std",
4242
"sp-runtime/std",
4343
"sp-std/std",
44+
"sp-io/std",
4445
"sp-staking/std",
4546
"sp-core/std",
4647
"log/std",

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

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod mock;
2424

2525
use frame_benchmarking::{account, frame_support::traits::Currency, vec, whitelist_account, Vec};
2626
use frame_election_provider_support::SortedListProvider;
27-
use frame_support::{ensure, traits::Get};
27+
use frame_support::{assert_ok, ensure, traits::Get};
2828
use frame_system::RawOrigin as Origin;
2929
use pallet_nomination_pools::{
3030
BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, MaxPoolMembers,
@@ -48,6 +48,12 @@ pub trait Config:
4848

4949
pub struct Pallet<T: Config>(Pools<T>);
5050

51+
fn min_create_bond<T: Config>() -> BalanceOf<T> {
52+
MinCreateBond::<T>::get()
53+
.max(T::StakingInterface::minimum_bond())
54+
.max(CurrencyOf::<T>::minimum_balance())
55+
}
56+
5157
fn create_funded_user_with_balance<T: pallet_nomination_pools::Config>(
5258
string: &'static str,
5359
n: u32,
@@ -209,9 +215,7 @@ impl<T: Config> ListScenario<T> {
209215

210216
frame_benchmarking::benchmarks! {
211217
join {
212-
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
213-
.max(CurrencyOf::<T>::minimum_balance())
214-
* 2u32.into();
218+
let origin_weight = min_create_bond::<T>() * 2u32.into();
215219

216220
// setup the worst case list scenario.
217221
let scenario = ListScenario::<T>::new(origin_weight, true)?;
@@ -237,9 +241,7 @@ frame_benchmarking::benchmarks! {
237241
}
238242

239243
bond_extra_transfer {
240-
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
241-
.max(CurrencyOf::<T>::minimum_balance())
242-
* 2u32.into();
244+
let origin_weight = min_create_bond::<T>() * 2u32.into();
243245
let scenario = ListScenario::<T>::new(origin_weight, true)?;
244246
let extra = scenario.dest_weight.clone() - origin_weight;
245247

@@ -254,9 +256,7 @@ frame_benchmarking::benchmarks! {
254256
}
255257

256258
bond_extra_reward {
257-
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
258-
.max(CurrencyOf::<T>::minimum_balance())
259-
* 2u32.into();
259+
let origin_weight = min_create_bond::<T>() * 2u32.into();
260260
let scenario = ListScenario::<T>::new(origin_weight, true)?;
261261
let extra = (scenario.dest_weight.clone() - origin_weight).max(CurrencyOf::<T>::minimum_balance());
262262

@@ -274,7 +274,7 @@ frame_benchmarking::benchmarks! {
274274
}
275275

276276
claim_payout {
277-
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get().max(CurrencyOf::<T>::minimum_balance()) * 2u32.into();
277+
let origin_weight = min_create_bond::<T>() * 2u32.into();
278278
let ed = CurrencyOf::<T>::minimum_balance();
279279
let (depositor, pool_account) = create_pool_account::<T>(0, origin_weight);
280280
let reward_account = Pools::<T>::create_reward_account(1);
@@ -304,9 +304,7 @@ frame_benchmarking::benchmarks! {
304304
unbond {
305305
// The weight the nominator will start at. The value used here is expected to be
306306
// significantly higher than the first position in a list (e.g. the first bag threshold).
307-
let origin_weight = BalanceOf::<T>::try_from(952_994_955_240_703u128)
308-
.map_err(|_| "balance expected to be a u128")
309-
.unwrap();
307+
let origin_weight = min_create_bond::<T>() * 200u32.into();
310308
let scenario = ListScenario::<T>::new(origin_weight, false)?;
311309
let amount = origin_weight - scenario.dest_weight.clone();
312310

@@ -336,9 +334,7 @@ frame_benchmarking::benchmarks! {
336334
pool_withdraw_unbonded {
337335
let s in 0 .. MAX_SPANS;
338336

339-
let min_create_bond = MinCreateBond::<T>::get()
340-
.max(T::StakingInterface::minimum_bond())
341-
.max(CurrencyOf::<T>::minimum_balance());
337+
let min_create_bond = min_create_bond::<T>();
342338
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
343339

344340
// Add a new member
@@ -380,9 +376,7 @@ frame_benchmarking::benchmarks! {
380376
withdraw_unbonded_update {
381377
let s in 0 .. MAX_SPANS;
382378

383-
let min_create_bond = MinCreateBond::<T>::get()
384-
.max(T::StakingInterface::minimum_bond())
385-
.max(CurrencyOf::<T>::minimum_balance());
379+
let min_create_bond = min_create_bond::<T>();
386380
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
387381

388382
// Add a new member
@@ -427,10 +421,7 @@ frame_benchmarking::benchmarks! {
427421
withdraw_unbonded_kill {
428422
let s in 0 .. MAX_SPANS;
429423

430-
let min_create_bond = MinCreateBond::<T>::get()
431-
.max(T::StakingInterface::minimum_bond())
432-
.max(CurrencyOf::<T>::minimum_balance());
433-
424+
let min_create_bond = min_create_bond::<T>();
434425
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
435426

436427
// We set the pool to the destroying state so the depositor can leave
@@ -494,9 +485,7 @@ frame_benchmarking::benchmarks! {
494485
}
495486

496487
create {
497-
let min_create_bond = MinCreateBond::<T>::get()
498-
.max(T::StakingInterface::minimum_bond())
499-
.max(CurrencyOf::<T>::minimum_balance());
488+
let min_create_bond = min_create_bond::<T>();
500489
let depositor: T::AccountId = account("depositor", USER_SEED, 0);
501490

502491
// Give the depositor some balance to bond
@@ -542,9 +531,7 @@ frame_benchmarking::benchmarks! {
542531
let n in 1 .. T::MaxNominations::get();
543532

544533
// Create a pool
545-
let min_create_bond = MinCreateBond::<T>::get()
546-
.max(T::StakingInterface::minimum_bond())
547-
.max(CurrencyOf::<T>::minimum_balance());
534+
let min_create_bond = min_create_bond::<T>() * 2u32.into();
548535
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
549536

550537
// Create some accounts to nominate. For the sake of benchmarking they don't need to be
@@ -581,9 +568,7 @@ frame_benchmarking::benchmarks! {
581568

582569
set_state {
583570
// Create a pool
584-
let min_create_bond = MinCreateBond::<T>::get()
585-
.max(T::StakingInterface::minimum_bond())
586-
.max(CurrencyOf::<T>::minimum_balance());
571+
let min_create_bond = min_create_bond::<T>();
587572
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
588573
BondedPools::<T>::mutate(&1, |maybe_pool| {
589574
// Force the pool into an invalid state
@@ -601,10 +586,7 @@ frame_benchmarking::benchmarks! {
601586
let n in 1 .. <T as pallet_nomination_pools::Config>::MaxMetadataLen::get();
602587

603588
// Create a pool
604-
let min_create_bond = MinCreateBond::<T>::get()
605-
.max(T::StakingInterface::minimum_bond())
606-
.max(CurrencyOf::<T>::minimum_balance());
607-
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
589+
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());
608590

609591
// Create metadata of the max possible size
610592
let metadata: Vec<u8> = (0..n).map(|_| 42).collect();
@@ -633,7 +615,7 @@ frame_benchmarking::benchmarks! {
633615

634616
update_roles {
635617
let first_id = pallet_nomination_pools::LastPoolId::<T>::get() + 1;
636-
let (root, _) = create_pool_account::<T>(0, CurrencyOf::<T>::minimum_balance() * 2u32.into());
618+
let (root, _) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());
637619
let random: T::AccountId = account("but is anything really random in computers..?", 0, USER_SEED);
638620
}:_(
639621
Origin::Signed(root.clone()),
@@ -653,6 +635,24 @@ frame_benchmarking::benchmarks! {
653635
)
654636
}
655637

638+
chill {
639+
// Create a pool
640+
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());
641+
642+
// Nominate with the pool.
643+
let validators: Vec<_> = (0..T::MaxNominations::get())
644+
.map(|i| account("stash", USER_SEED, i))
645+
.collect();
646+
647+
assert_ok!(Pools::<T>::nominate(Origin::Signed(depositor.clone()).into(), 1, validators));
648+
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_some());
649+
650+
whitelist_account!(depositor);
651+
}:_(Origin::Signed(depositor.clone()), 1)
652+
verify {
653+
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_none());
654+
}
655+
656656
impl_benchmark_test_suite!(
657657
Pallet,
658658
crate::mock::new_test_ext(),

0 commit comments

Comments
 (0)