From c8d837e61adff12497a31899188e42ab41cd7c4e Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Fri, 22 Nov 2024 00:03:36 +0100 Subject: [PATCH 1/2] Migrate to V2 --- .../src/configuration/benchmarking.rs | 102 +++++++++++++----- 1 file changed, 78 insertions(+), 24 deletions(-) diff --git a/polkadot/runtime/parachains/src/configuration/benchmarking.rs b/polkadot/runtime/parachains/src/configuration/benchmarking.rs index adc7f31a7b29..8d2eef118e26 100644 --- a/polkadot/runtime/parachains/src/configuration/benchmarking.rs +++ b/polkadot/runtime/parachains/src/configuration/benchmarking.rs @@ -13,45 +13,99 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +#![cfg(feature = "runtime-benchmarks")] use crate::configuration::*; -use frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::v2::*; use frame_system::RawOrigin; use polkadot_primitives::{ExecutorParam, ExecutorParams, PvfExecKind, PvfPrepKind}; use sp_runtime::traits::One; -benchmarks! { - set_config_with_block_number {}: set_code_retention_period(RawOrigin::Root, One::one()) +#[benchmarks] +mod benchmarks { + use super::*; - set_config_with_u32 {}: set_max_code_size(RawOrigin::Root, 100) + #[benchmark] + fn set_config_with_block_number() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_code_retention_period(RawOrigin::Root, One::one()); + Ok(()) + } - set_config_with_option_u32 {}: set_max_validators(RawOrigin::Root, Some(10)) + #[benchmark] + fn set_config_with_u32() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_max_code_size(RawOrigin::Root, 100); + Ok(()) + } - set_hrmp_open_request_ttl {}: { - Err(BenchmarkError::Override( - BenchmarkResult::from_weight(T::BlockWeights::get().max_block) - ))?; + #[benchmark] + fn set_config_with_option_u32() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_max_validators(RawOrigin::Root, Some(10)); + Ok(()) } - set_config_with_balance {}: set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000) + #[benchmark] + fn set_hrmp_open_request_ttl() -> Result<(), BenchmarkError> { + #[block] + { + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + T::BlockWeights::get().max_block, + )))?; + } + Ok(()) + } - set_config_with_executor_params {}: set_executor_params(RawOrigin::Root, ExecutorParams::from(&[ - ExecutorParam::MaxMemoryPages(2080), - ExecutorParam::StackLogicalMax(65536), - ExecutorParam::StackNativeMax(256 * 1024 * 1024), - ExecutorParam::WasmExtBulkMemory, - ExecutorParam::PrecheckingMaxMemory(2 * 1024 * 1024 * 1024), - ExecutorParam::PvfPrepTimeout(PvfPrepKind::Precheck, 60_000), - ExecutorParam::PvfPrepTimeout(PvfPrepKind::Prepare, 360_000), - ExecutorParam::PvfExecTimeout(PvfExecKind::Backing, 2_000), - ExecutorParam::PvfExecTimeout(PvfExecKind::Approval, 12_000), - ][..])) + #[benchmark] + fn set_config_with_balance() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000); + Ok(()) + } - set_config_with_perbill {}: set_on_demand_fee_variability(RawOrigin::Root, Perbill::from_percent(100)) + #[benchmark] + fn set_config_with_executor_params() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_executor_params( + RawOrigin::Root, + ExecutorParams::from( + &[ + ExecutorParam::MaxMemoryPages(2080), + ExecutorParam::StackLogicalMax(65536), + ExecutorParam::StackNativeMax(256 * 1024 * 1024), + ExecutorParam::WasmExtBulkMemory, + ExecutorParam::PrecheckingMaxMemory(2 * 1024 * 1024 * 1024), + ExecutorParam::PvfPrepTimeout(PvfPrepKind::Precheck, 60_000), + ExecutorParam::PvfPrepTimeout(PvfPrepKind::Prepare, 360_000), + ExecutorParam::PvfExecTimeout(PvfExecKind::Backing, 2_000), + ExecutorParam::PvfExecTimeout(PvfExecKind::Approval, 12_000), + ][..], + ), + ); + Ok(()) + } - set_node_feature{}: set_node_feature(RawOrigin::Root, 255, true) + #[benchmark] + fn set_config_with_perbill() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_on_demand_fee_variability(RawOrigin::Root, Perbill::from_percent(100)); + Ok(()) + } + + #[benchmark] + fn set_node_feature() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_node_feature(RawOrigin::Root, 255, true); + Ok(()) + } - set_config_with_scheduler_params {} : set_scheduler_params(RawOrigin::Root, SchedulerParams::default()) + #[benchmark] + fn set_config_with_scheduler_params() -> Result<(), BenchmarkError> { + #[extrinsic_call] + set_scheduler_params(RawOrigin::Root, SchedulerParams::default()); + Ok(()) + } impl_benchmark_test_suite!( Pallet, From 5ddb574bb4b56561f4e6638350ab6c7e1ad79637 Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Wed, 11 Dec 2024 11:41:05 +0100 Subject: [PATCH 2/2] removed unused returns --- .../src/configuration/benchmarking.rs | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/polkadot/runtime/parachains/src/configuration/benchmarking.rs b/polkadot/runtime/parachains/src/configuration/benchmarking.rs index 8d2eef118e26..49c1876adca0 100644 --- a/polkadot/runtime/parachains/src/configuration/benchmarking.rs +++ b/polkadot/runtime/parachains/src/configuration/benchmarking.rs @@ -26,24 +26,21 @@ mod benchmarks { use super::*; #[benchmark] - fn set_config_with_block_number() -> Result<(), BenchmarkError> { + fn set_config_with_block_number() { #[extrinsic_call] set_code_retention_period(RawOrigin::Root, One::one()); - Ok(()) } #[benchmark] - fn set_config_with_u32() -> Result<(), BenchmarkError> { + fn set_config_with_u32() { #[extrinsic_call] set_max_code_size(RawOrigin::Root, 100); - Ok(()) } #[benchmark] - fn set_config_with_option_u32() -> Result<(), BenchmarkError> { + fn set_config_with_option_u32() { #[extrinsic_call] set_max_validators(RawOrigin::Root, Some(10)); - Ok(()) } #[benchmark] @@ -58,14 +55,13 @@ mod benchmarks { } #[benchmark] - fn set_config_with_balance() -> Result<(), BenchmarkError> { + fn set_config_with_balance() { #[extrinsic_call] set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000); - Ok(()) } #[benchmark] - fn set_config_with_executor_params() -> Result<(), BenchmarkError> { + fn set_config_with_executor_params() { #[extrinsic_call] set_executor_params( RawOrigin::Root, @@ -83,28 +79,24 @@ mod benchmarks { ][..], ), ); - Ok(()) } #[benchmark] - fn set_config_with_perbill() -> Result<(), BenchmarkError> { + fn set_config_with_perbill() { #[extrinsic_call] set_on_demand_fee_variability(RawOrigin::Root, Perbill::from_percent(100)); - Ok(()) } #[benchmark] - fn set_node_feature() -> Result<(), BenchmarkError> { + fn set_node_feature() { #[extrinsic_call] set_node_feature(RawOrigin::Root, 255, true); - Ok(()) } #[benchmark] - fn set_config_with_scheduler_params() -> Result<(), BenchmarkError> { + fn set_config_with_scheduler_params() { #[extrinsic_call] set_scheduler_params(RawOrigin::Root, SchedulerParams::default()); - Ok(()) } impl_benchmark_test_suite!(