From e5aa4e4de525a04b893fc7c85ca9e1785e244655 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 27 Apr 2022 11:04:12 +0200 Subject: [PATCH] refactor: benchmark cmd match --- nodes/parachain/src/command.rs | 88 +++++++++++++++------------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/nodes/parachain/src/command.rs b/nodes/parachain/src/command.rs index cf991240d8..f64ee5a733 100644 --- a/nodes/parachain/src/command.rs +++ b/nodes/parachain/src/command.rs @@ -270,71 +270,59 @@ pub fn run() -> Result<()> { Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(cmd)?; - let runtime = match cli.runtime.as_str() { - "peregrine" => Ok(ParachainRuntime::Peregrine), - "spiritnet" => Ok(ParachainRuntime::Spiritnet), - _ => Err("Unknown runtime"), - }?; - // Switch on the concrete benchmark sub-command - match cmd { - BenchmarkCmd::Pallet(cmd) => { + match (cmd, cli.runtime.as_str()) { + (BenchmarkCmd::Pallet(cmd), runtime) => { if cfg!(feature = "runtime-benchmarks") { match runtime { - ParachainRuntime::Spiritnet => { - runner.sync_run(|config| cmd.run::(config)) - } - ParachainRuntime::Peregrine => { - runner.sync_run(|config| cmd.run::(config)) - } + "spiritnet" => runner.sync_run(|config| cmd.run::(config)), + "peregrine" => runner.sync_run(|config| cmd.run::(config)), + _ => Err("Unknown parachain runtime".into()), } } else { Err("Benchmarking wasn't enabled when building the node. \ - You can enable it with `--features runtime-benchmarks`." + You can enable it with `--features runtime-benchmarks`." .into()) } } - BenchmarkCmd::Block(cmd) => runner.sync_run(|config| match runtime { - ParachainRuntime::Spiritnet => { - let partials = new_partial::( - &config, - crate::service::build_import_queue, - )?; - cmd.run(partials.client) - } - ParachainRuntime::Peregrine => { - let partials = new_partial::( - &config, - crate::service::build_import_queue, - )?; - cmd.run(partials.client) - } + (BenchmarkCmd::Block(cmd), "spiritnet") => runner.sync_run(|config| { + let partials = new_partial::( + &config, + crate::service::build_import_queue, + )?; + cmd.run(partials.client) }), - BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| match runtime { - ParachainRuntime::Spiritnet => { - let partials = new_partial::( - &config, - crate::service::build_import_queue, - )?; + (BenchmarkCmd::Block(cmd), "peregrine") => runner.sync_run(|config| { + let partials = new_partial::( + &config, + crate::service::build_import_queue, + )?; + cmd.run(partials.client) + }), + (BenchmarkCmd::Storage(cmd), "spiritnet") => runner.sync_run(|config| { + let partials = new_partial::( + &config, + crate::service::build_import_queue, + )?; - let db = partials.backend.expose_db(); - let storage = partials.backend.expose_storage(); + let db = partials.backend.expose_db(); + let storage = partials.backend.expose_storage(); - cmd.run(config, partials.client.clone(), db, storage) - } - ParachainRuntime::Peregrine => { - let partials = new_partial::( - &config, - crate::service::build_import_queue, - )?; + cmd.run(config, partials.client.clone(), db, storage) + }), + (BenchmarkCmd::Storage(cmd), "peregrine") => runner.sync_run(|config| { + let partials = new_partial::( + &config, + crate::service::build_import_queue, + )?; - let db = partials.backend.expose_db(); - let storage = partials.backend.expose_storage(); + let db = partials.backend.expose_db(); + let storage = partials.backend.expose_storage(); - cmd.run(config, partials.client.clone(), db, storage) - } + cmd.run(config, partials.client.clone(), db, storage) }), - BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()), + (BenchmarkCmd::Overhead(_), _) => Err("Unsupported benchmarking command".into()), + (_, _) => Err("Unknown parachain runtime".into()), } } Some(Subcommand::ExportGenesisState(params)) => {