Skip to content

Commit a9aeabe

Browse files
krisbitneybkchr
andauthored
Allow for 0 existential deposit in benchmarks for pallet_staking, pallet_session, and pallet_balances (#4346)
This PR ensures non-zero values are available in benchmarks for `pallet_staking`, `pallet_session`, and `pallet_balances` where required for them to run. This small change makes it possible to run the benchmarks for `pallet_staking`, `pallet_session`, and `pallet_balances` in a runtime for which existential deposit is set to 0. The benchmarks for `pallet_staking` and `pallet_session` will still fail in runtimes that use `U128CurrencyToVote`, but that is easy to work around by creating a new `CurrencyToVote` implementation for benchmarking. The changes are implemented by checking if existential deposit equals 0 and using 1 if so. --------- Co-authored-by: command-bot <> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 6580101 commit a9aeabe

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

prdoc/pr_4346.prdoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Allow for 0 existential deposit in benchmarks for pallet_staking, pallet_session, and pallet_balances
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
Changes were made to benchmarks for `pallet_staking`, `pallet_session`, and `pallet-balances` to accommodate runtimes with 0 existential deposit. This should not affect the vast majority of runtimes. For runtimes with 0 existential deposit, the benchmarks for `pallet_staking` and `pallet_session` will still fail when using `U128CurrencyToVote` in the `pallet-staking` config; developers can use or write another `CurrencyToVote` implementation for benchmarking to work around this.
10+
11+
crates:
12+
- name: pallet-staking
13+
bump: patch
14+
- name: pallet-session-benchmarking
15+
bump: patch
16+
- name: pallet-balances
17+
bump: patch

substrate/frame/balances/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod benchmarks {
4444
let caller = whitelisted_caller();
4545

4646
// Give some multiple of the existential deposit
47-
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
47+
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into()).max(1u32.into());
4848
let _ = <Balances<T, I> as Currency<_>>::make_free_balance_be(&caller, balance);
4949

5050
// Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account,

substrate/frame/staking/src/testing_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub fn create_stash_controller<T: Config>(
7777
destination: RewardDestination<T::AccountId>,
7878
) -> Result<(T::AccountId, T::AccountId), &'static str> {
7979
let staker = create_funded_user::<T>("stash", n, balance_factor);
80-
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
80+
let amount =
81+
T::Currency::minimum_balance().max(1u64.into()) * (balance_factor / 10).max(1).into();
8182
Staking::<T>::bond(RawOrigin::Signed(staker.clone()).into(), amount, destination)?;
8283
Ok((staker.clone(), staker))
8384
}

0 commit comments

Comments
 (0)