From 983b32d2e1e30651ab93d9c82686a28f0a82f560 Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Mon, 22 May 2023 10:29:47 +0200
Subject: [PATCH] feat(runtime) enforce gdev-benchmark for benchmark commands

---
 node/src/command.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/node/src/command.rs b/node/src/command.rs
index ce6f6d500..a7a594f94 100644
--- a/node/src/command.rs
+++ b/node/src/command.rs
@@ -42,6 +42,20 @@ lazy_static! {
     };
 }*/
 
+//Currently, only `gdev-benchmark` supports the benchmark of all the extrinsics. Storage and overhead are equivalent with `gdev-benchmark` and `gdev`, so we enforce `gdev-benchmark` for all benchmark-related commands.
+#[cfg(feature = "runtime-benchmarks")]
+fn ensure_dev(spec: &Box<dyn sc_service::ChainSpec>) -> std::result::Result<(), String> {
+    if spec.id() == "gdev-benchmark" {
+        Ok(())
+    } else {
+        Err(format!(
+            "{}{}",
+            "can only use subcommand with --chain [gdev-benchmark], got ",
+            spec.id()
+        ))
+    }
+}
+
 /// Unwraps a [`crate::client::Client`] into the concrete runtime client.
 #[cfg(feature = "runtime-benchmarks")]
 macro_rules! unwrap_client {
@@ -263,6 +277,7 @@ pub fn run() -> sc_cli::Result<()> {
         Some(Subcommand::Benchmark(cmd)) => {
             let runner = cli.create_runner(cmd)?;
             let chain_spec = &runner.config().chain_spec;
+            ensure_dev(chain_spec)?;
 
             match cmd {
                 BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| {
-- 
GitLab