From 65f21c7660070765384f3af8b9d5a24a03e48f4d Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Thu, 21 Nov 2024 11:55:15 +0100 Subject: [PATCH 1/7] [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/7] [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()) } From 2a1e94192365901fd14e603c63e6cca22c18c5ad Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:53:06 +0100 Subject: [PATCH 3/7] Update polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- .../runtime/parachains/src/disputes/slashing/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index 6f673075558d..3bd59af64770 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -148,7 +148,7 @@ mod benchmarks { // in this setup we have a single `ForInvalid` dispute // submitted for a past session #[benchmark] - fn report_dispute_lost(n: Linear<4, { max_validators_for::() }>) { + fn report_dispute_lost_unsigned(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); From 07c4ae40004ad49f57b056bdd10769b35761d94b Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:53:12 +0100 Subject: [PATCH 4/7] Update polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- .../parachains/src/disputes/slashing/benchmarking.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index 3bd59af64770..e14d11753e13 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -153,15 +153,8 @@ mod benchmarks { let (session_index, key_owner_proof, validator_id) = setup_validator_set::(n); let dispute_proof = setup_dispute::(session_index, validator_id); - #[block] - { - let result = Pallet::::report_dispute_lost_unsigned( - origin, - Box::new(dispute_proof), - key_owner_proof, - ); - assert!(result.is_ok()); - } + #[extrinsic_call] + _(origin, Box::new(dispute_proof), key_owner_proof); let unapplied = >::get(session_index, CANDIDATE_HASH); assert!(unapplied.is_none()); From 15481f4336b3f26fe416081580a694e194018ed5 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 18 Dec 2024 09:01:09 +0100 Subject: [PATCH 5/7] [parachains/disputes/slashing] rename weight report_dispute_lost -> report_dispute_lost_unsigned --- polkadot/runtime/parachains/src/disputes/slashing.rs | 6 +++--- .../polkadot_runtime_parachains_disputes_slashing.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing.rs b/polkadot/runtime/parachains/src/disputes/slashing.rs index 2e09ea667f74..95dbf2ba42bb 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing.rs @@ -355,12 +355,12 @@ impl HandleReports for () { } pub trait WeightInfo { - fn report_dispute_lost(validator_count: ValidatorSetCount) -> Weight; + fn report_dispute_lost_unsigned(validator_count: ValidatorSetCount) -> Weight; } pub struct TestWeightInfo; impl WeightInfo for TestWeightInfo { - fn report_dispute_lost(_validator_count: ValidatorSetCount) -> Weight { + fn report_dispute_lost_unsigned(_validator_count: ValidatorSetCount) -> Weight { Weight::zero() } } @@ -445,7 +445,7 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::report_dispute_lost( + #[pallet::weight(::WeightInfo::report_dispute_lost_unsigned( key_owner_proof.validator_count() ))] pub fn report_dispute_lost_unsigned( diff --git a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs index a035ea2b0b5e..f4dbca0f29ff 100644 --- a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs +++ b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs @@ -85,7 +85,7 @@ impl polkadot_runtime_parachains::disputes::slashing::W /// Storage: Staking UnappliedSlashes (r:1 w:1) /// Proof Skipped: Staking UnappliedSlashes (max_values: None, max_size: None, mode: Measured) /// The range of component `n` is `[4, 300]`. - fn report_dispute_lost(n: u32, ) -> Weight { + fn report_dispute_lost_unsigned(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `4531 + n * (189 ±0)` // Estimated: `7843 + n * (192 ±0)` From e289e1a709a008d4d54c2ef8bd01719f8c9bef1f Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 18 Dec 2024 09:05:06 +0100 Subject: [PATCH 6/7] [parachains/disputes/slashing] fix type annotations needed in origin --- .../runtime/parachains/src/disputes/slashing/benchmarking.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index e14d11753e13..d5cfec6319cb 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -149,12 +149,11 @@ mod benchmarks { // submitted for a past session #[benchmark] fn report_dispute_lost_unsigned(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); #[extrinsic_call] - _(origin, Box::new(dispute_proof), key_owner_proof); + _(RawOrigin::None, Box::new(dispute_proof), key_owner_proof); let unapplied = >::get(session_index, CANDIDATE_HASH); assert!(unapplied.is_none()); From 74ed98387c3009bea3dd3fb09e644708684ca454 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 18 Dec 2024 09:13:17 +0100 Subject: [PATCH 7/7] [parachains/disputes/slashing] add some minor documentation --- .../parachains/src/disputes/slashing/benchmarking.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index d5cfec6319cb..bfd46d752438 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -111,6 +111,7 @@ where (session_index, key_owner_proof, validator_id) } +/// Submits a single `ForInvalid` dispute. fn setup_dispute(session_index: SessionIndex, validator_id: ValidatorId) -> DisputeProof where T: Config, @@ -130,6 +131,7 @@ where dispute_proof(session_index, validator_id, validator_index) } +/// Creates a `ForInvalid` dispute proof. fn dispute_proof( session_index: SessionIndex, validator_id: ValidatorId, @@ -145,11 +147,11 @@ fn dispute_proof( mod benchmarks { use super::*; - // in this setup we have a single `ForInvalid` dispute - // submitted for a past session #[benchmark] fn report_dispute_lost_unsigned(n: Linear<4, { max_validators_for::() }>) { let (session_index, key_owner_proof, validator_id) = setup_validator_set::(n); + + // submit a single `ForInvalid` dispute for a past session. let dispute_proof = setup_dispute::(session_index, validator_id); #[extrinsic_call]