From a6af616f10d440981f1c08f4e3afc256f28405a3 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Fri, 10 May 2024 15:17:40 +0100 Subject: [PATCH] benchmarks: account existential deposit in pallet randomness benchmarks --- pallets/randomness/Cargo.toml | 6 ++++-- pallets/randomness/src/benchmarks.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pallets/randomness/Cargo.toml b/pallets/randomness/Cargo.toml index dc049d2c..7e21aa6a 100644 --- a/pallets/randomness/Cargo.toml +++ b/pallets/randomness/Cargo.toml @@ -24,13 +24,13 @@ sp-consensus-babe = { workspace = true } # Benchmarks frame-benchmarking = { workspace = true, optional = true } +pallet-balances = { workspace = true, optional = true, features = [ "insecure_zero_ed" ] } hex = { workspace = true } [dev-dependencies] derive_more = { workspace = true } pallet-author-mapping = { workspace = true, features = [ "std" ] } -pallet-balances = { workspace = true, features = [ "std", "insecure_zero_ed" ] } [features] default = [ "std" ] @@ -49,10 +49,12 @@ std = [ "sp-io/std", "sp-runtime/std", "sp-std/std", - "schnorrkel/std" + "schnorrkel/std", + "pallet-balances/std" ] runtime-benchmarks = [ "frame-benchmarking", + "pallet-balances", "session-keys-primitives/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime" ] diff --git a/pallets/randomness/src/benchmarks.rs b/pallets/randomness/src/benchmarks.rs index ec3aa10f..5415a10d 100644 --- a/pallets/randomness/src/benchmarks.rs +++ b/pallets/randomness/src/benchmarks.rs @@ -44,15 +44,30 @@ use sp_runtime::traits::{Convert, One}; use sp_std::{mem::size_of, vec}; /// Create a funded user from the input -fn fund_user(user: H160, fee: BalanceOf) { - let total_minted = fee + <::Deposit as Get>>::get(); +fn fund_user>>( + user: H160, + fee: BalanceOf, +) { + let existential_deposit = ::ExistentialDeposit::get(); + let total_minted = + existential_deposit + fee + <::Deposit as Get>>::get(); T::Currency::make_free_balance_be(&T::AddressMapping::convert(user), total_minted); T::Currency::issue(total_minted); } +fn fund_pallet_account_with_existential_deposit< + T: Config + pallet_balances::Config>, +>() { + let existential_deposit = ::ExistentialDeposit::get(); + T::Currency::make_free_balance_be(&Pallet::::account_id(), existential_deposit); + T::Currency::issue(existential_deposit); +} + benchmarks! { where_clause { - where >::Account: From + where + >::Account: From, + T: pallet_balances::Config> } // Benchmark for inherent included in every block set_babe_randomness_results { @@ -190,6 +205,7 @@ benchmarks! { let x in 1..T::MaxRandomWords::get().into(); let more = <::Deposit as Get>>::get(); fund_user::(H160::default(), more); + let result = Pallet::::request_randomness(Request { refund_address: H160::default(), contract_address: H160::default(), @@ -214,6 +230,8 @@ benchmarks! { finish_fulfillment { let more = <::Deposit as Get>>::get(); fund_user::(H160::default(), more); + fund_pallet_account_with_existential_deposit::(); + let result = Pallet::::request_randomness(Request { refund_address: H160::default(), contract_address: H160::default(), @@ -254,6 +272,7 @@ benchmarks! { increase_fee { let more = <::Deposit as Get>>::get(); fund_user::(H160::default(), more); + let result = Pallet::::request_randomness(Request { refund_address: H160::default(), contract_address: H160::default(), @@ -276,6 +295,8 @@ benchmarks! { execute_request_expiration { let more = <::Deposit as Get>>::get(); fund_user::(H160::default(), more); + fund_pallet_account_with_existential_deposit::(); + let result = Pallet::::request_randomness(Request { refund_address: H160::default(), contract_address: H160::default(),