From 0ceee42e00c533c515d5dc2f34642d6225c3be1b Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Tue, 5 Sep 2023 12:33:11 +0200 Subject: [PATCH 01/23] Draft benchmark sanity weight test --- cumulus/parachain-template/runtime/src/lib.rs | 10 +- polkadot/runtime/rococo/src/lib.rs | 8 +- .../bin/node-template/runtime/src/lib.rs | 13 +- substrate/bin/node/runtime/src/lib.rs | 8 +- substrate/frame/benchmarking/src/utils.rs | 7 +- .../benchmarking-cli/src/pallet/command.rs | 108 ++++++++---- .../frame/benchmarking-cli/src/pallet/mod.rs | 5 + .../benchmarking-cli/src/pallet/writer.rs | 159 +++++++++++++++--- 8 files changed, 244 insertions(+), 74 deletions(-) diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 038597096f6a..9417ce80c16a 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -31,8 +31,8 @@ use frame_support::{ parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, + constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, RuntimeDbWeight, Weight, + WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, }; @@ -698,6 +698,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -708,7 +710,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e043852901f1..30eb9abc80c9 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -63,7 +63,7 @@ use frame_support::{ Contains, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, }, - weights::{ConstantMultiplier, WeightMeter}, + weights::{ConstantMultiplier, RuntimeDbWeight, WeightMeter}, PalletId, }; use frame_system::EnsureRoot; @@ -2092,6 +2092,8 @@ sp_api::impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2103,7 +2105,9 @@ sp_api::impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 216be9588bca..e102c85d8b70 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -25,7 +25,9 @@ use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. pub use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + dispatch::DispatchClass, + parameter_types, traits::{ ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo, @@ -34,7 +36,7 @@ pub use frame_support::{ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - IdentityFee, Weight, + IdentityFee, RuntimeDbWeight, Weight, }, StorageValue, }; @@ -514,6 +516,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + RuntimeDbWeight, ) { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -524,8 +528,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4f34e4ecd812..8c6bf9cfeeeb 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -45,7 +45,7 @@ use frame_support::{ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - ConstantMultiplier, IdentityFee, Weight, + ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, }, BoundedVec, PalletId, }; @@ -2683,6 +2683,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + RuntimeDbWeight, ) { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2701,8 +2703,10 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info) + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index b9b3f91e2dd7..1374ebca2c90 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -17,7 +17,10 @@ //! Interfaces, types and utils for benchmarking a FRAME runtime. use codec::{Decode, Encode}; -use frame_support::{dispatch::DispatchErrorWithPostInfo, pallet_prelude::*, traits::StorageInfo}; +use frame_support::{ + dispatch::DispatchErrorWithPostInfo, pallet_prelude::*, traits::StorageInfo, + weights::RuntimeDbWeight, +}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -235,7 +238,7 @@ sp_api::decl_runtime_apis! { /// Parameters /// - `extra`: Also list benchmarks marked "extra" which would otherwise not be /// needed for weight calculation. - fn benchmark_metadata(extra: bool) -> (Vec, Vec); + fn benchmark_metadata(extra: bool) -> (Vec, Vec, Weight, RuntimeDbWeight); /// Dispatch the given benchmark. fn dispatch_benchmark(config: BenchmarkConfig) -> Result, sp_runtime::RuntimeString>; diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 84da3aaa02c0..80e1feaab19b 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -18,10 +18,13 @@ use super::{writer, PalletCmd}; use codec::{Decode, Encode}; use frame_benchmarking::{ - Analysis, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkList, BenchmarkParameter, - BenchmarkResult, BenchmarkSelector, + Analysis, AnalysisChoice, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkList, + BenchmarkParameter, BenchmarkResult, BenchmarkSelector, +}; +use frame_support::{ + traits::StorageInfo, + weights::{RuntimeDbWeight, Weight}, }; -use frame_support::traits::StorageInfo; use linked_hash_map::LinkedHashMap; use sc_cli::{execution_method_from_cli, CliConfiguration, Result, SharedParams}; use sc_client_db::BenchmarkingState; @@ -48,11 +51,11 @@ const LOG_TARGET: &'static str = "frame::benchmark::pallet"; #[derive(Serialize, Debug, Clone, Eq, PartialEq)] pub(crate) struct ComponentRange { /// Name of the component. - name: String, + pub(crate) name: String, /// Minimal valid value of the component. min: u32, /// Maximal valid value of the component. - max: u32, + pub(crate) max: u32, } /// How the PoV size of a storage item should be estimated. @@ -175,20 +178,6 @@ impl PalletCmd { }; } - if let Some(json_input) = &self.json_input { - let raw_data = match std::fs::read(json_input) { - Ok(raw_data) => raw_data, - Err(error) => - return Err(format!("Failed to read {:?}: {}", json_input, error).into()), - }; - let batches: Vec = match serde_json::from_slice(&raw_data) { - Ok(batches) => batches, - Err(error) => - return Err(format!("Failed to deserialize {:?}: {}", json_input, error).into()), - }; - return self.output_from_results(&batches) - } - let spec = config.chain_spec; let pallet = self.pallet.clone().unwrap_or_default(); let pallet = pallet.as_bytes(); @@ -257,9 +246,25 @@ impl PalletCmd { .execute() .map_err(|e| format!("{}: {}", ERROR_METADATA_NOT_FOUND, e))?; - let (list, storage_info) = - <(Vec, Vec) as Decode>::decode(&mut &result[..]) - .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))?; + let (list, storage_info, max_extrinsic_weight, db_weight) = + <(Vec, Vec, Weight, RuntimeDbWeight) as Decode>::decode( + &mut &result[..], + ) + .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))?; + + if let Some(json_input) = &self.json_input { + let raw_data = match std::fs::read(json_input) { + Ok(raw_data) => raw_data, + Err(error) => + return Err(format!("Failed to read {:?}: {}", json_input, error).into()), + }; + let batches: Vec = match serde_json::from_slice(&raw_data) { + Ok(batches) => batches, + Err(error) => + return Err(format!("Failed to deserialize {:?}: {}", json_input, error).into()), + }; + return self.output_from_results(&batches, max_extrinsic_weight, db_weight) + } // Use the benchmark list and the user input to determine the set of benchmarks to run. let mut benchmarks_to_run = Vec::new(); @@ -501,7 +506,14 @@ impl PalletCmd { // Combine all of the benchmark results, so that benchmarks of the same pallet/function // are together. let batches = combine_batches(batches, batches_db); - self.output(&batches, &storage_info, &component_ranges, pov_modes) + self.output( + &batches, + &storage_info, + &component_ranges, + pov_modes, + max_extrinsic_weight, + db_weight, + ) } fn output( @@ -510,6 +522,8 @@ impl PalletCmd { storage_info: &[StorageInfo], component_ranges: &HashMap<(Vec, Vec), Vec>, pov_modes: PovModesMap, + max_extrinsic_weight: Weight, + db_weight: RuntimeDbWeight, ) -> Result<()> { // Jsonify the result and write it to a file or stdout if desired. if !self.jsonify(&batches)? { @@ -517,24 +531,43 @@ impl PalletCmd { self.print_summary(&batches, &storage_info, pov_modes.clone()) } + // Which analysis function should be used when outputting benchmarks + let analysis_choice: AnalysisChoice = + self.output_analysis.clone().try_into().map_err(writer::io_error)?; + let pov_analysis_choice: AnalysisChoice = + self.output_pov_analysis.clone().try_into().map_err(writer::io_error)?; + + // // Organize results by pallet into a JSON map + let all_results = writer::map_results( + &batches, + &storage_info, + &component_ranges, + pov_modes.clone(), + self.default_pov_mode, + &analysis_choice, + &pov_analysis_choice, + self.worst_case_map_values, + self.additional_trie_layers, + max_extrinsic_weight, + db_weight, + self.sanity_check, + )?; + // Create the weights.rs file. if let Some(output_path) = &self.output { - writer::write_results( - &batches, - &storage_info, - &component_ranges, - pov_modes, - self.default_pov_mode, - output_path, - self, - )?; + writer::write_results(output_path, self, analysis_choice, all_results)?; } Ok(()) } /// Re-analyze a batch historic benchmark timing data. Will not take the PoV into account. - fn output_from_results(&self, batches: &[BenchmarkBatchSplitResults]) -> Result<()> { + fn output_from_results( + &self, + batches: &[BenchmarkBatchSplitResults], + max_extrinsic_weight: Weight, + db_weight: RuntimeDbWeight, + ) -> Result<()> { let mut component_ranges = HashMap::<(Vec, Vec), HashMap>::new(); for batch in batches { @@ -566,7 +599,14 @@ impl PalletCmd { }) .collect(); - self.output(batches, &[], &component_ranges, Default::default()) + self.output( + batches, + &[], + &component_ranges, + Default::default(), + max_extrinsic_weight, + db_weight, + ) } /// Jsonifies the passed batches and writes them to stdout or into a file. diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs index c69ce1765fc9..d895657c91b9 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs @@ -201,4 +201,9 @@ pub struct PalletCmd { /// This exists only to restore legacy behaviour. It should never actually be needed. #[arg(long)] pub unsafe_overwrite_results: bool, + + /// Sanity check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max + /// extrinsic weight. If present, it takes the max value within the component range. + #[arg(long)] + pub sanity_check: bool, } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 69c95d13c098..a2a20d11e6cd 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -35,7 +35,10 @@ use crate::{ use frame_benchmarking::{ Analysis, AnalysisChoice, BenchmarkBatchSplitResults, BenchmarkResult, BenchmarkSelector, }; -use frame_support::traits::StorageInfo; +use frame_support::{ + traits::StorageInfo, + weights::{RuntimeDbWeight, Weight}, +}; use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::Zero; @@ -59,7 +62,7 @@ struct TemplateData { // This was the final data we have about each benchmark. #[derive(Serialize, Default, Debug, Clone, PartialEq)] -struct BenchmarkData { +pub(crate) struct BenchmarkData { name: String, components: Vec, #[serde(serialize_with = "string_serialize")] @@ -116,7 +119,7 @@ struct ComponentSlope { } // Small helper to create an `io::Error` from a string. -fn io_error(s: &str) -> std::io::Error { +pub(crate) fn io_error(s: &str) -> std::io::Error { use std::io::{Error, ErrorKind}; Error::new(ErrorKind::Other, s) } @@ -129,7 +132,7 @@ fn io_error(s: &str) -> std::io::Error { // p1 -> [b1, b2, b3] // p2 -> [b1, b2] // ``` -fn map_results( +pub(crate) fn map_results( batches: &[BenchmarkBatchSplitResults], storage_info: &[StorageInfo], component_ranges: &HashMap<(Vec, Vec), Vec>, @@ -139,6 +142,9 @@ fn map_results( pov_analysis_choice: &AnalysisChoice, worst_case_map_values: u32, additional_trie_layers: u8, + max_extrinsic_weight: Weight, + db_weight: RuntimeDbWeight, + sanity_check: bool, ) -> Result>, std::io::Error> { // Skip if batches is empty. if batches.is_empty() { @@ -166,12 +172,86 @@ fn map_results( worst_case_map_values, additional_trie_layers, ); + // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max + // component) exceeds the max extrinsic weight. + benchmark_sanity_check(&benchmark_data, max_extrinsic_weight, db_weight, sanity_check)?; let pallet_benchmarks = all_benchmarks.entry((pallet_string, instance_string)).or_default(); pallet_benchmarks.push(benchmark_data); } Ok(all_benchmarks) } +// Calculates the total maximum weight of an extrinsic, based on the max component, and compares it +// with the max extrinsic weight. +// +// `max_extrinsic_weight` & `db_weight` are obtained from the runtime. +fn benchmark_sanity_check( + result: &BenchmarkData, + max_extrinsic_weight: Weight, + db_weight: RuntimeDbWeight, + sanity_check: bool, +) -> Result<(), std::io::Error> { + fn max_component(parameter: &ComponentSlope, component_ranges: &Vec) -> u64 { + for component in component_ranges { + if parameter.name == component.name { + return component.max.into() + } + } + 0 + } + + let mut total_weight = Weight::from_parts( + result.base_weight.try_into().unwrap(), + result.base_calculated_proof_size.try_into().unwrap(), + ); + for component in &result.component_weight { + total_weight = total_weight.saturating_add( + Weight::from_parts(component.slope.try_into().unwrap(), 0) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + total_weight = + total_weight.saturating_add(db_weight.reads(result.base_reads.try_into().unwrap())); + for component in &result.component_reads { + total_weight = total_weight.saturating_add( + db_weight + .reads(component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + total_weight = + total_weight.saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); + for component in &result.component_writes { + total_weight = total_weight.saturating_add( + db_weight + .writes(component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + for component in &result.component_calculated_proof_size { + total_weight = total_weight.saturating_add( + Weight::from_parts(0, component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + if total_weight.ref_time() > max_extrinsic_weight.ref_time() || + total_weight.proof_size() > max_extrinsic_weight.proof_size() + { + let err_message = format!("Extrinsic {} exceeds the max extrinsic weight", result.name); + println!("\u{1b}[31mWARNING!!!\u{1b}[39m {:?}", err_message); + println!("Extrinsic {}: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)", + result.name, + total_weight, + (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, + (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, + ); + if sanity_check { + return Err(io_error(&err_message)) + } + } + Ok(()) +} + // Get an iterator of errors. fn extract_errors(errors: &Option>) -> impl Iterator + '_ { errors @@ -376,13 +456,10 @@ fn get_benchmark_data( /// Create weight file from benchmark data and Handlebars template. pub(crate) fn write_results( - batches: &[BenchmarkBatchSplitResults], - storage_info: &[StorageInfo], - component_ranges: &HashMap<(Vec, Vec), Vec>, - pov_modes: PovModesMap, - default_pov_mode: PovEstimationMode, path: &PathBuf, cmd: &PalletCmd, + analysis_choice: AnalysisChoice, + all_results: HashMap<(String, String), Vec>, ) -> Result<(), sc_cli::Error> { // Use custom template if provided. let template: String = match &cmd.template { @@ -405,12 +482,6 @@ pub(crate) fn write_results( // Full CLI args passed to trigger the benchmark. let args = std::env::args().collect::>(); - // Which analysis function should be used when outputting benchmarks - let analysis_choice: AnalysisChoice = - cmd.output_analysis.clone().try_into().map_err(io_error)?; - let pov_analysis_choice: AnalysisChoice = - cmd.output_pov_analysis.clone().try_into().map_err(io_error)?; - if cmd.additional_trie_layers > 4 { println!( "WARNING: `additional_trie_layers` is unexpectedly large. It assumes {} storage items.", @@ -439,18 +510,6 @@ pub(crate) fn write_results( // Don't HTML escape any characters. handlebars.register_escape_fn(|s| -> String { s.to_string() }); - // Organize results by pallet into a JSON map - let all_results = map_results( - batches, - storage_info, - component_ranges, - pov_modes, - default_pov_mode, - &analysis_choice, - &pov_analysis_choice, - cmd.worst_case_map_values, - cmd.additional_trie_layers, - )?; let mut created_files = Vec::new(); for ((pallet, instance), results) in all_results.iter() { @@ -964,6 +1023,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let result = @@ -1021,6 +1083,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let result = @@ -1078,6 +1143,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let result = @@ -1133,6 +1201,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let result = @@ -1190,6 +1261,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let result = @@ -1218,6 +1292,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); @@ -1253,6 +1330,25 @@ mod test { ); } + #[test] + fn sanity_check_works() { + assert!(map_results( + &[test_data(b"first", b"first", BenchmarkParameter::a, 10, 3),], + &test_storage_info(), + &Default::default(), + Default::default(), + PovEstimationMode::MaxEncodedLen, + &AnalysisChoice::default(), + &AnalysisChoice::MedianSlopes, + 1_000_000, + 0, + Weight::from_parts(20_000, 1_000_000), + RuntimeDbWeight { read: 1000, write: 1000 }, + true, + ) + .is_err()); + } + #[test] fn additional_trie_layers_work() { let mapped_results = map_results( @@ -1265,6 +1361,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 2, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let with_layer = &mapped_results @@ -1280,6 +1379,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); let without_layer = &mapped_results @@ -1313,6 +1415,9 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + Weight::MAX, + RuntimeDbWeight { read: 1000, write: 1000 }, + false, ) .unwrap(); From 81165e3e6ffe80ee5003ad9f03a18d6ed751fdb2 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Tue, 17 Oct 2023 08:55:12 +0200 Subject: [PATCH 02/23] error || warning --- .../benchmarking-cli/src/pallet/command.rs | 9 +- .../frame/benchmarking-cli/src/pallet/mod.rs | 8 +- .../benchmarking-cli/src/pallet/writer.rs | 130 ++++++++++-------- 3 files changed, 79 insertions(+), 68 deletions(-) diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 80e1feaab19b..f09b7e336ad8 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -548,16 +548,17 @@ impl PalletCmd { &pov_analysis_choice, self.worst_case_map_values, self.additional_trie_layers, - max_extrinsic_weight, - db_weight, - self.sanity_check, )?; // Create the weights.rs file. if let Some(output_path) = &self.output { - writer::write_results(output_path, self, analysis_choice, all_results)?; + writer::write_results(output_path, self, analysis_choice, &all_results)?; } + // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max + // component) exceeds the max extrinsic weight. + writer::sanity_weight_check(all_results, max_extrinsic_weight, db_weight, self.sanity_weight_check_warning)?; + Ok(()) } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs index d895657c91b9..917896264d2b 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs @@ -202,8 +202,10 @@ pub struct PalletCmd { #[arg(long)] pub unsafe_overwrite_results: bool, - /// Sanity check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max - /// extrinsic weight. If present, it takes the max value within the component range. + /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max + /// extrinsic weight. If present, it takes the max value of the component range. + /// + /// Default will error out if max extrinsic weight is exceeded. #[arg(long)] - pub sanity_check: bool, + pub sanity_weight_check_warning: bool, } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index a2a20d11e6cd..b8f9f863c97b 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -19,6 +19,7 @@ use std::{ collections::{HashMap, HashSet}, + fmt::Write, fs, path::PathBuf, }; @@ -142,9 +143,6 @@ pub(crate) fn map_results( pov_analysis_choice: &AnalysisChoice, worst_case_map_values: u32, additional_trie_layers: u8, - max_extrinsic_weight: Weight, - db_weight: RuntimeDbWeight, - sanity_check: bool, ) -> Result>, std::io::Error> { // Skip if batches is empty. if batches.is_empty() { @@ -172,25 +170,26 @@ pub(crate) fn map_results( worst_case_map_values, additional_trie_layers, ); - // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max - // component) exceeds the max extrinsic weight. - benchmark_sanity_check(&benchmark_data, max_extrinsic_weight, db_weight, sanity_check)?; let pallet_benchmarks = all_benchmarks.entry((pallet_string, instance_string)).or_default(); pallet_benchmarks.push(benchmark_data); } Ok(all_benchmarks) } -// Calculates the total maximum weight of an extrinsic, based on the max component, and compares it -// with the max extrinsic weight. +// Calculates the total maximum weight of an extrinsic (if present, based on the max component) and compares it +// with the max extrinsic weight allowed in a single block. // -// `max_extrinsic_weight` & `db_weight` are obtained from the runtime. -fn benchmark_sanity_check( - result: &BenchmarkData, +// `max_extrinsic_weight` & `db_weight` are obtained from the runtime configuration. +pub(crate) fn sanity_weight_check( + all_results: HashMap<(String, String), Vec>, max_extrinsic_weight: Weight, db_weight: RuntimeDbWeight, - sanity_check: bool, + sanity_weight_check_warning: bool, ) -> Result<(), std::io::Error> { + let mut err_message = String::new(); + let mut sanity_weight_check_failed = false; + + // Helper function to return max component value. fn max_component(parameter: &ComponentSlope, component_ranges: &Vec) -> u64 { for component in component_ranges { if parameter.name == component.name { @@ -200,56 +199,65 @@ fn benchmark_sanity_check( 0 } - let mut total_weight = Weight::from_parts( - result.base_weight.try_into().unwrap(), - result.base_calculated_proof_size.try_into().unwrap(), - ); - for component in &result.component_weight { - total_weight = total_weight.saturating_add( - Weight::from_parts(component.slope.try_into().unwrap(), 0) - .saturating_mul(max_component(&component, &result.component_ranges)), - ); - } - total_weight = - total_weight.saturating_add(db_weight.reads(result.base_reads.try_into().unwrap())); - for component in &result.component_reads { - total_weight = total_weight.saturating_add( - db_weight - .reads(component.slope.try_into().unwrap()) - .saturating_mul(max_component(&component, &result.component_ranges)), - ); - } - total_weight = - total_weight.saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); - for component in &result.component_writes { - total_weight = total_weight.saturating_add( - db_weight - .writes(component.slope.try_into().unwrap()) - .saturating_mul(max_component(&component, &result.component_ranges)), - ); - } - for component in &result.component_calculated_proof_size { - total_weight = total_weight.saturating_add( - Weight::from_parts(0, component.slope.try_into().unwrap()) - .saturating_mul(max_component(&component, &result.component_ranges)), - ); - } - if total_weight.ref_time() > max_extrinsic_weight.ref_time() || - total_weight.proof_size() > max_extrinsic_weight.proof_size() - { - let err_message = format!("Extrinsic {} exceeds the max extrinsic weight", result.name); - println!("\u{1b}[31mWARNING!!!\u{1b}[39m {:?}", err_message); - println!("Extrinsic {}: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)", - result.name, - total_weight, - (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, - (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, - ); - if sanity_check { - return Err(io_error(&err_message)) + // Loop through all benchmark results. + for ((_, _), results) in all_results.iter() { + // Per pallet where there can be multiple instances of a pallet. + for result in results { + let mut total_weight = Weight::from_parts( + result.base_weight.try_into().unwrap(), + result.base_calculated_proof_size.try_into().unwrap(), + ); + for component in &result.component_weight { + total_weight = total_weight.saturating_add( + Weight::from_parts(component.slope.try_into().unwrap(), 0) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + total_weight = + total_weight.saturating_add(db_weight.reads(result.base_reads.try_into().unwrap())); + for component in &result.component_reads { + total_weight = total_weight.saturating_add( + db_weight + .reads(component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + total_weight = + total_weight.saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); + for component in &result.component_writes { + total_weight = total_weight.saturating_add( + db_weight + .writes(component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + for component in &result.component_calculated_proof_size { + total_weight = total_weight.saturating_add( + Weight::from_parts(0, component.slope.try_into().unwrap()) + .saturating_mul(max_component(&component, &result.component_ranges)), + ); + } + if total_weight.ref_time() > max_extrinsic_weight.ref_time() || + total_weight.proof_size() > max_extrinsic_weight.proof_size() + { + sanity_weight_check_failed = true; + let error = format!("\nExtrinsic {} exceeds the max extrinsic weight", result.name); + println!("\u{1b}[31mWARNING!!!\u{1b}[39m {:?}", error); + println!("Extrinsic {}: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)", + result.name, + total_weight, + (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, + (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, + ); + write!(&mut err_message, "{}", error); + } } } - Ok(()) + if sanity_weight_check_failed && !sanity_weight_check_warning { + Err(io_error(&err_message)) + } else { + Ok(()) + } } // Get an iterator of errors. @@ -459,7 +467,7 @@ pub(crate) fn write_results( path: &PathBuf, cmd: &PalletCmd, analysis_choice: AnalysisChoice, - all_results: HashMap<(String, String), Vec>, + all_results: &HashMap<(String, String), Vec>, ) -> Result<(), sc_cli::Error> { // Use custom template if provided. let template: String = match &cmd.template { From 8fc1fcaad8c8fc7e593ca11fb90ddd5fbd90d20d Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 18 Oct 2023 12:06:01 +0200 Subject: [PATCH 03/23] allow enable, warning & ignore + output improvement --- substrate/client/cli/src/arg_enums.rs | 15 +++ .../client/cli/src/params/shared_params.rs | 12 +- .../benchmarking-cli/src/pallet/command.rs | 2 +- .../frame/benchmarking-cli/src/pallet/mod.rs | 7 -- .../benchmarking-cli/src/pallet/writer.rs | 119 ++++++++++-------- 5 files changed, 92 insertions(+), 63 deletions(-) diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index 40d86fd97988..1ed275f498a4 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -70,6 +70,21 @@ impl std::fmt::Display for WasmExecutionMethod { } } +/// What to do when an extrinsic's weight exceeds the max extrinsic weight +/// per block. +#[allow(missing_docs)] +#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)] +#[value(rename_all = "kebab-case")] +pub enum SanityWeightCheck { + Error, + Warning, + Ignore, +} + +/// The default [`SanityWeightCheck`]. +pub const DEFAULT_SANITY_WEIGHT_CHECK: SanityWeightCheck = + SanityWeightCheck::Error; + /// Converts the execution method and instantiation strategy command line arguments /// into an execution method which can be used internally. pub fn execution_method_from_cli( diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index 3d20ca504a69..b6ae22f0af83 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::arg_enums::TracingReceiver; +use crate::{SanityWeightCheck, DEFAULT_SANITY_WEIGHT_CHECK, arg_enums::TracingReceiver}; use clap::Args; use sc_service::config::BasePath; use std::path::PathBuf; @@ -71,6 +71,16 @@ pub struct SharedParams { /// Receiver to process tracing messages. #[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)] pub tracing_receiver: TracingReceiver, + + /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max + /// extrinsic weight. + #[arg( + long, + value_name = "OUTPUT", + value_enum, + default_value_t = DEFAULT_SANITY_WEIGHT_CHECK, + )] + pub sanity_weight_check: SanityWeightCheck, } impl SharedParams { diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index f09b7e336ad8..cada8169b3d9 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -557,7 +557,7 @@ impl PalletCmd { // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max // component) exceeds the max extrinsic weight. - writer::sanity_weight_check(all_results, max_extrinsic_weight, db_weight, self.sanity_weight_check_warning)?; + writer::sanity_weight_check(all_results, max_extrinsic_weight, db_weight, self.shared_params.sanity_weight_check)?; Ok(()) } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs index 917896264d2b..c69ce1765fc9 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs @@ -201,11 +201,4 @@ pub struct PalletCmd { /// This exists only to restore legacy behaviour. It should never actually be needed. #[arg(long)] pub unsafe_overwrite_results: bool, - - /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max - /// extrinsic weight. If present, it takes the max value of the component range. - /// - /// Default will error out if max extrinsic weight is exceeded. - #[arg(long)] - pub sanity_weight_check_warning: bool, } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index b8f9f863c97b..4d340b3b1ba9 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -19,7 +19,6 @@ use std::{ collections::{HashMap, HashSet}, - fmt::Write, fs, path::PathBuf, }; @@ -27,6 +26,7 @@ use std::{ use inflector::Inflector; use itertools::Itertools; use serde::Serialize; +use sc_cli::SanityWeightCheck; use crate::{ pallet::command::{ComponentRange, PovEstimationMode, PovModesMap}, @@ -184,12 +184,12 @@ pub(crate) fn sanity_weight_check( all_results: HashMap<(String, String), Vec>, max_extrinsic_weight: Weight, db_weight: RuntimeDbWeight, - sanity_weight_check_warning: bool, + sanity_weight_check: SanityWeightCheck, ) -> Result<(), std::io::Error> { - let mut err_message = String::new(); - let mut sanity_weight_check_failed = false; - - // Helper function to return max component value. + if sanity_weight_check == SanityWeightCheck::Ignore { + return Ok(()); + } + // Helper function to return max. component value (i.e. max. complexity parameter). fn max_component(parameter: &ComponentSlope, component_ranges: &Vec) -> u64 { for component in component_ranges { if parameter.name == component.name { @@ -199,22 +199,33 @@ pub(crate) fn sanity_weight_check( 0 } + println!("\n\x1B[1mSanity Weight Check 🧐:\x1B[0m each extrinsic's weight function is executed \ + in the worst case scenario and compared with the maximum extrinsic weight (the maximum weight \ + that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In other words, \ + each extrinsic is checked whether it will fit in an empty (meaning; empty of \ + `DispatchClass::Normal` extrinsics) block.\n\n\x1B[4mResults:\x1B[0m\n" + ); + let mut sanity_weight_check_passed = true; // Loop through all benchmark results. for ((_, _), results) in all_results.iter() { - // Per pallet where there can be multiple instances of a pallet. + // Per pallet, because there can be multiple instances of a pallet. for result in results { + // Constant `ref_time` & `pov_size`. let mut total_weight = Weight::from_parts( result.base_weight.try_into().unwrap(), result.base_calculated_proof_size.try_into().unwrap(), ); + // `ref_time` multiplied by complexity parameter. for component in &result.component_weight { total_weight = total_weight.saturating_add( Weight::from_parts(component.slope.try_into().unwrap(), 0) .saturating_mul(max_component(&component, &result.component_ranges)), ); } + // Constant storage reads. total_weight = total_weight.saturating_add(db_weight.reads(result.base_reads.try_into().unwrap())); + // Storage reads multiplied by complexity parameter. for component in &result.component_reads { total_weight = total_weight.saturating_add( db_weight @@ -222,8 +233,10 @@ pub(crate) fn sanity_weight_check( .saturating_mul(max_component(&component, &result.component_ranges)), ); } + // Constant storage writes. total_weight = total_weight.saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); + // Storage writes multiplied by complexity parameter. for component in &result.component_writes { total_weight = total_weight.saturating_add( db_weight @@ -231,33 +244,41 @@ pub(crate) fn sanity_weight_check( .saturating_mul(max_component(&component, &result.component_ranges)), ); } + // `pov_size` multiplied by complexity parameter. for component in &result.component_calculated_proof_size { total_weight = total_weight.saturating_add( Weight::from_parts(0, component.slope.try_into().unwrap()) .saturating_mul(max_component(&component, &result.component_ranges)), ); } + // Comparing (worst case scenario) the extrinsic weight against the maximum extrinsic weight. if total_weight.ref_time() > max_extrinsic_weight.ref_time() || - total_weight.proof_size() > max_extrinsic_weight.proof_size() - { - sanity_weight_check_failed = true; - let error = format!("\nExtrinsic {} exceeds the max extrinsic weight", result.name); - println!("\u{1b}[31mWARNING!!!\u{1b}[39m {:?}", error); - println!("Extrinsic {}: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)", - result.name, - total_weight, - (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, - (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, - ); - write!(&mut err_message, "{}", error); + total_weight.proof_size() > max_extrinsic_weight.proof_size() { + sanity_weight_check_passed = false; + println!("\x1B[31m\x1B[1mWARNING!!!\x1B[0m",); + println!("\x1B[31mThe following extrinsic exceeds the maximum extrinsic weight:\x1B[0m",); } + println!("- \x1B[1m'{}'\x1B[0m: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", + result.name, + total_weight, + (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, + (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, + ); } } - if sanity_weight_check_failed && !sanity_weight_check_warning { - Err(io_error(&err_message)) - } else { - Ok(()) + match sanity_weight_check_passed { + false => { + println!("\x1B[31mYour extrinsics failed the Sanity Weight Check, please review \ + the extrinsic's logic and/or the associated benchmark function.\x1B[0m\n",); + if sanity_weight_check == SanityWeightCheck::Error { + return Err(io_error(&String::from("One or more extrinsics exceed the maximum extrinsic weight"))); + } + }, + true => { + println!("\x1B[32mYour extrinsics passed the Sanity Weight Check 😃!\x1B[0m\n"); + }, } + Ok(()) } // Get an iterator of errors. @@ -1031,9 +1052,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let result = @@ -1091,9 +1109,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let result = @@ -1151,9 +1166,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let result = @@ -1209,9 +1221,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let result = @@ -1269,9 +1278,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let result = @@ -1300,9 +1306,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); @@ -1340,7 +1343,7 @@ mod test { #[test] fn sanity_check_works() { - assert!(map_results( + let mapped_results = map_results( &[test_data(b"first", b"first", BenchmarkParameter::a, 10, 3),], &test_storage_info(), &Default::default(), @@ -1350,11 +1353,28 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, + ).unwrap(); + + assert!(sanity_weight_check( + mapped_results.clone(), Weight::from_parts(20_000, 1_000_000), RuntimeDbWeight { read: 1000, write: 1000 }, - true, - ) - .is_err()); + SanityWeightCheck::Error, + ).is_err()); + + assert!(sanity_weight_check( + mapped_results.clone(), + Weight::from_parts(20_000, 1_000_000), + RuntimeDbWeight { read: 1000, write: 1000 }, + SanityWeightCheck::Warning, + ).is_ok()); + + assert!(sanity_weight_check( + mapped_results, + Weight::from_parts(20_000, 1_000_000), + RuntimeDbWeight { read: 1000, write: 1000 }, + SanityWeightCheck::Ignore, + ).is_ok()); } #[test] @@ -1369,9 +1389,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 2, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let with_layer = &mapped_results @@ -1387,9 +1404,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); let without_layer = &mapped_results @@ -1423,9 +1437,6 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - Weight::MAX, - RuntimeDbWeight { read: 1000, write: 1000 }, - false, ) .unwrap(); From d476d7f0eefa4a7702580b5be1e2a96ead02eaf0 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 18 Oct 2023 13:18:23 +0200 Subject: [PATCH 04/23] fmt --- polkadot/runtime/rococo/src/lib.rs | 6 +-- substrate/client/cli/src/arg_enums.rs | 3 +- .../client/cli/src/params/shared_params.rs | 6 +-- .../benchmarking-cli/src/pallet/command.rs | 7 ++- .../benchmarking-cli/src/pallet/writer.rs | 51 ++++++++++++------- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 5b8816d69433..6bd55a55ee39 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -71,7 +71,7 @@ use frame_support::{ InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, }, - weights::{ConstantMultiplier, RuntimeDbWeight, WeightMeter}, + weights::{ConstantMultiplier, WeightMeter}, PalletId, }; use frame_system::EnsureRoot; @@ -2046,7 +2046,7 @@ sp_api::impl_runtime_apis! { Vec, Vec, Weight, - RuntimeDbWeight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2059,7 +2059,7 @@ sp_api::impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); - let db_weight: RuntimeDbWeight = ::DbWeight::get(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index 85a30b80c60f..ce7bf15e80bd 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -76,8 +76,7 @@ pub enum SanityWeightCheck { } /// The default [`SanityWeightCheck`]. -pub const DEFAULT_SANITY_WEIGHT_CHECK: SanityWeightCheck = - SanityWeightCheck::Error; +pub const DEFAULT_SANITY_WEIGHT_CHECK: SanityWeightCheck = SanityWeightCheck::Error; /// Converts the execution method and instantiation strategy command line arguments /// into an execution method which can be used internally. diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index b6ae22f0af83..30750734bed4 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{SanityWeightCheck, DEFAULT_SANITY_WEIGHT_CHECK, arg_enums::TracingReceiver}; +use crate::{arg_enums::TracingReceiver, SanityWeightCheck, DEFAULT_SANITY_WEIGHT_CHECK}; use clap::Args; use sc_service::config::BasePath; use std::path::PathBuf; @@ -72,8 +72,8 @@ pub struct SharedParams { #[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)] pub tracing_receiver: TracingReceiver, - /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds the max - /// extrinsic weight. + /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds + /// the max extrinsic weight. #[arg( long, value_name = "OUTPUT", diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index cada8169b3d9..e184aef91a05 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -557,7 +557,12 @@ impl PalletCmd { // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max // component) exceeds the max extrinsic weight. - writer::sanity_weight_check(all_results, max_extrinsic_weight, db_weight, self.shared_params.sanity_weight_check)?; + writer::sanity_weight_check( + all_results, + max_extrinsic_weight, + db_weight, + self.shared_params.sanity_weight_check, + )?; Ok(()) } diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 6aaa4c702fbc..5ee3fc2ed197 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -25,8 +25,8 @@ use std::{ use inflector::Inflector; use itertools::Itertools; -use serde::Serialize; use sc_cli::SanityWeightCheck; +use serde::Serialize; use crate::{ pallet::command::{ComponentRange, PovEstimationMode, PovModesMap}, @@ -176,8 +176,8 @@ pub(crate) fn map_results( Ok(all_benchmarks) } -// Calculates the total maximum weight of an extrinsic (if present, based on the max component) and compares it -// with the max extrinsic weight allowed in a single block. +// Calculates the total maximum weight of an extrinsic (if present, based on the max component) and +// compares it with the max extrinsic weight allowed in a single block. // // `max_extrinsic_weight` & `db_weight` are obtained from the runtime configuration. pub(crate) fn sanity_weight_check( @@ -187,7 +187,7 @@ pub(crate) fn sanity_weight_check( sanity_weight_check: SanityWeightCheck, ) -> Result<(), std::io::Error> { if sanity_weight_check == SanityWeightCheck::Ignore { - return Ok(()); + return Ok(()) } // Helper function to return max. component value (i.e. max. complexity parameter). fn max_component(parameter: &ComponentSlope, component_ranges: &Vec) -> u64 { @@ -199,14 +199,15 @@ pub(crate) fn sanity_weight_check( 0 } - println!("\n\x1B[1mSanity Weight Check 🧐:\x1B[0m each extrinsic's weight function is executed \ + println!( + "\n\x1B[1mSanity Weight Check 🧐:\x1B[0m each extrinsic's weight function is executed \ in the worst case scenario and compared with the maximum extrinsic weight (the maximum weight \ that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In other words, \ each extrinsic is checked whether it will fit in an empty (meaning; empty of \ `DispatchClass::Normal` extrinsics) block.\n\n\x1B[4mResults:\x1B[0m\n" ); let mut sanity_weight_check_passed = true; - // Loop through all benchmark results. + // Loop through all benchmark results. for ((_, _), results) in all_results.iter() { // Per pallet, because there can be multiple instances of a pallet. for result in results { @@ -234,8 +235,8 @@ pub(crate) fn sanity_weight_check( ); } // Constant storage writes. - total_weight = - total_weight.saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); + total_weight = total_weight + .saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); // Storage writes multiplied by complexity parameter. for component in &result.component_writes { total_weight = total_weight.saturating_add( @@ -251,12 +252,16 @@ pub(crate) fn sanity_weight_check( .saturating_mul(max_component(&component, &result.component_ranges)), ); } - // Comparing (worst case scenario) the extrinsic weight against the maximum extrinsic weight. + // Comparing (worst case scenario) the extrinsic weight against the maximum extrinsic + // weight. if total_weight.ref_time() > max_extrinsic_weight.ref_time() || - total_weight.proof_size() > max_extrinsic_weight.proof_size() { + total_weight.proof_size() > max_extrinsic_weight.proof_size() + { sanity_weight_check_passed = false; println!("\x1B[31m\x1B[1mWARNING!!!\x1B[0m",); - println!("\x1B[31mThe following extrinsic exceeds the maximum extrinsic weight:\x1B[0m",); + println!( + "\x1B[31mThe following extrinsic exceeds the maximum extrinsic weight:\x1B[0m", + ); } println!("- \x1B[1m'{}'\x1B[0m: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", result.name, @@ -268,10 +273,14 @@ pub(crate) fn sanity_weight_check( } match sanity_weight_check_passed { false => { - println!("\x1B[31mYour extrinsics failed the Sanity Weight Check, please review \ - the extrinsic's logic and/or the associated benchmark function.\x1B[0m\n",); + println!( + "\x1B[31mYour extrinsics failed the Sanity Weight Check, please review \ + the extrinsic's logic and/or the associated benchmark function.\x1B[0m\n", + ); if sanity_weight_check == SanityWeightCheck::Error { - return Err(io_error(&String::from("One or more extrinsics exceed the maximum extrinsic weight"))); + return Err(io_error(&String::from( + "One or more extrinsics exceed the maximum extrinsic weight", + ))) } }, true => { @@ -1345,7 +1354,7 @@ mod test { #[test] fn sanity_check_works() { let mapped_results = map_results( - &[test_data(b"first", b"first", BenchmarkParameter::a, 10, 3),], + &[test_data(b"first", b"first", BenchmarkParameter::a, 10, 3)], &test_storage_info(), &Default::default(), Default::default(), @@ -1354,28 +1363,32 @@ mod test { &AnalysisChoice::MedianSlopes, 1_000_000, 0, - ).unwrap(); + ) + .unwrap(); assert!(sanity_weight_check( mapped_results.clone(), Weight::from_parts(20_000, 1_000_000), RuntimeDbWeight { read: 1000, write: 1000 }, SanityWeightCheck::Error, - ).is_err()); + ) + .is_err()); assert!(sanity_weight_check( mapped_results.clone(), Weight::from_parts(20_000, 1_000_000), RuntimeDbWeight { read: 1000, write: 1000 }, SanityWeightCheck::Warning, - ).is_ok()); + ) + .is_ok()); assert!(sanity_weight_check( mapped_results, Weight::from_parts(20_000, 1_000_000), RuntimeDbWeight { read: 1000, write: 1000 }, SanityWeightCheck::Ignore, - ).is_ok()); + ) + .is_ok()); } #[test] From a6982589c15c408e1b4b256831cce92f1033fb9d Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 18 Oct 2023 14:08:22 +0200 Subject: [PATCH 05/23] spelling & ci tests --- cumulus/parachain-template/runtime/src/lib.rs | 8 ++++---- substrate/bin/node-template/runtime/src/lib.rs | 6 +++--- substrate/bin/node/runtime/src/lib.rs | 6 +++--- substrate/client/cli/src/arg_enums.rs | 2 +- substrate/client/cli/src/params/shared_params.rs | 4 ++-- .../utils/frame/benchmarking-cli/src/pallet/command.rs | 4 ++-- .../utils/frame/benchmarking-cli/src/pallet/writer.rs | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 741629202f89..a21babbb8721 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -32,8 +32,8 @@ use frame_support::{ parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, RuntimeDbWeight, Weight, - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, }; @@ -700,7 +700,7 @@ impl_runtime_apis! { Vec, Vec, Weight, - RuntimeDbWeight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -712,7 +712,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); - let db_weight: RuntimeDbWeight = ::DbWeight::get(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 1157e231ce10..3fd281d24586 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -37,7 +37,7 @@ pub use frame_support::{ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - IdentityFee, RuntimeDbWeight, Weight, + IdentityFee, Weight, }, StorageValue, }; @@ -518,7 +518,7 @@ impl_runtime_apis! { Vec, Vec, Weight, - RuntimeDbWeight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -530,7 +530,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); - let db_weight: RuntimeDbWeight = ::DbWeight::get(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 490c6e89caf1..a870d3a493fc 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -47,7 +47,7 @@ use frame_support::{ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, + ConstantMultiplier, IdentityFee, Weight, }, BoundedVec, PalletId, }; @@ -2746,7 +2746,7 @@ impl_runtime_apis! { Vec, Vec, Weight, - RuntimeDbWeight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2766,7 +2766,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); - let db_weight: RuntimeDbWeight = ::DbWeight::get(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index ce7bf15e80bd..b9b47a11551f 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -64,7 +64,7 @@ impl std::fmt::Display for WasmExecutionMethod { } } -/// What to do when an extrinsic's weight exceeds the max extrinsic weight +/// What to do when a (`DispatchClass::Normal`) extrinsic's weight exceeds the max. extrinsic weight /// per block. #[allow(missing_docs)] #[derive(Debug, Clone, Copy, ValueEnum, PartialEq)] diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index 30750734bed4..3963064c9770 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -72,8 +72,8 @@ pub struct SharedParams { #[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)] pub tracing_receiver: TracingReceiver, - /// Sanity weight check for benchmarks. Checks whether an extrinsic's maximum weight exceeds - /// the max extrinsic weight. + /// Sanity weight check for benchmarks. Checks whether an (`DispatchClass::Normal`) extrinsic's + /// weight exceeds the max. extrinsic weight. #[arg( long, value_name = "OUTPUT", diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index e184aef91a05..7a55694a32ad 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -555,8 +555,8 @@ impl PalletCmd { writer::write_results(output_path, self, analysis_choice, &all_results)?; } - // Sanity check for benchmarks. Checks whether an extrinsic's maximum weight (based on max - // component) exceeds the max extrinsic weight. + // Sanity check for benchmarks. Checks whether an (`DispatchClass::Normal`) extrinsic's + // weight exceeds the max. extrinsic weight. writer::sanity_weight_check( all_results, max_extrinsic_weight, diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 5ee3fc2ed197..d64081404164 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -176,8 +176,8 @@ pub(crate) fn map_results( Ok(all_benchmarks) } -// Calculates the total maximum weight of an extrinsic (if present, based on the max component) and -// compares it with the max extrinsic weight allowed in a single block. +// Calculates the total maximum weight of an extrinsic (if present, based on the max. component +// value) and compares it with the max. extrinsic weight allowed in a single block. // // `max_extrinsic_weight` & `db_weight` are obtained from the runtime configuration. pub(crate) fn sanity_weight_check( @@ -263,7 +263,7 @@ pub(crate) fn sanity_weight_check( "\x1B[31mThe following extrinsic exceeds the maximum extrinsic weight:\x1B[0m", ); } - println!("- \x1B[1m'{}'\x1B[0m: {:?}\nPercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", + println!("- \x1B[1m'{}'\x1B[0m: {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", result.name, total_weight, (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, From 6081db0c271c3068abcecd9b6900c185641b32c4 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 18 Oct 2023 15:44:17 +0200 Subject: [PATCH 06/23] fix failing ci tests --- polkadot/runtime/westend/src/lib.rs | 6 +++++- substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0e93b3449fec..13ed373cc0aa 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2132,6 +2132,8 @@ sp_api::impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2149,7 +2151,9 @@ sp_api::impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index d64081404164..57e358542c96 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -208,8 +208,8 @@ pub(crate) fn sanity_weight_check( ); let mut sanity_weight_check_passed = true; // Loop through all benchmark results. - for ((_, _), results) in all_results.iter() { - // Per pallet, because there can be multiple instances of a pallet. + for ((pallet, instance), results) in all_results.iter() { + println!("Pallet: {}\nInstance: {}\n", pallet, instance); for result in results { // Constant `ref_time` & `pov_size`. let mut total_weight = Weight::from_parts( From 540ce57540910ca603c3030f78bd706ef6db617c Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 18 Oct 2023 17:06:09 +0200 Subject: [PATCH 07/23] more ci tests --- .../parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 6 +++++- .../runtimes/assets/asset-hub-polkadot/src/lib.rs | 6 +++++- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 6 +++++- .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 6 +++++- .../runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 6 +++++- .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 6 +++++- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 6 +++++- .../runtimes/collectives/collectives-polkadot/src/lib.rs | 6 +++++- .../runtimes/contracts/contracts-rococo/src/lib.rs | 6 +++++- .../parachains/runtimes/glutton/glutton-kusama/src/lib.rs | 6 +++++- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 6 +++++- 11 files changed, 55 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 40ce122112d2..8bd349227ea4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1159,6 +1159,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -1183,7 +1185,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index d4f7d6ef3616..f0809f48f6f5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -1039,6 +1039,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -1062,7 +1064,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 3328ff0edaf4..0f014c6c1a94 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1226,6 +1226,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -1254,7 +1256,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 943332087627..26e0c287b0a2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1210,6 +1210,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -1234,7 +1236,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 791751e77368..03218445dc20 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -628,6 +628,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -644,7 +646,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 928b9d091ec5..79be1dc232a6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -628,6 +628,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -644,7 +646,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 3a8507ccf93e..107f407ec66c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -967,6 +967,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -987,7 +989,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index ff16f93d8f54..46ed9a4f88cd 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -885,6 +885,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -895,7 +897,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 70392c5ecbcc..258a3df80f4d 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -640,6 +640,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -650,7 +652,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs index f5d52239e543..d5fda3ca837c 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs @@ -437,6 +437,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -447,7 +449,9 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index fe0f19c30632..5584c90d25cb 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -787,6 +787,8 @@ impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, + Weight, + frame_support::weights::RuntimeDbWeight, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -797,7 +799,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( From df4f1c4689b666bf7884e95999b9cebf858ab467 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Thu, 19 Oct 2023 10:04:49 +0200 Subject: [PATCH 08/23] more... --- .../parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 3 ++- .../runtimes/assets/asset-hub-polkadot/src/lib.rs | 3 ++- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 3 ++- .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 3 ++- .../runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 3 ++- .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 5 +++-- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 3 ++- .../runtimes/collectives/collectives-polkadot/src/lib.rs | 3 ++- .../runtimes/contracts/contracts-rococo/src/lib.rs | 3 ++- .../parachains/runtimes/glutton/glutton-kusama/src/lib.rs | 4 ++-- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 3 ++- substrate/client/cli/src/arg_enums.rs | 3 +-- .../utils/frame/benchmarking-cli/src/pallet/command.rs | 4 ++-- substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs | 6 +++++- 14 files changed, 31 insertions(+), 18 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 8bd349227ea4..b4202acf64f4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1166,6 +1166,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1185,7 +1186,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index f0809f48f6f5..f3b5530b70f4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -1046,6 +1046,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1064,7 +1065,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 0f014c6c1a94..e56fa1d89474 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1234,6 +1234,7 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use pallet_xcm_bridge_hub_router::benchmarking::Pallet as XcmBridgeHubRouterBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1256,7 +1257,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 26e0c287b0a2..9cb95b0e9f2f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1217,6 +1217,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1236,7 +1237,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 03218445dc20..5a42a4e82c82 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -635,6 +635,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -646,7 +647,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 79be1dc232a6..f2115935a2e9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -635,6 +635,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -646,9 +647,9 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic, db_weight) + (list, storage_info, max_extrinsic_weight, db_weight) } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 107f407ec66c..bd1b027e5281 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -974,6 +974,7 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -989,7 +990,7 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 46ed9a4f88cd..3af98ed27baa 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -892,12 +892,13 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 258a3df80f4d..a131d027a228 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -647,12 +647,13 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs index d5fda3ca837c..fa4448343723 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs @@ -443,13 +443,13 @@ impl_runtime_apis! { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; + use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 5584c90d25cb..bbe5328d93e2 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -794,12 +794,13 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); (list, storage_info, max_extrinsic_weight, db_weight) } diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index b9b47a11551f..c0a40f0eff1b 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -64,8 +64,7 @@ impl std::fmt::Display for WasmExecutionMethod { } } -/// What to do when a (`DispatchClass::Normal`) extrinsic's weight exceeds the max. extrinsic weight -/// per block. +/// How to output the result of the sanity weight check. #[allow(missing_docs)] #[derive(Debug, Clone, Copy, ValueEnum, PartialEq)] #[value(rename_all = "kebab-case")] diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 7a55694a32ad..fd3fed0030b7 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -555,8 +555,8 @@ impl PalletCmd { writer::write_results(output_path, self, analysis_choice, &all_results)?; } - // Sanity check for benchmarks. Checks whether an (`DispatchClass::Normal`) extrinsic's - // weight exceeds the max. extrinsic weight. + // Sanity weight check for benchmark results. Checks whether an (`DispatchClass::Normal`) + // extrinsic's weight exceeds the max. extrinsic weight. writer::sanity_weight_check( all_results, max_extrinsic_weight, diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 57e358542c96..cc22425a61ea 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -1352,7 +1352,8 @@ mod test { } #[test] - fn sanity_check_works() { + fn sanity_weight_check_works() { + // Create benchmark results that will fail the sanity weight check. let mapped_results = map_results( &[test_data(b"first", b"first", BenchmarkParameter::a, 10, 3)], &test_storage_info(), @@ -1366,6 +1367,7 @@ mod test { ) .unwrap(); + // Flag set to `error`. assert!(sanity_weight_check( mapped_results.clone(), Weight::from_parts(20_000, 1_000_000), @@ -1374,6 +1376,7 @@ mod test { ) .is_err()); + // Flag set to `warning`. assert!(sanity_weight_check( mapped_results.clone(), Weight::from_parts(20_000, 1_000_000), @@ -1382,6 +1385,7 @@ mod test { ) .is_ok()); + // Flag set to `ignore`. assert!(sanity_weight_check( mapped_results, Weight::from_parts(20_000, 1_000_000), From d64188f6d1ebf53f93409e1b77a3182e95ef136b Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 25 Oct 2023 12:14:33 +0200 Subject: [PATCH 09/23] add to gitlab pipeline --- .gitlab/pipeline/short-benchmarks.yml | 5 ++--- .gitlab/pipeline/test.yml | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.gitlab/pipeline/short-benchmarks.yml b/.gitlab/pipeline/short-benchmarks.yml index 6d060077a7c7..eef90e8f416a 100644 --- a/.gitlab/pipeline/short-benchmarks.yml +++ b/.gitlab/pipeline/short-benchmarks.yml @@ -24,7 +24,7 @@ short-benchmark-westend: &short-bench tags: - benchmark script: - - ./artifacts/polkadot benchmark pallet --chain $RUNTIME-dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 + - ./artifacts/polkadot benchmark pallet --chain $RUNTIME-dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --sanity-weight-check ignore # run short-benchmarks for system parachain runtimes from cumulus @@ -47,8 +47,7 @@ short-benchmark-westend: &short-bench tags: - benchmark script: - - ./artifacts/polkadot-parachain benchmark pallet --chain $RUNTIME_CHAIN --pallet "*" --extrinsic "*" --steps 2 --repeat 1 - + - ./artifacts/polkadot-parachain benchmark pallet --chain $RUNTIME_CHAIN --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --sanity-weight-check ignore short-benchmark-asset-hub-polkadot: <<: *short-bench-cumulus variables: diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml index 7d7007acd8a8..972005bd29d4 100644 --- a/.gitlab/pipeline/test.yml +++ b/.gitlab/pipeline/test.yml @@ -69,7 +69,6 @@ test-linux-stable-runtime-benchmarks: RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" script: - time cargo nextest run --workspace --features runtime-benchmarks benchmark --locked --cargo-profile testnet - # can be used to run all tests # test-linux-stable-all: # stage: test @@ -352,8 +351,7 @@ quick-benchmarks: WASM_BUILD_NO_COLOR: 1 WASM_BUILD_RUSTFLAGS: "-C debug-assertions -D warnings" script: - - time cargo run --locked --release -p node-cli --bin substrate-node --features runtime-benchmarks -- benchmark pallet --execution wasm --wasm-execution compiled --chain dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 - + - time cargo run --locked --release -p node-cli --bin substrate-node --features runtime-benchmarks -- benchmark pallet --execution wasm --wasm-execution compiled --chain dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --sanity-weight-check ignore test-frame-examples-compile-to-wasm: # into one job stage: test From eace65b09e7a20287d1b4c72458afdf4793abed1 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 25 Oct 2023 14:35:53 +0200 Subject: [PATCH 10/23] fix: unused import --- .../assets/asset-hub-kusama/src/lib.rs | 150 ++++++++--------- .../assets/asset-hub-polkadot/src/lib.rs | 146 ++++++++--------- .../assets/asset-hub-rococo/src/lib.rs | 150 ++++++++--------- .../assets/asset-hub-westend/src/lib.rs | 152 +++++++++--------- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 1 - .../bridge-hub-polkadot/src/lib.rs | 1 - .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 - .../collectives-polkadot/src/lib.rs | 47 +++--- .../contracts/contracts-rococo/src/lib.rs | 1 - .../runtimes/testing/penpal/src/lib.rs | 1 - 10 files changed, 322 insertions(+), 328 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index c506b2be46d3..e960bb9ea090 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -481,97 +481,98 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } + | RuntimeCall::Assets { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), } } @@ -1169,7 +1170,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index d29727e2091a..ae0b6248325d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -419,95 +419,96 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } + | RuntimeCall::Assets { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), } } @@ -1049,7 +1050,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 8d020b98b254..9652cea5d250 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -487,97 +487,98 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } + | RuntimeCall::Assets { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), } } @@ -1249,7 +1250,6 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use pallet_xcm_bridge_hub_router::benchmarking::Pallet as XcmBridgeHubRouterBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index a88963a62f54..ad3ff77d85c5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -456,97 +456,98 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } + | RuntimeCall::Assets { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } | - RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } + | RuntimeCall::NftFractionalization { .. } + | RuntimeCall::Nfts { .. } + | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | - RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) + | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) + | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) + | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), } } @@ -1233,7 +1234,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1492,7 +1492,7 @@ pub mod migrations { let pool_asset_id = pool_info.lp_token.clone(); if old_pool_id.0.as_ref() != &invalid_native_asset { // skip, if ok - continue + continue; } // fix new account diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index d4b8a13cfe23..40e81c7105f3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -638,7 +638,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index a37571a26663..b22aa714f836 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -638,7 +638,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index a27678cfb540..4d63eb0cc0b2 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -818,7 +818,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index f715f716f64f..078a7d6432f3 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -312,41 +312,41 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Alliance => matches!( c, - RuntimeCall::AllianceMotion { .. } | - RuntimeCall::Alliance { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::AllianceMotion { .. } + | RuntimeCall::Alliance { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Fellowship => matches!( c, - RuntimeCall::FellowshipCollective { .. } | - RuntimeCall::FellowshipReferenda { .. } | - RuntimeCall::FellowshipCore { .. } | - RuntimeCall::FellowshipSalary { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::FellowshipCollective { .. } + | RuntimeCall::FellowshipReferenda { .. } + | RuntimeCall::FellowshipCore { .. } + | RuntimeCall::FellowshipSalary { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Ambassador => matches!( c, - RuntimeCall::AmbassadorCollective { .. } | - RuntimeCall::AmbassadorReferenda { .. } | - RuntimeCall::AmbassadorContent { .. } | - RuntimeCall::AmbassadorCore { .. } | - RuntimeCall::AmbassadorSalary { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::AmbassadorCollective { .. } + | RuntimeCall::AmbassadorReferenda { .. } + | RuntimeCall::AmbassadorContent { .. } + | RuntimeCall::AmbassadorCore { .. } + | RuntimeCall::AmbassadorSalary { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), } } @@ -909,7 +909,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index f917380d8f24..2cde9e4ac041 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -652,7 +652,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 4c8f7ec187a7..fd08b1dd7a3e 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -797,7 +797,6 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use sp_core::Get; let mut list = Vec::::new(); list_benchmarks!(list, extra); From 98485c5d7d38e0fff2558bc141c831db2b5f966c Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Wed, 25 Oct 2023 14:43:21 +0200 Subject: [PATCH 11/23] fmt --- .../assets/asset-hub-kusama/src/lib.rs | 149 +++++++++-------- .../assets/asset-hub-polkadot/src/lib.rs | 145 +++++++++-------- .../assets/asset-hub-rococo/src/lib.rs | 149 +++++++++-------- .../assets/asset-hub-westend/src/lib.rs | 151 +++++++++--------- .../collectives-polkadot/src/lib.rs | 46 +++--- 5 files changed, 318 insertions(+), 322 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index e960bb9ea090..17ef1653e8a0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -481,98 +481,97 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } - | RuntimeCall::Assets { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } | + RuntimeCall::Assets { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index ae0b6248325d..03e34521a049 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -419,96 +419,95 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } - | RuntimeCall::Assets { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } | + RuntimeCall::Assets { .. } | + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } | + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 9652cea5d250..1004b7d7a716 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -487,98 +487,97 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } - | RuntimeCall::Assets { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } | + RuntimeCall::Assets { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index ad3ff77d85c5..ec8cb168a171 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -456,98 +456,97 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances { .. } - | RuntimeCall::Assets { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Balances { .. } | + RuntimeCall::Assets { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } - | RuntimeCall::NftFractionalization { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } | + RuntimeCall::NftFractionalization { .. } | + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } @@ -1492,7 +1491,7 @@ pub mod migrations { let pool_asset_id = pool_info.lp_token.clone(); if old_pool_id.0.as_ref() != &invalid_native_asset { // skip, if ok - continue; + continue } // fix new account diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 078a7d6432f3..8867e6bbbf01 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -312,41 +312,41 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Alliance => matches!( c, - RuntimeCall::AllianceMotion { .. } - | RuntimeCall::Alliance { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::AllianceMotion { .. } | + RuntimeCall::Alliance { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Fellowship => matches!( c, - RuntimeCall::FellowshipCollective { .. } - | RuntimeCall::FellowshipReferenda { .. } - | RuntimeCall::FellowshipCore { .. } - | RuntimeCall::FellowshipSalary { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::FellowshipCollective { .. } | + RuntimeCall::FellowshipReferenda { .. } | + RuntimeCall::FellowshipCore { .. } | + RuntimeCall::FellowshipSalary { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Ambassador => matches!( c, - RuntimeCall::AmbassadorCollective { .. } - | RuntimeCall::AmbassadorReferenda { .. } - | RuntimeCall::AmbassadorContent { .. } - | RuntimeCall::AmbassadorCore { .. } - | RuntimeCall::AmbassadorSalary { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::AmbassadorCollective { .. } | + RuntimeCall::AmbassadorReferenda { .. } | + RuntimeCall::AmbassadorContent { .. } | + RuntimeCall::AmbassadorCore { .. } | + RuntimeCall::AmbassadorSalary { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } From 8795558f6231a366a19b9ba7100f8a23473a9b0f Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Fri, 27 Oct 2023 13:13:30 +0200 Subject: [PATCH 12/23] improve based on first comments (1/2) --- substrate/client/cli/src/arg_enums.rs | 5 ++++- .../client/cli/src/params/shared_params.rs | 6 ++--- .../utils/frame/benchmarking-cli/Cargo.toml | 1 + .../benchmarking-cli/src/pallet/command.rs | 3 +-- .../benchmarking-cli/src/pallet/writer.rs | 22 +++++++++---------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index c0a40f0eff1b..24183dbd012f 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -64,13 +64,16 @@ impl std::fmt::Display for WasmExecutionMethod { } } -/// How to output the result of the sanity weight check. +/// How to output the result of the sanity weight check and what to do when it fails. #[allow(missing_docs)] #[derive(Debug, Clone, Copy, ValueEnum, PartialEq)] #[value(rename_all = "kebab-case")] pub enum SanityWeightCheck { + /// Prints the results in the terminal and on failing returns an error. Error, + /// Prints the results in the terminal. Warning, + /// Sanity weight check is ignored. Ignore, } diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index 3963064c9770..923543a09dfa 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -72,11 +72,11 @@ pub struct SharedParams { #[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)] pub tracing_receiver: TracingReceiver, - /// Sanity weight check for benchmarks. Checks whether an (`DispatchClass::Normal`) extrinsic's - /// weight exceeds the max. extrinsic weight. + /// Sanity weight check for benchmarks. Checks that no benchmark function has a weight larger + /// than the (`DispatchClass::Normal`) max. normal class extrinsic weight. #[arg( long, - value_name = "OUTPUT", + value_name = "ERROR-LEVEL", value_enum, default_value_t = DEFAULT_SANITY_WEIGHT_CHECK, )] diff --git a/substrate/utils/frame/benchmarking-cli/Cargo.toml b/substrate/utils/frame/benchmarking-cli/Cargo.toml index e32fe47b7297..c5ecc1785a83 100644 --- a/substrate/utils/frame/benchmarking-cli/Cargo.toml +++ b/substrate/utils/frame/benchmarking-cli/Cargo.toml @@ -17,6 +17,7 @@ array-bytes = "6.1" chrono = "0.4" clap = { version = "4.4.6", features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.6.1" } +color-print = "0.3.4" comfy-table = { version = "7.0.1", default-features = false } handlebars = "4.2.2" Inflector = "0.11.4" diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index fd3fed0030b7..d76e37e866db 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -555,8 +555,7 @@ impl PalletCmd { writer::write_results(output_path, self, analysis_choice, &all_results)?; } - // Sanity weight check for benchmark results. Checks whether an (`DispatchClass::Normal`) - // extrinsic's weight exceeds the max. extrinsic weight. + // Execute sanity weight check. writer::sanity_weight_check( all_results, max_extrinsic_weight, diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index cc22425a61ea..dcec7ffc256d 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -199,12 +199,12 @@ pub(crate) fn sanity_weight_check( 0 } - println!( - "\n\x1B[1mSanity Weight Check 🧐:\x1B[0m each extrinsic's weight function is executed \ + color_print::cprintln!( + "\nSanity Weight Check 🧐: each extrinsic's weight function is executed \ in the worst case scenario and compared with the maximum extrinsic weight (the maximum weight \ that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In other words, \ each extrinsic is checked whether it will fit in an empty (meaning; empty of \ - `DispatchClass::Normal` extrinsics) block.\n\n\x1B[4mResults:\x1B[0m\n" + `DispatchClass::Normal` extrinsics) block.\n\nResults:\n" ); let mut sanity_weight_check_passed = true; // Loop through all benchmark results. @@ -258,12 +258,12 @@ pub(crate) fn sanity_weight_check( total_weight.proof_size() > max_extrinsic_weight.proof_size() { sanity_weight_check_passed = false; - println!("\x1B[31m\x1B[1mWARNING!!!\x1B[0m",); - println!( - "\x1B[31mThe following extrinsic exceeds the maximum extrinsic weight:\x1B[0m", + color_print::cprintln!("WARNING!!!",); + color_print::cprintln!( + "The following extrinsic exceeds the maximum extrinsic weight:", ); } - println!("- \x1B[1m'{}'\x1B[0m: {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", + color_print::cprintln!("- '{}': {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", result.name, total_weight, (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, @@ -273,9 +273,9 @@ pub(crate) fn sanity_weight_check( } match sanity_weight_check_passed { false => { - println!( - "\x1B[31mYour extrinsics failed the Sanity Weight Check, please review \ - the extrinsic's logic and/or the associated benchmark function.\x1B[0m\n", + color_print::cprintln!( + "Your extrinsics failed the Sanity Weight Check, please review \ + the extrinsic's logic and/or the associated benchmark function.\n", ); if sanity_weight_check == SanityWeightCheck::Error { return Err(io_error(&String::from( @@ -284,7 +284,7 @@ pub(crate) fn sanity_weight_check( } }, true => { - println!("\x1B[32mYour extrinsics passed the Sanity Weight Check 😃!\x1B[0m\n"); + color_print::cprintln!("Your extrinsics passed the Sanity Weight Check 😃!\n"); }, } Ok(()) From 741329f8ab17df700a629240ea92b9184d06fe27 Mon Sep 17 00:00:00 2001 From: Daan van der Plas Date: Fri, 27 Oct 2023 14:03:32 +0200 Subject: [PATCH 13/23] add Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index d1a1b1877a92..d0449acb3280 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5233,6 +5233,7 @@ dependencies = [ "array-bytes 6.1.0", "chrono", "clap 4.4.6", + "color-print", "comfy-table", "frame-benchmarking", "frame-support", From 1d35a4c8854ed3de543b5af7f9e0b66ad792d666 Mon Sep 17 00:00:00 2001 From: dastansam Date: Mon, 8 Apr 2024 02:48:55 +0200 Subject: [PATCH 14/23] Resolve comments and add prdoc --- cumulus/parachain-template/runtime/src/lib.rs | 12 ++-- .../assets/asset-hub-rococo/src/lib.rs | 11 +--- .../assets/asset-hub-westend/src/lib.rs | 12 ++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 11 +--- .../bridge-hubs/bridge-hub-westend/src/lib.rs | 12 ++-- .../collectives-westend/src/lib.rs | 11 +--- .../contracts/contracts-rococo/src/lib.rs | 11 +--- .../coretime/coretime-rococo/src/lib.rs | 12 ++-- .../coretime/coretime-westend/src/lib.rs | 11 +--- .../glutton/glutton-westend/src/lib.rs | 11 +--- .../runtimes/people/people-rococo/src/lib.rs | 12 ++-- .../runtimes/people/people-westend/src/lib.rs | 11 +--- .../runtimes/testing/penpal/src/lib.rs | 11 +--- .../asset_hub_polkadot_aura.rs | 5 +- .../src/fake_runtime_api/aura.rs | 5 +- polkadot/runtime/rococo/src/lib.rs | 11 +--- polkadot/runtime/westend/src/lib.rs | 11 +--- prdoc/pr_1493.prdoc | 61 +++++++++++++++++++ .../bin/node-template/runtime/src/lib.rs | 11 +--- substrate/bin/node/runtime/src/lib.rs | 11 +--- substrate/client/cli/src/arg_enums.rs | 2 +- substrate/frame/benchmarking/src/utils.rs | 26 +++++++- .../benchmarking-cli/src/pallet/command.rs | 34 +++++------ .../benchmarking-cli/src/pallet/writer.rs | 42 ++++++------- 24 files changed, 188 insertions(+), 179 deletions(-) create mode 100644 prdoc/pr_1493.prdoc diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index b546f6801f80..012582b7a485 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -704,13 +704,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -721,7 +716,8 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + + BenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 1fc27f75d896..d2022fe48701 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1291,13 +1291,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1326,7 +1321,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 7c141c0c3238..548cd7dedc5d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1369,13 +1369,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1404,7 +1399,8 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index b650bd49460e..5e92331a8827 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1056,13 +1056,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1087,7 +1082,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index edfb08f163bf..8dd1eba80bee 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -753,11 +753,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -779,7 +776,10 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index d0a2c6008ade..2352f7bd679d 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -946,13 +946,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -964,7 +959,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index eb44b01e1e3e..0f656331e400 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -672,13 +672,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -690,7 +685,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 1e880cf6cce6..ace5337bb5a4 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -662,11 +662,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -682,7 +679,10 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index b36756494b7a..4e50579934b8 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -649,13 +649,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -673,7 +668,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index a6478cd49436..5191794a0b09 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -432,13 +432,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use sp_core::Get; @@ -449,7 +444,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 790be31da030..6c473a7a1341 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -635,11 +635,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -655,7 +652,10 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 38dff4fed17b..916bda560dbb 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -635,13 +635,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -659,7 +654,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 575da3b96d8f..b2602351cc07 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -844,13 +844,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -861,7 +856,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 76dd7347ccbc..76501d38470e 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -174,10 +174,7 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(_: bool) -> ( - Vec, - Vec, - ) { + fn benchmark_metadata(_: bool) -> frame_benchmarking::BenchmarkInfo { unimplemented!() } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 0f01b85ebcf6..6b4e180328ae 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -174,10 +174,7 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(_: bool) -> ( - Vec, - Vec, - ) { + fn benchmark_metadata(_: bool) -> frame_benchmarking::BenchmarkInfo { unimplemented!() } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index d31460ee1759..a461932bd320 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2226,13 +2226,8 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; @@ -2246,7 +2241,7 @@ sp_api::impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index a7a692e6700b..222fe7c02ab0 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2240,13 +2240,8 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use pallet_session_benchmarking::Pallet as SessionBench; @@ -2265,7 +2260,7 @@ sp_api::impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/prdoc/pr_1493.prdoc b/prdoc/pr_1493.prdoc new file mode 100644 index 000000000000..cfba1f61da44 --- /dev/null +++ b/prdoc/pr_1493.prdoc @@ -0,0 +1,61 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "Benchmarking: automatic weight sanity check" + +doc: + - audience: Runtime Dev + description: | + This PR introduces a new sanity weight check during benchmark execution to ensure that the weight of the function/extrinsic does not exceed the given limit. + Maximum extrinsic weight value and `RuntimeDbWeight` should be provided by the runtime API. Maximum weight value is usually `max_extrinsic` from + `RuntimeBlockWeights` for `DispatchClass::Normal` type extrinsics. + + During benchmark execution developers can either choose to throw an error, log a warning, or ignore if the weight exceeds the limit. Default behaviour is + warning. This can be configured by passing an argument to `--sanity-check` flag in the benchmarking CLI. + + Note: This introduces a breaking change for `frame_benchmarking::Benchmark` runtime API. `benchmark_metadata` function now returns new struct `BenchmarkInfo` + that encapsulates exhaustive benchmarks related information. To ensure backwards compatibility, `BenchmarkInfo` can be created from previous + return type: `(Vec, Vec)`. + + The easiest way to migrate is to replace is to change return type and convert the tuple to `BenchmarkInfo`: + + ``` + --- a/path/to/runtime.rs + +++ b/path/to/runtime.rs + @@ -1,3 +1,4 @@ + -fn benchmark_metadata(extra: bool) -> (Vec, Vec) { + +fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + /// ... + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + + -(list, storage_info) + +(list, storage_info).into() + } + ``` + + However, it is strongly recommended to use weight sanity check to ensure your benchmarks are within the weight limit: + + ``` + --- a/path/to/runtime.rs + +++ b/path/to/runtime.rs + @@ -1,3 +1,4 @@ + -fn benchmark_metadata(extra: bool) -> (Vec, Vec) { + +fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + /// ... + +let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + +let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + -(list, storage_info) + +BenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + } + ``` + +crates: + - name: "frame-benchmarking" + bump: "major" + - name: "frame-benchmarking-cli" + bump: "major" + - name: "sc-cli" + bump: "minor" \ No newline at end of file diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 9b7cf906737b..ac9e21e32bc2 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -493,13 +493,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; @@ -510,7 +505,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 217109ea43d2..a9f7ae10be37 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2845,13 +2845,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - Weight, - frame_support::weights::RuntimeDbWeight, - ) { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, BenchmarkInfo}; use frame_support::traits::StorageInfoTrait; // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency @@ -2871,7 +2866,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - (list, storage_info, max_extrinsic_weight, db_weight) + BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index e11dfd2d0bff..6872c28547fd 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -79,7 +79,7 @@ pub enum SanityWeightCheck { } /// The default [`SanityWeightCheck`]. -pub const DEFAULT_SANITY_WEIGHT_CHECK: SanityWeightCheck = SanityWeightCheck::Error; +pub const DEFAULT_SANITY_WEIGHT_CHECK: SanityWeightCheck = SanityWeightCheck::Warning; /// Converts the execution method and instantiation strategy command line arguments /// into an execution method which can be used internally. diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index 1374ebca2c90..d722552901e8 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -230,6 +230,27 @@ pub struct BenchmarkMetadata { pub pov_modes: Vec<(Vec, Vec)>, } +/// Exhaustive benchmark info provided by the runtime. +#[derive(Encode, Decode, Default, Clone, PartialEq, Debug, TypeInfo)] +pub struct BenchmarkInfo { + /// List of all benchmarks available for this runtime. + pub list: Vec, + /// List of all metadata about storage items. + pub storage_info: Vec, + /// Maximum extrinsic weight that can be achieved in `DispatchClass::Normal`. + pub max_extrinsic_weight: Option, + /// Weight of the runtime database. + pub db_weight: Option, +} + +/// Convert a tuple of benchmark lists and storage info into a `BenchmarkInfo` struct. +/// For backwards compatibility. +impl From<(Vec, Vec)> for BenchmarkInfo { + fn from((list, storage_info): (Vec, Vec)) -> Self { + Self { list, storage_info, max_extrinsic_weight: None, db_weight: None } + } +} + sp_api::decl_runtime_apis! { /// Runtime api for benchmarking a FRAME runtime. pub trait Benchmark { @@ -238,7 +259,10 @@ sp_api::decl_runtime_apis! { /// Parameters /// - `extra`: Also list benchmarks marked "extra" which would otherwise not be /// needed for weight calculation. - fn benchmark_metadata(extra: bool) -> (Vec, Vec, Weight, RuntimeDbWeight); + /// + /// Returns: + /// - `BenchmarkInfo` - Complete benchmark metadata available for this runtime. + fn benchmark_metadata(extra: bool) -> BenchmarkInfo; /// Dispatch the given benchmark. fn dispatch_benchmark(config: BenchmarkConfig) -> Result, sp_runtime::RuntimeString>; diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index a30a824585f0..789db6c3fd5b 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -18,7 +18,7 @@ use super::{writer, PalletCmd}; use codec::{Decode, Encode}; use frame_benchmarking::{ - Analysis, AnalysisChoice, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkList, + Analysis, AnalysisChoice, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkInfo, BenchmarkParameter, BenchmarkResult, BenchmarkSelector, }; use frame_support::{ @@ -254,11 +254,9 @@ impl PalletCmd { .execute() .map_err(|e| format!("{}: {}", ERROR_METADATA_NOT_FOUND, e))?; - let (list, storage_info, max_extrinsic_weight, db_weight) = - <(Vec, Vec, Weight, RuntimeDbWeight) as Decode>::decode( - &mut &result[..], - ) - .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))?; + let BenchmarkInfo { list, storage_info, max_extrinsic_weight, db_weight } = + ::decode(&mut &result[..]) + .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))?; if let Some(json_input) = &self.json_input { let raw_data = match std::fs::read(json_input) { @@ -530,8 +528,8 @@ impl PalletCmd { storage_info: &[StorageInfo], component_ranges: &HashMap<(Vec, Vec), Vec>, pov_modes: PovModesMap, - max_extrinsic_weight: Weight, - db_weight: RuntimeDbWeight, + max_extrinsic_weight: Option, + db_weight: Option, ) -> Result<()> { // Jsonify the result and write it to a file or stdout if desired. if !self.jsonify(&batches)? { @@ -563,13 +561,15 @@ impl PalletCmd { writer::write_results(output_path, self, analysis_choice, &all_results)?; } - // Execute sanity weight check. - writer::sanity_weight_check( - all_results, - max_extrinsic_weight, - db_weight, - self.shared_params.sanity_weight_check, - )?; + if let (Some(max_extrinsic_weight), Some(db_weight)) = (max_extrinsic_weight, db_weight) { + // Execute sanity weight check. + writer::sanity_weight_check( + all_results, + max_extrinsic_weight, + db_weight, + self.shared_params.sanity_weight_check, + )?; + } Ok(()) } @@ -578,8 +578,8 @@ impl PalletCmd { fn output_from_results( &self, batches: &[BenchmarkBatchSplitResults], - max_extrinsic_weight: Weight, - db_weight: RuntimeDbWeight, + max_extrinsic_weight: Option, + db_weight: Option, ) -> Result<()> { let mut component_ranges = HashMap::<(Vec, Vec), HashMap>::new(); diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index dcec7ffc256d..70f3f24fa9f6 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -218,28 +218,29 @@ pub(crate) fn sanity_weight_check( ); // `ref_time` multiplied by complexity parameter. for component in &result.component_weight { - total_weight = total_weight.saturating_add( + total_weight.saturating_accrue( Weight::from_parts(component.slope.try_into().unwrap(), 0) .saturating_mul(max_component(&component, &result.component_ranges)), ); } // Constant storage reads. - total_weight = - total_weight.saturating_add(db_weight.reads(result.base_reads.try_into().unwrap())); + total_weight.saturating_accrue(db_weight.reads(result.base_reads.try_into().unwrap())); + // Storage reads multiplied by complexity parameter. for component in &result.component_reads { - total_weight = total_weight.saturating_add( + total_weight.saturating_accrue( db_weight .reads(component.slope.try_into().unwrap()) .saturating_mul(max_component(&component, &result.component_ranges)), ); } // Constant storage writes. - total_weight = total_weight - .saturating_add(db_weight.writes(result.base_writes.try_into().unwrap())); + total_weight + .saturating_accrue(db_weight.writes(result.base_writes.try_into().unwrap())); + // Storage writes multiplied by complexity parameter. for component in &result.component_writes { - total_weight = total_weight.saturating_add( + total_weight.saturating_accrue( db_weight .writes(component.slope.try_into().unwrap()) .saturating_mul(max_component(&component, &result.component_ranges)), @@ -247,7 +248,7 @@ pub(crate) fn sanity_weight_check( } // `pov_size` multiplied by complexity parameter. for component in &result.component_calculated_proof_size { - total_weight = total_weight.saturating_add( + total_weight.saturating_accrue( Weight::from_parts(0, component.slope.try_into().unwrap()) .saturating_mul(max_component(&component, &result.component_ranges)), ); @@ -271,21 +272,18 @@ pub(crate) fn sanity_weight_check( ); } } - match sanity_weight_check_passed { - false => { - color_print::cprintln!( - "Your extrinsics failed the Sanity Weight Check, please review \ + if sanity_weight_check_passed { + color_print::cprintln!("Your extrinsics passed the Sanity Weight Check 😃!\n"); + } else { + color_print::cprintln!( + "Your extrinsics failed the Sanity Weight Check, please review \ the extrinsic's logic and/or the associated benchmark function.\n", - ); - if sanity_weight_check == SanityWeightCheck::Error { - return Err(io_error(&String::from( - "One or more extrinsics exceed the maximum extrinsic weight", - ))) - } - }, - true => { - color_print::cprintln!("Your extrinsics passed the Sanity Weight Check 😃!\n"); - }, + ); + if sanity_weight_check == SanityWeightCheck::Error { + return Err(io_error(&String::from( + "One or more extrinsics exceed the maximum extrinsic weight", + ))) + } } Ok(()) } From 759ddbb53d1c4d56d2a7d643580bfdd66bdc26ea Mon Sep 17 00:00:00 2001 From: dastansam Date: Mon, 8 Apr 2024 02:51:23 +0200 Subject: [PATCH 15/23] Temp rename prdoc --- prdoc/{pr_1493.prdoc => pr_4020.prdoc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/{pr_1493.prdoc => pr_4020.prdoc} (100%) diff --git a/prdoc/pr_1493.prdoc b/prdoc/pr_4020.prdoc similarity index 100% rename from prdoc/pr_1493.prdoc rename to prdoc/pr_4020.prdoc From 85ff5538922f381d4795bf6d6f1f800df8e76cf0 Mon Sep 17 00:00:00 2001 From: dastansam Date: Mon, 8 Apr 2024 02:54:17 +0200 Subject: [PATCH 16/23] Remove bump --- prdoc/pr_4020.prdoc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/prdoc/pr_4020.prdoc b/prdoc/pr_4020.prdoc index cfba1f61da44..68af52649d4d 100644 --- a/prdoc/pr_4020.prdoc +++ b/prdoc/pr_4020.prdoc @@ -54,8 +54,5 @@ doc: crates: - name: "frame-benchmarking" - bump: "major" - name: "frame-benchmarking-cli" - bump: "major" - - name: "sc-cli" - bump: "minor" \ No newline at end of file + - name: "sc-cli" \ No newline at end of file From 6b353d2ec3c93803169d49c6c5b0f2290f195dab Mon Sep 17 00:00:00 2001 From: dastansam Date: Thu, 11 Apr 2024 22:41:25 +0200 Subject: [PATCH 17/23] Add runtime version check, rename `BenchmarkInfo` --- cumulus/parachain-template/runtime/src/lib.rs | 6 +-- .../assets/asset-hub-rococo/src/lib.rs | 6 +-- .../assets/asset-hub-westend/src/lib.rs | 6 +-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 6 +-- .../bridge-hubs/bridge-hub-westend/src/lib.rs | 6 +-- .../collectives-westend/src/lib.rs | 6 +-- .../contracts/contracts-rococo/src/lib.rs | 6 +-- .../coretime/coretime-rococo/src/lib.rs | 6 +-- .../coretime/coretime-westend/src/lib.rs | 6 +-- .../glutton/glutton-westend/src/lib.rs | 6 +-- .../runtimes/people/people-rococo/src/lib.rs | 6 +-- .../runtimes/people/people-westend/src/lib.rs | 6 +-- .../runtimes/testing/penpal/src/lib.rs | 6 +-- .../asset_hub_polkadot_aura.rs | 2 +- .../src/fake_runtime_api/aura.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 6 +-- polkadot/runtime/westend/src/lib.rs | 6 +-- .../bin/node-template/runtime/src/lib.rs | 6 +-- substrate/bin/node/runtime/src/lib.rs | 6 +-- substrate/frame/benchmarking/src/utils.rs | 11 ++-- .../benchmarking-cli/src/pallet/command.rs | 51 ++++++++++++++++--- 21 files changed, 103 insertions(+), 65 deletions(-) diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 012582b7a485..1ea2f723f0d9 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -704,8 +704,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -717,7 +717,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index d2022fe48701..cdae04248832 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1291,8 +1291,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1321,7 +1321,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 548cd7dedc5d..5a218eba9c5d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1369,8 +1369,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1400,7 +1400,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 5e92331a8827..b4264cabd002 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1056,8 +1056,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -1082,7 +1082,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 8dd1eba80bee..dd11bbbf3724 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -753,8 +753,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -779,7 +779,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 2352f7bd679d..cde1b39a2053 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -946,8 +946,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -959,7 +959,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 0f656331e400..32df37400b1d 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -672,8 +672,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -685,7 +685,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index ace5337bb5a4..0bbdb878dd1f 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -662,8 +662,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -682,7 +682,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 4e50579934b8..1393f235b409 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -649,8 +649,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -668,7 +668,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 5191794a0b09..f1f02ea19030 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -432,8 +432,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use sp_core::Get; @@ -444,7 +444,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 6c473a7a1341..b48154c9ae5a 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -635,8 +635,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -655,7 +655,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 916bda560dbb..eee4bf5f5b73 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -635,8 +635,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -654,7 +654,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index b2602351cc07..a13a4135ac1a 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -844,8 +844,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; @@ -856,7 +856,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 76501d38470e..52cb79f16873 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -174,7 +174,7 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(_: bool) -> frame_benchmarking::BenchmarkInfo { + fn benchmark_metadata(_: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { unimplemented!() } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 6b4e180328ae..30a90af5038e 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -174,7 +174,7 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(_: bool) -> frame_benchmarking::BenchmarkInfo { + fn benchmark_metadata(_: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { unimplemented!() } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index a461932bd320..6b2238404208 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2226,8 +2226,8 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; @@ -2241,7 +2241,7 @@ sp_api::impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 222fe7c02ab0..25a40051ac75 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2240,8 +2240,8 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use pallet_session_benchmarking::Pallet as SessionBench; @@ -2260,7 +2260,7 @@ sp_api::impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index ac9e21e32bc2..0ecd17282f06 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -493,8 +493,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; @@ -505,7 +505,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index a9f7ae10be37..a39bb870fd87 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2845,8 +2845,8 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, BenchmarkInfo}; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; use frame_support::traits::StorageInfoTrait; // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency @@ -2866,7 +2866,7 @@ impl_runtime_apis! { let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); - BenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } fn dispatch_benchmark( diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index d722552901e8..0b07a94064eb 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -232,7 +232,7 @@ pub struct BenchmarkMetadata { /// Exhaustive benchmark info provided by the runtime. #[derive(Encode, Decode, Default, Clone, PartialEq, Debug, TypeInfo)] -pub struct BenchmarkInfo { +pub struct RuntimeBenchmarkInfo { /// List of all benchmarks available for this runtime. pub list: Vec, /// List of all metadata about storage items. @@ -243,9 +243,9 @@ pub struct BenchmarkInfo { pub db_weight: Option, } -/// Convert a tuple of benchmark lists and storage info into a `BenchmarkInfo` struct. +/// Convert a tuple of benchmark lists and storage info into a `RuntimeBenchmarkInfo` struct. /// For backwards compatibility. -impl From<(Vec, Vec)> for BenchmarkInfo { +impl From<(Vec, Vec)> for RuntimeBenchmarkInfo { fn from((list, storage_info): (Vec, Vec)) -> Self { Self { list, storage_info, max_extrinsic_weight: None, db_weight: None } } @@ -253,6 +253,7 @@ impl From<(Vec, Vec)> for BenchmarkInfo { sp_api::decl_runtime_apis! { /// Runtime api for benchmarking a FRAME runtime. + #[api_version(2)] pub trait Benchmark { /// Get the benchmark metadata available for this runtime. /// @@ -261,8 +262,8 @@ sp_api::decl_runtime_apis! { /// needed for weight calculation. /// /// Returns: - /// - `BenchmarkInfo` - Complete benchmark metadata available for this runtime. - fn benchmark_metadata(extra: bool) -> BenchmarkInfo; + /// - `RuntimeBenchmarkInfo` - Complete benchmark metadata available for this runtime. + fn benchmark_metadata(extra: bool) -> RuntimeBenchmarkInfo; /// Dispatch the given benchmark. fn dispatch_benchmark(config: BenchmarkConfig) -> Result, sp_runtime::RuntimeString>; diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 789db6c3fd5b..943449fe396c 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -18,8 +18,8 @@ use super::{writer, PalletCmd}; use codec::{Decode, Encode}; use frame_benchmarking::{ - Analysis, AnalysisChoice, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkInfo, - BenchmarkParameter, BenchmarkResult, BenchmarkSelector, + Analysis, AnalysisChoice, BenchmarkBatch, BenchmarkBatchSplitResults, BenchmarkList, + BenchmarkParameter, BenchmarkResult, BenchmarkSelector, RuntimeBenchmarkInfo, }; use frame_support::{ traits::StorageInfo, @@ -28,10 +28,11 @@ use frame_support::{ use linked_hash_map::LinkedHashMap; use sc_cli::{execution_method_from_cli, CliConfiguration, Result, SharedParams}; use sc_client_db::BenchmarkingState; -use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; +use sc_executor::{HeapAllocStrategy, RuntimeVersion, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; use sc_service::Configuration; use serde::Serialize; use sp_core::{ + blake2_64, offchain::{ testing::{TestOffchainExt, TestTransactionPoolExt}, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, @@ -142,6 +143,10 @@ This could mean that you either did not build the node correctly with the \ `--features runtime-benchmarks` flag, or the chain spec that you are using was \ not created by a node that was compiled with the flag"; +/// Could not query `RuntimeVersion`, which is required +const ERROR_RUNTIME_VERSION_NOT_FOUND: &'static str = "Could not query the runtime version. \ +This should never happen, please report this issue."; + impl PalletCmd { /// Runs the command and benchmarks the chain. pub fn run(&self, config: Configuration) -> Result<()> @@ -239,8 +244,33 @@ impl PalletCmd { extensions }; - // Get Benchmark List let state = &state_without_tracking; + + // Get runtime version + let runtime_version_raw = StateMachine::new( + state, + &mut changes, + &executor, + "Core_version", + &[], + &mut extensions(), + &sp_state_machine::backend::BackendRuntimeCode::new(state).runtime_code()?, + CallContext::Offchain, + ) + .execute() + .map_err(|e| format!("{}: {}", ERROR_RUNTIME_VERSION_NOT_FOUND, e))?; + + let runtime_version = ::decode(&mut &runtime_version_raw[..]) + .map_err(|e| format!("Failed to decode runtime version: {:?}", e))?; + + // Get the version of `Benchmark` runtime API. + let (_, version) = runtime_version + .apis + .iter() + .find(|(name, _)| name == &blake2_64(b"Benchmark")) + .ok_or("Benchmark API not found in runtime version apis")?; + + // Get Benchmark List let result = StateMachine::new( state, &mut changes, @@ -254,9 +284,16 @@ impl PalletCmd { .execute() .map_err(|e| format!("{}: {}", ERROR_METADATA_NOT_FOUND, e))?; - let BenchmarkInfo { list, storage_info, max_extrinsic_weight, db_weight } = - ::decode(&mut &result[..]) - .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))?; + let RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight, db_weight } = { + if *version == 2 { + ::decode(&mut &result[..]) + .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))? + } else { + <(Vec, Vec) as Decode>::decode(&mut &result[..]) + .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))? + .into() + } + }; if let Some(json_input) = &self.json_input { let raw_data = match std::fs::read(json_input) { From d9920b5c04d17e627b9439fef512251518badb46 Mon Sep 17 00:00:00 2001 From: dastansam Date: Fri, 12 Apr 2024 18:59:31 +0200 Subject: [PATCH 18/23] Resolve comments --- .gitlab/pipeline/test.yml | 2 +- Cargo.lock | 2 +- prdoc/pr_4020.prdoc | 37 ++++---- .../benchmarking-cli/src/pallet/command.rs | 89 +++++++------------ templates/parachain/runtime/src/apis.rs | 20 +++-- 5 files changed, 69 insertions(+), 81 deletions(-) diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml index ffbee9cdcb47..f0ea6959c084 100644 --- a/.gitlab/pipeline/test.yml +++ b/.gitlab/pipeline/test.yml @@ -338,7 +338,7 @@ quick-benchmarks-omni: WASM_BUILD_RUSTFLAGS: "-C debug-assertions" script: - time cargo build --locked --quiet --release -p asset-hub-westend-runtime --features runtime-benchmarks - - time cargo run --locked --release -p frame-omni-bencher --quiet -- v1 benchmark pallet --runtime target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm --all --steps 2 --repeat 1 --quiet --repeat 1 --sanity-weight-check ignore + - time cargo run --locked --release -p frame-omni-bencher --quiet -- v1 benchmark pallet --runtime target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm --all --steps 2 --repeat 1 --quiet --sanity-weight-check ignore test-frame-examples-compile-to-wasm: # into one job diff --git a/Cargo.lock b/Cargo.lock index c636f7af2aa0..f741a6fa1277 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5728,7 +5728,7 @@ dependencies = [ "Inflector", "array-bytes 6.1.0", "chrono", - "clap 4.4.18", + "clap 4.5.3", "color-print", "comfy-table", "frame-benchmarking", diff --git a/prdoc/pr_4020.prdoc b/prdoc/pr_4020.prdoc index 68af52649d4d..57077ff986f3 100644 --- a/prdoc/pr_4020.prdoc +++ b/prdoc/pr_4020.prdoc @@ -13,45 +13,52 @@ doc: During benchmark execution developers can either choose to throw an error, log a warning, or ignore if the weight exceeds the limit. Default behaviour is warning. This can be configured by passing an argument to `--sanity-check` flag in the benchmarking CLI. - Note: This introduces a breaking change for `frame_benchmarking::Benchmark` runtime API. `benchmark_metadata` function now returns new struct `BenchmarkInfo` - that encapsulates exhaustive benchmarks related information. To ensure backwards compatibility, `BenchmarkInfo` can be created from previous + Note: This introduces a breaking change for `frame_benchmarking::Benchmark` runtime API. `benchmark_metadata` function now returns new struct `RuntimeBenchmarkInfo` + that encapsulates exhaustive benchmarks related information. To ensure backwards compatibility, `RuntimeBenchmarkInfo` can be created from previous return type: `(Vec, Vec)`. - The easiest way to migrate is to replace is to change return type and convert the tuple to `BenchmarkInfo`: + It is strongly recommended to use weight sanity check to ensure your benchmarks are within the weight limit: ``` --- a/path/to/runtime.rs +++ b/path/to/runtime.rs @@ -1,3 +1,4 @@ -fn benchmark_metadata(extra: bool) -> (Vec, Vec) { - +fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + +fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { /// ... - let mut list = Vec::::new(); - list_benchmarks!(list, extra); - - let storage_info = AllPalletsWithSystem::storage_info(); - + +let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + +let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); -(list, storage_info) - +(list, storage_info).into() + +RuntimeBenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } ``` - However, it is strongly recommended to use weight sanity check to ensure your benchmarks are within the weight limit: + If you choose to ignore it, the easiest way to migrate is to change the return type by converting previous tuple to `RuntimeBenchmarkInfo`: ``` --- a/path/to/runtime.rs +++ b/path/to/runtime.rs @@ -1,3 +1,4 @@ -fn benchmark_metadata(extra: bool) -> (Vec, Vec) { - +fn benchmark_metadata(extra: bool) -> frame_benchmarking::BenchmarkInfo { + +fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { /// ... - +let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); - +let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + -(list, storage_info) - +BenchmarkInfo {list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } + +(list, storage_info).into() } ``` + Once the node is compiled with `runtime-benchmarks` feature, you can pass the `--sanity-check` flag to the benchmarking CLI or `ombi-bencher`: + + ``` + ./target/release/node benchmark pallet --sanity-check warning + frame-omni-bencher v1 benchmark pallet --sanity-check error + ``` + crates: - name: "frame-benchmarking" - name: "frame-benchmarking-cli" diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 3af884d91dcb..394998838a5a 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -34,8 +34,6 @@ use sc_chain_spec::json_patch::merge as json_merge; use sc_cli::{execution_method_from_cli, ChainSpec, CliConfiguration, Result, SharedParams}; use sc_client_db::BenchmarkingState; use sc_executor::{HeapAllocStrategy, RuntimeVersion, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; -use sc_service::Configuration; -use serde::Serialize; use sp_core::{ blake2_64, offchain::{ @@ -59,16 +57,6 @@ use std::{ time, }; -/// The inclusive range of a component. -#[derive(Serialize, Debug, Clone, Eq, PartialEq)] -pub(crate) struct ComponentRange { - /// Name of the component. - pub(crate) name: String, - /// Minimal valid value of the component. - min: u32, - /// Maximal valid value of the component. - pub(crate) max: u32, -} const LOG_TARGET: &'static str = "polkadot_sdk_frame::benchmark::pallet"; /// How the PoV size of a storage item should be estimated. @@ -217,20 +205,6 @@ impl PalletCmd { }) }); - if let Some(json_input) = &self.json_input { - let raw_data = match std::fs::read(json_input) { - Ok(raw_data) => raw_data, - Err(error) => - return Err(format!("Failed to read {:?}: {}", json_input, error).into()), - }; - let batches: Vec = match serde_json::from_slice(&raw_data) { - Ok(batches) => batches, - Err(error) => - return Err(format!("Failed to deserialize {:?}: {}", json_input, error).into()), - }; - return self.output_from_results(&batches) - } - let (genesis_storage, genesis_changes) = self.genesis_storage::(&chain_spec)?; let mut changes = genesis_changes.clone(); @@ -274,9 +248,7 @@ impl PalletCmd { .with_runtime_cache_size(2) .build(); - let state = &state_without_tracking; - - let runtime_version_raw = Self::exec_state_machine( + let runtime_version: RuntimeVersion = Self::exec_state_machine( StateMachine::new( state, &mut changes, @@ -290,9 +262,6 @@ impl PalletCmd { ERROR_RUNTIME_VERSION_NOT_FOUND, )?; - let runtime_version = ::decode(&mut &runtime_version_raw[..]) - .map_err(|e| format!("Failed to decode runtime version: {:?}", e))?; - // Get the version of `Benchmark` runtime API. let (_, version) = runtime_version .apis @@ -300,31 +269,38 @@ impl PalletCmd { .find(|(name, _)| name == &blake2_64(b"Benchmark")) .ok_or("Benchmark API not found in runtime version apis")?; - // Get Benchmark List - let benchmarks_metadata = Self::exec_state_machine( - StateMachine::new( - state, - &mut changes, - &executor, - "Benchmark_benchmark_metadata", - &(self.extra).encode(), - &mut Self::build_extensions(executor.clone()), - &runtime_code, - CallContext::Offchain, - ), - ERROR_METADATA_NOT_FOUND, - )?; - let RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight, db_weight } = { if *version == 1 { - <(Vec, Vec) as Decode>::decode( - &mut &benchmarks_metadata[..], - ) - .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))? - .into() + // This ensures that we don't run sanity checks on API v1. + let old_benchmark_data: (Vec, Vec) = + Self::exec_state_machine( + StateMachine::new( + state, + &mut changes, + &executor, + "Benchmark_benchmark_metadata", + &(self.extra).encode(), + &mut Self::build_extensions(executor.clone()), + &runtime_code, + CallContext::Offchain, + ), + ERROR_METADATA_NOT_FOUND, + )?; + old_benchmark_data.into() } else { - ::decode(&mut &benchmarks_metadata[..]) - .map_err(|e| format!("Failed to decode benchmark metadata: {:?}", e))? + Self::exec_state_machine( + StateMachine::new( + state, + &mut changes, + &executor, + "Benchmark_benchmark_metadata", + &(self.extra).encode(), + &mut Self::build_extensions(executor.clone()), + &runtime_code, + CallContext::Offchain, + ), + ERROR_METADATA_NOT_FOUND, + )? } }; @@ -850,7 +826,7 @@ impl PalletCmd { let pov_analysis_choice: AnalysisChoice = self.output_pov_analysis.clone().try_into().map_err(writer::io_error)?; - // // Organize results by pallet into a JSON map + // Organize results by pallet into a JSON map let all_results = writer::map_results( &batches, &storage_info, @@ -888,8 +864,7 @@ impl PalletCmd { max_extrinsic_weight: Option, db_weight: Option, ) -> Result<()> { - let mut component_ranges = - HashMap::<(Vec, Vec), HashMap>::new(); + let mut component_ranges = HashMap::<(String, String), HashMap>::new(); for batch in batches { let range = component_ranges .entry(( diff --git a/templates/parachain/runtime/src/apis.rs b/templates/parachain/runtime/src/apis.rs index b13ba278fae6..3b542f6dbd39 100644 --- a/templates/parachain/runtime/src/apis.rs +++ b/templates/parachain/runtime/src/apis.rs @@ -213,21 +213,27 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; + fn benchmark_metadata(extra: bool) -> frame_benchmarking::RuntimeBenchmarkInfo { + use frame_benchmarking::{Benchmarking, BenchmarkList, RuntimeBenchmarkInfo}; + use frame_support::{traits::StorageInfoTrait, dispatch::DispatchClass}; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use super::configs::RuntimeBlockWeights; use super::*; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) + let max_extrinsic_weight = RuntimeBlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); + let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + + RuntimeBenchmarkInfo { + list, + storage_info, + max_extrinsic_weight: Some(max_extrinsic_weight), + db_weight: Some(db_weight), + } } fn dispatch_benchmark( From 9e933953420c5aea34331c3a02b047a0a4d61fe0 Mon Sep 17 00:00:00 2001 From: dastansam Date: Fri, 12 Apr 2024 22:24:32 +0200 Subject: [PATCH 19/23] Fix failing benchmarks --- substrate/utils/frame/benchmarking-cli/src/pallet/command.rs | 2 +- substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 394998838a5a..4758d99f7f62 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -254,7 +254,7 @@ impl PalletCmd { &mut changes, &executor, "Core_version", - &(self.extra).encode(), + &[], &mut Self::build_extensions(executor.clone()), &runtime_code, CallContext::Offchain, diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 92cd37344631..cf691b2a48d4 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -207,7 +207,10 @@ pub(crate) fn sanity_weight_check( in the worst case scenario and compared with the maximum extrinsic weight (the maximum weight \ that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In other words, \ each extrinsic is checked whether it will fit in an empty (meaning; empty of \ - `DispatchClass::Normal` extrinsics) block.\n\nResults:\n" + `DispatchClass::Normal` extrinsics) block. \n\nProvided values for the maximum extrinsic weight: \ + {:?} (ref_time), {:?} (proof_size)\n\nResults:\n", + max_extrinsic_weight.ref_time(), + max_extrinsic_weight.proof_size() ); let mut sanity_weight_check_passed = true; // Loop through all benchmark results. From 6a24466c296936402ca53f7f9310db2a216efe7a Mon Sep 17 00:00:00 2001 From: Dastan <88332432+dastansam@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:27:09 +0200 Subject: [PATCH 20/23] Update prdoc/pr_4020.prdoc Co-authored-by: Oliver Tale-Yazdi --- prdoc/pr_4020.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4020.prdoc b/prdoc/pr_4020.prdoc index 57077ff986f3..8ca1c64c720c 100644 --- a/prdoc/pr_4020.prdoc +++ b/prdoc/pr_4020.prdoc @@ -6,7 +6,7 @@ title: "Benchmarking: automatic weight sanity check" doc: - audience: Runtime Dev description: | - This PR introduces a new sanity weight check during benchmark execution to ensure that the weight of the function/extrinsic does not exceed the given limit. + This PR introduces a new sanity weight check after benchmark execution to ensure that the weight of the function/extrinsic does not exceed the block limit. Maximum extrinsic weight value and `RuntimeDbWeight` should be provided by the runtime API. Maximum weight value is usually `max_extrinsic` from `RuntimeBlockWeights` for `DispatchClass::Normal` type extrinsics. From 10e759f6936ba4cd83591f2fcfeb94dcd55354de Mon Sep 17 00:00:00 2001 From: dastansam Date: Mon, 15 Apr 2024 20:32:48 +0200 Subject: [PATCH 21/23] Resolve comments --- Cargo.lock | 1 - prdoc/pr_4020.prdoc | 6 +-- substrate/client/cli/src/arg_enums.rs | 1 - .../client/cli/src/params/shared_params.rs | 7 ++- substrate/frame/benchmarking/src/utils.rs | 12 ++++- .../utils/frame/benchmarking-cli/Cargo.toml | 1 - .../benchmarking-cli/src/pallet/writer.rs | 54 +++++++------------ templates/solochain/runtime/src/lib.rs | 1 + 8 files changed, 39 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 022485dd246f..2339aff34bcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5731,7 +5731,6 @@ dependencies = [ "array-bytes 6.1.0", "chrono", "clap 4.5.3", - "color-print", "comfy-table", "frame-benchmarking", "frame-support", diff --git a/prdoc/pr_4020.prdoc b/prdoc/pr_4020.prdoc index 8ca1c64c720c..d5fb8faa637a 100644 --- a/prdoc/pr_4020.prdoc +++ b/prdoc/pr_4020.prdoc @@ -52,11 +52,11 @@ doc: } ``` - Once the node is compiled with `runtime-benchmarks` feature, you can pass the `--sanity-check` flag to the benchmarking CLI or `ombi-bencher`: + Once the node is compiled with `runtime-benchmarks` feature, you can pass the `--sanity-weight-check` flag to the benchmarking CLI or `ombi-bencher`: ``` - ./target/release/node benchmark pallet --sanity-check warning - frame-omni-bencher v1 benchmark pallet --sanity-check error + ./target/release/node benchmark pallet --sanity-weight-check warning ... + frame-omni-bencher v1 benchmark pallet --sanity-weight-check error ... ``` crates: diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index 8674cb782eca..566bb02d4600 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -66,7 +66,6 @@ impl std::fmt::Display for WasmExecutionMethod { } /// How to output the result of the sanity weight check and what to do when it fails. -#[allow(missing_docs)] #[derive(Debug, Clone, Copy, ValueEnum, PartialEq)] #[value(rename_all = "kebab-case")] pub enum SanityWeightCheck { diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index 2a517bc1143b..42b9f66e5fd0 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -88,8 +88,11 @@ pub struct SharedParams { #[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)] pub tracing_receiver: TracingReceiver, - /// Sanity weight check for benchmarks. Checks that no benchmark function has a weight larger - /// than the (`DispatchClass::Normal`) max. normal class extrinsic weight. + /// Sanity weight check for benchmarks. Each extrinsic's weight function is executed + /// in the worst case scenario and compared with the maximum extrinsic weight (the maximum + /// weight that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In + /// other words, each extrinsic is checked whether it will fit in an empty (meaning; empty of + /// `DispatchClass::Normal` extrinsics) block. #[arg( long, value_name = "ERROR-LEVEL", diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index 60a124957457..fa6fe168ed76 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -230,7 +230,7 @@ pub struct BenchmarkMetadata { pub pov_modes: Vec<(Vec, Vec)>, } -/// Exhaustive benchmark info provided by the runtime. +/// Benchmark info provided by the runtime. #[derive(Encode, Decode, Default, Clone, PartialEq, Debug, TypeInfo)] pub struct RuntimeBenchmarkInfo { /// List of all benchmarks available for this runtime. @@ -255,6 +255,16 @@ sp_api::decl_runtime_apis! { /// Runtime api for benchmarking a FRAME runtime. #[api_version(2)] pub trait Benchmark { + /// Get the benchmark metadata available for this runtime. + /// + /// Parameters + /// - `extra`: Also list benchmarks marked "extra" which would otherwise not be + /// needed for weight calculation. + /// + /// Returns: + /// - `(Vec, Vec);` - list of all benchmarks available for this runtime. + #[changed_in(2)] + fn benchmark_metadata(extra: bool) -> (Vec, Vec); /// Get the benchmark metadata available for this runtime. /// /// Parameters diff --git a/substrate/utils/frame/benchmarking-cli/Cargo.toml b/substrate/utils/frame/benchmarking-cli/Cargo.toml index 55c271ce3a81..eeec21251049 100644 --- a/substrate/utils/frame/benchmarking-cli/Cargo.toml +++ b/substrate/utils/frame/benchmarking-cli/Cargo.toml @@ -21,7 +21,6 @@ chrono = "0.4" clap = { version = "4.5.3", features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.6.1" } comfy-table = { version = "7.1.0", default-features = false } -color-print = "0.3.4" handlebars = "5.1.0" Inflector = "0.11.4" itertools = "0.10.3" diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index cf691b2a48d4..2df7ab659c4d 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -25,6 +25,7 @@ use std::{ use inflector::Inflector; use itertools::Itertools; +use log::log; use sc_cli::SanityWeightCheck; use serde::Serialize; @@ -189,9 +190,12 @@ pub(crate) fn sanity_weight_check( db_weight: RuntimeDbWeight, sanity_weight_check: SanityWeightCheck, ) -> Result<(), std::io::Error> { - if sanity_weight_check == SanityWeightCheck::Ignore { - return Ok(()) - } + let log_level = match sanity_weight_check { + SanityWeightCheck::Error => log::Level::Error, + SanityWeightCheck::Warning => log::Level::Warn, + SanityWeightCheck::Ignore => return Ok(()), + }; + // Helper function to return max. component value (i.e. max. complexity parameter). fn max_component(parameter: &ComponentSlope, component_ranges: &Vec) -> u64 { for component in component_ranges { @@ -202,20 +206,13 @@ pub(crate) fn sanity_weight_check( 0 } - color_print::cprintln!( - "\nSanity Weight Check 🧐: each extrinsic's weight function is executed \ - in the worst case scenario and compared with the maximum extrinsic weight (the maximum weight \ - that can be put in a single block for an extrinsic with `DispatchClass::Normal`). In other words, \ - each extrinsic is checked whether it will fit in an empty (meaning; empty of \ - `DispatchClass::Normal` extrinsics) block. \n\nProvided values for the maximum extrinsic weight: \ - {:?} (ref_time), {:?} (proof_size)\n\nResults:\n", - max_extrinsic_weight.ref_time(), - max_extrinsic_weight.proof_size() + log::info!( + "Starting the Sanity Weight Check:\nMaximum extrinsic weight value: {:?}\nResults:\n", + max_extrinsic_weight ); let mut sanity_weight_check_passed = true; // Loop through all benchmark results. - for ((pallet, instance), results) in all_results.iter() { - println!("Pallet: {}\nInstance: {}\n", pallet, instance); + for (_, results) in all_results.iter() { for result in results { // Constant `ref_time` & `pov_size`. let mut total_weight = Weight::from_parts( @@ -261,36 +258,23 @@ pub(crate) fn sanity_weight_check( } // Comparing (worst case scenario) the extrinsic weight against the maximum extrinsic // weight. - if total_weight.ref_time() > max_extrinsic_weight.ref_time() || - total_weight.proof_size() > max_extrinsic_weight.proof_size() - { + if total_weight.any_gt(max_extrinsic_weight) { sanity_weight_check_passed = false; - color_print::cprintln!("WARNING!!!",); - color_print::cprintln!( - "The following extrinsic exceeds the maximum extrinsic weight:", - ); - } - color_print::cprintln!("- '{}': {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", + log!(log_level, "The following extrinsic exceeds the maximum extrinsic weight: \n - '{}': {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", result.name, total_weight, (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, (total_weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, ); + } } } - if sanity_weight_check_passed { - color_print::cprintln!("Your extrinsics passed the Sanity Weight Check 😃!\n"); - } else { - color_print::cprintln!( - "Your extrinsics failed the Sanity Weight Check, please review \ - the extrinsic's logic and/or the associated benchmark function.\n", - ); - if sanity_weight_check == SanityWeightCheck::Error { - return Err(io_error(&String::from( - "One or more extrinsics exceed the maximum extrinsic weight", - ))) - } + if !sanity_weight_check_passed && sanity_weight_check == SanityWeightCheck::Error { + return Err(io_error(&String::from( + "One or more extrinsics exceed the maximum extrinsic weight", + ))) } + Ok(()) } diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 9966115c9d15..e383071fe7de 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -527,6 +527,7 @@ impl_runtime_apis! { let storage_info = AllPalletsWithSystem::storage_info(); let max_extrinsic_weight = BlockWeights::get().per_class.get(DispatchClass::Normal).max_extrinsic.unwrap(); let db_weight: frame_support::weights::RuntimeDbWeight = ::DbWeight::get(); + RuntimeBenchmarkInfo { list, storage_info, max_extrinsic_weight: Some(max_extrinsic_weight), db_weight: Some(db_weight) } } From 1f225d1129394945a48ae1268a27bb84a42d1d8d Mon Sep 17 00:00:00 2001 From: dastansam Date: Mon, 15 Apr 2024 22:29:33 +0200 Subject: [PATCH 22/23] More log fixes --- substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs index 2df7ab659c4d..abccc114a106 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs @@ -212,7 +212,7 @@ pub(crate) fn sanity_weight_check( ); let mut sanity_weight_check_passed = true; // Loop through all benchmark results. - for (_, results) in all_results.iter() { + for ((pallet, _), results) in all_results.iter() { for result in results { // Constant `ref_time` & `pov_size`. let mut total_weight = Weight::from_parts( @@ -260,7 +260,7 @@ pub(crate) fn sanity_weight_check( // weight. if total_weight.any_gt(max_extrinsic_weight) { sanity_weight_check_passed = false; - log!(log_level, "The following extrinsic exceeds the maximum extrinsic weight: \n - '{}': {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", + log!(log_level, " The following extrinsic exceeds the maximum extrinsic weight: \n - '{pallet}:{}': {:?}\nPercentage of max. extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)\n", result.name, total_weight, (total_weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, From d9efe906062551241368486d7715f5d3948e50ac Mon Sep 17 00:00:00 2001 From: Dastan <88332432+dastansam@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:21:37 +0200 Subject: [PATCH 23/23] Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi --- prdoc/pr_4020.prdoc | 2 +- substrate/utils/frame/benchmarking-cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_4020.prdoc b/prdoc/pr_4020.prdoc index d5fb8faa637a..da740c47c332 100644 --- a/prdoc/pr_4020.prdoc +++ b/prdoc/pr_4020.prdoc @@ -11,7 +11,7 @@ doc: `RuntimeBlockWeights` for `DispatchClass::Normal` type extrinsics. During benchmark execution developers can either choose to throw an error, log a warning, or ignore if the weight exceeds the limit. Default behaviour is - warning. This can be configured by passing an argument to `--sanity-check` flag in the benchmarking CLI. + warning. This can be configured by passing an argument to `--sanity-weight-check` flag in the benchmarking CLI. Note: This introduces a breaking change for `frame_benchmarking::Benchmark` runtime API. `benchmark_metadata` function now returns new struct `RuntimeBenchmarkInfo` that encapsulates exhaustive benchmarks related information. To ensure backwards compatibility, `RuntimeBenchmarkInfo` can be created from previous diff --git a/substrate/utils/frame/benchmarking-cli/Cargo.toml b/substrate/utils/frame/benchmarking-cli/Cargo.toml index eeec21251049..92169484c928 100644 --- a/substrate/utils/frame/benchmarking-cli/Cargo.toml +++ b/substrate/utils/frame/benchmarking-cli/Cargo.toml @@ -21,7 +21,7 @@ chrono = "0.4" clap = { version = "4.5.3", features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.6.1" } comfy-table = { version = "7.1.0", default-features = false } -handlebars = "5.1.0" +handlebars = "5.1.0" Inflector = "0.11.4" itertools = "0.10.3" lazy_static = "1.4.0"