build: 🔨 Optimize node dependencies by feature-gating benchmarking (#341)

## 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 <noreply@anthropic.com>
This commit is contained in:
Steve Degosserie 2025-12-09 12:26:05 +01:00 committed by GitHub
parent 0d5f294097
commit ef3ddaaf69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 23 deletions

View file

@ -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 }

View file

@ -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",

View file

@ -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),

View file

@ -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::<sp_runtime::traits::HashingFor<Block>, ()>(Some(
BenchmarkCmd::Pallet(cmd) => cmd
.run_with_spec::<sp_runtime::traits::HashingFor<Block>, ()>(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();

View file

@ -17,6 +17,7 @@
//! Substrate Node Template CLI library.
#![warn(missing_docs)]
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
mod chain_spec;
mod cli;