Skip to content

Commit efa0d69

Browse files
iulianbarbugithub-actions[bot]
authored andcommitted
omni-node: fix benchmark pallet to work with --runtime (#8594)
# Description The PR fixes the logic so that `polkadot-omni-node benchmark pallet` subcommand pulls in the appropriate arguments, while not needing to instatiate the full node configuration, which requires always passing `--chain` flag. ## Integration Developers will be able to use `polkadot-omni-node benchmark pallet` with `--runtime` flag, same as `frame-omni-bencher`. ## Review Notes Did a few things in this PR: - made `polkadot-omni-node benchmark pallet` not require always the `--chain` flag - removed the deprecated `run` method for `benchmark pallet` from `benchmarking-cli`. - removed the check that disallows the chain flag from `frame-omni-bencher` since it is allowed and usable TODO: - [x] a few more testing of the commands with both `--runtime` and `--chain`. - [x] remove `runtime-benchmarks` feature guard for benchmark cmds --------- Signed-off-by: Iulian Barbu <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f55094e commit efa0d69

4 files changed

Lines changed: 68 additions & 49 deletions

File tree

cumulus/polkadot-omni-node/lib/src/command.rs

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -227,38 +227,61 @@ where
227227
})
228228
},
229229
Some(Subcommand::Benchmark(cmd)) => {
230-
let runner = cli.create_runner(cmd)?;
231-
232230
// Switch on the concrete benchmark sub-command-
233231
match cmd {
234232
#[cfg(feature = "runtime-benchmarks")]
235-
BenchmarkCmd::Pallet(cmd) => runner.sync_run(|config| {
236-
cmd.run_with_spec::<HashingFor<Block<u32>>, ReclaimHostFunctions>(Some(
237-
config.chain_spec,
238-
))
239-
}),
240-
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
241-
let node = new_node_spec(
242-
&config,
243-
&cmd_config.runtime_resolver,
244-
&cli.node_extra_args(),
245-
)?;
246-
node.run_benchmark_block_cmd(config, cmd)
247-
}),
233+
BenchmarkCmd::Pallet(cmd) => {
234+
let chain = cmd
235+
.shared_params
236+
.chain
237+
.as_ref()
238+
.map(|chain| cli.load_spec(&chain))
239+
.transpose()?;
240+
cmd.run_with_spec::<HashingFor<Block<u32>>, ReclaimHostFunctions>(chain)
241+
},
242+
BenchmarkCmd::Block(cmd) => {
243+
// The command needs the full node configuration because it uses the node
244+
// client and the database source, which in its turn has a dependency on the
245+
// chain spec, given via the `--chain` flag.
246+
let runner = cli.create_runner(cmd)?;
247+
runner.sync_run(|config| {
248+
let node = new_node_spec(
249+
&config,
250+
&cmd_config.runtime_resolver,
251+
&cli.node_extra_args(),
252+
)?;
253+
node.run_benchmark_block_cmd(config, cmd)
254+
})
255+
},
248256
#[cfg(feature = "runtime-benchmarks")]
249-
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
250-
let node = new_node_spec(
251-
&config,
252-
&cmd_config.runtime_resolver,
253-
&cli.node_extra_args(),
254-
)?;
255-
node.run_benchmark_storage_cmd(config, cmd)
256-
}),
257-
BenchmarkCmd::Machine(cmd) =>
258-
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())),
257+
BenchmarkCmd::Storage(cmd) => {
258+
// The command needs the full node configuration because it uses the node
259+
// client and the database API, storage and shared_trie_cache. It requires
260+
// the `--chain` flag to be passed.
261+
let runner = cli.create_runner(cmd)?;
262+
runner.sync_run(|config| {
263+
let node = new_node_spec(
264+
&config,
265+
&cmd_config.runtime_resolver,
266+
&cli.node_extra_args(),
267+
)?;
268+
node.run_benchmark_storage_cmd(config, cmd)
269+
})
270+
},
271+
BenchmarkCmd::Machine(cmd) => {
272+
// The command needs the full node configuration, and implicitly a chain
273+
// spec to be passed, even if it doesn't use it directly. The `--chain` flag is
274+
// relevant in determining the database path, which is used for the disk
275+
// benchmark.
276+
//
277+
// TODO: change `machine` subcommand to take instead a disk path we want to
278+
// benchmark?.
279+
let runner = cli.create_runner(cmd)?;
280+
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()))
281+
},
259282
#[allow(unreachable_patterns)]
260283
_ => Err("Benchmarking sub-command unsupported or compilation feature missing. \
261-
Make sure to compile with --features=runtime-benchmarks \
284+
Make sure to compile omni-node with --features=runtime-benchmarks \
262285
to enable all supported benchmarks."
263286
.into()),
264287
}

prdoc/pr_8594.prdoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: 'omni-node: fix `benchmark pallet` to work with `--runtime`'
2+
doc:
3+
- audience: Node Dev
4+
description: |
5+
`polkadot-omni-node benchmark pallet` can use one of `--runtime` or `--chain` now, like `frame-omni-bencher` does.
6+
7+
crates:
8+
- name: polkadot-omni-node-lib
9+
bump: patch
10+
- name: frame-benchmarking-cli
11+
bump: major
12+
- name: frame-omni-bencher
13+
bump: patch
14+
- name: polkadot-sdk
15+
bump: patch
16+
- name: polkadot-omni-node
17+
bump: patch
18+
- name: polkadot-parachain-bin
19+
bump: patch

substrate/utils/frame/benchmarking-cli/src/pallet/command.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,6 @@ This could mean that you either did not build the node correctly with the \
159159
not created by a node that was compiled with the flag";
160160

161161
impl PalletCmd {
162-
/// Runs the command and benchmarks a pallet.
163-
#[deprecated(
164-
note = "`run` will be removed after December 2024. Use `run_with_spec` instead or \
165-
completely remove the code and use the `frame-benchmarking-cli` instead (see \
166-
https://github.com/paritytech/polkadot-sdk/pull/3512)."
167-
)]
168-
pub fn run<Hasher, ExtraHostFunctions>(&self, config: sc_service::Configuration) -> Result<()>
169-
where
170-
Hasher: Hash,
171-
<Hasher as Hash>::Output: DecodeWithMemTracking,
172-
ExtraHostFunctions: HostFunctions,
173-
{
174-
self.run_with_spec::<Hasher, ExtraHostFunctions>(Some(config.chain_spec))
175-
}
176-
177162
fn state_handler_from_cli<HF: HostFunctions>(
178163
&self,
179164
chain_spec_from_api: Option<Box<dyn ChainSpec>>,

substrate/utils/frame/omni-bencher/src/command.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ impl V1SubCommand {
134134
match self {
135135
V1SubCommand::Benchmark(V1BenchmarkCommand { sub }) => match sub {
136136
BenchmarkCmd::Pallet(pallet) => {
137-
if let Some(spec) = pallet.shared_params.chain {
138-
return Err(format!(
139-
"Chain specs are not supported. Please remove `--chain={spec}` and use \
140-
`--runtime=<PATH>` instead"
141-
)
142-
.into());
143-
}
144-
145137
pallet.run_with_spec::<BlakeTwo256, HostFunctions>(None)
146138
},
147139
BenchmarkCmd::Overhead(overhead_cmd) =>

0 commit comments

Comments
 (0)