From 65f21c7660070765384f3af8b9d5a24a03e48f4d Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Thu, 21 Nov 2024 11:55:15 +0100 Subject: [PATCH 1/2] [polkadot-runtime-parachains] migrate disputes::slashing to benchmarking v2 --- .../src/disputes/slashing/benchmarking.rs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index b53f98caeea3..6f673075558d 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -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; @@ -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() -> u32 { + <::BenchmarkingConfig as BenchmarkingConfiguration>::MAX_VALIDATORS +} + pub trait Config: pallet_session::Config + pallet_session::historical::Config @@ -136,27 +141,28 @@ fn dispute_proof( DisputeProof { time_slot, kind, validator_index, validator_id } } -benchmarks! { - where_clause { - where T: Config, - } +#[benchmarks(where T: Config)] +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..<::BenchmarkingConfig as BenchmarkingConfiguration>::MAX_VALIDATORS; - + #[benchmark] + fn report_dispute_lost(n: Linear<4, { max_validators_for::() }>) { let origin = RawOrigin::None.into(); let (session_index, key_owner_proof, validator_id) = setup_validator_set::(n); let dispute_proof = setup_dispute::(session_index, validator_id); - }: { - let result = Pallet::::report_dispute_lost_unsigned( - origin, - Box::new(dispute_proof), - key_owner_proof, - ); - assert!(result.is_ok()); - } verify { + + #[block] + { + let result = Pallet::::report_dispute_lost_unsigned( + origin, + Box::new(dispute_proof), + key_owner_proof, + ); + assert!(result.is_ok()); + } + let unapplied = >::get(session_index, CANDIDATE_HASH); assert!(unapplied.is_none()); } From b4a1642d446c48b5917cc034020f90bc4fcfe4c1 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Thu, 21 Nov 2024 11:57:16 +0100 Subject: [PATCH 2/2] [polkadot-runtime-parachains] migrate disputes to benchmarking v2 --- .../parachains/src/disputes/benchmarking.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/benchmarking.rs index 05f4b3f1ac81..571c44d1ac24 100644 --- a/polkadot/runtime/parachains/src/disputes/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/benchmarking.rs @@ -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::::set(Some(One::one())); - }: _(RawOrigin::Root) - verify { + + #[extrinsic_call] + _(RawOrigin::Root); + assert!(Frozen::::get().is_none()) }