From a50ca393df805c153e82675cba93e6096f9bb211 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Thu, 27 Apr 2023 03:17:38 +0400 Subject: [PATCH] fix bench --- runtime/common/src/auctions.rs | 40 +++++++---------- runtime/common/src/crowdloan/mod.rs | 63 +++++++-------------------- runtime/common/src/paras_registrar.rs | 46 +++++++------------ runtime/common/src/slots/mod.rs | 24 +++------- 4 files changed, 53 insertions(+), 120 deletions(-) diff --git a/runtime/common/src/auctions.rs b/runtime/common/src/auctions.rs index bbdbc0cd299c..3b1f941b5257 100644 --- a/runtime/common/src/auctions.rs +++ b/runtime/common/src/auctions.rs @@ -1731,17 +1731,16 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Auctions, *}; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; - use frame_support::traits::{EnsureOrigin, OnInitialize}; + use frame_support::{ + assert_ok, + traits::{EnsureOrigin, OnInitialize}, + }; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; - use sp_keyring::Sr25519Keyring; + use runtime_parachains::paras; use sp_runtime::{traits::Bounded, SaturatedConversion}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1750,12 +1749,9 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn fill_winners( - lease_period_index: LeasePeriodOf, - ) { + fn fill_winners(lease_period_index: LeasePeriodOf) { let auction_index = AuctionCounter::::get(); let minimum_balance = CurrencyOf::::minimum_balance(); - let session_index = shared::Pallet::::session_index(); for n in 1..=SlotRange::SLOT_RANGE_COUNT as u32 { let owner = account("owner", n, 0); @@ -1771,11 +1767,10 @@ mod benchmarking { ) .is_ok()); } - conclude_pvf_checking::( - &T::Registrar::worst_validation_code(), - VALIDATORS, - session_index, - ); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + T::Registrar::worst_validation_code(), + )); T::Registrar::execute_pending_transitions(); @@ -1799,7 +1794,7 @@ mod benchmarking { } benchmarks! { - where_clause { where T: pallet_babe::Config + paras::Config + shared::Config } + where_clause { where T: pallet_babe::Config + paras::Config } new_auction { let duration = T::BlockNumber::max_value(); @@ -1817,8 +1812,6 @@ mod benchmarking { // Worst case scenario a new bid comes in which kicks out an existing bid for the same slot. bid { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (_, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1840,9 +1833,10 @@ mod benchmarking { let worst_validation_code = T::Registrar::worst_validation_code(); T::Registrar::register(owner.clone(), para, worst_head_data.clone(), worst_validation_code.clone())?; T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code.clone())?; - - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&T::Registrar::worst_validation_code(), VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + worst_validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -1875,8 +1869,6 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and we need to calculate the winner for auction end. // Entire winner map should be full and removed at the end of the benchmark. on_initialize { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1922,8 +1914,6 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and winning data is full. cancel_auction { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index be92415da489..737a36989964 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -1951,19 +1951,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Crowdloan, *}; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::{assert_ok, traits::OnInitialize}; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; + use runtime_parachains::paras; use sp_core::crypto::UncheckedFrom; - use sp_keyring::Sr25519Keyring; use sp_runtime::traits::{Bounded, CheckedSub}; use sp_std::prelude::*; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1972,10 +1968,7 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn create_fund( - id: u32, - end: T::BlockNumber, - ) -> ParaId { + fn create_fund(id: u32, end: T::BlockNumber) -> ParaId { let cap = BalanceOf::::max_value(); let (_, offset) = T::Auctioneer::lease_period_length(); // Set to the very beginning of lease period index 0. @@ -1993,7 +1986,6 @@ mod benchmarking { // Assume ed25519 is most complex signature format let pubkey = crypto::create_ed25519_pubkey(b"//verifier".to_vec()); - let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); assert_ok!(T::Registrar::register( @@ -2002,8 +1994,10 @@ mod benchmarking { head_data, validation_code.clone() )); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); - + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); T::Registrar::execute_pending_transitions(); assert_ok!(Crowdloan::::create( @@ -2036,12 +2030,9 @@ mod benchmarking { } benchmarks! { - where_clause { where T: paras::Config + shared::Config } + where_clause { where T: paras::Config } create { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2050,7 +2041,6 @@ mod benchmarking { let end = lpl + offset; let caller: T::AccountId = whitelisted_caller(); - let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); @@ -2058,7 +2048,11 @@ mod benchmarking { CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); + T::Registrar::execute_pending_transitions(); }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier)) @@ -2068,9 +2062,6 @@ mod benchmarking { // Contribute has two arms: PreEnding and Ending, but both are equal complexity. contribute { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2091,9 +2082,6 @@ mod benchmarking { } withdraw { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2110,10 +2098,6 @@ mod benchmarking { #[skip_meta] refund { let k in 0 .. T::RemoveKeysLimit::get(); - - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2123,7 +2107,6 @@ mod benchmarking { contribute_fund::(&account("contributor", i, 0), fund_index); } - let caller: T::AccountId = whitelisted_caller(); frame_system::Pallet::::set_block_number(T::BlockNumber::max_value()); }: _(RawOrigin::Signed(caller), fund_index) @@ -2132,9 +2115,6 @@ mod benchmarking { } dissolve { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2146,9 +2126,6 @@ mod benchmarking { } edit { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2159,13 +2136,15 @@ mod benchmarking { let caller: T::AccountId = whitelisted_caller(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); - let session_index = shared::Pallet::::session_index(); let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0)); CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -2181,9 +2160,6 @@ mod benchmarking { } add_memo { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2200,9 +2176,6 @@ mod benchmarking { } poke { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2222,10 +2195,6 @@ mod benchmarking { on_initialize { // We test the complexity over different number of new raise let n in 2 .. 100; - - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end_block = lpl + offset - 1u32.into(); diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 9ace5234bb4b..f38dafa590b4 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -1337,21 +1337,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Registrar, *}; - use crate::{ - mock::{conclude_pvf_checking, validators_public_keys}, - traits::Registrar as RegistrarT, - }; + use crate::traits::Registrar as RegistrarT; use frame_support::assert_ok; use frame_system::RawOrigin; use primitives::{MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE}; use runtime_parachains::{paras, shared, Origin as ParaOrigin}; - use sp_keyring::Sr25519Keyring; use sp_runtime::traits::Bounded; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1360,9 +1354,8 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_para(id: u32) -> ParaId { + fn register_para(id: u32) -> ParaId { let para = ParaId::from(id); - let session_index = shared::Pallet::::session_index(); let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); let caller: T::AccountId = whitelisted_caller(); @@ -1374,7 +1367,10 @@ mod benchmarking { genesis_head, validation_code.clone() )); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); return para } @@ -1389,11 +1385,7 @@ mod benchmarking { } benchmarks! { - where_clause { - where - ParaOrigin: Into<::RuntimeOrigin>, - T: paras::Config + shared::Config, - } + where_clause { where ParaOrigin: Into<::RuntimeOrigin> } reserve { let caller: T::AccountId = whitelisted_caller(); @@ -1406,9 +1398,6 @@ mod benchmarking { } register { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para = LOWEST_PUBLIC_ID; let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); @@ -1419,16 +1408,15 @@ mod benchmarking { verify { assert_last_event::(Event::::Registered{ para_id: para, manager: caller }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } force_register { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let manager: T::AccountId = account("manager", 0, 0); let deposit = 0u32.into(); let para = ParaId::from(69); @@ -1438,16 +1426,15 @@ mod benchmarking { verify { assert_last_event::(Event::::Registered { para_id: para, manager }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } deregister { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para = register_para::(LOWEST_PUBLIC_ID.into()); next_scheduled_session::(); let caller: T::AccountId = whitelisted_caller(); @@ -1457,9 +1444,6 @@ mod benchmarking { } swap { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let parathread = register_para::(LOWEST_PUBLIC_ID.into()); let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); diff --git a/runtime/common/src/slots/mod.rs b/runtime/common/src/slots/mod.rs index 8d8b4f4f2e63..162d3031855a 100644 --- a/runtime/common/src/slots/mod.rs +++ b/runtime/common/src/slots/mod.rs @@ -986,19 +986,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::*; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::assert_ok; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; - use sp_keyring::Sr25519Keyring; + use runtime_parachains::paras; use sp_runtime::traits::{Bounded, One}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; use crate::slots::Pallet as Slots; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1007,10 +1003,7 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_a_parathread( - i: u32, - ) -> (ParaId, T::AccountId) { - let session_index = shared::Pallet::::session_index(); + fn register_a_parathread(i: u32) -> (ParaId, T::AccountId) { let para = ParaId::from(i); let leaser: T::AccountId = account("leaser", i, 0); T::Currency::make_free_balance_be(&leaser, BalanceOf::::max_value()); @@ -1023,7 +1016,10 @@ mod benchmarking { worst_head_data, worst_validation_code.clone(), )); - conclude_pvf_checking::(&worst_validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + worst_validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -1031,7 +1027,7 @@ mod benchmarking { } benchmarks! { - where_clause { where T: paras::Config + shared::Config } + where_clause { where T: paras::Config } force_lease { // If there is an offset, we need to be on that block to be able to do lease things. @@ -1061,9 +1057,6 @@ mod benchmarking { let c in 0 .. 100; let t in 0 .. 100; - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let period_begin = 1u32.into(); let period_count = 4u32.into(); @@ -1153,9 +1146,6 @@ mod benchmarking { } trigger_onboard { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - // get a parachain into a bad state where they did not onboard let (para, _) = register_a_parathread::(1); Leases::::insert(para, vec![Some((account::("lease_insert", 0, 0), BalanceOf::::default()))]);