Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to specify chain type in chain-spec-builder #4542

Merged
merged 9 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_4542.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: "Adds ability to specify chain type in chain-spec-builder"

doc:
- audience: Node Operator
description: |
Currently, `chain-spec-builder` only creates a spec with Live chain type. This PR adds the
ability to specify it while keeping the same default.

crates:
- name: staging-chain-spec-builder
bump: patch
- name: sc-chain-spec
bump: patch
2 changes: 1 addition & 1 deletion substrate/bin/utils/chain-spec-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ crate-type = ["rlib"]
[dependencies]
clap = { version = "4.5.3", features = ["derive"] }
log = { workspace = true, default-features = true }
sc-chain-spec = { path = "../../../client/chain-spec" }
sc-chain-spec = { path = "../../../client/chain-spec", features = ["clap"] }
serde_json = { workspace = true, default-features = true }
sp-tracing = { path = "../../../primitives/tracing" }
9 changes: 7 additions & 2 deletions substrate/bin/utils/chain-spec-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
use std::{fs, path::PathBuf};

use clap::{Parser, Subcommand};
use sc_chain_spec::{GenericChainSpec, GenesisConfigBuilderRuntimeCaller};
use sc_chain_spec::{ChainType, GenericChainSpec, GenesisConfigBuilderRuntimeCaller};
use serde_json::Value;

/// A utility to easily create a chain spec definition.
Expand Down Expand Up @@ -154,6 +154,9 @@ pub struct CreateCmd {
/// The chain id.
#[arg(long, short = 'i', default_value = "custom")]
chain_id: String,
/// The chain type.
#[arg(value_enum, short = 't', default_value = "live")]
chain_type: ChainType,
/// The path to runtime wasm blob.
#[arg(long, short)]
runtime_wasm_path: PathBuf,
Expand Down Expand Up @@ -261,10 +264,12 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result<String, String
let code = fs::read(cmd.runtime_wasm_path.as_path())
.map_err(|e| format!("wasm blob shall be readable {e}"))?;

let chain_type = &cmd.chain_type;

let builder = GenericChainSpec::<()>::builder(&code[..], Default::default())
.with_name(&cmd.chain_name[..])
.with_id(&cmd.chain_id[..])
.with_chain_type(sc_chain_spec::ChainType::Live);
.with_chain_type(chain_type.clone());

let builder = match cmd.action {
GenesisBuildAction::NamedPreset(NamedPresetCmd { ref preset_name }) =>
Expand Down
1 change: 1 addition & 0 deletions substrate/client/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
clap = { version = "4.5.3", features = ["derive"], optional = true }
codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] }
memmap2 = "0.9.3"
serde = { features = ["derive"], workspace = true, default-features = true }
Expand Down
2 changes: 2 additions & 0 deletions substrate/client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ use sp_runtime::BuildStorage;
/// This can be used by tools to determine the type of a chain for displaying
/// additional information or enabling additional features.
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum ChainType {
/// A development chain that runs mainly on one node.
Development,
Expand All @@ -360,6 +361,7 @@ pub enum ChainType {
/// A live chain.
Live,
/// Some custom chain type.
#[cfg_attr(feature = "clap", clap(skip))]
Custom(String),
}

Expand Down
Loading