From cf52a0d960a17b4d023bb7c9351e159c60227c85 Mon Sep 17 00:00:00 2001 From: seemantaggarwal <32275622+seemantaggarwal@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:18:11 +0530 Subject: [PATCH] effort towards getting chainspecbuilder into omni-node fix 5567 (#7619) Adding chain-spec-builder as a subcommand into Polkadot omni node --- Cargo.lock | 13 +++++++------ cumulus/polkadot-omni-node/lib/Cargo.toml | 1 + cumulus/polkadot-omni-node/lib/src/cli.rs | 11 +++++++++-- cumulus/polkadot-omni-node/lib/src/command.rs | 3 +++ prdoc/pr_7619.prdoc | 11 +++++++++++ substrate/bin/utils/chain-spec-builder/src/lib.rs | 6 +++--- 6 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 prdoc/pr_7619.prdoc diff --git a/Cargo.lock b/Cargo.lock index 125b49be7e0..264fc8efb0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18454,6 +18454,7 @@ dependencies = [ "sp-transaction-pool 26.0.0", "sp-version 29.0.0", "sp-weights 27.0.0", + "staging-chain-spec-builder", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-state-trie-migration-rpc", @@ -21234,7 +21235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" dependencies = [ "rand_chacha 0.9.0", - "rand_core 0.9.1", + "rand_core 0.9.2", "zerocopy 0.8.20", ] @@ -21255,7 +21256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.1", + "rand_core 0.9.2", ] [[package]] @@ -21275,9 +21276,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a88e0da7a2c97baa202165137c158d0a2e824ac465d13d81046727b34cb247d3" +checksum = "7a509b1a2ffbe92afab0e55c8fd99dea1c280e8171bd2d88682bb20bc41cbc2c" dependencies = [ "getrandom 0.3.1", "zerocopy 0.8.20", @@ -29836,9 +29837,9 @@ checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] name = "target-triple" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a4d50cdb458045afc8131fd91b64904da29548bcb63c7236e0844936c13078" +checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790" [[package]] name = "tempfile" diff --git a/cumulus/polkadot-omni-node/lib/Cargo.toml b/cumulus/polkadot-omni-node/lib/Cargo.toml index 020d980d3d9..9cc4c0c635b 100644 --- a/cumulus/polkadot-omni-node/lib/Cargo.toml +++ b/cumulus/polkadot-omni-node/lib/Cargo.toml @@ -16,6 +16,7 @@ path = "src/lib.rs" [dependencies] async-trait = { workspace = true } +chain-spec-builder = { workspace = true } clap = { features = ["derive"], workspace = true } codec = { workspace = true, default-features = true } color-print = { workspace = true } diff --git a/cumulus/polkadot-omni-node/lib/src/cli.rs b/cumulus/polkadot-omni-node/lib/src/cli.rs index 1c47eae5773..995a50b2e48 100644 --- a/cumulus/polkadot-omni-node/lib/src/cli.rs +++ b/cumulus/polkadot-omni-node/lib/src/cli.rs @@ -23,6 +23,7 @@ use crate::{ NodeExtraArgs, }, }; +use chain_spec_builder::ChainSpecBuilder; use clap::{Command, CommandFactory, FromArgMatches}; use sc_chain_spec::ChainSpec; use sc_cli::{ @@ -31,7 +32,6 @@ use sc_cli::{ }; use sc_service::{config::PrometheusConfig, BasePath}; use std::{fmt::Debug, marker::PhantomData, path::PathBuf}; - /// Trait that can be used to customize some of the customer-facing info related to the node binary /// that is being built using this library. /// @@ -89,9 +89,16 @@ pub enum Subcommand { /// Revert the chain to a previous state. Revert(sc_cli::RevertCmd), + /// Subcommand for generating and managing chain specifications. + /// + /// Unlike `build-spec`, which generates a chain specification based on existing + /// configurations, `chain-spec-builder` provides a more interactive and customizable approach + /// to defining a chain spec. It allows users to create specifications with additional + /// parameters and validation steps before finalizing the output. + ChainSpecBuilder(ChainSpecBuilder), + /// Remove the whole chain. PurgeChain(cumulus_client_cli::PurgeChainCmd), - /// Export the genesis state of the parachain. #[command(alias = "export-genesis-state")] ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), diff --git a/cumulus/polkadot-omni-node/lib/src/command.rs b/cumulus/polkadot-omni-node/lib/src/command.rs index bf0d264e8c9..b4d89b151bf 100644 --- a/cumulus/polkadot-omni-node/lib/src/command.rs +++ b/cumulus/polkadot-omni-node/lib/src/command.rs @@ -148,6 +148,9 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<() node.prepare_revert_cmd(config, cmd) }) }, + Some(Subcommand::ChainSpecBuilder(cmd)) => + cmd.run().map_err(|err| sc_cli::Error::Application(err.into())), + Some(Subcommand::PurgeChain(cmd)) => { let runner = cli.create_runner(cmd)?; let polkadot_cli = diff --git a/prdoc/pr_7619.prdoc b/prdoc/pr_7619.prdoc new file mode 100644 index 00000000000..29f82d9dcfd --- /dev/null +++ b/prdoc/pr_7619.prdoc @@ -0,0 +1,11 @@ +title: 'Add chain-spec-builder as a subcommand to the polkadot-omni-node' +doc: +- audience: Runtime Dev + + description: |- + This PR add chain-spec-builder as a subcommand to the polkadot-omni-node +crates: +- name: polkadot-omni-node-lib + bump: major +- name: staging-chain-spec-builder + bump: patch diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 972958eda43..b98eb12e215 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -224,10 +224,10 @@ type ChainSpec = GenericChainSpec<()>; impl ChainSpecBuilder { /// Executes the internal command. - pub fn run(self) -> Result<(), String> { + pub fn run(&self) -> Result<(), String> { let chain_spec_path = self.chain_spec_path.to_path_buf(); - match self.command { + match &self.command { ChainSpecBuilderCmd::Create(cmd) => { let chain_spec_json = generate_chain_spec_for_runtime(&cmd)?; fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; @@ -259,7 +259,7 @@ impl ChainSpecBuilder { &mut chain_spec_json, &fs::read(runtime.as_path()) .map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..], - block_height, + *block_height, ); let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json) .map_err(|e| format!("to pretty failed: {e}"))?; -- GitLab