Skip to content

Commit

Permalink
benchmarks: account existential deposit in pallet randomness benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed May 10, 2024
1 parent 4184393 commit a6af616
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 4 additions & 2 deletions pallets/randomness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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" ]
27 changes: 24 additions & 3 deletions pallets/randomness/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config>(user: H160, fee: BalanceOf<T>) {
let total_minted = fee + <<T as Config>::Deposit as Get<BalanceOf<T>>>::get();
fn fund_user<T: Config + pallet_balances::Config<Balance = BalanceOf<T>>>(
user: H160,
fee: BalanceOf<T>,
) {
let existential_deposit = <T as pallet_balances::Config>::ExistentialDeposit::get();
let total_minted =
existential_deposit + fee + <<T as Config>::Deposit as Get<BalanceOf<T>>>::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<Balance = BalanceOf<T>>,
>() {
let existential_deposit = <T as pallet_balances::Config>::ExistentialDeposit::get();
T::Currency::make_free_balance_be(&Pallet::<T>::account_id(), existential_deposit);
T::Currency::issue(existential_deposit);
}

benchmarks! {
where_clause {
where <T::VrfKeyLookup as KeysLookup<NimbusId, VrfId>>::Account: From<T::AccountId>
where
<T::VrfKeyLookup as KeysLookup<NimbusId, VrfId>>::Account: From<T::AccountId>,
T: pallet_balances::Config<Balance = BalanceOf<T>>
}
// Benchmark for inherent included in every block
set_babe_randomness_results {
Expand Down Expand Up @@ -190,6 +205,7 @@ benchmarks! {
let x in 1..T::MaxRandomWords::get().into();
let more = <<T as Config>::Deposit as Get<BalanceOf<T>>>::get();
fund_user::<T>(H160::default(), more);

let result = Pallet::<T>::request_randomness(Request {
refund_address: H160::default(),
contract_address: H160::default(),
Expand All @@ -214,6 +230,8 @@ benchmarks! {
finish_fulfillment {
let more = <<T as Config>::Deposit as Get<BalanceOf<T>>>::get();
fund_user::<T>(H160::default(), more);
fund_pallet_account_with_existential_deposit::<T>();

let result = Pallet::<T>::request_randomness(Request {
refund_address: H160::default(),
contract_address: H160::default(),
Expand Down Expand Up @@ -254,6 +272,7 @@ benchmarks! {
increase_fee {
let more = <<T as Config>::Deposit as Get<BalanceOf<T>>>::get();
fund_user::<T>(H160::default(), more);

let result = Pallet::<T>::request_randomness(Request {
refund_address: H160::default(),
contract_address: H160::default(),
Expand All @@ -276,6 +295,8 @@ benchmarks! {
execute_request_expiration {
let more = <<T as Config>::Deposit as Get<BalanceOf<T>>>::get();
fund_user::<T>(H160::default(), more);
fund_pallet_account_with_existential_deposit::<T>();

let result = Pallet::<T>::request_randomness(Request {
refund_address: H160::default(),
contract_address: H160::default(),
Expand Down

0 comments on commit a6af616

Please sign in to comment.