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 disputes and disputes/slashing to benchmarking to bench v2 syntax #6577

Merged
merged 10 commits into from
Dec 19, 2024
Merged
16 changes: 11 additions & 5 deletions polkadot/runtime/parachains/src/disputes/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@

use super::*;

use frame_benchmarking::benchmarks;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_runtime::traits::One;

benchmarks! {
force_unfreeze {
#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn force_unfreeze() {
Frozen::<T>::set(Some(One::one()));
}: _(RawOrigin::Root)
verify {

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

assert!(Frozen::<T>::get().is_none())
}

Expand Down
38 changes: 22 additions & 16 deletions polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::*;

use crate::{disputes::SlashingHandler, initializer, shared};
use codec::Decode;
use frame_benchmarking::{benchmarks, whitelist_account};
use frame_benchmarking::v2::*;
use frame_support::traits::{OnFinalize, OnInitialize};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use pallet_staking::testing_utils::create_validators;
Expand All @@ -29,6 +29,11 @@ use sp_session::MembershipProof;
// Candidate hash of the disputed candidate.
const CANDIDATE_HASH: CandidateHash = CandidateHash(Hash::zero());

// Simplify getting the value in the benchmark
pub const fn max_validators_for<T: super::Config>() -> u32 {
<<T>::BenchmarkingConfig as BenchmarkingConfiguration>::MAX_VALIDATORS
}

pub trait Config:
pallet_session::Config
+ pallet_session::historical::Config
Expand Down Expand Up @@ -136,27 +141,28 @@ fn dispute_proof(
DisputeProof { time_slot, kind, validator_index, validator_id }
}

benchmarks! {
where_clause {
where T: Config<KeyOwnerProof = MembershipProof>,
}
#[benchmarks(where T: Config<KeyOwnerProof = MembershipProof>)]
mod benchmarks {
use super::*;

// in this setup we have a single `ForInvalid` dispute
// submitted for a past session
report_dispute_lost {
let n in 4..<<T as super::Config>::BenchmarkingConfig as BenchmarkingConfiguration>::MAX_VALIDATORS;

#[benchmark]
fn report_dispute_lost(n: Linear<4, { max_validators_for::<T>() }>) {
clangenb marked this conversation as resolved.
Show resolved Hide resolved
let origin = RawOrigin::None.into();
let (session_index, key_owner_proof, validator_id) = setup_validator_set::<T>(n);
let dispute_proof = setup_dispute::<T>(session_index, validator_id);
}: {
let result = Pallet::<T>::report_dispute_lost_unsigned(
origin,
Box::new(dispute_proof),
key_owner_proof,
);
assert!(result.is_ok());
} verify {

#[block]
{
let result = Pallet::<T>::report_dispute_lost_unsigned(
origin,
Box::new(dispute_proof),
key_owner_proof,
);
assert!(result.is_ok());
}
clangenb marked this conversation as resolved.
Show resolved Hide resolved

let unapplied = <UnappliedSlashes<T>>::get(session_index, CANDIDATE_HASH);
assert!(unapplied.is_none());
}
Expand Down
Loading