From ef3ddaaf69a172671378fdba19f15a276bbde05f Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Tue, 9 Dec 2025 12:26:05 +0100 Subject: [PATCH] =?UTF-8?q?build:=20=F0=9F=94=A8=20Optimize=20node=20depen?= =?UTF-8?q?dencies=20by=20feature-gating=20benchmarking=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Feature-gate `frame-benchmarking-cli` behind `runtime-benchmarks` feature, making it an optional dependency - Remove unused `cumulus-client-service` workspace dependency - Remove unused `storage-hub-runtime` workspace dependency - Add `#[cfg(feature = "runtime-benchmarks")]` guards to benchmark-related code ## Motivation The `frame-benchmarking-cli` crate pulls in `cumulus-client-parachain-inherent` and other cumulus dependencies transitively. Since DataHaven is a solochain (not a parachain), these dependencies are unnecessary for regular builds. By making the benchmarking CLI optional and only compiling it when the `runtime-benchmarks` feature is enabled, we reduce: - Compile time for regular development builds - Final binary size (when not benchmarking) - Dependency tree complexity Co-authored-by: Claude --- operator/Cargo.toml | 2 -- operator/node/Cargo.toml | 5 +++-- operator/node/src/cli.rs | 1 + operator/node/src/command.rs | 27 ++++++++------------------- operator/node/src/main.rs | 1 + 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/operator/Cargo.toml b/operator/Cargo.toml index b1b67819..6616222d 100644 --- a/operator/Cargo.toml +++ b/operator/Cargo.toml @@ -284,9 +284,7 @@ shp-file-metadata = { git = "https://github.com/Moonsong-Labs/storage-hub.git", shp-forest-verifier = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } shp-traits = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } shp-treasury-funding = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } -storage-hub-runtime = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } ## Client -cumulus-client-service = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2412-6", default-features = false } shc-actors-derive = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } shc-actors-framework = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } shc-blockchain-service = { git = "https://github.com/Moonsong-Labs/storage-hub.git", tag = "v0.2.5", default-features = false } diff --git a/operator/node/Cargo.toml b/operator/node/Cargo.toml index 5f3ab481..8374a7d4 100644 --- a/operator/node/Cargo.toml +++ b/operator/node/Cargo.toml @@ -40,7 +40,7 @@ pallet-beefy-mmr = { workspace = true, default-features = true } pallet-mmr = { workspace = true, default-features = true } # Polkadot SDK -frame-benchmarking-cli = { workspace = true, default-features = true } +frame-benchmarking-cli = { workspace = true, default-features = true, optional = true } frame-metadata-hash-extension = { workspace = true, default-features = true } frame-system = { workspace = true, default-features = true } frame-system-rpc-runtime-api = { workspace = true } @@ -146,7 +146,8 @@ std = [ # Dependencies that are only required if runtime benchmarking should be build. runtime-benchmarks = [ - "frame-benchmarking-cli/runtime-benchmarks", + "dep:frame-benchmarking-cli", + "frame-benchmarking-cli?/runtime-benchmarks", "frame-system/runtime-benchmarks", "sc-service/runtime-benchmarks", "datahaven-runtime-common/runtime-benchmarks", diff --git a/operator/node/src/cli.rs b/operator/node/src/cli.rs index 3689428f..dc491ab5 100644 --- a/operator/node/src/cli.rs +++ b/operator/node/src/cli.rs @@ -112,6 +112,7 @@ pub enum Subcommand { Revert(sc_cli::RevertCmd), /// Sub-commands concerned with benchmarking. + #[cfg(feature = "runtime-benchmarks")] #[command(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), diff --git a/operator/node/src/command.rs b/operator/node/src/command.rs index 53d01944..dbe0d0d2 100644 --- a/operator/node/src/command.rs +++ b/operator/node/src/command.rs @@ -16,15 +16,17 @@ use std::sync::Arc; +#[cfg(feature = "runtime-benchmarks")] +use crate::benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder}; use crate::config; use crate::service::frontier_database_dir; use crate::{ - benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder}, chain_spec::{self, NetworkType}, cli::{Cli, ProviderType, StorageLayer, Subcommand}, service, }; use datahaven_runtime_common::Block; +#[cfg(feature = "runtime-benchmarks")] use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; use sc_cli::SubstrateCli; use sc_service::{ChainType, DatabaseSource}; @@ -172,6 +174,7 @@ macro_rules! construct_async_run { }} } +#[cfg(feature = "runtime-benchmarks")] macro_rules! construct_benchmark_partials { ($cli:expr, $config:expr, |$partials:ident| $code:expr) => { match $config.chain_spec { @@ -260,6 +263,7 @@ pub fn run() -> sc_cli::Result<()> { Ok(cmd.run(components.client, components.backend, Some(aux_revert))) }) } + #[cfg(feature = "runtime-benchmarks")] Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -267,29 +271,14 @@ pub fn run() -> sc_cli::Result<()> { // This switch needs to be in the client, since the client decides // which sub-commands it wants to support. match cmd { - BenchmarkCmd::Pallet(cmd) => { - if !cfg!(feature = "runtime-benchmarks") { - return Err( - "Runtime benchmarking wasn't enabled when building the node. \ - You can enable it with `--features runtime-benchmarks`." - .into(), - ); - } - - cmd.run_with_spec::, ()>(Some( + BenchmarkCmd::Pallet(cmd) => cmd + .run_with_spec::, ()>(Some( config.chain_spec, - )) - } + )), BenchmarkCmd::Block(cmd) => { construct_benchmark_partials!(cli, config, |partials| cmd .run(partials.client)) } - #[cfg(not(feature = "runtime-benchmarks"))] - BenchmarkCmd::Storage(_) => Err( - "Storage benchmarking can be enabled with `--features runtime-benchmarks`." - .into(), - ), - #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => { construct_benchmark_partials!(cli, config, |partials| { let db = partials.backend.expose_db(); diff --git a/operator/node/src/main.rs b/operator/node/src/main.rs index 226697c0..294105af 100644 --- a/operator/node/src/main.rs +++ b/operator/node/src/main.rs @@ -17,6 +17,7 @@ //! Substrate Node Template CLI library. #![warn(missing_docs)] +#[cfg(feature = "runtime-benchmarks")] mod benchmarking; mod chain_spec; mod cli;