Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

paras: dismiss pvf_checking_enabled configuration #7138

Merged
merged 16 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
runtime benchmark tests
  • Loading branch information
slumber committed Apr 26, 2023
commit 2d2fbb0884e13acf5c6bd1a9cfd240569a6b8a29
29 changes: 26 additions & 3 deletions runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,12 +1731,17 @@ 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_system::RawOrigin;
use runtime_parachains::{paras, shared};
use sp_keyring::Sr25519Keyring;
use sp_runtime::{traits::Bounded, SaturatedConversion};

use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};

const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice];

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
Expand All @@ -1745,9 +1750,12 @@ mod benchmarking {
assert_eq!(event, &system_event);
}

fn fill_winners<T: Config>(lease_period_index: LeasePeriodOf<T>) {
fn fill_winners<T: Config + paras::Config + shared::Config>(
lease_period_index: LeasePeriodOf<T>,
) {
let auction_index = AuctionCounter::<T>::get();
let minimum_balance = CurrencyOf::<T>::minimum_balance();
let session_index = shared::Pallet::<T>::session_index();

for n in 1..=SlotRange::SLOT_RANGE_COUNT as u32 {
let owner = account("owner", n, 0);
Expand All @@ -1763,6 +1771,11 @@ mod benchmarking {
)
.is_ok());
}
conclude_pvf_checking::<T>(
&T::Registrar::worst_validation_code(),
VALIDATORS,
session_index,
);

T::Registrar::execute_pending_transitions();

Expand All @@ -1786,7 +1799,7 @@ mod benchmarking {
}

benchmarks! {
where_clause { where T: pallet_babe::Config }
where_clause { where T: pallet_babe::Config + paras::Config + shared::Config }

new_auction {
let duration = T::BlockNumber::max_value();
Expand All @@ -1804,6 +1817,8 @@ 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::<T>::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::<T>::set_block_number(offset + One::one());
Expand All @@ -1824,7 +1839,11 @@ mod benchmarking {
let worst_head_data = T::Registrar::worst_head_data();
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)?;
T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code.clone())?;

let session_index = shared::Pallet::<T>::session_index();
conclude_pvf_checking::<T>(&T::Registrar::worst_validation_code(), VALIDATORS, session_index);

T::Registrar::execute_pending_transitions();

// Make an existing bid
Expand Down Expand Up @@ -1856,6 +1875,8 @@ 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::<T>::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::<T>::set_block_number(offset + One::one());
Expand Down Expand Up @@ -1901,6 +1922,8 @@ 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::<T>::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::<T>::set_block_number(offset + One::one());
Expand Down
61 changes: 57 additions & 4 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,14 +1951,19 @@ 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 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<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
Expand All @@ -1967,7 +1972,10 @@ mod benchmarking {
assert_eq!(event, &system_event);
}

fn create_fund<T: Config>(id: u32, end: T::BlockNumber) -> ParaId {
fn create_fund<T: Config + shared::Config + paras::Config>(
id: u32,
end: T::BlockNumber,
) -> ParaId {
let cap = BalanceOf::<T>::max_value();
let (_, offset) = T::Auctioneer::lease_period_length();
// Set to the very beginning of lease period index 0.
Expand All @@ -1985,9 +1993,17 @@ mod benchmarking {
// Assume ed25519 is most complex signature format
let pubkey = crypto::create_ed25519_pubkey(b"//verifier".to_vec());

let session_index = shared::Pallet::<T>::session_index();
let head_data = T::Registrar::worst_head_data();
let validation_code = T::Registrar::worst_validation_code();
assert_ok!(T::Registrar::register(caller.clone(), para_id, head_data, validation_code));
assert_ok!(T::Registrar::register(
caller.clone(),
para_id,
head_data,
validation_code.clone()
));
conclude_pvf_checking::<T>(&validation_code, VALIDATORS, session_index);

T::Registrar::execute_pending_transitions();

assert_ok!(Crowdloan::<T>::create(
Expand Down Expand Up @@ -2020,7 +2036,12 @@ mod benchmarking {
}

benchmarks! {
where_clause { where T: paras::Config + shared::Config }

create {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let para_id = ParaId::from(1_u32);
let cap = BalanceOf::<T>::max_value();
let first_period = 0u32.into();
Expand All @@ -2029,13 +2050,15 @@ mod benchmarking {
let end = lpl + offset;

let caller: T::AccountId = whitelisted_caller();
let session_index = shared::Pallet::<T>::session_index();
let head_data = T::Registrar::worst_head_data();
let validation_code = T::Registrar::worst_validation_code();

let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0));

CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?;
T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?;
conclude_pvf_checking::<T>(&validation_code, VALIDATORS, session_index);
T::Registrar::execute_pending_transitions();

}: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier))
Expand All @@ -2045,6 +2068,9 @@ mod benchmarking {

// Contribute has two arms: PreEnding and Ending, but both are equal complexity.
contribute {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1, end);
Expand All @@ -2065,6 +2091,9 @@ mod benchmarking {
}

withdraw {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
Expand All @@ -2081,6 +2110,10 @@ mod benchmarking {
#[skip_meta]
refund {
let k in 0 .. T::RemoveKeysLimit::get();

let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
Expand All @@ -2090,6 +2123,7 @@ mod benchmarking {
contribute_fund::<T>(&account("contributor", i, 0), fund_index);
}


let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
}: _(RawOrigin::Signed(caller), fund_index)
Expand All @@ -2098,6 +2132,9 @@ mod benchmarking {
}

dissolve {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
Expand All @@ -2109,6 +2146,9 @@ mod benchmarking {
}

edit {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let para_id = ParaId::from(1_u32);
let cap = BalanceOf::<T>::max_value();
let first_period = 0u32.into();
Expand All @@ -2119,11 +2159,14 @@ 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::<T>::session_index();

let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0));

CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?;
T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?;
conclude_pvf_checking::<T>(&validation_code, VALIDATORS, session_index);

T::Registrar::execute_pending_transitions();

Crowdloan::<T>::create(
Expand All @@ -2138,6 +2181,9 @@ mod benchmarking {
}

add_memo {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1, end);
Expand All @@ -2154,6 +2200,9 @@ mod benchmarking {
}

poke {
let public = validators_public_keys(VALIDATORS);
shared::Pallet::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1, end);
Expand All @@ -2173,6 +2222,10 @@ 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::<T>::set_active_validators_ascending(public);

let (lpl, offset) = T::Auctioneer::lease_period_length();
let end_block = lpl + offset - 1u32.into();

Expand Down
Loading