From d29508011e80ddc70ad17b2f4e5873a08af561fe Mon Sep 17 00:00:00 2001 From: Seemant Aggarwal <seemant.aggarwal@parity.io> Date: Tue, 4 Mar 2025 17:39:37 +0530 Subject: [PATCH] adding export chain spec command everywhere --- cumulus/polkadot-omni-node/lib/src/cli.rs | 4 +--- cumulus/polkadot-omni-node/lib/src/command.rs | 6 ------ polkadot/cli/src/cli.rs | 3 +++ polkadot/cli/src/command.rs | 5 +++++ substrate/bin/node/cli/src/cli.rs | 4 ++++ substrate/bin/node/cli/src/command.rs | 5 +++++ substrate/client/cli/src/commands/export_chain_spec_cmd.rs | 2 +- templates/minimal/node/src/cli.rs | 4 ++++ templates/minimal/node/src/command.rs | 5 +++++ templates/parachain/node/src/cli.rs | 4 ++++ templates/parachain/node/src/command.rs | 5 +++++ templates/solochain/node/src/cli.rs | 5 ++++- templates/solochain/node/src/command.rs | 5 +++++ 13 files changed, 46 insertions(+), 11 deletions(-) diff --git a/cumulus/polkadot-omni-node/lib/src/cli.rs b/cumulus/polkadot-omni-node/lib/src/cli.rs index aefc9d249c0..7d3b0303876 100644 --- a/cumulus/polkadot-omni-node/lib/src/cli.rs +++ b/cumulus/polkadot-omni-node/lib/src/cli.rs @@ -27,7 +27,7 @@ use chain_spec_builder::ChainSpecBuilder; use clap::{Command, CommandFactory, FromArgMatches}; use sc_chain_spec::ChainSpec; use sc_cli::{ - CliConfiguration, DefaultConfigurationValues, ExportChainSpecCmd, ImportParams, KeystoreParams, + CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, RpcEndpoint, SharedParams, SubstrateCli, }; use sc_service::{config::PrometheusConfig, BasePath}; @@ -106,8 +106,6 @@ pub enum Subcommand { /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), - /// Export the chain specification. - ExportChainSpec(ExportChainSpecCmd), /// Sub-commands concerned with benchmarking. /// The pallet benchmarking moved to the `pallet` sub-command. diff --git a/cumulus/polkadot-omni-node/lib/src/command.rs b/cumulus/polkadot-omni-node/lib/src/command.rs index 99f653f90b0..b4d89b151bf 100644 --- a/cumulus/polkadot-omni-node/lib/src/command.rs +++ b/cumulus/polkadot-omni-node/lib/src/command.rs @@ -167,12 +167,6 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<() cmd.run(config, polkadot_config) }) }, - Some(Subcommand::ExportChainSpec(cmd)) => { - // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(&*spec) - }, - Some(Subcommand::ExportGenesisHead(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { diff --git a/polkadot/cli/src/cli.rs b/polkadot/cli/src/cli.rs index 721a4714992..bc5b80f9a94 100644 --- a/polkadot/cli/src/cli.rs +++ b/polkadot/cli/src/cli.rs @@ -27,6 +27,9 @@ pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), + /// Export the chain specification. + ExportChainSpec(sc_cli::ExportChainSpecCmd), + /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs index 6b716d48783..dcd6640d812 100644 --- a/polkadot/cli/src/command.rs +++ b/polkadot/cli/src/command.rs @@ -291,6 +291,11 @@ pub fn run() -> Result<()> { let runner = cli.create_runner(cmd)?; Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?) }, + Some(Subcommand::ExportChainSpec(cmd)) => { + // Directly load the embedded chain spec using the CLI’s load_spec method. + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(spec) + }, Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?; let chain_spec = &runner.config().chain_spec; diff --git a/substrate/bin/node/cli/src/cli.rs b/substrate/bin/node/cli/src/cli.rs index 1d7001a5dcc..e9fe2e330f8 100644 --- a/substrate/bin/node/cli/src/cli.rs +++ b/substrate/bin/node/cli/src/cli.rs @@ -17,6 +17,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use polkadot_sdk::*; +use polkadot_sdk::sc_cli::ExportChainSpecCmd; /// An overarching CLI command definition. #[derive(Debug, clap::Parser)] @@ -80,6 +81,9 @@ pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), + /// Export the chain specification. + ExportChainSpec(ExportChainSpecCmd), + /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/substrate/bin/node/cli/src/command.rs b/substrate/bin/node/cli/src/command.rs index 2910002e5b2..c55f9deae86 100644 --- a/substrate/bin/node/cli/src/command.rs +++ b/substrate/bin/node/cli/src/command.rs @@ -93,6 +93,11 @@ pub fn run() -> Result<()> { runner.sync_run(|config| cmd.run::<Block, RuntimeApi>(config)) }, + Some(Subcommand::ExportChainSpec(cmd)) => { + // Directly load the embedded chain spec using the CLI’s load_spec method. + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(spec) + }, Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs index 78f11a67bcb..c865ead3e7f 100644 --- a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs +++ b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs @@ -58,7 +58,7 @@ pub struct ExportChainSpecCmd { impl ExportChainSpecCmd { /// Run the export-chain-spec command - pub fn run(&self, spec: &Box<dyn ChainSpec>) -> Result<()> { + pub fn run(&self, spec: Box<dyn ChainSpec>) -> Result<()> { let json = chain_ops::build_spec(spec.as_ref(), self.raw)?; if let Some(ref path) = self.output { fs::write(path, json)?; diff --git a/templates/minimal/node/src/cli.rs b/templates/minimal/node/src/cli.rs index f349f8c8da0..8dbf55b656b 100644 --- a/templates/minimal/node/src/cli.rs +++ b/templates/minimal/node/src/cli.rs @@ -16,6 +16,7 @@ // limitations under the License. use polkadot_sdk::{sc_cli::RunCmd, *}; +use polkadot_sdk::sc_cli::ExportChainSpecCmd; #[derive(Debug, Clone)] pub enum Consensus { @@ -61,6 +62,9 @@ pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), + /// Export the chain specification. + ExportChainSpec(ExportChainSpecCmd), + /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/minimal/node/src/command.rs b/templates/minimal/node/src/command.rs index 5cb0694d982..ea5684b5f7d 100644 --- a/templates/minimal/node/src/command.rs +++ b/templates/minimal/node/src/command.rs @@ -74,6 +74,11 @@ pub fn run() -> sc_cli::Result<()> { Ok((cmd.run(client, import_queue), task_manager)) }) }, + Some(Subcommand::ExportChainSpec(cmd)) => { + // Directly load the embedded chain spec using the CLI’s load_spec method. + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(&*spec) + }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index c8bdbc10d75..412a715e938 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,5 +1,6 @@ use polkadot_sdk::*; use std::path::PathBuf; +use polkadot_sdk::sc_cli::ExportChainSpecCmd; /// Sub-commands supported by the collator. #[allow(clippy::large_enum_variant)] @@ -8,6 +9,9 @@ pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), + /// Export the chain specification. + ExportChainSpec(ExportChainSpecCmd), + /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 5d9308aed15..983d9ecd004 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -123,6 +123,11 @@ pub fn run() -> Result<()> { Ok(cmd.run(components.client, components.import_queue)) }) }, + Some(Subcommand::ExportChainSpec(cmd)) => { + // Directly load the embedded chain spec using the CLI’s load_spec method. + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(&*spec) + }, Some(Subcommand::ExportBlocks(cmd)) => { construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, config.database)) diff --git a/templates/solochain/node/src/cli.rs b/templates/solochain/node/src/cli.rs index b2c53aa7094..ba5dc2caf62 100644 --- a/templates/solochain/node/src/cli.rs +++ b/templates/solochain/node/src/cli.rs @@ -1,4 +1,4 @@ -use sc_cli::RunCmd; +use sc_cli::{ExportChainSpecCmd, RunCmd}; #[derive(Debug, clap::Parser)] pub struct Cli { @@ -19,6 +19,9 @@ pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), + /// Export the chain specification. + ExportChainSpec(ExportChainSpecCmd), + /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index 1c23e395ede..5d7cd61a90d 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -63,6 +63,11 @@ pub fn run() -> sc_cli::Result<()> { Ok((cmd.run(client, import_queue), task_manager)) }) }, + Some(Subcommand::ExportChainSpec(cmd)) => { + // Directly load the embedded chain spec using the CLI’s load_spec method. + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(&*spec) + }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { -- GitLab