Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[polkadot-runtime-parachains] migrate paras module to benchmarking v2 syntax #6576

Merged
Changes from all commits
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
168 changes: 108 additions & 60 deletions polkadot/runtime/parachains/src/paras/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::*;
use crate::configuration::HostConfiguration;
use alloc::vec;
use frame_benchmarking::benchmarks;
use frame_benchmarking::v2::*;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use polkadot_primitives::{
HeadData, Id as ParaId, ValidationCode, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE,
Expand Down Expand Up @@ -84,41 +84,58 @@ fn generate_disordered_actions_queue<T: Config>() {
});
}

benchmarks! {
force_set_current_code {
let c in MIN_CODE_SIZE .. MAX_CODE_SIZE;
#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn force_set_current_code(c: Linear<MIN_CODE_SIZE, MAX_CODE_SIZE>) {
let new_code = ValidationCode(vec![0; c as usize]);
let para_id = ParaId::from(c as u32);
CurrentCodeHash::<T>::insert(&para_id, new_code.hash());
generate_disordered_pruning::<T>();
}: _(RawOrigin::Root, para_id, new_code)
verify {

#[extrinsic_call]
_(RawOrigin::Root, para_id, new_code);

assert_last_event::<T>(Event::CurrentCodeUpdated(para_id).into());
}
force_set_current_head {
let s in MIN_CODE_SIZE .. MAX_HEAD_DATA_SIZE;

#[benchmark]
fn force_set_current_head(s: Linear<MIN_CODE_SIZE, MAX_HEAD_DATA_SIZE>) {
let new_head = HeadData(vec![0; s as usize]);
let para_id = ParaId::from(1000);
}: _(RawOrigin::Root, para_id, new_head)
verify {

#[extrinsic_call]
_(RawOrigin::Root, para_id, new_head);

assert_last_event::<T>(Event::CurrentHeadUpdated(para_id).into());
}
force_set_most_recent_context {

#[benchmark]
fn force_set_most_recent_context() {
let para_id = ParaId::from(1000);
let context = BlockNumberFor::<T>::from(1000u32);
}: _(RawOrigin::Root, para_id, context)
force_schedule_code_upgrade {
let c in MIN_CODE_SIZE .. MAX_CODE_SIZE;

#[extrinsic_call]
_(RawOrigin::Root, para_id, context);
}

#[benchmark]
fn force_schedule_code_upgrade(c: Linear<MIN_CODE_SIZE, MAX_CODE_SIZE>) {
let new_code = ValidationCode(vec![0; c as usize]);
let para_id = ParaId::from(c as u32);
let block = BlockNumberFor::<T>::from(c);
generate_disordered_upgrades::<T>();
}: _(RawOrigin::Root, para_id, new_code, block)
verify {

#[extrinsic_call]
_(RawOrigin::Root, para_id, new_code, block);

assert_last_event::<T>(Event::CodeUpgradeScheduled(para_id).into());
}
force_note_new_head {
let s in MIN_CODE_SIZE .. MAX_HEAD_DATA_SIZE;

#[benchmark]
fn force_note_new_head(s: Linear<MIN_CODE_SIZE, MAX_HEAD_DATA_SIZE>) {
let para_id = ParaId::from(1000);
let new_head = HeadData(vec![0; s as usize]);
let old_code_hash = ValidationCode(vec![0]).hash();
Expand All @@ -135,70 +152,101 @@ benchmarks! {
&config,
UpgradeStrategy::SetGoAheadSignal,
);
}: _(RawOrigin::Root, para_id, new_head)
verify {

#[extrinsic_call]
_(RawOrigin::Root, para_id, new_head);

assert_last_event::<T>(Event::NewHeadNoted(para_id).into());
}
force_queue_action {

#[benchmark]
fn force_queue_action() {
let para_id = ParaId::from(1000);
generate_disordered_actions_queue::<T>();
}: _(RawOrigin::Root, para_id)
verify {
let next_session = crate::shared::CurrentSessionIndex::<T>::get().saturating_add(One::one());

#[extrinsic_call]
_(RawOrigin::Root, para_id);

let next_session =
crate::shared::CurrentSessionIndex::<T>::get().saturating_add(One::one());
assert_last_event::<T>(Event::ActionQueued(para_id, next_session).into());
}

add_trusted_validation_code {
let c in MIN_CODE_SIZE .. MAX_CODE_SIZE;
#[benchmark]
fn add_trusted_validation_code(c: Linear<MIN_CODE_SIZE, MAX_CODE_SIZE>) {
let new_code = ValidationCode(vec![0; c as usize]);

pvf_check::prepare_bypassing_bench::<T>(new_code.clone());
}: _(RawOrigin::Root, new_code)

poke_unused_validation_code {
#[extrinsic_call]
_(RawOrigin::Root, new_code);
}

#[benchmark]
fn poke_unused_validation_code() {
let code_hash = [0; 32].into();
}: _(RawOrigin::Root, code_hash)

include_pvf_check_statement {
#[extrinsic_call]
_(RawOrigin::Root, code_hash);
}

#[benchmark]
fn include_pvf_check_statement() {
let (stmt, signature) = pvf_check::prepare_inclusion_bench::<T>();
}: {
let _ = Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);

#[block]
{
let _ =
Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
}
}

include_pvf_check_statement_finalize_upgrade_accept {
let (stmt, signature) = pvf_check::prepare_finalization_bench::<T>(
VoteCause::Upgrade,
VoteOutcome::Accept,
);
}: {
let _ = Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
#[benchmark]
fn include_pvf_check_statement_finalize_upgrade_accept() {
let (stmt, signature) =
pvf_check::prepare_finalization_bench::<T>(VoteCause::Upgrade, VoteOutcome::Accept);

#[block]
{
let _ =
Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
}
}

include_pvf_check_statement_finalize_upgrade_reject {
let (stmt, signature) = pvf_check::prepare_finalization_bench::<T>(
VoteCause::Upgrade,
VoteOutcome::Reject,
);
}: {
let _ = Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
#[benchmark]
fn include_pvf_check_statement_finalize_upgrade_reject() {
let (stmt, signature) =
pvf_check::prepare_finalization_bench::<T>(VoteCause::Upgrade, VoteOutcome::Reject);

#[block]
{
let _ =
Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
}
}

include_pvf_check_statement_finalize_onboarding_accept {
let (stmt, signature) = pvf_check::prepare_finalization_bench::<T>(
VoteCause::Onboarding,
VoteOutcome::Accept,
);
}: {
let _ = Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
#[benchmark]
fn include_pvf_check_statement_finalize_onboarding_accept() {
let (stmt, signature) =
pvf_check::prepare_finalization_bench::<T>(VoteCause::Onboarding, VoteOutcome::Accept);

#[block]
{
let _ =
Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
}
}

include_pvf_check_statement_finalize_onboarding_reject {
let (stmt, signature) = pvf_check::prepare_finalization_bench::<T>(
VoteCause::Onboarding,
VoteOutcome::Reject,
);
}: {
let _ = Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
#[benchmark]
fn include_pvf_check_statement_finalize_onboarding_reject() {
let (stmt, signature) =
pvf_check::prepare_finalization_bench::<T>(VoteCause::Onboarding, VoteOutcome::Reject);

#[block]
{
let _ =
Pallet::<T>::include_pvf_check_statement(RawOrigin::None.into(), stmt, signature);
}
}

impl_benchmark_test_suite!(
Expand Down
Loading