From 821aed2aa1dd3f364684149fe6603b89057fb9c5 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 29 Apr 2022 09:58:16 +0000 Subject: [PATCH] fix: benchmarking subcommand --- --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ .PHONY: _bench _bench: - cargo run --release --features runtime-benchmarks -- \ - benchmark --pallet pallet-$(PALLET) \ + cargo run --release --features runtime-benchmarks,unique-runtime -- \ + benchmark pallet --pallet pallet-$(PALLET) \ --wasm-execution compiled --extrinsic '*' \ --template .maintain/frame-weight-template.hbs --steps=50 --repeat=200 --heap-pages=4096 \ --output=./pallets/$(PALLET)/src/weights.rs --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -371,8 +371,47 @@ Ok(()) } + #[cfg(feature = "unique-runtime")] + Some(Subcommand::Benchmark(cmd)) => { + use frame_benchmarking_cli::BenchmarkCmd; + let runner = cli.create_runner(cmd)?; + // Switch on the concrete benchmark sub-command- + match cmd { + BenchmarkCmd::Pallet(cmd) => { + if cfg!(feature = "runtime-benchmarks") { + runner.sync_run(|config| cmd.run::(config)) + } else { + Err("Benchmarking wasn't enabled when building the node. \ + You can enable it with `--features runtime-benchmarks`." + .into()) + } + } + BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { + let partials = new_partial::< + unique_runtime::RuntimeApi, + UniqueRuntimeExecutor, + _, + >(&config, crate::service::parachain_build_import_queue)?; + cmd.run(partials.client) + }), + BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { + let partials = new_partial::< + unique_runtime::RuntimeApi, + UniqueRuntimeExecutor, + _, + >(&config, crate::service::parachain_build_import_queue)?; + let db = partials.backend.expose_db(); + let storage = partials.backend.expose_storage(); - Some(Subcommand::Benchmark(_cmd)) => todo!(), + cmd.run(config, partials.client.clone(), db, storage) + }), + BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()), + } + } + #[cfg(not(feature = "unique-runtime"))] + Some(Subcommand::Benchmark(..)) => { + Err("benchmarking is only available with unique runtime enabled".into()) + } None => { let runner = cli.create_runner(&cli.run.normalize())?; let collator_options = cli.run.collator_options(); --- a/runtime/common/src/runtime_apis.rs +++ b/runtime/common/src/runtime_apis.rs @@ -401,6 +401,9 @@ hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + + // Transactional depth + hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(), ]; let mut batches = Vec::::new(); -- gitstuff