Skip to content

Commit cf52a0d

Browse files
effort towards getting chainspecbuilder into omni-node fix 5567 (#7619)
Adding chain-spec-builder as a subcommand into Polkadot omni node
1 parent 16ed029 commit cf52a0d

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

Cargo.lock

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/polkadot-omni-node/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path = "src/lib.rs"
1616

1717
[dependencies]
1818
async-trait = { workspace = true }
19+
chain-spec-builder = { workspace = true }
1920
clap = { features = ["derive"], workspace = true }
2021
codec = { workspace = true, default-features = true }
2122
color-print = { workspace = true }

cumulus/polkadot-omni-node/lib/src/cli.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::{
2323
NodeExtraArgs,
2424
},
2525
};
26+
use chain_spec_builder::ChainSpecBuilder;
2627
use clap::{Command, CommandFactory, FromArgMatches};
2728
use sc_chain_spec::ChainSpec;
2829
use sc_cli::{
@@ -31,7 +32,6 @@ use sc_cli::{
3132
};
3233
use sc_service::{config::PrometheusConfig, BasePath};
3334
use std::{fmt::Debug, marker::PhantomData, path::PathBuf};
34-
3535
/// Trait that can be used to customize some of the customer-facing info related to the node binary
3636
/// that is being built using this library.
3737
///
@@ -89,9 +89,16 @@ pub enum Subcommand {
8989
/// Revert the chain to a previous state.
9090
Revert(sc_cli::RevertCmd),
9191

92+
/// Subcommand for generating and managing chain specifications.
93+
///
94+
/// Unlike `build-spec`, which generates a chain specification based on existing
95+
/// configurations, `chain-spec-builder` provides a more interactive and customizable approach
96+
/// to defining a chain spec. It allows users to create specifications with additional
97+
/// parameters and validation steps before finalizing the output.
98+
ChainSpecBuilder(ChainSpecBuilder),
99+
92100
/// Remove the whole chain.
93101
PurgeChain(cumulus_client_cli::PurgeChainCmd),
94-
95102
/// Export the genesis state of the parachain.
96103
#[command(alias = "export-genesis-state")]
97104
ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),

cumulus/polkadot-omni-node/lib/src/command.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<()
148148
node.prepare_revert_cmd(config, cmd)
149149
})
150150
},
151+
Some(Subcommand::ChainSpecBuilder(cmd)) =>
152+
cmd.run().map_err(|err| sc_cli::Error::Application(err.into())),
153+
151154
Some(Subcommand::PurgeChain(cmd)) => {
152155
let runner = cli.create_runner(cmd)?;
153156
let polkadot_cli =

prdoc/pr_7619.prdoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: 'Add chain-spec-builder as a subcommand to the polkadot-omni-node'
2+
doc:
3+
- audience: Runtime Dev
4+
5+
description: |-
6+
This PR add chain-spec-builder as a subcommand to the polkadot-omni-node
7+
crates:
8+
- name: polkadot-omni-node-lib
9+
bump: major
10+
- name: staging-chain-spec-builder
11+
bump: patch

substrate/bin/utils/chain-spec-builder/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ type ChainSpec = GenericChainSpec<()>;
224224

225225
impl ChainSpecBuilder {
226226
/// Executes the internal command.
227-
pub fn run(self) -> Result<(), String> {
227+
pub fn run(&self) -> Result<(), String> {
228228
let chain_spec_path = self.chain_spec_path.to_path_buf();
229229

230-
match self.command {
230+
match &self.command {
231231
ChainSpecBuilderCmd::Create(cmd) => {
232232
let chain_spec_json = generate_chain_spec_for_runtime(&cmd)?;
233233
fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?;
@@ -259,7 +259,7 @@ impl ChainSpecBuilder {
259259
&mut chain_spec_json,
260260
&fs::read(runtime.as_path())
261261
.map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..],
262-
block_height,
262+
*block_height,
263263
);
264264
let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json)
265265
.map_err(|e| format!("to pretty failed: {e}"))?;

0 commit comments

Comments
 (0)