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

Allow nomination pools to chill + fix dismantle scenario #11426

Merged
merged 43 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ea30833
make pool roles optional
kianenigma May 13, 2022
00e8c87
undo lock file changes?
kianenigma May 13, 2022
fa5e95a
add migration
kianenigma May 13, 2022
f2df79e
add the ability for pools to chill themselves
kianenigma May 14, 2022
56cf997
boilerplate of tests
kianenigma May 14, 2022
508bc0a
new system works, tests need fixing
kianenigma May 15, 2022
f83944a
somewhat stable, but I think I found another bug as well
kianenigma May 15, 2022
ac48c37
Fix it all
kianenigma May 16, 2022
cbeb9fb
Master.into()
kianenigma May 16, 2022
031040f
Add more more sophisticated test + capture one more bug.
kianenigma May 16, 2022
efc7b4f
Update frame/staking/src/lib.rs
kianenigma May 16, 2022
60d42f1
reduce the diff a little bit
kianenigma May 17, 2022
02aa7d4
add some test for the slashing bug
kianenigma May 19, 2022
90db26e
cleanup
kianenigma May 19, 2022
5bf6d9c
Merge branch 'kiz-pool-chill' of github.com:paritytech/substrate into…
kianenigma May 19, 2022
1d8c940
Master.into()
kianenigma May 19, 2022
2ec4857
Merge branch 'master' of github.com:paritytech/substrate into kiz-poo…
kianenigma May 20, 2022
a51e408
fix lock file?
kianenigma May 20, 2022
28c8852
Fix
kianenigma May 20, 2022
c9413a2
fmt
kianenigma May 20, 2022
433476d
Merge branch 'master' of github.com:paritytech/substrate into kiz-poo…
kianenigma May 23, 2022
c34b655
Update frame/nomination-pools/src/lib.rs
kianenigma May 23, 2022
d0d75a1
Update frame/nomination-pools/src/lib.rs
kianenigma May 23, 2022
a6afb06
Update frame/nomination-pools/src/lib.rs
kianenigma May 23, 2022
a3a43e7
Update frame/nomination-pools/src/mock.rs
kianenigma May 23, 2022
4b7b0c7
Fix build
kianenigma May 23, 2022
3f66688
Merge branch 'kiz-pool-chill' of github.com:paritytech/substrate into…
kianenigma May 23, 2022
640ec31
fix some fishy tests..
kianenigma May 23, 2022
398ddfe
add one last integrity check for MinCreateBond
kianenigma May 24, 2022
d5dc697
remove bad assertion -- needs to be dealt with later
kianenigma May 24, 2022
05fb517
Merge branch 'master' of github.com:paritytech/substrate into kiz-poo…
kianenigma May 24, 2022
f4dbd0a
nits
shawntabrizi May 25, 2022
0a79c80
Master.into()
kianenigma Jun 8, 2022
78c0310
Merge branch 'kiz-pool-chill' of github.com:paritytech/substrate into…
kianenigma Jun 9, 2022
0fb1125
fix tests and add benchmarks for chill
kianenigma Jun 9, 2022
12773bb
remove stuff
kianenigma Jun 9, 2022
ca475df
fix benchmarks
kianenigma Jun 10, 2022
44a2722
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jun 10, 2022
f027faf
cargo run --quiet --profile=production --features=runtime-benchmarks…
Jun 10, 2022
33b581c
Master.into()
kianenigma Jun 11, 2022
c77613f
Merge branch 'kiz-pool-chill' of github.com:paritytech/substrate into…
kianenigma Jun 11, 2022
d69af2c
remove defensive
kianenigma Jun 11, 2022
d318197
Merge branch 'master' of github.com:paritytech/substrate into kiz-poo…
kianenigma Jun 13, 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
24 changes: 24 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 @@ -115,6 +115,7 @@ members = [
"frame/proxy",
"frame/nomination-pools",
"frame/nomination-pools/benchmarking",
"frame/nomination-pools/test-staking",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new pallet with end to end tests around staking and pools. I can recommend giving it a read. Other test changes are not really important.

"frame/randomness-collective-flip",
"frame/ranked-collective",
"frame/recovery",
Expand Down
11 changes: 8 additions & 3 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ use hex_literal::hex;
use node_runtime::{
constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig,
BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig,
ImOnlineConfig, IndicesConfig, MaxNominations, SessionConfig, SessionKeys, SocietyConfig,
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig, SessionConfig,
SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down Expand Up @@ -365,7 +366,11 @@ pub fn testnet_genesis(
transaction_payment: Default::default(),
alliance: Default::default(),
alliance_motion: Default::default(),
nomination_pools: Default::default(),
nomination_pools: NominationPoolsConfig {
min_create_bond: 10 * DOLLARS,
min_join_bond: 1 * DOLLARS,
..Default::default()
},
}
}

Expand Down
3 changes: 2 additions & 1 deletion frame/nomination-pools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../primit
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" }
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
log = { version = "0.4.0", default-features = false }

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

[features]
Expand All @@ -41,6 +41,7 @@ std = [
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"sp-staking/std",
"sp-core/std",
"log/std",
Expand Down
76 changes: 38 additions & 38 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod mock;

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

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

fn min_create_bond<T: Config>() -> BalanceOf<T> {
MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance())
}

fn create_funded_user_with_balance<T: pallet_nomination_pools::Config>(
string: &'static str,
n: u32,
Expand Down Expand Up @@ -209,9 +215,7 @@ impl<T: Config> ListScenario<T> {

frame_benchmarking::benchmarks! {
join {
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
.max(CurrencyOf::<T>::minimum_balance())
* 2u32.into();
let origin_weight = min_create_bond::<T>() * 2u32.into();

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

bond_extra_transfer {
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
.max(CurrencyOf::<T>::minimum_balance())
* 2u32.into();
let origin_weight = min_create_bond::<T>() * 2u32.into();
let scenario = ListScenario::<T>::new(origin_weight, true)?;
let extra = scenario.dest_weight.clone() - origin_weight;

Expand All @@ -254,9 +256,7 @@ frame_benchmarking::benchmarks! {
}

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

Expand All @@ -274,7 +274,7 @@ frame_benchmarking::benchmarks! {
}

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

Expand Down Expand Up @@ -336,9 +334,7 @@ frame_benchmarking::benchmarks! {
pool_withdraw_unbonded {
let s in 0 .. MAX_SPANS;

let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());
let min_create_bond = min_create_bond::<T>();
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);

// Add a new member
Expand Down Expand Up @@ -380,9 +376,7 @@ frame_benchmarking::benchmarks! {
withdraw_unbonded_update {
let s in 0 .. MAX_SPANS;

let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());
let min_create_bond = min_create_bond::<T>();
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);

// Add a new member
Expand Down Expand Up @@ -427,10 +421,7 @@ frame_benchmarking::benchmarks! {
withdraw_unbonded_kill {
let s in 0 .. MAX_SPANS;

let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());

let min_create_bond = min_create_bond::<T>();
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);

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

create {
let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());
let min_create_bond = min_create_bond::<T>();
let depositor: T::AccountId = account("depositor", USER_SEED, 0);

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

// Create a pool
let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());
let min_create_bond = min_create_bond::<T>() * 2u32.into();
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);

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

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

// Create a pool
let min_create_bond = MinCreateBond::<T>::get()
.max(T::StakingInterface::minimum_bond())
.max(CurrencyOf::<T>::minimum_balance());
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond);
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());

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

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

chill {
// Create a pool
let (depositor, pool_account) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());

// Nominate with the pool.
let validators: Vec<_> = (0..T::MaxNominations::get())
.map(|i| account("stash", USER_SEED, i))
.collect();

assert_ok!(Pools::<T>::nominate(Origin::Signed(depositor.clone()).into(), 1, validators));
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_some());

whitelist_account!(depositor);
}:_(Origin::Signed(depositor.clone()), 1)
verify {
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_none());
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
Expand Down
Loading