From 651741c1647903f6f5e6e5dad109190ad270dd36 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> Date: Fri, 17 May 2024 16:53:06 +0100 Subject: [PATCH] benchmarks(pallet-author-mapping, pallet-randomness): account existential deposit in benchmarks (#42) * benchmarks: account existential deposit in author mapping benchmarks * benchmarks: account existential deposit in pallet randomness benchmarks --- pallets/author-mapping/Cargo.toml | 4 +++- pallets/author-mapping/src/benchmarks.rs | 15 +++++++------ pallets/randomness/Cargo.toml | 6 ++++-- pallets/randomness/src/benchmarks.rs | 27 +++++++++++++++++++++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/pallets/author-mapping/Cargo.toml b/pallets/author-mapping/Cargo.toml index 2b83b3e3..06dff9a5 100644 --- a/pallets/author-mapping/Cargo.toml +++ b/pallets/author-mapping/Cargo.toml @@ -18,6 +18,7 @@ serde = { workspace = true, optional = true } frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } +pallet-balances = { workspace = true, optional = true } parity-scale-codec = { workspace = true, features = [ "derive" ] } scale-info = { workspace = true, features = [ "derive" ] } sp-runtime = { workspace = true } @@ -27,7 +28,6 @@ sp-std = { workspace = true } session-keys-primitives = { workspace = true } [dev-dependencies] -pallet-balances = { workspace = true, features = ["std"] } sp-core = { workspace = true } sp-io = { workspace = true } @@ -45,9 +45,11 @@ std = [ "session-keys-primitives/std", "sp-runtime/std", "sp-std/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/author-mapping/src/benchmarks.rs b/pallets/author-mapping/src/benchmarks.rs index f8d356a1..8ab844c2 100644 --- a/pallets/author-mapping/src/benchmarks.rs +++ b/pallets/author-mapping/src/benchmarks.rs @@ -28,13 +28,14 @@ use nimbus_primitives::NimbusId; use parity_scale_codec::Decode; /// Create a funded user. -fn create_funded_user() -> T::AccountId { +fn create_funded_user>>() -> T::AccountId +{ let user = account("account id", 0u32, 0u32); - T::DepositCurrency::make_free_balance_be( - &user, - <::DepositAmount as Get>>::get(), - ); - T::DepositCurrency::issue(<::DepositAmount as Get>>::get()); + let existential_deposit = ::ExistentialDeposit::get(); + let amount = existential_deposit + <::DepositAmount as Get>>::get(); + + T::DepositCurrency::make_free_balance_be(&user, amount); + T::DepositCurrency::issue(amount); user } @@ -45,6 +46,8 @@ pub fn nimbus_id(seed: u8) -> NimbusId { } benchmarks! { + where_clause { where T: pallet_balances::Config> } + add_association { let caller = create_funded_user::(); let id = nimbus_id(1u8); 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(),