Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overhead benchmark to frame-omni-bencher #5891

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/client/parachain-inherent/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
/// in addition to the messages themselves, you must provide some information about
/// your parachain's configuration in order to mock the MQC heads properly.
/// See [`MockXcmConfig`] for more information
#[derive(Default)]
pub struct MockValidationDataInherentDataProvider<R = ()> {
/// The current block number of the local block chain (the parachain).
pub current_para_block: u32,
Expand Down
34 changes: 17 additions & 17 deletions cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ wait-timeout = { workspace = true }
[features]
default = []
rococo-native = [
"polkadot-cli/rococo-native",
"polkadot-cli/rococo-native",
]
westend-native = [
"polkadot-cli/westend-native",
"polkadot-cli/westend-native",
]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-transaction-payment/try-runtime",
"polkadot-cli/try-runtime",
"sp-runtime/try-runtime",
"frame-support/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-transaction-payment/try-runtime",
"polkadot-cli/try-runtime",
"sp-runtime/try-runtime",
]
25 changes: 24 additions & 1 deletion cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{
#[cfg(feature = "runtime-benchmarks")]
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicBuilder, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
use sc_cli::{Result, SubstrateCli};
use sp_runtime::traits::AccountIdConversion;
Expand All @@ -47,6 +47,21 @@ pub struct RunConfig {
pub chain_spec_loader: Box<dyn LoadSpec>,
/// A custom runtime resolver.
pub runtime_resolver: Box<dyn RuntimeResolver>,
/// Extrinsic builder to use in benchmarks.
///
/// Some benchmarks attempt to build blocks. This extrinsic builder
/// is used to populate these blocks with extrinsics.
pub extrinsic_builder: Option<Box<dyn ExtrinsicBuilder>>,
}

impl RunConfig {
/// Create a new `RunConfig`
pub fn new(
runtime_resolver: Box<dyn RuntimeResolver>,
chain_spec_loader: Box<dyn LoadSpec>,
) -> Self {
RunConfig { chain_spec_loader, runtime_resolver, extrinsic_builder: None }
}
}

pub fn new_aura_node_spec<Block>(
Expand Down Expand Up @@ -199,6 +214,14 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<()
}),
BenchmarkCmd::Machine(cmd) =>
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())),
BenchmarkCmd::Overhead(cmd) => runner.sync_run(|config| {
let node = new_node_spec(
&config,
&cmd_config.runtime_resolver,
&cli.node_extra_args(),
)?;
node.run_benchmark_overhead_cmd(cmd, cmd_config.extrinsic_builder)
}),
#[allow(unreachable_patterns)]
_ => Err("Benchmarking sub-command unsupported or compilation feature missing. \
Make sure to compile with --features=runtime-benchmarks \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

use crate::common::spec::NodeSpec;
use cumulus_client_cli::ExportGenesisHeadCommand;
use frame_benchmarking_cli::BlockCmd;
#[cfg(any(feature = "runtime-benchmarks"))]
use frame_benchmarking_cli::StorageCmd;
use frame_benchmarking_cli::{BlockCmd, ExtrinsicBuilder, OverheadCmd};
use sc_cli::{CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
use sc_service::{Configuration, TaskManager};
use std::{future::Future, pin::Pin};
Expand Down Expand Up @@ -77,6 +77,12 @@ pub trait NodeCommandRunner {
config: Configuration,
cmd: &StorageCmd,
) -> SyncCmdResult;

fn run_benchmark_overhead_cmd(
self: Box<Self>,
cmd: &OverheadCmd,
ext_builder: Option<Box<dyn ExtrinsicBuilder>>,
) -> SyncCmdResult;
}

impl<T> NodeCommandRunner for T
Expand Down Expand Up @@ -158,4 +164,12 @@ where

cmd.run(config, partial.client, db, storage)
}

fn run_benchmark_overhead_cmd(
self: Box<Self>,
cmd: &OverheadCmd,
ext_builder: Option<Box<dyn ExtrinsicBuilder>>,
) -> SyncCmdResult {
cmd.run_with_extrinsic_builder::<<Self as NodeSpec>::Block, ()>(ext_builder)
}
}
5 changes: 1 addition & 4 deletions cumulus/polkadot-parachain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ impl CliConfigT for CliConfig {
fn main() -> color_eyre::eyre::Result<()> {
color_eyre::install()?;

let config = RunConfig {
chain_spec_loader: Box::new(chain_spec::ChainSpecLoader),
runtime_resolver: Box::new(chain_spec::RuntimeResolver),
};
let config = RunConfig::new(Box::new(chain_spec::RuntimeResolver), Box::new(chain_spec::ChainSpecLoader));
Ok(run::<CliConfig>(config)?)
}
6 changes: 3 additions & 3 deletions cumulus/test/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sp_consensus_aura::{AuraApi, Slot};
use sp_core::Pair;
use sp_io::TestExternalities;
use sp_keystore::testing::MemoryKeystore;
use sp_runtime::{generic::Era, traits::Header, BuildStorage, SaturatedConversion};
use sp_runtime::{generic::Era, traits::Header, BuildStorage, MultiAddress, SaturatedConversion};
use std::sync::Arc;
pub use substrate_test_client::*;

Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn generate_extrinsic_with_pair(

UncheckedExtrinsic::new_signed(
function,
origin.public().into(),
MultiAddress::Id(origin.public().into()),
Signature::Sr25519(signature),
extra,
)
Expand All @@ -180,7 +180,7 @@ pub fn transfer(
value: Balance,
) -> UncheckedExtrinsic {
let function = RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: dest.public().into(),
dest: MultiAddress::Id(dest.public().into()),
value,
});

Expand Down
4 changes: 4 additions & 0 deletions cumulus/test/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ workspace = true
[dependencies]
codec = { features = ["derive"], workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde_json = { workspace = true }

# Substrate
frame-executive = { workspace = true }
Expand Down Expand Up @@ -38,6 +39,7 @@ sp-session = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
sp-keyring = { workspace = true }

# Cumulus
cumulus-pallet-parachain-system = { workspace = true }
Expand Down Expand Up @@ -89,6 +91,8 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"substrate-wasm-builder",
"serde_json/std",
"sp-keyring/std"
]
increment-spec-version = []
elastic-scaling = []
Loading
Loading