Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NPoS] Fix for Reward Deficit in the pool #1255

Merged
merged 116 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 98 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
7429f0b
make total reward payout counter never decrease
Ank4n Aug 29, 2023
fc135d7
improve comments
Ank4n Aug 29, 2023
a580bc1
new call to top up the pool
Ank4n Aug 29, 2023
aace388
format
Ank4n Aug 29, 2023
66b593d
topped up funds are not rewardeable to delegators
Ank4n Aug 29, 2023
56cafc4
test for top up function
Ank4n Aug 29, 2023
767cc3a
check user has enough balance and limit max transfer to their free ba…
Ank4n Aug 29, 2023
626f544
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 2, 2023
c4c7e96
contracts: Update to wasmi 0.31 (#1350)
athei Sep 2, 2023
a1a6d3e
substrate: chain-spec paths corrected in zombienet tests (#1362)
michalkucharczyk Sep 2, 2023
bda10a8
Ensure cumulus/bridges is ignored by formatter and run it (#1369)
gavofyork Sep 3, 2023
60895d0
feat: add futures api to `TransactionPool` (#1348)
yjhmelody Sep 3, 2023
86f0cc1
Bump proc-macro-warning from 0.4.1 to 0.4.2 (#1376)
dependabot[bot] Sep 4, 2023
0423b0d
Bump the known_good_semver group with 1 update (#1375)
dependabot[bot] Sep 4, 2023
2b89df6
Update `fmt` file and some authors (#1379)
ggwpez Sep 4, 2023
d3ba197
Markdown linter (#1309)
chevdor Sep 4, 2023
b14a908
[xcm-emulator] Redo Parachain init (#1356)
NachoPal Sep 4, 2023
5d37b81
add Treasurer to SchedulerOrigin (#1325)
xlc Sep 4, 2023
3d4089c
Cleanup repo (a tiny bit) (#1382)
ggwpez Sep 4, 2023
79edd91
approval-voting: use proper hash when querying session info (#1387)
ordian Sep 4, 2023
daf6141
[ci] Remove runtime-benchmarks from tests (#1335)
alvicsam Sep 4, 2023
c08d14d
Extract block announce validation from `ChainSync` (#1170)
dmitry-markin Sep 4, 2023
8e484a8
Contracts: Update read_sandbox (#1390)
pgherveou Sep 4, 2023
b5433ff
rust docs: add simple analytics (#1377)
liamaharon Sep 5, 2023
b1a3223
Move Relay-Specific Shared Code to One Place (#1193)
joepetrowski Sep 5, 2023
5bec497
Bump thiserror from 1.0.47 to 1.0.48 (#1396)
dependabot[bot] Sep 5, 2023
25f30b8
Bump actions/checkout from 3 to 4 (#1398)
dependabot[bot] Sep 5, 2023
d5565d3
Get rid of polling in `WarpSync` (#1265)
dmitry-markin Sep 5, 2023
23926b7
Remove redundant calls to `borrow()` (#1393)
mrcnski Sep 5, 2023
c292021
Remove dynamic dispatch using `Ext` (#1399)
athei Sep 5, 2023
d129363
Enforce a decoding limit in MultiAssets (#1395)
franciscoaguirre Sep 5, 2023
3e4576f
fmt fixes (#1413)
chevdor Sep 6, 2023
37161ee
Add PRdoc check (#1408)
chevdor Sep 6, 2023
a27e24e
RFC 14: Improve locking mechanism for parachains (#1290)
xlc Sep 6, 2023
425a72d
Bump enumn from 0.1.11 to 0.1.12 (#1412)
dependabot[bot] Sep 6, 2023
7520e04
Fix the wasm runtime substitute caching bug (#1416)
Sep 6, 2023
a317ef9
Fix PRdoc check (#1419)
chevdor Sep 6, 2023
c725bbe
Remove deprecated `pallet_balances`'s `set_balance_deprecated` and `t…
juangirini Sep 6, 2023
5e56b1a
pallet asset-conversion additional quote tests (#1371)
gilescope Sep 6, 2023
1be427e
GHW for building and publishing docker images (#1391)
EgorPopelyaev Sep 6, 2023
2f31a4c
Fix nothing scheduled on session boundary (#1403)
eskimor Sep 6, 2023
43d7a8c
Prevent a fail prdoc check to block (#1433)
chevdor Sep 6, 2023
433bc9d
zombienet: use another collator image for the slashing test (#1386)
ordian Sep 6, 2023
c6f1b9f
Adds base benchmark for do_tick in broker pallet (#1235)
gupnik Sep 7, 2023
7f2ae6e
Forgotten `polkadot-core-primitives/std` (#1440)
bkontur Sep 7, 2023
024210b
remove unused `keystore_uri` (#1421)
yjhmelody Sep 7, 2023
3ff561f
[ci] Enable flacky collector for tests (#1439)
alvicsam Sep 7, 2023
329df04
polkadot: pin one block per session (#1220)
ordian Sep 7, 2023
5fb02e7
[ci] Return publish-rustdoc (#1402)
alvicsam Sep 7, 2023
301c438
[ci] change image for prdoc gha (#1452)
alvicsam Sep 7, 2023
cbc1d0d
Update Chrono to 0.4.30 (#1451)
chevdor Sep 8, 2023
1089fe8
Bump actions/cache from 3.3.1 to 3.3.2 (#1456)
dependabot[bot] Sep 8, 2023
15898c3
Bump hex-literal from 0.3.4 to 0.4.1 (#1438)
dependabot[bot] Sep 8, 2023
eae53d5
Update ed25519-dalek to v2 (#1446)
chevdor Sep 8, 2023
f5d911a
Switch prdoc to the latest image (#1460)
chevdor Sep 8, 2023
675e7da
does not compile as balance is not serializable and used in genesis c…
Ank4n Sep 8, 2023
f3e8a4f
remove balance dependency in genesis config altogether
Ank4n Sep 8, 2023
8a3891e
compiles
Ank4n Sep 13, 2023
5848428
allow 1 holds
Ank4n Sep 13, 2023
84b6246
freezing currency is more appropriate here
Ank4n Sep 13, 2023
4d34b59
all tests pass
Ank4n Sep 13, 2023
c5fc61d
use Currency trait to read free balance
Ank4n Sep 13, 2023
22fd5de
verify ed is frozen
Ank4n Sep 13, 2023
b535954
format
Ank4n Sep 13, 2023
4a3387b
impl for adjusting ED
Ank4n Sep 13, 2023
36a87a4
use Runtime Freeze Reason
Ank4n Sep 14, 2023
de12c8f
add tests for adjusting ED
Ank4n Sep 14, 2023
138ecb2
fmt
Ank4n Sep 14, 2023
6a3bfc3
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 14, 2023
a1c4970
added by mistake while merging, reverting
Ank4n Sep 14, 2023
29465b1
basic migration
Ank4n Sep 14, 2023
05592c7
migrations
Ank4n Sep 15, 2023
b147cfe
add weights to new call
Ank4n Sep 15, 2023
8bfef28
use fungible traits in np bench
Ank4n Sep 15, 2023
e705898
bench for new instruction
Ank4n Sep 15, 2023
b0202e2
allow fn with runtime benchmarks
Ank4n Sep 15, 2023
05f4bd8
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 15, 2023
b0c00fe
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 15, 2023
d432fba
pending rewards for pools
Ank4n Sep 16, 2023
d960582
add missing features
Ank4n Sep 16, 2023
d3d8ef4
add a note about using Currency::balance()
Ank4n Sep 16, 2023
bb00d8d
rename misspelling in the function
Ank4n Sep 16, 2023
d4cd942
fix staking np integration test
Ank4n Sep 16, 2023
51a44c7
fix unused warning
Ank4n Sep 16, 2023
9b1042e
fix kitchensink runtime
Ank4n Sep 16, 2023
d54f029
use default config for node cli np chain spec
Ank4n Sep 16, 2023
14d4530
fmt
Ank4n Sep 16, 2023
ca17f83
remove unused imports
Ank4n Sep 16, 2023
88c8959
fix feature scopes
Ank4n Sep 16, 2023
3af90e9
minor
Ank4n Sep 16, 2023
4303bb5
make balances serde for genesis config
Ank4n Sep 16, 2023
809236e
add migration for pools to all runtimes
Ank4n Sep 16, 2023
e538a0f
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 16, 2023
ba9e53c
use balance everywhere in benchmark
Ank4n Sep 16, 2023
caac4e1
allow freezes in the kitchensink runtime
Ank4n Sep 16, 2023
d939a82
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 17, 2023
c138e17
add docs and minor refactor
Ank4n Sep 18, 2023
34541b2
comment
Ank4n Sep 18, 2023
5628881
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Sep 19, 2023
d20138a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Sep 19, 2023
7de37d3
PR comments
Ank4n Sep 21, 2023
7969fdf
defensive assert while dissolving pool
Ank4n Sep 21, 2023
1e993eb
make unversioned migration private
Ank4n Sep 21, 2023
a15af2b
fix migrations in runtime
Ank4n Sep 21, 2023
58612c3
migration fix and name the new call better
Ank4n Sep 21, 2023
04f89b7
rename freeze unfreeze functions
Ank4n Sep 21, 2023
be4a86c
fmt
Ank4n Sep 21, 2023
f1425c3
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 21, 2023
dd1ad02
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 22, 2023
0395a4c
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Sep 22, 2023
7b40492
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 22, 2023
9eee4f6
add pr doc
Ank4n Sep 22, 2023
7ea6b34
make adjust ed permissionless
Ank4n Sep 26, 2023
6bb9425
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 26, 2023
8d4361a
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 27, 2023
5f072c5
Merge branch 'master' into ankan/fix-np-reward-deficit
Ank4n Sep 29, 2023
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
9 changes: 6 additions & 3 deletions polkadot/runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ impl pallet_balances::Config for Runtime {
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
type FreezeIdentifier = ();
type MaxFreezes = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The runtime changes need to be made in the fellowship repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly this can be removed but do you know how is this going to really work? We will still need to make minimal changes to the runtimes for it to compile right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Kusama and Polkadot runtimes have been removed from polkadot-sdk now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean, its still there as much as I can see.

type RuntimeHoldReason = RuntimeHoldReason;
type MaxHolds = ConstU32<1>;
}
Expand Down Expand Up @@ -1457,6 +1457,7 @@ impl pallet_nomination_pools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_nomination_pools::WeightInfo<Self>;
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
Expand Down Expand Up @@ -1584,7 +1585,7 @@ construct_runtime! {
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 39,

// nomination pools: extension to staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 41,
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>, FreezeReason} = 41,

// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 42,
Expand Down Expand Up @@ -1763,6 +1764,8 @@ pub mod migrations {
parachains_configuration::migration::v9::MigrateToV9<Runtime>,
// Migrate parachain info format
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ParachainsToUnlock>,
// Freeze ED Deposits for pools
pallet_nomination_pools::migration::v6::VersionedMigrateV6<Runtime>,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,8 @@ impl<T: frame_system::Config> pallet_nomination_pools::WeightInfo for WeightInfo
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}

fn adjust_ed_deposit() -> Weight {
Weight::default()
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to run the bench bot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bench bot is not working anymore since kusama and polkadot runtime are not supposed to be used from Polkadot-sdk. I need to leave a placeholder for the code to compile but make sure this is benched in the fellowship runtime pr?

}
}
9 changes: 6 additions & 3 deletions polkadot/runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<0>;
}

parameter_types! {
Expand Down Expand Up @@ -1288,6 +1288,7 @@ parameter_types! {
impl pallet_nomination_pools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = FixedU128;
type BalanceToU256 = runtime_common::BalanceToU256;
type U256ToBalance = runtime_common::U256ToBalance;
Expand Down Expand Up @@ -1387,7 +1388,7 @@ construct_runtime! {
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 37,

// Nomination pools: extension to staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 39,
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>, FreezeReason} = 39,

// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 40,
Expand Down Expand Up @@ -1546,6 +1547,8 @@ pub mod migrations {
parachains_configuration::migration::v9::MigrateToV9<Runtime>,
// Migrate parachain info format
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ParachainsToUnlock>,
// Freeze ED Deposits for pools
pallet_nomination_pools::migration::v6::VersionedMigrateV6<Runtime>,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,8 @@ impl<T: frame_system::Config> pallet_nomination_pools::WeightInfo for WeightInfo
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}

fn adjust_ed_deposit() -> Weight {
Weight::default()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not that relevant anymore because the runtime configs come from the fellowship repo, but it would be great to run the bench bot,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not working anymore :(. I think these needs to be benched now in fellowship PRs and here we make the minimal change to compile everything. Hopefully we get rid of kusama and polkadot runtimes from this repository soon.

}
}
8 changes: 5 additions & 3 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<0>;
}

parameter_types! {
Expand Down Expand Up @@ -1246,6 +1246,7 @@ impl pallet_nomination_pools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_nomination_pools::WeightInfo<Self>;
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
Expand Down Expand Up @@ -1333,7 +1334,7 @@ construct_runtime! {
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 25,

// Nomination pools for staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 29,
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>, FreezeReason} = 29,

// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 30,
Expand Down Expand Up @@ -1431,6 +1432,7 @@ pub mod migrations {
UpgradeSessionKeys,
parachains_configuration::migration::v9::MigrateToV9<Runtime>,
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ()>,
pallet_nomination_pools::migration::v6::VersionedMigrateV6<Runtime>,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,8 @@ impl<T: frame_system::Config> pallet_nomination_pools::WeightInfo for WeightInfo
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}

fn adjust_ed_deposit() -> Weight {
Weight::default()
}
}
5 changes: 3 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Pallet<Runtime>;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type FreezeIdentifier = ();
type MaxFreezes = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type RuntimeHoldReason = RuntimeHoldReason;
type MaxHolds = ConstU32<2>;
}
Expand Down Expand Up @@ -879,6 +879,7 @@ impl pallet_nomination_pools::Config for Runtime {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
Expand Down
59 changes: 37 additions & 22 deletions substrate/frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use frame_benchmarking::v1::{account, whitelist_account};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
assert_ok, ensure,
traits::{Currency, Get},
traits::{
fungible::{Inspect, Mutate, Unbalanced},
Get,
},
};
use frame_system::RawOrigin as RuntimeOrigin;
use pallet_nomination_pools::{
Expand Down Expand Up @@ -67,7 +70,7 @@ fn create_funded_user_with_balance<T: pallet_nomination_pools::Config>(
balance: BalanceOf<T>,
) -> T::AccountId {
let user = account(string, n, USER_SEED);
T::Currency::make_free_balance_be(&user, balance);
T::Currency::set_balance(&user, balance);
user
}

Expand Down Expand Up @@ -148,8 +151,7 @@ impl<T: Config> ListScenario<T> {
);

// Burn the entire issuance.
let i = CurrencyOf::<T>::burn(CurrencyOf::<T>::total_issuance());
sp_std::mem::forget(i);
Ank4n marked this conversation as resolved.
Show resolved Hide resolved
CurrencyOf::<T>::set_total_issuance(Zero::zero());

// Create accounts with the origin weight
let (pool_creator1, pool_origin1) =
Expand Down Expand Up @@ -206,7 +208,7 @@ impl<T: Config> ListScenario<T> {

let joiner: T::AccountId = account("joiner", USER_SEED, 0);
self.origin1_member = Some(joiner.clone());
CurrencyOf::<T>::make_free_balance_be(&joiner, amount * 2u32.into());
CurrencyOf::<T>::set_balance(&joiner, amount * 2u32.into());

let original_bonded = T::Staking::active_stake(&self.origin1).unwrap();

Expand Down Expand Up @@ -254,7 +256,7 @@ frame_benchmarking::benchmarks! {
whitelist_account!(joiner);
}: _(RuntimeOrigin::Signed(joiner.clone()), max_additional, 1)
verify {
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), joiner_free - max_additional);
assert_eq!(CurrencyOf::<T>::balance(&joiner), joiner_free - max_additional);
assert_eq!(
T::Staking::active_stake(&scenario.origin1).unwrap(),
scenario.dest_weight
Expand Down Expand Up @@ -289,7 +291,7 @@ frame_benchmarking::benchmarks! {
// transfer exactly `extra` to the depositor of the src pool (1),
let reward_account1 = Pools::<T>::create_reward_account(1);
assert!(extra >= CurrencyOf::<T>::minimum_balance());
CurrencyOf::<T>::deposit_creating(&reward_account1, extra);
let _ = CurrencyOf::<T>::mint_into(&reward_account1, extra);

}: _(RuntimeOrigin::Signed(claimer), T::Lookup::unlookup(scenario.creator1.clone()), BondExtra::Rewards)
verify {
Expand All @@ -309,27 +311,27 @@ frame_benchmarking::benchmarks! {
let reward_account = Pools::<T>::create_reward_account(1);

// Send funds to the reward account of the pool
CurrencyOf::<T>::make_free_balance_be(&reward_account, ed + origin_weight);
CurrencyOf::<T>::set_balance(&reward_account, ed + origin_weight);

// set claim preferences to `PermissionlessAll` so any account can claim rewards on member's
// behalf.
let _ = Pools::<T>::set_claim_permission(RuntimeOrigin::Signed(depositor.clone()).into(), ClaimPermission::PermissionlessAll);

// Sanity check
assert_eq!(
CurrencyOf::<T>::free_balance(&depositor),
CurrencyOf::<T>::balance(&depositor),
origin_weight
);

whitelist_account!(depositor);
}:claim_payout_other(RuntimeOrigin::Signed(claimer), depositor.clone())
verify {
assert_eq!(
CurrencyOf::<T>::free_balance(&depositor),
CurrencyOf::<T>::balance(&depositor),
origin_weight + commission * origin_weight
);
assert_eq!(
CurrencyOf::<T>::free_balance(&reward_account),
CurrencyOf::<T>::balance(&reward_account),
ed + commission * origin_weight
);
}
Expand Down Expand Up @@ -383,7 +385,7 @@ frame_benchmarking::benchmarks! {
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond + min_join_bond
);
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
assert_eq!(CurrencyOf::<T>::balance(&joiner), min_join_bond);

// Unbond the new member
Pools::<T>::fully_unbond(RuntimeOrigin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
Expand All @@ -403,7 +405,7 @@ frame_benchmarking::benchmarks! {
}: _(RuntimeOrigin::Signed(pool_account.clone()), 1, s)
verify {
// The joiners funds didn't change
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
assert_eq!(CurrencyOf::<T>::balance(&joiner), min_join_bond);
// The unlocking chunk was removed
assert_eq!(pallet_staking::Ledger::<T>::get(pool_account).unwrap().unlocking.len(), 0);
}
Expand All @@ -426,7 +428,7 @@ frame_benchmarking::benchmarks! {
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond + min_join_bond
);
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
assert_eq!(CurrencyOf::<T>::balance(&joiner), min_join_bond);

// Unbond the new member
pallet_staking::CurrentEra::<T>::put(0);
Expand All @@ -447,8 +449,7 @@ frame_benchmarking::benchmarks! {
}: withdraw_unbonded(RuntimeOrigin::Signed(joiner.clone()), joiner_lookup, s)
verify {
assert_eq!(
CurrencyOf::<T>::free_balance(&joiner),
min_join_bond * 2u32.into()
CurrencyOf::<T>::balance(&joiner), min_join_bond * 2u32.into()
);
// The unlocking chunk was removed
assert_eq!(pallet_staking::Ledger::<T>::get(&pool_account).unwrap().unlocking.len(), 0);
Expand Down Expand Up @@ -485,7 +486,7 @@ frame_benchmarking::benchmarks! {
Zero::zero()
);
assert_eq!(
CurrencyOf::<T>::free_balance(&pool_account),
CurrencyOf::<T>::balance(&pool_account),
min_create_bond
);
assert_eq!(pallet_staking::Ledger::<T>::get(&pool_account).unwrap().unlocking.len(), 1);
Expand Down Expand Up @@ -515,7 +516,7 @@ frame_benchmarking::benchmarks! {

// Funds where transferred back correctly
assert_eq!(
CurrencyOf::<T>::free_balance(&depositor),
CurrencyOf::<T>::balance(&depositor),
// gets bond back + rewards collecting when unbonding
min_create_bond * 2u32.into() + CurrencyOf::<T>::minimum_balance()
);
Expand All @@ -527,7 +528,7 @@ frame_benchmarking::benchmarks! {
let depositor_lookup = T::Lookup::unlookup(depositor.clone());

// Give the depositor some balance to bond
CurrencyOf::<T>::make_free_balance_be(&depositor, min_create_bond * 2u32.into());
CurrencyOf::<T>::set_balance(&depositor, min_create_bond * 2u32.into());

// Make sure no Pools exist at a pre-condition for our verify checks
assert_eq!(RewardPools::<T>::count(), 0);
Expand Down Expand Up @@ -782,7 +783,7 @@ frame_benchmarking::benchmarks! {
let ed = CurrencyOf::<T>::minimum_balance();
let (depositor, pool_account) = create_pool_account::<T>(0, origin_weight, Some(commission));
let reward_account = Pools::<T>::create_reward_account(1);
CurrencyOf::<T>::make_free_balance_be(&reward_account, ed + origin_weight);
CurrencyOf::<T>::set_balance(&reward_account, ed + origin_weight);

// member claims a payout to make some commission available.
let _ = Pools::<T>::claim_payout(RuntimeOrigin::Signed(claimer).into());
Expand All @@ -791,15 +792,29 @@ frame_benchmarking::benchmarks! {
}:_(RuntimeOrigin::Signed(depositor.clone()), 1u32.into())
verify {
assert_eq!(
CurrencyOf::<T>::free_balance(&depositor),
CurrencyOf::<T>::balance(&depositor),
origin_weight + commission * origin_weight
);
assert_eq!(
CurrencyOf::<T>::free_balance(&reward_account),
CurrencyOf::<T>::balance(&reward_account),
ed + commission * origin_weight
);
}

adjust_ed_deposit {
// Create a pool
let (depositor, _) = create_pool_account::<T>(0, Pools::<T>::depositor_min_bond() * 2u32.into(), None);

// Remove ed freeze to create a scenario where the ed deposit needs to be adjusted.
let _ = Pools::<T>::remove_ed_freeze(&Pools::<T>::create_reward_account(1));
assert!(&Pools::<T>::check_ed_imbalance().is_err());

whitelist_account!(depositor);
}:_(RuntimeOrigin::Signed(depositor), 1)
verify {
assert!(&Pools::<T>::check_ed_imbalance().is_ok());
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type RuntimeHoldReason = ();
type MaxHolds = ();
}
Expand Down Expand Up @@ -160,6 +160,7 @@ impl pallet_nomination_pools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
Expand All @@ -183,7 +184,7 @@ frame_support::construct_runtime!(
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Staking: pallet_staking::{Pallet, Call, Config<T>, Storage, Event<T>},
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>},
Pools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>},
Pools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, FreezeReason},
}
);

Expand Down
Loading