Skip to content

Commit

Permalink
effort towards getting chainspecbuilder into omni-node fix 5567 (#7619)
Browse files Browse the repository at this point in the history
Adding chain-spec-builder as a subcommand into Polkadot omni node
  • Loading branch information
seemantaggarwal authored Feb 24, 2025
1 parent 16ed029 commit cf52a0d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/polkadot-omni-node/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 9 additions & 2 deletions cumulus/polkadot-omni-node/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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.
///
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_7619.prdoc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions substrate/bin/utils/chain-spec-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down Expand Up @@ -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}"))?;
Expand Down

0 comments on commit cf52a0d

Please sign in to comment.