From ad13331c2697cb11cd3987aea154b7179886d22c Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 16 Mar 2022 14:52:26 +0100 Subject: [PATCH 01/12] Integrate benchmark-overhead command Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 11 + cli/Cargo.toml | 2 + cli/src/cli.rs | 8 + cli/src/command.rs | 101 ++++++++- node/client/Cargo.toml | 10 + node/client/src/lib.rs | 253 ++++++++++++++++++++++- node/core/parachains-inherent/src/lib.rs | 5 + runtime/kusama/src/lib.rs | 2 + runtime/polkadot/src/lib.rs | 2 + runtime/rococo/src/lib.rs | 3 + runtime/westend/src/lib.rs | 2 + tests/benchmark_overhead_works.rs | 72 +++++++ 12 files changed, 466 insertions(+), 5 deletions(-) create mode 100644 tests/benchmark_overhead_works.rs diff --git a/Cargo.lock b/Cargo.lock index 8f0cc0fb1a1f..8024eabdcc45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6383,6 +6383,7 @@ dependencies = [ "frame-benchmarking-cli", "futures 0.3.21", "log", + "polkadot-client", "polkadot-node-core-pvf", "polkadot-node-metrics", "polkadot-performance-test", @@ -6404,12 +6405,18 @@ version = "0.9.18" dependencies = [ "beefy-primitives", "frame-benchmarking", + "frame-benchmarking-cli", + "frame-system", "frame-system-rpc-runtime-api", "kusama-runtime", "pallet-mmr-primitives", + "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "polkadot-core-primitives", + "polkadot-node-core-parachains-inherent", "polkadot-primitives", "polkadot-runtime", + "polkadot-runtime-common", "rococo-runtime", "sc-client-api", "sc-consensus", @@ -6421,11 +6428,15 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", + "sp-core", "sp-finality-grandpa", + "sp-inherents", + "sp-keyring", "sp-offchain", "sp-runtime", "sp-session", "sp-storage", + "sp-timestamp", "sp-transaction-pool", "westend-runtime", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 375360a0fb09..4bd4b2ad0e0f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -21,6 +21,7 @@ futures = "0.3.21" pyro = { package = "pyroscope", version = "0.3.1", optional = true } service = { package = "polkadot-service", path = "../node/service", default-features = false, optional = true } +polkadot-client = { path = "../node/client", optional = true } polkadot-node-core-pvf = { path = "../node/core/pvf", optional = true } polkadot-performance-test = { path = "../node/test/performance-test", optional = true } @@ -50,6 +51,7 @@ cli = [ "sc-tracing", "frame-benchmarking-cli", "try-runtime-cli", + "polkadot-client", "polkadot-node-core-pvf", "polkadot-performance-test", ] diff --git a/cli/src/cli.rs b/cli/src/cli.rs index e69259568ca5..fb4ee387a52e 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -54,6 +54,14 @@ pub enum Subcommand { #[clap(name = "benchmark", about = "Benchmark runtime pallets.")] Benchmark(frame_benchmarking_cli::BenchmarkCmd), + /// Sub command for benchmarking the per-block and per-extrinsic execution overhead. + #[clap( + name = "benchmark-overhead", + about = "Benchmark the per-block and per-extrinsic execution overhead." + )] + BenchmarkOverhead(frame_benchmarking_cli::OverheadCmd), + + /// Sub command for benchmarking the storage speed. #[clap(name = "benchmark-storage", about = "Benchmark storage speed.")] BenchmarkStorage(frame_benchmarking_cli::StorageCmd), diff --git a/cli/src/command.rs b/cli/src/command.rs index 9b817156031c..08b839a106e4 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -18,11 +18,11 @@ use crate::cli::{Cli, Subcommand}; use futures::future::TryFutureExt; use log::info; use sc_cli::{Role, RuntimeVersion, SubstrateCli}; -use service::{self, IdentifyVariant}; +use service::{self, HeaderBackend, IdentifyVariant}; use sp_core::crypto::Ss58AddressFormatRegistry; -use std::net::ToSocketAddrs; +use std::{net::ToSocketAddrs, sync::Arc}; -pub use crate::error::Error; +pub use crate::{error::Error, service::BlockId}; pub use polkadot_performance_test::PerfCheckError; impl std::convert::From for Error { @@ -475,6 +475,101 @@ pub fn run() -> Result<()> { #[cfg(not(feature = "polkadot-native"))] panic!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") }, + Some(Subcommand::BenchmarkOverhead(cmd)) => { + use polkadot_client::provide_inherent_data; + + let runner = cli.create_runner(cmd)?; + let chain_spec = &runner.config().chain_spec; + set_default_ss58_version(chain_spec); + ensure_dev(chain_spec).map_err(Error::Other)?; + + #[cfg(feature = "rococo-native")] + if chain_spec.is_rococo() || chain_spec.is_wococo() || chain_spec.is_versi() { + return Ok(runner.async_run(|mut config| { + let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; + + let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); + let inherent_data = provide_inherent_data(header) + .map_err(|e| format!("generating inherent data: {:?}", e))?; + + if let polkadot_client::Client::Rococo(pd) = &*client { + Ok(( + cmd.run(config, pd.clone(), inherent_data, client) + .map_err(Error::SubstrateCli), + task_manager, + )) + } else { + unreachable!("Checked above; qed") + } + })?) + } + + #[cfg(feature = "kusama-native")] + if chain_spec.is_kusama() { + return Ok(runner.async_run(|mut config| { + let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; + + let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); + let inherent_data = provide_inherent_data(header) + .map_err(|e| format!("generating inherent data: {:?}", e))?; + + if let polkadot_client::Client::Kusama(pd) = &*client { + Ok(( + cmd.run(config, pd.clone(), inherent_data, client) + .map_err(Error::SubstrateCli), + task_manager, + )) + } else { + unreachable!("Checked above; qed") + } + })?) + } + + #[cfg(feature = "westend-native")] + if chain_spec.is_westend() { + return Ok(runner.async_run(|mut config| { + let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; + + let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); + let inherent_data = provide_inherent_data(header) + .map_err(|e| format!("generating inherent data: {:?}", e))?; + + if let polkadot_client::Client::Westend(pd) = &*client { + Ok(( + cmd.run(config, pd.clone(), inherent_data, client) + .map_err(Error::SubstrateCli), + task_manager, + )) + } else { + unreachable!("Checked above; qed") + } + })?) + } + + #[cfg(feature = "polkadot-native")] + { + return Ok(runner.async_run(|mut config| { + let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; + + let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); + let inherent_data = provide_inherent_data(header) + .map_err(|e| format!("generating inherent data: {:?}", e))?; + + if let polkadot_client::Client::Polkadot(pd) = &*client { + Ok(( + cmd.run(config, pd.clone(), inherent_data, client) + .map_err(Error::SubstrateCli), + task_manager, + )) + } else { + unreachable!("Checked above; qed") + } + })?) + } + + #[cfg(not(feature = "polkadot-native"))] + unreachable!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") + }, Some(Subcommand::BenchmarkStorage(cmd)) => { let runner = cli.create_runner(cmd)?; let chain_spec = &runner.config().chain_spec; diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index b0eac0d72f7a..869612c64f6d 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -6,7 +6,10 @@ edition = "2021" [dependencies] frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -14,6 +17,10 @@ sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -37,7 +44,10 @@ kusama-runtime = { path = "../../runtime/kusama", optional = true } westend-runtime = { path = "../../runtime/westend", optional = true } rococo-runtime = { path = "../../runtime/rococo", optional = true } +polkadot-core-primitives = { path = "../../core-primitives" } polkadot-primitives = { path = "../../primitives" } +polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" } +polkadot-runtime-common = { path = "../../runtime/common" } [features] default = ["polkadot"] diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index e33cd096053b..f96d783f10ca 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -24,13 +24,15 @@ use polkadot_primitives::v2::{ }; use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider}; use sc_executor::NativeElseWasmExecutor; -use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi}; +use sp_api::{CallApiAt, Encode, NumberFor, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_consensus::BlockStatus; +use sp_core::Pair; +use sp_keyring::Sr25519Keyring; use sp_runtime::{ generic::{BlockId, SignedBlock}, traits::{BlakeTwo256, Block as BlockT}, - Justifications, + Justifications, OpaqueExtrinsic, }; use sp_storage::{ChildInfo, StorageData, StorageKey}; use std::sync::Arc; @@ -567,3 +569,250 @@ impl sp_blockchain::HeaderBackend for Client { } } } + +/// Provides a `SignedPayload` for any runtime. +/// +/// The first code block should set up all variables that are needed to create the +/// SignedPayload. The second block can make use of the SignedPayload. +/// +/// This is not done as a trait function since the return type depends on the runtime. +/// This macro therefore uses the same approach as [`with_client!`]. +macro_rules! with_raw_payload { + { + $self:ident, + { + $extra:ident, + $client:ident, + $raw_payload:ident + }, + { + $( $setup:tt )* + }, + ( + $period:expr, + $current_block:expr, + $nonce:expr, + $tip:expr, + $call:expr, + $genesis:expr + ), + { + $( $usage:tt )* + } + } => { + match $self { + #[cfg(feature = "polkadot")] + Self::Polkadot($client) => { + use polkadot_runtime as runtime; + + $( $setup )* + + let $extra: runtime::SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( + $period, + $current_block, + )), + frame_system::CheckNonce::::from($nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from($tip), + polkadot_runtime_common::claims::PrevalidateAttests::::new(), + ); + + let $raw_payload = runtime::SignedPayload::from_raw( + $call.clone(), + $extra.clone(), + ( + (), + runtime::VERSION.spec_version, + runtime::VERSION.transaction_version, + $genesis.clone(), + $genesis, + (), + (), + (), + (), + ), + ); + + $( $usage )* + }, + #[cfg(feature = "westend")] + Self::Westend($client) => { + use westend_runtime as runtime; + + $( $setup )* + + let $extra: runtime::SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( + $period, + $current_block, + )), + frame_system::CheckNonce::::from($nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from($tip), + ); + + let $raw_payload = runtime::SignedPayload::from_raw( + $call.clone(), + $extra.clone(), + ( + (), + runtime::VERSION.spec_version, + runtime::VERSION.transaction_version, + $genesis.clone(), + $genesis, + (), + (), + (), + ), + ); + + $( $usage )* + }, + #[cfg(feature = "kusama")] + Self::Kusama($client) => { + use kusama_runtime as runtime; + + $( $setup )* + + let $extra: runtime::SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( + $period, + $current_block, + )), + frame_system::CheckNonce::::from($nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from($tip), + ); + + let $raw_payload = runtime::SignedPayload::from_raw( + $call.clone(), + $extra.clone(), + ( + (), + runtime::VERSION.spec_version, + runtime::VERSION.transaction_version, + $genesis.clone(), + $genesis, + (), + (), + (), + ), + ); + + $( $usage )* + }, + #[cfg(feature = "rococo")] + Self::Rococo($client) => { + use rococo_runtime as runtime; + + $( $setup )* + + let $extra: runtime::SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( + $period, + $current_block, + )), + frame_system::CheckNonce::::from($nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from($tip), + ); + + let $raw_payload = runtime::SignedPayload::from_raw( + $call.clone(), + $extra.clone(), + ( + (), + runtime::VERSION.spec_version, + runtime::VERSION.transaction_version, + $genesis.clone(), + $genesis, + (), + (), + (), + ), + ); + + $( $usage )* + }, + } + } +} + +impl frame_benchmarking_cli::ExtrinsicBuilder for Client { + fn remark(&self, nonce: u32) -> std::result::Result { + with_raw_payload! { + self, + {extra, client, raw_payload}, + { + // First the setup code to init all the variables that are needed + // to build the signed extras. + use runtime::{Call, SystemCall}; + + let call = Call::System(SystemCall::remark { remark: vec![] }); + let bob = Sr25519Keyring::Bob.pair(); + + let period = polkadot_runtime_common::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; + + let current_block = 0; + let tip = 0; + let genesis = client.usage_info().chain.best_hash; + }, + (period, current_block, nonce, tip, call, genesis), + /* The SignedPayload is generated here */ + { + // Use the payload to generate a signature. + let signature = raw_payload.using_encoded(|payload| bob.sign(payload)); + + let ext = runtime::UncheckedExtrinsic::new_signed( + call, + sp_runtime::AccountId32::from(bob.public()).into(), + polkadot_core_primitives::Signature::Sr25519(signature.clone()), + extra, + ); + Ok(ext.into()) + } + } + } +} + +/// Generates inherent data for: Polkadot, Kusama, Westend and Rococo. +pub fn provide_inherent_data( + header: polkadot_core_primitives::Header, +) -> std::result::Result { + use sp_inherents::InherentDataProvider; + let mut inherent_data = sp_inherents::InherentData::new(); + + // Assume that all runtimes have the `timestamp` pallet. + let d = std::time::Duration::from_millis(0); + let timestamp = sp_timestamp::InherentDataProvider::new(d.into()); + timestamp.provide_inherent_data(&mut inherent_data)?; + + let para_data = polkadot_primitives::v2::InherentData { + bitfields: Vec::new(), + backed_candidates: Vec::new(), + disputes: Vec::new(), + parent_header: header, + }; + + polkadot_node_core_parachains_inherent::ParachainsInherentDataProvider::from_data(para_data) + .provide_inherent_data(&mut inherent_data)?; + + Ok(inherent_data) +} diff --git a/node/core/parachains-inherent/src/lib.rs b/node/core/parachains-inherent/src/lib.rs index 1feb7c5ffe3d..e7b465be1744 100644 --- a/node/core/parachains-inherent/src/lib.rs +++ b/node/core/parachains-inherent/src/lib.rs @@ -42,6 +42,11 @@ pub struct ParachainsInherentDataProvider { } impl ParachainsInherentDataProvider { + /// Create a [`Self`] directly from some [`ParachainsInherentData`]. + pub fn from_data(inherent_data: ParachainsInherentData) -> Self { + Self { inherent_data } + } + /// Create a new instance of the [`ParachainsInherentDataProvider`]. pub async fn create>( client: &C, diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index ae81a6999ca5..b950843294e2 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -75,6 +75,8 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; +#[cfg(feature = "std")] +pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; #[cfg(feature = "std")] diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 28bb3d0039bf..f310fdff8a16 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -77,6 +77,8 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; +#[cfg(feature = "std")] +pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; #[cfg(feature = "std")] diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index f459ca597536..7a6262110ffe 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -75,6 +75,9 @@ use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; +#[cfg(feature = "std")] +pub use frame_system::Call as SystemCall; + /// Constant values used within the runtime. use rococo_runtime_constants::{currency::*, fee::*, time::*}; diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index bffcdb73b9fd..fbc4d481a31e 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -72,6 +72,8 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use sp_version::NativeVersion; use sp_version::RuntimeVersion; +#[cfg(feature = "std")] +pub use frame_system::Call as SystemCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; #[cfg(feature = "std")] pub use pallet_staking::StakerStatus; diff --git a/tests/benchmark_overhead_works.rs b/tests/benchmark_overhead_works.rs new file mode 100644 index 000000000000..5cd7e0b999e3 --- /dev/null +++ b/tests/benchmark_overhead_works.rs @@ -0,0 +1,72 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use assert_cmd::cargo::cargo_bin; +use std::process::Command; +use tempfile::tempdir; + +static RUNTIMES: [&'static str; 6] = ["polkadot", "kusama", "westend", "rococo", "wococo", "versi"]; + +/// `benchmark-overhead` works for all dev runtimes. +#[test] +#[cfg(unix)] +fn benchmark_overhead_works() { + for runtime in RUNTIMES { + benchmark_overhead(format!("{}-dev", runtime)) + } +} + +/// `benchmark-overhead` rejects all non-dev runtimes. +#[test] +#[cfg(unix)] +fn benchmark_overhead_rejects_non_dev_runtimes() { + for runtime in RUNTIMES { + let tmp_dir = tempdir().expect("could not create a temp dir"); + let status = Command::new(cargo_bin("polkadot")) + .args(["benchmark-overhead", "--chain", runtime, "-d"]) + .arg(tmp_dir.path()) + .status() + .unwrap(); + + assert!(!status.success()); + } +} + +fn benchmark_overhead(runtime: String) { + let tmp_dir = tempdir().expect("could not create a temp dir"); + let base_path = tmp_dir.path(); + + // Only put 5 extrinsics into the block otherwise it takes forever to build it + // especially for a non-release build. + let status = Command::new(cargo_bin("polkadot")) + .args(["benchmark-overhead", "--chain", &runtime]) + .arg("-d") + .arg(base_path) + .arg("--weight-path") + .arg(base_path) + .args(["--warmup", "5", "--repeat", "5"]) + .args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) + .args(["--max-ext-per-block", "5"]) + .status() + .unwrap(); + assert!(status.success()); + + // Weight files have been created. + assert!(base_path.join("block_weights.rs").exists()); + assert!(base_path.join("extrinsic_weights.rs").exists()); +} From 81cf18fc1d51cb81b2409c2219cb0833925c8a0c Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 16 Mar 2022 16:05:05 +0100 Subject: [PATCH 02/12] Beauty fix test Signed-off-by: Oliver Tale-Yazdi --- cli/src/command.rs | 2 +- tests/benchmark_overhead_works.rs | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 08b839a106e4..028a312174f9 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -20,7 +20,7 @@ use log::info; use sc_cli::{Role, RuntimeVersion, SubstrateCli}; use service::{self, HeaderBackend, IdentifyVariant}; use sp_core::crypto::Ss58AddressFormatRegistry; -use std::{net::ToSocketAddrs, sync::Arc}; +use std::net::ToSocketAddrs; pub use crate::{error::Error, service::BlockId}; pub use polkadot_performance_test::PerfCheckError; diff --git a/tests/benchmark_overhead_works.rs b/tests/benchmark_overhead_works.rs index 5cd7e0b999e3..833169328b45 100644 --- a/tests/benchmark_overhead_works.rs +++ b/tests/benchmark_overhead_works.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use assert_cmd::cargo::cargo_bin; -use std::process::Command; +use std::{process::Command, result::Result}; use tempfile::tempdir; static RUNTIMES: [&'static str; 6] = ["polkadot", "kusama", "westend", "rococo", "wococo", "versi"]; @@ -27,7 +27,7 @@ static RUNTIMES: [&'static str; 6] = ["polkadot", "kusama", "westend", "rococo", #[cfg(unix)] fn benchmark_overhead_works() { for runtime in RUNTIMES { - benchmark_overhead(format!("{}-dev", runtime)) + assert!(benchmark_overhead(format!("{}-dev", runtime)).is_ok()); } } @@ -36,18 +36,11 @@ fn benchmark_overhead_works() { #[cfg(unix)] fn benchmark_overhead_rejects_non_dev_runtimes() { for runtime in RUNTIMES { - let tmp_dir = tempdir().expect("could not create a temp dir"); - let status = Command::new(cargo_bin("polkadot")) - .args(["benchmark-overhead", "--chain", runtime, "-d"]) - .arg(tmp_dir.path()) - .status() - .unwrap(); - - assert!(!status.success()); + assert!(benchmark_overhead(runtime.into()).is_err()); } } -fn benchmark_overhead(runtime: String) { +fn benchmark_overhead(runtime: String) -> Result<(), String> { let tmp_dir = tempdir().expect("could not create a temp dir"); let base_path = tmp_dir.path(); @@ -63,10 +56,14 @@ fn benchmark_overhead(runtime: String) { .args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) .args(["--max-ext-per-block", "5"]) .status() - .unwrap(); - assert!(status.success()); + .map_err(|e| format!("command failed: {:?}", e))?; + + if !status.success() { + return Err("Command failed".into()) + } // Weight files have been created. assert!(base_path.join("block_weights.rs").exists()); assert!(base_path.join("extrinsic_weights.rs").exists()); + Ok(()) } From 30e3f7eda53c36ce09a8eb42e16a7edcc236ed2a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 24 Mar 2022 12:39:12 +0100 Subject: [PATCH 03/12] Spellcheck on Signed-off-by: Oliver Tale-Yazdi --- node/client/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index f96d783f10ca..6b05c0f3507a 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -573,7 +573,7 @@ impl sp_blockchain::HeaderBackend for Client { /// Provides a `SignedPayload` for any runtime. /// /// The first code block should set up all variables that are needed to create the -/// SignedPayload. The second block can make use of the SignedPayload. +/// `SignedPayload`. The second block can make use of the `SignedPayload`. /// /// This is not done as a trait function since the return type depends on the runtime. /// This macro therefore uses the same approach as [`with_client!`]. From 2d3bcd0212c438f6b96755900a01762592d90265 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 24 Mar 2022 18:11:44 +0100 Subject: [PATCH 04/12] Remove constants:: module Signed-off-by: Oliver Tale-Yazdi --- runtime/kusama/constants/src/weights/mod.rs | 4 ++-- runtime/polkadot/constants/src/weights/mod.rs | 4 ++-- runtime/rococo/constants/src/weights/mod.rs | 4 ++-- runtime/westend/constants/src/weights/mod.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/constants/src/weights/mod.rs b/runtime/kusama/constants/src/weights/mod.rs index ed0b4dbcd47f..3f8bc612c064 100644 --- a/runtime/kusama/constants/src/weights/mod.rs +++ b/runtime/kusama/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::constants::BlockExecutionWeight; -pub use extrinsic_weights::constants::ExtrinsicBaseWeight; +pub use block_weights::BlockExecutionWeight; +pub use extrinsic_weights::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/polkadot/constants/src/weights/mod.rs b/runtime/polkadot/constants/src/weights/mod.rs index ed0b4dbcd47f..3f8bc612c064 100644 --- a/runtime/polkadot/constants/src/weights/mod.rs +++ b/runtime/polkadot/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::constants::BlockExecutionWeight; -pub use extrinsic_weights::constants::ExtrinsicBaseWeight; +pub use block_weights::BlockExecutionWeight; +pub use extrinsic_weights::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/rococo/constants/src/weights/mod.rs b/runtime/rococo/constants/src/weights/mod.rs index ed0b4dbcd47f..3f8bc612c064 100644 --- a/runtime/rococo/constants/src/weights/mod.rs +++ b/runtime/rococo/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::constants::BlockExecutionWeight; -pub use extrinsic_weights::constants::ExtrinsicBaseWeight; +pub use block_weights::BlockExecutionWeight; +pub use extrinsic_weights::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/westend/constants/src/weights/mod.rs b/runtime/westend/constants/src/weights/mod.rs index ed0b4dbcd47f..3f8bc612c064 100644 --- a/runtime/westend/constants/src/weights/mod.rs +++ b/runtime/westend/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::constants::BlockExecutionWeight; -pub use extrinsic_weights::constants::ExtrinsicBaseWeight; +pub use block_weights::BlockExecutionWeight; +pub use extrinsic_weights::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; From d77bf977f6bca0b1ded35daa2fd54b97e18a67db Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 24 Mar 2022 18:12:04 +0100 Subject: [PATCH 05/12] Update block+extrinsic weights Signed-off-by: Oliver Tale-Yazdi --- .../constants/src/weights/block_weights.rs | 90 +++++++++++++------ .../src/weights/extrinsic_weights.rs | 90 +++++++++++++------ .../constants/src/weights/block_weights.rs | 90 +++++++++++++------ .../src/weights/extrinsic_weights.rs | 90 +++++++++++++------ .../constants/src/weights/block_weights.rs | 90 +++++++++++++------ .../src/weights/extrinsic_weights.rs | 90 +++++++++++++------ .../constants/src/weights/block_weights.rs | 90 +++++++++++++------ .../src/weights/extrinsic_weights.rs | 90 +++++++++++++------ 8 files changed, 512 insertions(+), 208 deletions(-) diff --git a/runtime/kusama/constants/src/weights/block_weights.rs b/runtime/kusama/constants/src/weights/block_weights.rs index 4db90f0c0207..5c556de8e766 100644 --- a/runtime/kusama/constants/src/weights/block_weights.rs +++ b/runtime/kusama/constants/src/weights/block_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Importing a block with 0 Extrinsics. - pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/kusama/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// kusama-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/kusama/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute an empty block. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 4_118_220, 4_438_558 + /// Average: 4_168_174 + /// Median: 4_158_502 + /// StdDev: 47195.34 + /// + /// Percentiles [ns]: + /// 99th: 4_279_128 + /// 95th: 4_249_714 + /// 75th: 4_180_317 + pub const BlockExecutionWeight: Weight = 4_168_174 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::BlockExecutionWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::BlockExecutionWeight::get(); - - // At least 100 µs. - assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); - // At most 50 ms. - assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); - } + // At least 100 µs. + assert!( + w >= 100 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w <= 50 * constants::WEIGHT_PER_MILLIS, + "Weight should be at most 50 ms." + ); } } diff --git a/runtime/kusama/constants/src/weights/extrinsic_weights.rs b/runtime/kusama/constants/src/weights/extrinsic_weights.rs index 158ba99c6a4c..c4232ad900b5 100644 --- a/runtime/kusama/constants/src/weights/extrinsic_weights.rs +++ b/runtime/kusama/constants/src/weights/extrinsic_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Executing a NO-OP `System::remarks` Extrinsic. - pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/kusama/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// kusama-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/kusama/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute a NO-OP extrinsic eg. `System::remark`. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 80_176, 81_558 + /// Average: 80_350 + /// Median: 80_335 + /// StdDev: 136.56 + /// + /// Percentiles [ns]: + /// 99th: 80_492 + /// 95th: 80_459 + /// 75th: 80_377 + pub const ExtrinsicBaseWeight: Weight = 80_350 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::ExtrinsicBaseWeight::get(); - - // At least 10 µs. - assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); - // At most 1 ms. - assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); - } + // At least 10 µs. + assert!( + w >= 10 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w <= constants::WEIGHT_PER_MILLIS, + "Weight should be at most 1 ms." + ); } } diff --git a/runtime/polkadot/constants/src/weights/block_weights.rs b/runtime/polkadot/constants/src/weights/block_weights.rs index 4db90f0c0207..c035d0b88ed7 100644 --- a/runtime/polkadot/constants/src/weights/block_weights.rs +++ b/runtime/polkadot/constants/src/weights/block_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Importing a block with 0 Extrinsics. - pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/polkadot/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// polkadot-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/polkadot/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute an empty block. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 4_435_555, 4_779_868 + /// Average: 4_503_502 + /// Median: 4_486_327 + /// StdDev: 59779.5 + /// + /// Percentiles [ns]: + /// 99th: 4_723_698 + /// 95th: 4_609_303 + /// 75th: 4_543_258 + pub const BlockExecutionWeight: Weight = 4_503_502 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::BlockExecutionWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::BlockExecutionWeight::get(); - - // At least 100 µs. - assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); - // At most 50 ms. - assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); - } + // At least 100 µs. + assert!( + w >= 100 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w <= 50 * constants::WEIGHT_PER_MILLIS, + "Weight should be at most 50 ms." + ); } } diff --git a/runtime/polkadot/constants/src/weights/extrinsic_weights.rs b/runtime/polkadot/constants/src/weights/extrinsic_weights.rs index 158ba99c6a4c..2c20cd326fb9 100644 --- a/runtime/polkadot/constants/src/weights/extrinsic_weights.rs +++ b/runtime/polkadot/constants/src/weights/extrinsic_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Executing a NO-OP `System::remarks` Extrinsic. - pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/polkadot/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// polkadot-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/polkadot/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute a NO-OP extrinsic eg. `System::remark`. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 82_602, 83_486 + /// Average: 82_855 + /// Median: 82_831 + /// StdDev: 118.86 + /// + /// Percentiles [ns]: + /// 99th: 83_135 + /// 95th: 83_080 + /// 75th: 82_890 + pub const ExtrinsicBaseWeight: Weight = 82_855 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::ExtrinsicBaseWeight::get(); - - // At least 10 µs. - assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); - // At most 1 ms. - assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); - } + // At least 10 µs. + assert!( + w >= 10 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w <= constants::WEIGHT_PER_MILLIS, + "Weight should be at most 1 ms." + ); } } diff --git a/runtime/rococo/constants/src/weights/block_weights.rs b/runtime/rococo/constants/src/weights/block_weights.rs index 4db90f0c0207..9c00241a579e 100644 --- a/runtime/rococo/constants/src/weights/block_weights.rs +++ b/runtime/rococo/constants/src/weights/block_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Importing a block with 0 Extrinsics. - pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/rococo/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// rococo-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/rococo/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute an empty block. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 3_063_393, 3_278_407 + /// Average: 3_098_278 + /// Median: 3_076_394 + /// StdDev: 46158.3 + /// + /// Percentiles [ns]: + /// 99th: 3_266_514 + /// 95th: 3_205_264 + /// 75th: 3_101_379 + pub const BlockExecutionWeight: Weight = 3_098_278 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::BlockExecutionWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::BlockExecutionWeight::get(); - - // At least 100 µs. - assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); - // At most 50 ms. - assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); - } + // At least 100 µs. + assert!( + w >= 100 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w <= 50 * constants::WEIGHT_PER_MILLIS, + "Weight should be at most 50 ms." + ); } } diff --git a/runtime/rococo/constants/src/weights/extrinsic_weights.rs b/runtime/rococo/constants/src/weights/extrinsic_weights.rs index 158ba99c6a4c..ee4dfc3a89c7 100644 --- a/runtime/rococo/constants/src/weights/extrinsic_weights.rs +++ b/runtime/rococo/constants/src/weights/extrinsic_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Executing a NO-OP `System::remarks` Extrinsic. - pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/rococo/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// rococo-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/rococo/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute a NO-OP extrinsic eg. `System::remark`. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 73_999, 74_403 + /// Average: 74_171 + /// Median: 74_161 + /// StdDev: 85.56 + /// + /// Percentiles [ns]: + /// 99th: 74_375 + /// 95th: 74_309 + /// 75th: 74_241 + pub const ExtrinsicBaseWeight: Weight = 74_171 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::ExtrinsicBaseWeight::get(); - - // At least 10 µs. - assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); - // At most 1 ms. - assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); - } + // At least 10 µs. + assert!( + w >= 10 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w <= constants::WEIGHT_PER_MILLIS, + "Weight should be at most 1 ms." + ); } } diff --git a/runtime/westend/constants/src/weights/block_weights.rs b/runtime/westend/constants/src/weights/block_weights.rs index 4db90f0c0207..e2e2f0b4738b 100644 --- a/runtime/westend/constants/src/weights/block_weights.rs +++ b/runtime/westend/constants/src/weights/block_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Importing a block with 0 Extrinsics. - pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/westend/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// westend-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/westend/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute an empty block. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 3_553_100, 3_737_847 + /// Average: 3_592_873 + /// Median: 3_573_460 + /// StdDev: 34948.46 + /// + /// Percentiles [ns]: + /// 99th: 3_699_717 + /// 95th: 3_660_927 + /// 75th: 3_608_068 + pub const BlockExecutionWeight: Weight = 3_592_873 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::BlockExecutionWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::BlockExecutionWeight::get(); - - // At least 100 µs. - assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); - // At most 50 ms. - assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); - } + // At least 100 µs. + assert!( + w >= 100 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w <= 50 * constants::WEIGHT_PER_MILLIS, + "Weight should be at most 50 ms." + ); } } diff --git a/runtime/westend/constants/src/weights/extrinsic_weights.rs b/runtime/westend/constants/src/weights/extrinsic_weights.rs index 158ba99c6a4c..5e90f36d4842 100644 --- a/runtime/westend/constants/src/weights/extrinsic_weights.rs +++ b/runtime/westend/constants/src/weights/extrinsic_weights.rs @@ -15,32 +15,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; - - parameter_types! { - /// Executing a NO-OP `System::remarks` Extrinsic. - pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; - } +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24 (Y/M/D) +//! +//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` +//! WARMUPS: `10`, REPEAT: `100` +//! WEIGHT-PATH: `runtime/westend/constants/src/weights/` +//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot +// benchmark-overhead +// --chain +// westend-dev +// --execution=wasm +// --wasm-execution=compiled +// --weight-path +// runtime/westend/constants/src/weights/ +// --warmup +// 10 +// --repeat +// 100 + +use frame_support::{ + parameter_types, + weights::{constants::WEIGHT_PER_NANOS, Weight}, +}; + +parameter_types! { + /// Time to execute a NO-OP extrinsic eg. `System::remark`. + /// Calculated by multiplying the *Average* with `1` and adding `0`. + /// + /// Stats [ns]: + /// Min, Max: 72_528, 72_806 + /// Average: 72_650 + /// Median: 72_642 + /// StdDev: 62.3 + /// + /// Percentiles [ns]: + /// 99th: 72_767 + /// 95th: 72_755 + /// 75th: 72_700 + pub const ExtrinsicBaseWeight: Weight = 72_650 * WEIGHT_PER_NANOS; +} + +#[cfg(test)] +mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::ExtrinsicBaseWeight::get(); - - // At least 10 µs. - assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); - // At most 1 ms. - assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); - } + // At least 10 µs. + assert!( + w >= 10 * constants::WEIGHT_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w <= constants::WEIGHT_PER_MILLIS, + "Weight should be at most 1 ms." + ); } } From f44f149c16ee940260f623f0aaf71a1887cdcc70 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 24 Mar 2022 18:12:43 +0100 Subject: [PATCH 06/12] Revert "Update block+extrinsic weights" This reverts commit d77bf977f6bca0b1ded35daa2fd54b97e18a67db. --- .../constants/src/weights/block_weights.rs | 90 ++++++------------- .../src/weights/extrinsic_weights.rs | 90 ++++++------------- .../constants/src/weights/block_weights.rs | 90 ++++++------------- .../src/weights/extrinsic_weights.rs | 90 ++++++------------- .../constants/src/weights/block_weights.rs | 90 ++++++------------- .../src/weights/extrinsic_weights.rs | 90 ++++++------------- .../constants/src/weights/block_weights.rs | 90 ++++++------------- .../src/weights/extrinsic_weights.rs | 90 ++++++------------- 8 files changed, 208 insertions(+), 512 deletions(-) diff --git a/runtime/kusama/constants/src/weights/block_weights.rs b/runtime/kusama/constants/src/weights/block_weights.rs index 5c556de8e766..4db90f0c0207 100644 --- a/runtime/kusama/constants/src/weights/block_weights.rs +++ b/runtime/kusama/constants/src/weights/block_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/kusama/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// kusama-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/kusama/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute an empty block. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 4_118_220, 4_438_558 - /// Average: 4_168_174 - /// Median: 4_158_502 - /// StdDev: 47195.34 - /// - /// Percentiles [ns]: - /// 99th: 4_279_128 - /// 95th: 4_249_714 - /// 75th: 4_180_317 - pub const BlockExecutionWeight: Weight = 4_168_174 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::BlockExecutionWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; + } - // At least 100 µs. - assert!( - w >= 100 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w <= 50 * constants::WEIGHT_PER_MILLIS, - "Weight should be at most 50 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::BlockExecutionWeight::get(); + + // At least 100 µs. + assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); + // At most 50 ms. + assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); + } } } diff --git a/runtime/kusama/constants/src/weights/extrinsic_weights.rs b/runtime/kusama/constants/src/weights/extrinsic_weights.rs index c4232ad900b5..158ba99c6a4c 100644 --- a/runtime/kusama/constants/src/weights/extrinsic_weights.rs +++ b/runtime/kusama/constants/src/weights/extrinsic_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/kusama/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// kusama-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/kusama/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute a NO-OP extrinsic eg. `System::remark`. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 80_176, 81_558 - /// Average: 80_350 - /// Median: 80_335 - /// StdDev: 136.56 - /// - /// Percentiles [ns]: - /// 99th: 80_492 - /// 95th: 80_459 - /// 75th: 80_377 - pub const ExtrinsicBaseWeight: Weight = 80_350 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::ExtrinsicBaseWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; + } - // At least 10 µs. - assert!( - w >= 10 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w <= constants::WEIGHT_PER_MILLIS, - "Weight should be at most 1 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::ExtrinsicBaseWeight::get(); + + // At least 10 µs. + assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); + // At most 1 ms. + assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); + } } } diff --git a/runtime/polkadot/constants/src/weights/block_weights.rs b/runtime/polkadot/constants/src/weights/block_weights.rs index c035d0b88ed7..4db90f0c0207 100644 --- a/runtime/polkadot/constants/src/weights/block_weights.rs +++ b/runtime/polkadot/constants/src/weights/block_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/polkadot/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// polkadot-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/polkadot/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute an empty block. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 4_435_555, 4_779_868 - /// Average: 4_503_502 - /// Median: 4_486_327 - /// StdDev: 59779.5 - /// - /// Percentiles [ns]: - /// 99th: 4_723_698 - /// 95th: 4_609_303 - /// 75th: 4_543_258 - pub const BlockExecutionWeight: Weight = 4_503_502 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::BlockExecutionWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; + } - // At least 100 µs. - assert!( - w >= 100 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w <= 50 * constants::WEIGHT_PER_MILLIS, - "Weight should be at most 50 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::BlockExecutionWeight::get(); + + // At least 100 µs. + assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); + // At most 50 ms. + assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); + } } } diff --git a/runtime/polkadot/constants/src/weights/extrinsic_weights.rs b/runtime/polkadot/constants/src/weights/extrinsic_weights.rs index 2c20cd326fb9..158ba99c6a4c 100644 --- a/runtime/polkadot/constants/src/weights/extrinsic_weights.rs +++ b/runtime/polkadot/constants/src/weights/extrinsic_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/polkadot/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// polkadot-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/polkadot/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute a NO-OP extrinsic eg. `System::remark`. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 82_602, 83_486 - /// Average: 82_855 - /// Median: 82_831 - /// StdDev: 118.86 - /// - /// Percentiles [ns]: - /// 99th: 83_135 - /// 95th: 83_080 - /// 75th: 82_890 - pub const ExtrinsicBaseWeight: Weight = 82_855 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::ExtrinsicBaseWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; + } - // At least 10 µs. - assert!( - w >= 10 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w <= constants::WEIGHT_PER_MILLIS, - "Weight should be at most 1 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::ExtrinsicBaseWeight::get(); + + // At least 10 µs. + assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); + // At most 1 ms. + assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); + } } } diff --git a/runtime/rococo/constants/src/weights/block_weights.rs b/runtime/rococo/constants/src/weights/block_weights.rs index 9c00241a579e..4db90f0c0207 100644 --- a/runtime/rococo/constants/src/weights/block_weights.rs +++ b/runtime/rococo/constants/src/weights/block_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/rococo/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// rococo-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/rococo/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute an empty block. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 3_063_393, 3_278_407 - /// Average: 3_098_278 - /// Median: 3_076_394 - /// StdDev: 46158.3 - /// - /// Percentiles [ns]: - /// 99th: 3_266_514 - /// 95th: 3_205_264 - /// 75th: 3_101_379 - pub const BlockExecutionWeight: Weight = 3_098_278 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::BlockExecutionWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; + } - // At least 100 µs. - assert!( - w >= 100 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w <= 50 * constants::WEIGHT_PER_MILLIS, - "Weight should be at most 50 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::BlockExecutionWeight::get(); + + // At least 100 µs. + assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); + // At most 50 ms. + assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); + } } } diff --git a/runtime/rococo/constants/src/weights/extrinsic_weights.rs b/runtime/rococo/constants/src/weights/extrinsic_weights.rs index ee4dfc3a89c7..158ba99c6a4c 100644 --- a/runtime/rococo/constants/src/weights/extrinsic_weights.rs +++ b/runtime/rococo/constants/src/weights/extrinsic_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/rococo/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// rococo-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/rococo/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute a NO-OP extrinsic eg. `System::remark`. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 73_999, 74_403 - /// Average: 74_171 - /// Median: 74_161 - /// StdDev: 85.56 - /// - /// Percentiles [ns]: - /// 99th: 74_375 - /// 95th: 74_309 - /// 75th: 74_241 - pub const ExtrinsicBaseWeight: Weight = 74_171 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::ExtrinsicBaseWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; + } - // At least 10 µs. - assert!( - w >= 10 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w <= constants::WEIGHT_PER_MILLIS, - "Weight should be at most 1 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::ExtrinsicBaseWeight::get(); + + // At least 10 µs. + assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); + // At most 1 ms. + assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); + } } } diff --git a/runtime/westend/constants/src/weights/block_weights.rs b/runtime/westend/constants/src/weights/block_weights.rs index e2e2f0b4738b..4db90f0c0207 100644 --- a/runtime/westend/constants/src/weights/block_weights.rs +++ b/runtime/westend/constants/src/weights/block_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/westend/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// westend-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/westend/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute an empty block. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 3_553_100, 3_737_847 - /// Average: 3_592_873 - /// Median: 3_573_460 - /// StdDev: 34948.46 - /// - /// Percentiles [ns]: - /// 99th: 3_699_717 - /// 95th: 3_660_927 - /// 75th: 3_608_068 - pub const BlockExecutionWeight: Weight = 3_592_873 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::BlockExecutionWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS; + } - // At least 100 µs. - assert!( - w >= 100 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w <= 50 * constants::WEIGHT_PER_MILLIS, - "Weight should be at most 50 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::BlockExecutionWeight::get(); + + // At least 100 µs. + assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs."); + // At most 50 ms. + assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms."); + } } } diff --git a/runtime/westend/constants/src/weights/extrinsic_weights.rs b/runtime/westend/constants/src/weights/extrinsic_weights.rs index 5e90f36d4842..158ba99c6a4c 100644 --- a/runtime/westend/constants/src/weights/extrinsic_weights.rs +++ b/runtime/westend/constants/src/weights/extrinsic_weights.rs @@ -15,70 +15,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24 (Y/M/D) -//! -//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development` -//! WARMUPS: `10`, REPEAT: `100` -//! WEIGHT-PATH: `runtime/westend/constants/src/weights/` -//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0` - -// Executed Command: -// ./target/production/polkadot -// benchmark-overhead -// --chain -// westend-dev -// --execution=wasm -// --wasm-execution=compiled -// --weight-path -// runtime/westend/constants/src/weights/ -// --warmup -// 10 -// --repeat -// 100 - -use frame_support::{ - parameter_types, - weights::{constants::WEIGHT_PER_NANOS, Weight}, -}; - -parameter_types! { - /// Time to execute a NO-OP extrinsic eg. `System::remark`. - /// Calculated by multiplying the *Average* with `1` and adding `0`. - /// - /// Stats [ns]: - /// Min, Max: 72_528, 72_806 - /// Average: 72_650 - /// Median: 72_642 - /// StdDev: 62.3 - /// - /// Percentiles [ns]: - /// 99th: 72_767 - /// 95th: 72_755 - /// 75th: 72_700 - pub const ExtrinsicBaseWeight: Weight = 72_650 * WEIGHT_PER_NANOS; -} - -#[cfg(test)] -mod test_weights { - use frame_support::weights::constants; - - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::ExtrinsicBaseWeight::get(); +pub mod constants { + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; + + parameter_types! { + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS; + } - // At least 10 µs. - assert!( - w >= 10 * constants::WEIGHT_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w <= constants::WEIGHT_PER_MILLIS, - "Weight should be at most 1 ms." - ); + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::ExtrinsicBaseWeight::get(); + + // At least 10 µs. + assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs."); + // At most 1 ms. + assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms."); + } } } From aa2f7732be3aea13602c7fbaae0dc17ef85443d4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 24 Mar 2022 18:13:03 +0100 Subject: [PATCH 07/12] Revert "Remove constants:: module" This reverts commit 2d3bcd0212c438f6b96755900a01762592d90265. --- runtime/kusama/constants/src/weights/mod.rs | 4 ++-- runtime/polkadot/constants/src/weights/mod.rs | 4 ++-- runtime/rococo/constants/src/weights/mod.rs | 4 ++-- runtime/westend/constants/src/weights/mod.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/constants/src/weights/mod.rs b/runtime/kusama/constants/src/weights/mod.rs index 3f8bc612c064..ed0b4dbcd47f 100644 --- a/runtime/kusama/constants/src/weights/mod.rs +++ b/runtime/kusama/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::BlockExecutionWeight; -pub use extrinsic_weights::ExtrinsicBaseWeight; +pub use block_weights::constants::BlockExecutionWeight; +pub use extrinsic_weights::constants::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/polkadot/constants/src/weights/mod.rs b/runtime/polkadot/constants/src/weights/mod.rs index 3f8bc612c064..ed0b4dbcd47f 100644 --- a/runtime/polkadot/constants/src/weights/mod.rs +++ b/runtime/polkadot/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::BlockExecutionWeight; -pub use extrinsic_weights::ExtrinsicBaseWeight; +pub use block_weights::constants::BlockExecutionWeight; +pub use extrinsic_weights::constants::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/rococo/constants/src/weights/mod.rs b/runtime/rococo/constants/src/weights/mod.rs index 3f8bc612c064..ed0b4dbcd47f 100644 --- a/runtime/rococo/constants/src/weights/mod.rs +++ b/runtime/rococo/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::BlockExecutionWeight; -pub use extrinsic_weights::ExtrinsicBaseWeight; +pub use block_weights::constants::BlockExecutionWeight; +pub use extrinsic_weights::constants::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/westend/constants/src/weights/mod.rs b/runtime/westend/constants/src/weights/mod.rs index 3f8bc612c064..ed0b4dbcd47f 100644 --- a/runtime/westend/constants/src/weights/mod.rs +++ b/runtime/westend/constants/src/weights/mod.rs @@ -22,7 +22,7 @@ pub mod extrinsic_weights; pub mod paritydb_weights; pub mod rocksdb_weights; -pub use block_weights::BlockExecutionWeight; -pub use extrinsic_weights::ExtrinsicBaseWeight; +pub use block_weights::constants::BlockExecutionWeight; +pub use extrinsic_weights::constants::ExtrinsicBaseWeight; pub use paritydb_weights::constants::ParityDbWeight; pub use rocksdb_weights::constants::RocksDbWeight; From bb056fc8f8fda9d7e81fd41dcaaa28cacc77eb0b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 28 Mar 2022 13:39:10 +0200 Subject: [PATCH 08/12] Review fixes Signed-off-by: Oliver Tale-Yazdi --- cli/src/command.rs | 10 +++++----- node/client/src/lib.rs | 6 ++++-- runtime/kusama/src/lib.rs | 1 - runtime/polkadot/src/lib.rs | 1 - runtime/rococo/src/lib.rs | 1 - runtime/westend/src/lib.rs | 1 - tests/benchmark_overhead_works.rs | 8 +++++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 028a312174f9..f8b73bca70b2 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -476,7 +476,7 @@ pub fn run() -> Result<()> { panic!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") }, Some(Subcommand::BenchmarkOverhead(cmd)) => { - use polkadot_client::provide_inherent_data; + use polkadot_client::benchmark_inherent_data; let runner = cli.create_runner(cmd)?; let chain_spec = &runner.config().chain_spec; @@ -489,7 +489,7 @@ pub fn run() -> Result<()> { let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); - let inherent_data = provide_inherent_data(header) + let inherent_data = benchmark_inherent_data(header) .map_err(|e| format!("generating inherent data: {:?}", e))?; if let polkadot_client::Client::Rococo(pd) = &*client { @@ -510,7 +510,7 @@ pub fn run() -> Result<()> { let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); - let inherent_data = provide_inherent_data(header) + let inherent_data = benchmark_inherent_data(header) .map_err(|e| format!("generating inherent data: {:?}", e))?; if let polkadot_client::Client::Kusama(pd) = &*client { @@ -531,7 +531,7 @@ pub fn run() -> Result<()> { let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); - let inherent_data = provide_inherent_data(header) + let inherent_data = benchmark_inherent_data(header) .map_err(|e| format!("generating inherent data: {:?}", e))?; if let polkadot_client::Client::Westend(pd) = &*client { @@ -552,7 +552,7 @@ pub fn run() -> Result<()> { let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)?; let header = client.header(BlockId::Number(0_u32.into())).unwrap().unwrap(); - let inherent_data = provide_inherent_data(header) + let inherent_data = benchmark_inherent_data(header) .map_err(|e| format!("generating inherent data: {:?}", e))?; if let polkadot_client::Client::Polkadot(pd) = &*client { diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index 6b05c0f3507a..d2ce6b429f1a 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -792,8 +792,10 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for Client { } } -/// Generates inherent data for: Polkadot, Kusama, Westend and Rococo. -pub fn provide_inherent_data( +/// Generates inherent data for benchmarking Polkadot, Kusama, Westend and Rococo. +/// +/// Not to be used outside of benchmarking since it returns mocked values. +pub fn benchmark_inherent_data( header: polkadot_core_primitives::Header, ) -> std::result::Result { use sp_inherents::InherentDataProvider; diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 41c0f91786c5..51d69e0e0dc8 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -75,7 +75,6 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -#[cfg(feature = "std")] pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index d9a59536c051..631c2b56b140 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -77,7 +77,6 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -#[cfg(feature = "std")] pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index d6eeb14c6628..904fcbdeaed0 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -75,7 +75,6 @@ use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; -#[cfg(feature = "std")] pub use frame_system::Call as SystemCall; /// Constant values used within the runtime. diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 845e25bfb5d6..d72e8557028e 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -72,7 +72,6 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -#[cfg(feature = "std")] pub use frame_system::Call as SystemCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; #[cfg(feature = "std")] diff --git a/tests/benchmark_overhead_works.rs b/tests/benchmark_overhead_works.rs index 833169328b45..63a819246cb3 100644 --- a/tests/benchmark_overhead_works.rs +++ b/tests/benchmark_overhead_works.rs @@ -27,7 +27,8 @@ static RUNTIMES: [&'static str; 6] = ["polkadot", "kusama", "westend", "rococo", #[cfg(unix)] fn benchmark_overhead_works() { for runtime in RUNTIMES { - assert!(benchmark_overhead(format!("{}-dev", runtime)).is_ok()); + let runtime = format!("{}-dev", runtime); + assert!(benchmark_overhead(runtime).is_ok()); } } @@ -44,8 +45,7 @@ fn benchmark_overhead(runtime: String) -> Result<(), String> { let tmp_dir = tempdir().expect("could not create a temp dir"); let base_path = tmp_dir.path(); - // Only put 5 extrinsics into the block otherwise it takes forever to build it - // especially for a non-release build. + // Invoke `benchmark-overhead` with all options to make sure that they are valid. let status = Command::new(cargo_bin("polkadot")) .args(["benchmark-overhead", "--chain", &runtime]) .arg("-d") @@ -54,6 +54,8 @@ fn benchmark_overhead(runtime: String) -> Result<(), String> { .arg(base_path) .args(["--warmup", "5", "--repeat", "5"]) .args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) + // Only put 5 extrinsics into the block otherwise it takes forever to build it + // especially for a non-release builds. .args(["--max-ext-per-block", "5"]) .status() .map_err(|e| format!("command failed: {:?}", e))?; From 64b523090cb3960adca4c03fb92a1a31fb367295 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 29 Mar 2022 11:51:27 +0200 Subject: [PATCH 09/12] Review fixes Signed-off-by: Oliver Tale-Yazdi --- node/client/src/lib.rs | 141 ++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 86 deletions(-) diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index d2ce6b429f1a..f3f5e0a86093 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -572,12 +572,14 @@ impl sp_blockchain::HeaderBackend for Client { /// Provides a `SignedPayload` for any runtime. /// +/// Should only be used for benchmarking as it is not tested for regular usage. +/// /// The first code block should set up all variables that are needed to create the /// `SignedPayload`. The second block can make use of the `SignedPayload`. /// /// This is not done as a trait function since the return type depends on the runtime. /// This macro therefore uses the same approach as [`with_client!`]. -macro_rules! with_raw_payload { +macro_rules! with_signed_payload { { $self:ident, { @@ -646,34 +648,8 @@ macro_rules! with_raw_payload { $( $setup )* - let $extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( - $period, - $current_block, - )), - frame_system::CheckNonce::::from($nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from($tip), - ); - - let $raw_payload = runtime::SignedPayload::from_raw( - $call.clone(), - $extra.clone(), - ( - (), - runtime::VERSION.spec_version, - runtime::VERSION.transaction_version, - $genesis.clone(), - $genesis, - (), - (), - (), - ), - ); + signed_payload!($extra, $raw_payload, + ($period, $current_block, $nonce, $tip, $call, $genesis)); $( $usage )* }, @@ -683,34 +659,8 @@ macro_rules! with_raw_payload { $( $setup )* - let $extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( - $period, - $current_block, - )), - frame_system::CheckNonce::::from($nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from($tip), - ); - - let $raw_payload = runtime::SignedPayload::from_raw( - $call.clone(), - $extra.clone(), - ( - (), - runtime::VERSION.spec_version, - runtime::VERSION.transaction_version, - $genesis.clone(), - $genesis, - (), - (), - (), - ), - ); + signed_payload!($extra, $raw_payload, + ($period, $current_block, $nonce, $tip, $call, $genesis)); $( $usage )* }, @@ -720,34 +670,8 @@ macro_rules! with_raw_payload { $( $setup )* - let $extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( - $period, - $current_block, - )), - frame_system::CheckNonce::::from($nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from($tip), - ); - - let $raw_payload = runtime::SignedPayload::from_raw( - $call.clone(), - $extra.clone(), - ( - (), - runtime::VERSION.spec_version, - runtime::VERSION.transaction_version, - $genesis.clone(), - $genesis, - (), - (), - (), - ), - ); + signed_payload!($extra, $raw_payload, + ($period, $current_block, $nonce, $tip, $call, $genesis)); $( $usage )* }, @@ -755,9 +679,54 @@ macro_rules! with_raw_payload { } } +/// Generates a `SignedPayload` for the Kusama, Westend and Rococo runtime. +/// +/// Should only be used for benchmarking as it is not tested for regular usage. +macro_rules! signed_payload { + ( + $extra:ident, $raw_payload:ident, + ( + $period:expr, + $current_block:expr, + $nonce:expr, + $tip:expr, + $call:expr, + $genesis:expr + ) + ) => { + let $extra: runtime::SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from( + sp_runtime::generic::Era::mortal($period, $current_block), + ), + frame_system::CheckNonce::::from($nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from($tip), + ); + + let $raw_payload = runtime::SignedPayload::from_raw( + $call.clone(), + $extra.clone(), + ( + (), + runtime::VERSION.spec_version, + runtime::VERSION.transaction_version, + $genesis.clone(), + $genesis, + (), + (), + (), + ), + ); + }; +} + impl frame_benchmarking_cli::ExtrinsicBuilder for Client { fn remark(&self, nonce: u32) -> std::result::Result { - with_raw_payload! { + with_signed_payload! { self, {extra, client, raw_payload}, { From 04c4397531ae4dadcf89ac9537945c4e3ef21688 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 30 Mar 2022 16:46:34 +0200 Subject: [PATCH 10/12] Review fixes Signed-off-by: Oliver Tale-Yazdi --- tests/benchmark_overhead_works.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/benchmark_overhead_works.rs b/tests/benchmark_overhead_works.rs index 63a819246cb3..19d949a5bfbc 100644 --- a/tests/benchmark_overhead_works.rs +++ b/tests/benchmark_overhead_works.rs @@ -24,7 +24,6 @@ static RUNTIMES: [&'static str; 6] = ["polkadot", "kusama", "westend", "rococo", /// `benchmark-overhead` works for all dev runtimes. #[test] -#[cfg(unix)] fn benchmark_overhead_works() { for runtime in RUNTIMES { let runtime = format!("{}-dev", runtime); @@ -34,7 +33,6 @@ fn benchmark_overhead_works() { /// `benchmark-overhead` rejects all non-dev runtimes. #[test] -#[cfg(unix)] fn benchmark_overhead_rejects_non_dev_runtimes() { for runtime in RUNTIMES { assert!(benchmark_overhead(runtime.into()).is_err()); From eecf736cd555a1bbda5d0286e2c1a3afed504ab3 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 30 Mar 2022 16:52:07 +0200 Subject: [PATCH 11/12] Review fixes Signed-off-by: Oliver Tale-Yazdi --- node/client/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index f3f5e0a86093..36c64c1714d0 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -682,6 +682,7 @@ macro_rules! with_signed_payload { /// Generates a `SignedPayload` for the Kusama, Westend and Rococo runtime. /// /// Should only be used for benchmarking as it is not tested for regular usage. +#[cfg(not(feature = "polkadot-native"))] macro_rules! signed_payload { ( $extra:ident, $raw_payload:ident, From 4a398e4d35c1a3d1c2f946966d9186a4e6d6002b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 30 Mar 2022 17:04:09 +0200 Subject: [PATCH 12/12] CI Signed-off-by: Oliver Tale-Yazdi --- node/client/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index 36c64c1714d0..8446950fe4df 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -682,7 +682,7 @@ macro_rules! with_signed_payload { /// Generates a `SignedPayload` for the Kusama, Westend and Rococo runtime. /// /// Should only be used for benchmarking as it is not tested for regular usage. -#[cfg(not(feature = "polkadot-native"))] +#[allow(unused_macros)] macro_rules! signed_payload { ( $extra:ident, $raw_payload:ident,