Skip to content
Snippets Groups Projects
Unverified Commit a9aeabe9 authored by Kris Bitney's avatar Kris Bitney Committed by GitHub
Browse files

Allow for 0 existential deposit in benchmarks for `pallet_staking`,...

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: default avatarBastian Köcher <git@kchr.de>
parent 6580101e
No related merge requests found
Pipeline #471763 failed with stages
in 1 hour, 15 minutes, and 11 seconds
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: Allow for 0 existential deposit in benchmarks for pallet_staking, pallet_session, and pallet_balances
doc:
- audience: Runtime Dev
description: |
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.
crates:
- name: pallet-staking
bump: patch
- name: pallet-session-benchmarking
bump: patch
- name: pallet-balances
bump: patch
......@@ -44,7 +44,7 @@ mod benchmarks {
let caller = whitelisted_caller();
// Give some multiple of the existential deposit
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into()).max(1u32.into());
let _ = <Balances<T, I> as Currency<_>>::make_free_balance_be(&caller, balance);
// Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account,
......
......@@ -77,7 +77,8 @@ pub fn create_stash_controller<T: Config>(
destination: RewardDestination<T::AccountId>,
) -> Result<(T::AccountId, T::AccountId), &'static str> {
let staker = create_funded_user::<T>("stash", n, balance_factor);
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
let amount =
T::Currency::minimum_balance().max(1u64.into()) * (balance_factor / 10).max(1).into();
Staking::<T>::bond(RawOrigin::Signed(staker.clone()).into(), amount, destination)?;
Ok((staker.clone(), staker))
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment