From c8e76ad60936283e379f791c815bd980c199555f Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 27 May 2024 19:24:22 +0200 Subject: [PATCH 01/10] Chain spec builder substitute --- Cargo.lock | 4 ++ .../bin/utils/chain-spec-builder/Cargo.toml | 4 ++ .../bin/utils/chain-spec-builder/bin/main.rs | 38 +++++++++++++--- .../bin/utils/chain-spec-builder/src/lib.rs | 43 ++++++++++++++++++- substrate/client/chain-spec/src/chain_spec.rs | 10 +++++ substrate/client/chain-spec/src/lib.rs | 4 +- 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82dfd34c2528..c28c67cc4033 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20525,7 +20525,11 @@ dependencies = [ "clap 4.5.3", "log", "sc-chain-spec", + "sc-service", + "serde", "serde_json", + "sp-core", + "sp-runtime", "sp-tracing 16.0.0", ] diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index 5c8a3ab4e89a..0f3cd90d8d67 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -28,3 +28,7 @@ log = { workspace = true, default-features = true } sc-chain-spec = { path = "../../../client/chain-spec" } serde_json = { workspace = true, default-features = true } sp-tracing = { path = "../../../primitives/tracing" } +serde = { features = ["derive"], workspace = true, default-features = true } +sp-runtime = { path = "../../../primitives/runtime" } +sp-core = { path = "../../../primitives/core" } +sc-service = { path = "../../../client/service", default-features = false } diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 8d6425a46c77..ce5ca70eb3da 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -17,12 +17,13 @@ // along with this program. If not, see . use chain_spec_builder::{ - generate_chain_spec_for_runtime, ChainSpecBuilder, ChainSpecBuilderCmd, ConvertToRawCmd, - DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, + generate_chain_spec_for_runtime, AddCodeSubstituteCmd, ChainSpecBuilder, ChainSpecBuilderCmd, + ConvertToRawCmd, DisplayPresetCmd, Extensions, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; use sc_chain_spec::{ - update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, + set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, GenericChainSpec, + GenesisConfigBuilderRuntimeCaller, }; use staging_chain_spec_builder as chain_spec_builder; use std::fs; @@ -50,7 +51,8 @@ fn inner_main() -> Result<(), String> { ref input_chain_spec, ref runtime_wasm_path, }) => { - let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let chain_spec = + GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; let mut chain_spec_json = serde_json::from_str::(&chain_spec.as_json(false)?) @@ -65,8 +67,31 @@ fn inner_main() -> Result<(), String> { .map_err(|e| format!("to pretty failed: {e}"))?; fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; }, + ChainSpecBuilderCmd::AddCodeSubstitute(AddCodeSubstituteCmd { + ref input_chain_spec, + ref runtime_wasm_path, + block_height, + }) => { + let chain_spec = + GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; + + let mut chain_spec_json = + serde_json::from_str::(&chain_spec.as_json(false)?) + .map_err(|e| format!("Conversion to json failed: {e}"))?; + + set_code_substitute_in_json_chain_spec( + &mut chain_spec_json, + &fs::read(runtime_wasm_path.as_path()) + .map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..], + block_height, + ); + let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json) + .map_err(|e| format!("to pretty failed: {e}"))?; + fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; + }, ChainSpecBuilderCmd::ConvertToRaw(ConvertToRawCmd { ref input_chain_spec }) => { - let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let chain_spec = + GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; let chain_spec_json = serde_json::from_str::(&chain_spec.as_json(true)?) @@ -77,7 +102,8 @@ fn inner_main() -> Result<(), String> { fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; }, ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec }) => { - let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let chain_spec = + GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; let _ = serde_json::from_str::(&chain_spec.as_json(true)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; }, diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 7982da76227a..78a8f21a33e9 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -120,7 +120,10 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; -use sc_chain_spec::{GenericChainSpec, GenesisConfigBuilderRuntimeCaller}; +use sc_chain_spec::{ + ChainSpecExtension, ChainSpecGroup, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, +}; +use serde::{Deserialize, Serialize}; use serde_json::Value; /// A utility to easily create a chain spec definition. @@ -143,6 +146,7 @@ pub enum ChainSpecBuilderCmd { ConvertToRaw(ConvertToRawCmd), ListPresets(ListPresetsCmd), DisplayPreset(DisplayPresetCmd), + AddCodeSubstitute(AddCodeSubstituteCmd), } /// Create a new chain spec by interacting with the provided runtime wasm blob. @@ -214,6 +218,20 @@ pub struct UpdateCodeCmd { pub runtime_wasm_path: PathBuf, } +/// Add a code substitute in the chain spec. +/// +/// The `codeSubstitute` object of the chain spec will be updated with the block height as key and +/// runtime code as value. This operation supports both plain and raw formats. +#[derive(Parser, Debug, Clone)] +pub struct AddCodeSubstituteCmd { + /// Chain spec to be updated. + pub input_chain_spec: PathBuf, + /// New runtime wasm blob that should replace the existing code. + pub runtime_wasm_path: PathBuf, + /// The block height at which the code should be substituted. + pub block_height: u64, +} + /// Converts the given chain spec into the raw format. #[derive(Parser, Debug, Clone)] pub struct ConvertToRawCmd { @@ -240,6 +258,29 @@ pub struct DisplayPresetCmd { pub preset_name: Option, } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct Extensions { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: String, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + +impl sp_runtime::BuildStorage for Extensions { + /// Assimilate the storage for this module into pre-existing overlays. + fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { + unimplemented!(); + } +} /// Verifies the provided input chain spec. /// /// Silently checks if given input chain spec can be converted to raw. It allows to check if all diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index a9cdce4bf955..b80cf6535a4f 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -863,6 +863,16 @@ pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) } } +/// This function sets a codeSubstitute in the chain spec. +pub fn set_code_substitute_in_json_chain_spec( + chain_spec: &mut json::Value, + code: &[u8], + block_height: u64, +) { + let substitutes = json::json!({"codeSubstitutes":{ &block_height.to_string(): sp_core::bytes::to_hex(code, false) }}); + crate::json_patch::merge(chain_spec, substitutes); +} + #[cfg(test)] mod tests { use super::*; diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index abe01dafd924..ac7f755cb129 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -329,8 +329,8 @@ pub mod json_patch; pub use self::{ chain_spec::{ - update_code_in_json_chain_spec, ChainSpec as GenericChainSpec, ChainSpecBuilder, - NoExtension, + set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, + ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension, }, extension::{get_extension, get_extension_mut, Extension, Fork, Forks, GetExtension, Group}, genesis_block::{ From c45be3a209c83796661393908f9589c7ad30aa5f Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 3 Jun 2024 15:18:55 +0200 Subject: [PATCH 02/10] Extract chain-spec-extension --- Cargo.lock | 14 ++++++- Cargo.toml | 1 + .../client/chain-spec-extension/Cargo.toml | 14 +++++++ .../client/chain-spec-extension/src/lib.rs | 38 +++++++++++++++++++ cumulus/polkadot-parachain/Cargo.toml | 2 +- .../polkadot-parachain/src/chain_spec/mod.rs | 21 +--------- cumulus/polkadot-parachain/src/cli.rs | 3 +- cumulus/polkadot-parachain/src/command.rs | 2 +- cumulus/test/service/Cargo.toml | 1 + cumulus/test/service/src/chain_spec.rs | 20 ++-------- cumulus/test/service/src/main.rs | 7 ++-- .../bin/utils/chain-spec-builder/Cargo.toml | 1 + .../bin/utils/chain-spec-builder/bin/main.rs | 17 ++++----- .../bin/utils/chain-spec-builder/src/lib.rs | 26 +------------ templates/parachain/node/Cargo.toml | 2 +- templates/parachain/node/src/chain_spec.rs | 21 +--------- templates/parachain/node/src/cli.rs | 4 +- templates/parachain/node/src/command.rs | 3 +- 18 files changed, 96 insertions(+), 101 deletions(-) create mode 100644 cumulus/client/chain-spec-extension/Cargo.toml create mode 100644 cumulus/client/chain-spec-extension/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c28c67cc4033..b88da679808e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3583,6 +3583,14 @@ dependencies = [ "cipher 0.4.4", ] +[[package]] +name = "cumulus-client-chain-spec-extension" +version = "0.1.0" +dependencies = [ + "sc-chain-spec", + "serde", +] + [[package]] name = "cumulus-client-cli" version = "0.7.0" @@ -4367,6 +4375,7 @@ dependencies = [ "async-trait", "clap 4.5.3", "criterion", + "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -11706,6 +11715,7 @@ version = "0.0.0" dependencies = [ "clap 4.5.3", "color-print", + "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -11742,7 +11752,6 @@ dependencies = [ "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", - "serde", "serde_json", "sp-api", "sp-block-builder", @@ -13541,6 +13550,7 @@ dependencies = [ "contracts-rococo-runtime", "coretime-rococo-runtime", "coretime-westend-runtime", + "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -13591,7 +13601,6 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "seedling-runtime", - "serde", "serde_json", "shell-runtime", "sp-api", @@ -20523,6 +20532,7 @@ name = "staging-chain-spec-builder" version = "3.0.0" dependencies = [ "clap 4.5.3", + "cumulus-client-chain-spec-extension", "log", "sc-chain-spec", "sc-service", diff --git a/Cargo.toml b/Cargo.toml index d6099e420f91..0696580d8960 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,7 @@ members = [ "cumulus/client/consensus/common", "cumulus/client/consensus/proposer", "cumulus/client/consensus/relay-chain", + "cumulus/client/chain-spec-extension", "cumulus/client/network", "cumulus/client/parachain-inherent", "cumulus/client/pov-recovery", diff --git a/cumulus/client/chain-spec-extension/Cargo.toml b/cumulus/client/chain-spec-extension/Cargo.toml new file mode 100644 index 000000000000..7d27f944afed --- /dev/null +++ b/cumulus/client/chain-spec-extension/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "cumulus-client-chain-spec-extension" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +description = "Parachain chain-spec extension." +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[lints] +workspace = true + +[dependencies] +sc-chain-spec = { path = "../../../substrate/client/chain-spec" } +serde = { features = ["derive"], workspace = true, default-features = true } diff --git a/cumulus/client/chain-spec-extension/src/lib.rs b/cumulus/client/chain-spec-extension/src/lib.rs new file mode 100644 index 000000000000..495e084fd9cb --- /dev/null +++ b/cumulus/client/chain-spec-extension/src/lib.rs @@ -0,0 +1,38 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Chain spec extension for parachains. + +use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup}; +use serde::{Deserialize, Serialize}; + +/// The extensions for the [`ChainSpec`]. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct Extensions { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: String, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index a22606edb6c5..734fd07648a2 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -21,7 +21,6 @@ codec = { package = "parity-scale-codec", version = "3.6.12" } futures = "0.3.28" hex-literal = "0.4.1" log = { workspace = true, default-features = true } -serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } # Local @@ -112,6 +111,7 @@ cumulus-primitives-aura = { path = "../primitives/aura" } cumulus-primitives-core = { path = "../primitives/core" } cumulus-relay-chain-interface = { path = "../client/relay-chain-interface" } color-print = "0.3.4" +cumulus-client-chain-spec-extension = { path = "../client/chain-spec-extension" } [build-dependencies] substrate-build-script-utils = { path = "../../substrate/utils/build-script-utils" } diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 136a19e3166b..0b374b64dd91 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -14,9 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use cumulus_client_chain_spec_extension::Extensions; use parachains_common::{AccountId, Signature}; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; -use serde::{Deserialize, Serialize}; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -35,24 +34,6 @@ pub mod shell; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; -/// Generic extensions for Parachain ChainSpecs. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - /// Generic chain spec for all polkadot-parachain runtimes pub type GenericChainSpec = sc_service::GenericChainSpec<(), Extensions>; diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index f7d2fd0f0be3..c78af6ca1949 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use cumulus_client_chain_spec_extension::Extensions; use std::path::PathBuf; /// Sub-commands supported by the collator. @@ -113,7 +114,7 @@ impl RelayChainCli { para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, ) -> Self { - let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); + let extension = Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.path().join("polkadot"); Self { diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 041187de488f..7dd47037cb02 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -644,7 +644,7 @@ pub fn run() -> Result<()> { sc_sysinfo::gather_hwbench(Some(database_path)) })).flatten(); - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + let para_id = cumulus_client_chain_spec_extension::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or("Could not find parachain extension in chain-spec.")?; diff --git a/cumulus/test/service/Cargo.toml b/cumulus/test/service/Cargo.toml index 732d884528f8..45cda190fd41 100644 --- a/cumulus/test/service/Cargo.toml +++ b/cumulus/test/service/Cargo.toml @@ -88,6 +88,7 @@ cumulus-test-relay-sproof-builder = { path = "../relay-sproof-builder" } cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false } cumulus-primitives-storage-weight-reclaim = { path = "../../primitives/storage-weight-reclaim" } pallet-timestamp = { path = "../../../substrate/frame/timestamp" } +cumulus-client-chain-spec-extension = { path = "../../client/chain-spec-extension" } [dev-dependencies] futures = "0.3.28" diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 4db2513e2b63..ed839faa19c8 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -35,21 +35,6 @@ pub fn get_from_seed(seed: &str) -> ::Pu .public() } -/// The extensions for the [`ChainSpec`]. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -#[serde(deny_unknown_fields)] -pub struct Extensions { - /// The id of the Parachain. - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - type AccountPublic = ::Signer; /// Helper function to generate an account ID from seed. @@ -69,7 +54,10 @@ pub fn get_chain_spec_with_extra_endowed( ) -> ChainSpec { ChainSpec::builder( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into() }, + Extensions { + para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into(), + ..Default::default() + }, ) .with_name("Local Testnet") .with_id("local_testnet") diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 90d37173dd59..ac51fb52f962 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -77,9 +77,10 @@ fn main() -> Result<(), sc_cli::Error> { SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) .map_err(|err| format!("Relay chain argument error: {}", err))?; - let parachain_id = chain_spec::Extensions::try_get(&*config.chain_spec) - .map(|e| e.para_id) - .ok_or("Could not find parachain extension in chain-spec.")?; + let parachain_id = + cumulus_client_chain_spec_extension::Extensions::try_get(&*config.chain_spec) + .map(|e| e.para_id) + .ok_or("Could not find parachain extension in chain-spec.")?; tracing::info!("Parachain id: {:?}", parachain_id); tracing::info!( diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index 0f3cd90d8d67..cbef120f4ec7 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -32,3 +32,4 @@ serde = { features = ["derive"], workspace = true, default-features = true } sp-runtime = { path = "../../../primitives/runtime" } sp-core = { path = "../../../primitives/core" } sc-service = { path = "../../../client/service", default-features = false } +cumulus-client-chain-spec-extension = { path = "../../../../cumulus/client/chain-spec-extension" } diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index ce5ca70eb3da..3e8310bfbefe 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -18,9 +18,10 @@ use chain_spec_builder::{ generate_chain_spec_for_runtime, AddCodeSubstituteCmd, ChainSpecBuilder, ChainSpecBuilderCmd, - ConvertToRawCmd, DisplayPresetCmd, Extensions, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, + ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; +use cumulus_client_chain_spec_extension::Extensions; use sc_chain_spec::{ set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, @@ -28,6 +29,8 @@ use sc_chain_spec::{ use staging_chain_spec_builder as chain_spec_builder; use std::fs; +type ChainSpec = GenericChainSpec<(), Extensions>; + //avoid error message escaping fn main() { match inner_main() { @@ -51,8 +54,7 @@ fn inner_main() -> Result<(), String> { ref input_chain_spec, ref runtime_wasm_path, }) => { - let chain_spec = - GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; + let chain_spec = ChainSpec::from_json_file(input_chain_spec.clone())?; let mut chain_spec_json = serde_json::from_str::(&chain_spec.as_json(false)?) @@ -72,8 +74,7 @@ fn inner_main() -> Result<(), String> { ref runtime_wasm_path, block_height, }) => { - let chain_spec = - GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; + let chain_spec = ChainSpec::from_json_file(input_chain_spec.clone())?; let mut chain_spec_json = serde_json::from_str::(&chain_spec.as_json(false)?) @@ -90,8 +91,7 @@ fn inner_main() -> Result<(), String> { fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; }, ChainSpecBuilderCmd::ConvertToRaw(ConvertToRawCmd { ref input_chain_spec }) => { - let chain_spec = - GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; + let chain_spec = ChainSpec::from_json_file(input_chain_spec.clone())?; let chain_spec_json = serde_json::from_str::(&chain_spec.as_json(true)?) @@ -102,8 +102,7 @@ fn inner_main() -> Result<(), String> { fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; }, ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec }) => { - let chain_spec = - GenericChainSpec::<(), Extensions>::from_json_file(input_chain_spec.clone())?; + let chain_spec = ChainSpec::from_json_file(input_chain_spec.clone())?; let _ = serde_json::from_str::(&chain_spec.as_json(true)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; }, diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 78a8f21a33e9..2a681b7ae9e1 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -121,9 +121,8 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; use sc_chain_spec::{ - ChainSpecExtension, ChainSpecGroup, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, + GenericChainSpec, GenesisConfigBuilderRuntimeCaller, }; -use serde::{Deserialize, Serialize}; use serde_json::Value; /// A utility to easily create a chain spec definition. @@ -258,29 +257,6 @@ pub struct DisplayPresetCmd { pub preset_name: Option, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - -impl sp_runtime::BuildStorage for Extensions { - /// Assimilate the storage for this module into pre-existing overlays. - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - unimplemented!(); - } -} /// Verifies the provided input chain spec. /// /// Silently checks if given input chain spec can be converted to raw. It allows to check if all diff --git a/templates/parachain/node/Cargo.toml b/templates/parachain/node/Cargo.toml index 6f7150829829..ac99132fd123 100644 --- a/templates/parachain/node/Cargo.toml +++ b/templates/parachain/node/Cargo.toml @@ -20,7 +20,6 @@ workspace = true clap = { version = "4.5.3", features = ["derive"] } log = { workspace = true, default-features = true } codec = { package = "parity-scale-codec", version = "3.6.12" } -serde = { features = ["derive"], workspace = true, default-features = true } jsonrpsee = { version = "0.22", features = ["server"] } futures = "0.3.28" serde_json = { workspace = true, default-features = true } @@ -77,6 +76,7 @@ cumulus-primitives-core = { path = "../../../cumulus/primitives/core" } cumulus-primitives-parachain-inherent = { path = "../../../cumulus/primitives/parachain-inherent" } cumulus-relay-chain-interface = { path = "../../../cumulus/client/relay-chain-interface" } color-print = "0.3.4" +cumulus-client-chain-spec-extension = { path = "../../../cumulus/client/chain-spec-extension" } [build-dependencies] substrate-build-script-utils = { path = "../../../substrate/utils/build-script-utils" } diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs index 51710f1199c3..4f68323170d8 100644 --- a/templates/parachain/node/src/chain_spec.rs +++ b/templates/parachain/node/src/chain_spec.rs @@ -1,9 +1,8 @@ +use cumulus_client_chain_spec_extension::Extensions; use cumulus_primitives_core::ParaId; use parachain_template_runtime as runtime; use runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT}; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; -use serde::{Deserialize, Serialize}; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -20,24 +19,6 @@ pub fn get_from_seed(seed: &str) -> ::Pu .public() } -/// The extensions for the [`ChainSpec`]. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - type AccountPublic = ::Signer; /// Generate collator keys from seed. diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index cffbfbc1db23..ec77ce94fa59 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,5 +1,7 @@ use std::path::PathBuf; +use cumulus_client_chain_spec_extension::Extensions; + /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] pub enum Subcommand { @@ -98,7 +100,7 @@ impl RelayChainCli { para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, ) -> Self { - let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); + let extension = Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.path().join("polkadot"); Self { diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 56ae022cad2b..65f2e813f8f6 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -1,5 +1,6 @@ use std::net::SocketAddr; +use cumulus_client_chain_spec_extension::Extensions; use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; @@ -228,7 +229,7 @@ pub fn run() -> Result<()> { })) .flatten(); - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + let para_id = Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or("Could not find parachain ID in chain-spec.")?; From ae2d7c132d9687a30f72c236e3e621887c3c310d Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 3 Jun 2024 15:55:16 +0200 Subject: [PATCH 03/10] Fix build --- cumulus/test/service/src/chain_spec.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 1ae034c371d6..3169735fd49a 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -16,6 +16,7 @@ #![allow(missing_docs)] +use cumulus_client_chain_spec_extension::Extensions; use cumulus_primitives_core::ParaId; use cumulus_test_runtime::{AccountId, Signature}; use parachains_common::AuraId; @@ -56,7 +57,7 @@ pub fn get_chain_spec_with_extra_endowed( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into(), - ..Default::default() + relay_chain: "rococo-local", }, ) .with_name("Local Testnet") From fb588eaeb35a0e82376e91d18225a7833587c06b Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 3 Jun 2024 17:19:02 +0200 Subject: [PATCH 04/10] More fixes --- Cargo.lock | 2 +- cumulus/polkadot-parachain/Cargo.toml | 1 + cumulus/test/service/Cargo.toml | 1 - cumulus/test/service/src/chain_spec.rs | 4 +--- cumulus/test/service/src/main.rs | 2 +- substrate/bin/utils/chain-spec-builder/bin/main.rs | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4af722adf5d..1e0246229e67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4433,7 +4433,6 @@ dependencies = [ "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", - "serde", "serde_json", "sp-api", "sp-arithmetic", @@ -13617,6 +13616,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "seedling-runtime", + "serde", "serde_json", "shell-runtime", "sp-api", diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index de898fef266b..704e856eec90 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -21,6 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.6.12" } futures = "0.3.28" hex-literal = "0.4.1" log = { workspace = true, default-features = true } +serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } # Local diff --git a/cumulus/test/service/Cargo.toml b/cumulus/test/service/Cargo.toml index 45cda190fd41..dbfca72941bf 100644 --- a/cumulus/test/service/Cargo.toml +++ b/cumulus/test/service/Cargo.toml @@ -19,7 +19,6 @@ codec = { package = "parity-scale-codec", version = "3.6.12" } criterion = { version = "0.5.1", features = ["async_tokio"] } jsonrpsee = { version = "0.22", features = ["server"] } rand = "0.8.5" -serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } tokio = { version = "1.32.0", features = ["macros"] } tracing = "0.1.37" diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 3169735fd49a..456427886162 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -20,9 +20,7 @@ use cumulus_client_chain_spec_extension::Extensions; use cumulus_primitives_core::ParaId; use cumulus_test_runtime::{AccountId, Signature}; use parachains_common::AuraId; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; -use serde::{Deserialize, Serialize}; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -57,7 +55,7 @@ pub fn get_chain_spec_with_extra_endowed( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into(), - relay_chain: "rococo-local", + relay_chain: "rococo-local".to_string(), }, ) .with_name("Local Testnet") diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index ac51fb52f962..67f0e9354439 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_primitives_core::relay_chain::CollatorPair; -use cumulus_test_service::{chain_spec, new_partial, AnnounceBlockFn}; +use cumulus_test_service::{new_partial, AnnounceBlockFn}; use sc_cli::{CliConfiguration, SubstrateCli}; use sp_core::Pair; diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 3e8310bfbefe..aba2456793a7 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -29,7 +29,7 @@ use sc_chain_spec::{ use staging_chain_spec_builder as chain_spec_builder; use std::fs; -type ChainSpec = GenericChainSpec<(), Extensions>; +type ChainSpec = GenericChainSpec; //avoid error message escaping fn main() { From cc978aacf91c4a9f147343afc73bde1fc01934b1 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 3 Jun 2024 17:46:55 +0200 Subject: [PATCH 05/10] Make relay_chain_optional --- .../bin/utils/chain-spec-builder/bin/main.rs | 7 +++--- .../bin/utils/chain-spec-builder/src/lib.rs | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index aba2456793a7..73e7c968bb40 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -18,18 +18,17 @@ use chain_spec_builder::{ generate_chain_spec_for_runtime, AddCodeSubstituteCmd, ChainSpecBuilder, ChainSpecBuilderCmd, - ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, + ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, OptionalParaFieldsExtension, UpdateCodeCmd, + VerifyCmd, }; use clap::Parser; -use cumulus_client_chain_spec_extension::Extensions; use sc_chain_spec::{ set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, }; use staging_chain_spec_builder as chain_spec_builder; use std::fs; - -type ChainSpec = GenericChainSpec; +type ChainSpec = GenericChainSpec; //avoid error message escaping fn main() { diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index aa23ec6d4231..1cbb466321c3 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -120,7 +120,11 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; -use sc_chain_spec::{ChainType, GenericChainSpec, GenesisConfigBuilderRuntimeCaller}; +use sc_chain_spec::{ + ChainSpecExtension, ChainSpecGroup, ChainType, GenericChainSpec, + GenesisConfigBuilderRuntimeCaller, +}; +use serde::{Deserialize, Serialize}; use serde_json::Value; /// A utility to easily create a chain spec definition. @@ -325,3 +329,21 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result chain_spec.as_json(false), } } + +/// Chain-spec extension that provides access to optional `relay_chain` and `para_id` fields. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct OptionalParaFieldsExtension { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: Option, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: Option, +} + +impl OptionalParaFieldsExtension { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_chain_spec::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} From b50a2c5e8355954a2cab0e234fe63fdb80cfdfbf Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 4 Jun 2024 09:31:01 +0200 Subject: [PATCH 06/10] Refer to external extension but make optional --- Cargo.lock | 1 - .../bin/utils/chain-spec-builder/Cargo.toml | 1 - .../bin/utils/chain-spec-builder/bin/main.rs | 7 +++--- .../bin/utils/chain-spec-builder/src/lib.rs | 24 +------------------ 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e0246229e67..abdbc771ceda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20560,7 +20560,6 @@ dependencies = [ "log", "sc-chain-spec", "sc-service", - "serde", "serde_json", "sp-core", "sp-runtime", diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index a213d980a65b..2e0f5a149283 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -29,7 +29,6 @@ log = { workspace = true, default-features = true } sc-chain-spec = { path = "../../../client/chain-spec", features = ["clap"] } serde_json = { workspace = true, default-features = true } sp-tracing = { path = "../../../primitives/tracing" } -serde = { features = ["derive"], workspace = true, default-features = true } sp-runtime = { path = "../../../primitives/runtime" } sp-core = { path = "../../../primitives/core" } sc-service = { path = "../../../client/service", default-features = false } diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 73e7c968bb40..dd76517f4b12 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -18,17 +18,18 @@ use chain_spec_builder::{ generate_chain_spec_for_runtime, AddCodeSubstituteCmd, ChainSpecBuilder, ChainSpecBuilderCmd, - ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, OptionalParaFieldsExtension, UpdateCodeCmd, - VerifyCmd, + ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; +use cumulus_client_chain_spec_extension::Extensions; use sc_chain_spec::{ set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, }; use staging_chain_spec_builder as chain_spec_builder; use std::fs; -type ChainSpec = GenericChainSpec; + +type ChainSpec = GenericChainSpec, ()>; //avoid error message escaping fn main() { diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 1cbb466321c3..aa23ec6d4231 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -120,11 +120,7 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; -use sc_chain_spec::{ - ChainSpecExtension, ChainSpecGroup, ChainType, GenericChainSpec, - GenesisConfigBuilderRuntimeCaller, -}; -use serde::{Deserialize, Serialize}; +use sc_chain_spec::{ChainType, GenericChainSpec, GenesisConfigBuilderRuntimeCaller}; use serde_json::Value; /// A utility to easily create a chain spec definition. @@ -329,21 +325,3 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result chain_spec.as_json(false), } } - -/// Chain-spec extension that provides access to optional `relay_chain` and `para_id` fields. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct OptionalParaFieldsExtension { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: Option, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: Option, -} - -impl OptionalParaFieldsExtension { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_chain_spec::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} From 4259adbc9548a17968533db3258bc2fc572e53ee Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 4 Jun 2024 14:50:14 +0200 Subject: [PATCH 07/10] Add prdoc, fix toml format --- Cargo.toml | 2 +- prdoc/pr_4685.prdoc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_4685.prdoc diff --git a/Cargo.toml b/Cargo.toml index 0696580d8960..72dcdf5bdb59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,13 +61,13 @@ members = [ "bridges/snowbridge/primitives/router", "bridges/snowbridge/runtime/runtime-common", "bridges/snowbridge/runtime/test-common", + "cumulus/client/chain-spec-extension", "cumulus/client/cli", "cumulus/client/collator", "cumulus/client/consensus/aura", "cumulus/client/consensus/common", "cumulus/client/consensus/proposer", "cumulus/client/consensus/relay-chain", - "cumulus/client/chain-spec-extension", "cumulus/client/network", "cumulus/client/parachain-inherent", "cumulus/client/pov-recovery", diff --git a/prdoc/pr_4685.prdoc b/prdoc/pr_4685.prdoc new file mode 100644 index 000000000000..36b2b33c23ca --- /dev/null +++ b/prdoc/pr_4685.prdoc @@ -0,0 +1,16 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Chain-spec-builder supports parachain chain-specs and `codeSubstitutes`. + +doc: + - audience: Node Operator + description: | + Chain-spec-builder now supports parachain chain-specs. Parachain chain-specs have the `relay_chain` and `para_id` fields. + Before this change, the fields would get silently removed when using the chain-spec-builder. + In addition, a new subcommand `add-code-substitute` is available. It allows users to provide a runtime that should be used from a given + block onwards. + +crates: + - name: staging-chain-spec-builder + bump: major From 79155a9180bcb629b13f4b3d7271da1acc5ce1e0 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 4 Jun 2024 15:33:35 +0200 Subject: [PATCH 08/10] Change bump to minor --- prdoc/pr_4685.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4685.prdoc b/prdoc/pr_4685.prdoc index 36b2b33c23ca..a9d3bf49a277 100644 --- a/prdoc/pr_4685.prdoc +++ b/prdoc/pr_4685.prdoc @@ -13,4 +13,4 @@ doc: crates: - name: staging-chain-spec-builder - bump: major + bump: minor From 49ddf11eb3b38cd8975f9af961618afa0e1fe4eb Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 25 Jun 2024 13:44:16 +0200 Subject: [PATCH 09/10] Revert extension related changeS --- Cargo.lock | 17 +-------- Cargo.toml | 2 - .../client/chain-spec-extension/Cargo.toml | 14 ------- .../client/chain-spec-extension/src/lib.rs | 38 ------------------- cumulus/polkadot-parachain/Cargo.toml | 2 - .../polkadot-parachain/src/chain_spec/mod.rs | 21 +++++++++- cumulus/polkadot-parachain/src/cli.rs | 1 - cumulus/polkadot-parachain/src/command.rs | 2 +- cumulus/test/service/src/chain_spec.rs | 23 ++++++++--- cumulus/test/service/src/main.rs | 9 ++--- .../bin/utils/chain-spec-builder/Cargo.toml | 4 -- .../bin/utils/chain-spec-builder/bin/main.rs | 3 +- templates/parachain/node/Cargo.toml | 1 - templates/parachain/node/src/chain_spec.rs | 21 +++++++++- templates/parachain/node/src/cli.rs | 4 +- templates/parachain/node/src/command.rs | 3 +- 16 files changed, 68 insertions(+), 97 deletions(-) delete mode 100644 cumulus/client/chain-spec-extension/Cargo.toml delete mode 100644 cumulus/client/chain-spec-extension/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 98652e630704..22564aa9cae3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3618,14 +3618,6 @@ dependencies = [ "cipher 0.4.4", ] -[[package]] -name = "cumulus-client-chain-spec-extension" -version = "0.1.0" -dependencies = [ - "sc-chain-spec", - "serde", -] - [[package]] name = "cumulus-client-cli" version = "0.7.0" @@ -4425,7 +4417,6 @@ dependencies = [ "async-trait", "clap 4.5.3", "criterion", - "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -4477,6 +4468,7 @@ dependencies = [ "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", + "serde", "serde_json", "sp-api", "sp-arithmetic", @@ -11810,7 +11802,6 @@ version = "0.0.0" dependencies = [ "clap 4.5.3", "color-print", - "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -11847,6 +11838,7 @@ dependencies = [ "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", + "serde", "serde_json", "sp-api", "sp-block-builder", @@ -13653,7 +13645,6 @@ dependencies = [ "contracts-rococo-runtime", "coretime-rococo-runtime", "coretime-westend-runtime", - "cumulus-client-chain-spec-extension", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -20676,13 +20667,9 @@ name = "staging-chain-spec-builder" version = "1.6.1" dependencies = [ "clap 4.5.3", - "cumulus-client-chain-spec-extension", "log", "sc-chain-spec", - "sc-service", "serde_json", - "sp-core", - "sp-runtime", "sp-tracing 16.0.0", ] diff --git a/Cargo.toml b/Cargo.toml index a76d4eee7c7c..60459500a890 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,6 @@ members = [ "bridges/snowbridge/primitives/router", "bridges/snowbridge/runtime/runtime-common", "bridges/snowbridge/runtime/test-common", - "cumulus/client/chain-spec-extension", "cumulus/client/cli", "cumulus/client/collator", "cumulus/client/consensus/aura", @@ -680,7 +679,6 @@ cumulus-client-consensus-proposer = { path = "cumulus/client/consensus/proposer" cumulus-client-consensus-relay-chain = { path = "cumulus/client/consensus/relay-chain", default-features = false } cumulus-client-network = { path = "cumulus/client/network", default-features = false } cumulus-client-parachain-inherent = { path = "cumulus/client/parachain-inherent", default-features = false } -cumulus-client-chain-spec-extension = { path = "cumulus/client/chain-spec-extension", default-features = false } cumulus-client-pov-recovery = { path = "cumulus/client/pov-recovery", default-features = false } cumulus-client-service = { path = "cumulus/client/service", default-features = false } cumulus-pallet-aura-ext = { path = "cumulus/pallets/aura-ext", default-features = false } diff --git a/cumulus/client/chain-spec-extension/Cargo.toml b/cumulus/client/chain-spec-extension/Cargo.toml deleted file mode 100644 index 7d27f944afed..000000000000 --- a/cumulus/client/chain-spec-extension/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "cumulus-client-chain-spec-extension" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -description = "Parachain chain-spec extension." -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" - -[lints] -workspace = true - -[dependencies] -sc-chain-spec = { path = "../../../substrate/client/chain-spec" } -serde = { features = ["derive"], workspace = true, default-features = true } diff --git a/cumulus/client/chain-spec-extension/src/lib.rs b/cumulus/client/chain-spec-extension/src/lib.rs deleted file mode 100644 index 495e084fd9cb..000000000000 --- a/cumulus/client/chain-spec-extension/src/lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! Chain spec extension for parachains. - -use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup}; -use serde::{Deserialize, Serialize}; - -/// The extensions for the [`ChainSpec`]. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 37b0cca9b329..d12eaa5c0d49 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -112,8 +112,6 @@ cumulus-client-service = { workspace = true, default-features = true } cumulus-primitives-aura = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } -cumulus-client-chain-spec-extension = { workspace = true, default-features = true } - [build-dependencies] substrate-build-script-utils = { workspace = true, default-features = true } diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index ae3d5b248caa..19047b073b05 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use cumulus_client_chain_spec_extension::Extensions; use parachains_common::{AccountId, Signature}; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; +use serde::{Deserialize, Serialize}; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -34,6 +35,24 @@ pub mod shell; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; +/// Generic extensions for Parachain ChainSpecs. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct Extensions { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: String, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + /// Generic chain spec for all polkadot-parachain runtimes pub type GenericChainSpec = sc_service::GenericChainSpec; diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index 117c75ca44f0..fa4b4da1ba9c 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -15,7 +15,6 @@ // along with Cumulus. If not, see . use clap::{CommandFactory, FromArgMatches}; -use cumulus_client_chain_spec_extension::Extensions; use std::path::PathBuf; /// Sub-commands supported by the collator. diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 8dcfb0e98fa5..6b3f4b4cd0a7 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -641,7 +641,7 @@ pub fn run() -> Result<()> { sc_sysinfo::gather_hwbench(Some(database_path)) })).flatten(); - let para_id = cumulus_client_chain_spec_extension::Extensions::try_get(&*config.chain_spec) + let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or("Could not find parachain extension in chain-spec.")?; diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index fd289f8591ab..174d478f2575 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -16,11 +16,12 @@ #![allow(missing_docs)] -use cumulus_client_chain_spec_extension::Extensions; use cumulus_primitives_core::ParaId; use cumulus_test_runtime::{AccountId, Signature}; use parachains_common::AuraId; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; +use serde::{Deserialize, Serialize}; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -34,6 +35,21 @@ pub fn get_from_seed(seed: &str) -> ::Pu .public() } +/// The extensions for the [`ChainSpec`]. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[serde(deny_unknown_fields)] +pub struct Extensions { + /// The id of the Parachain. + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + type AccountPublic = ::Signer; /// Helper function to generate an account ID from seed. @@ -53,10 +69,7 @@ pub fn get_chain_spec_with_extra_endowed( ) -> ChainSpec { ChainSpec::builder( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { - para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into(), - relay_chain: "rococo-local".to_string(), - }, + Extensions { para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into() }, ) .with_name("Local Testnet") .with_id("local_testnet") diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 67f0e9354439..90d37173dd59 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_primitives_core::relay_chain::CollatorPair; -use cumulus_test_service::{new_partial, AnnounceBlockFn}; +use cumulus_test_service::{chain_spec, new_partial, AnnounceBlockFn}; use sc_cli::{CliConfiguration, SubstrateCli}; use sp_core::Pair; @@ -77,10 +77,9 @@ fn main() -> Result<(), sc_cli::Error> { SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) .map_err(|err| format!("Relay chain argument error: {}", err))?; - let parachain_id = - cumulus_client_chain_spec_extension::Extensions::try_get(&*config.chain_spec) - .map(|e| e.para_id) - .ok_or("Could not find parachain extension in chain-spec.")?; + let parachain_id = chain_spec::Extensions::try_get(&*config.chain_spec) + .map(|e| e.para_id) + .ok_or("Could not find parachain extension in chain-spec.")?; tracing::info!("Parachain id: {:?}", parachain_id); tracing::info!( diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index bbb8e858d221..083f2191f3c5 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -29,7 +29,3 @@ log = { workspace = true, default-features = true } sc-chain-spec = { features = ["clap"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } sp-tracing = { workspace = true, default-features = true } -sp-runtime = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -sc-service = { workspace = true, default-features = true } -cumulus-client-chain-spec-extension = { workspace = true, default-features = true } \ No newline at end of file diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 01eb46e5e19e..39fa054b4806 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -21,7 +21,6 @@ use chain_spec_builder::{ ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; -use cumulus_client_chain_spec_extension::Extensions; use sc_chain_spec::{ set_code_substitute_in_json_chain_spec, update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, @@ -29,7 +28,7 @@ use sc_chain_spec::{ use staging_chain_spec_builder as chain_spec_builder; use std::fs; -type ChainSpec = GenericChainSpec, ()>; +type ChainSpec = GenericChainSpec<(), ()>; //avoid error message escaping fn main() { diff --git a/templates/parachain/node/Cargo.toml b/templates/parachain/node/Cargo.toml index 86cf0f5826ac..7cf1f1fddc7b 100644 --- a/templates/parachain/node/Cargo.toml +++ b/templates/parachain/node/Cargo.toml @@ -73,7 +73,6 @@ cumulus-client-service = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } -cumulus-client-chain-spec-extension = { workspace = true, default-features = true } color-print = { workspace = true } [build-dependencies] diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs index 85389b05cb40..3fa91c026162 100644 --- a/templates/parachain/node/src/chain_spec.rs +++ b/templates/parachain/node/src/chain_spec.rs @@ -1,8 +1,9 @@ -use cumulus_client_chain_spec_extension::Extensions; use cumulus_primitives_core::ParaId; use parachain_template_runtime as runtime; use runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT}; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; +use serde::{Deserialize, Serialize}; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -19,6 +20,24 @@ pub fn get_from_seed(seed: &str) -> ::Pu .public() } +/// The extensions for the [`ChainSpec`]. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct Extensions { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: String, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + type AccountPublic = ::Signer; /// Generate collator keys from seed. diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index b87e39708ca9..f008e856d99b 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,7 +1,5 @@ use std::path::PathBuf; -use cumulus_client_chain_spec_extension::Extensions; - /// Sub-commands supported by the collator. #[allow(clippy::large_enum_variant)] #[derive(Debug, clap::Subcommand)] @@ -101,7 +99,7 @@ impl RelayChainCli { para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, ) -> Self { - let extension = Extensions::try_get(&*para_config.chain_spec); + let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.path().join("polkadot"); Self { diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 17014f0e9880..eba7fdcdae71 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -1,6 +1,5 @@ use std::net::SocketAddr; -use cumulus_client_chain_spec_extension::Extensions; use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; @@ -227,7 +226,7 @@ pub fn run() -> Result<()> { })) .flatten(); - let para_id = Extensions::try_get(&*config.chain_spec) + let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or("Could not find parachain ID in chain-spec.")?; From b078a7f2776480fc3cc9d40e981d999e25ac2edc Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 25 Jun 2024 14:12:04 +0200 Subject: [PATCH 10/10] Update prdoc --- prdoc/pr_4685.prdoc | 10 +++++----- substrate/bin/utils/chain-spec-builder/src/lib.rs | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/prdoc/pr_4685.prdoc b/prdoc/pr_4685.prdoc index a9d3bf49a277..e212919ba2e5 100644 --- a/prdoc/pr_4685.prdoc +++ b/prdoc/pr_4685.prdoc @@ -1,15 +1,15 @@ # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json -title: Chain-spec-builder supports parachain chain-specs and `codeSubstitutes`. +title: Chain-spec-builder supports `codeSubstitutes`. doc: - audience: Node Operator description: | - Chain-spec-builder now supports parachain chain-specs. Parachain chain-specs have the `relay_chain` and `para_id` fields. - Before this change, the fields would get silently removed when using the chain-spec-builder. - In addition, a new subcommand `add-code-substitute` is available. It allows users to provide a runtime that should be used from a given - block onwards. + A new subcommand `add-code-substitute` is available for the `chain-spec-builder` binary. It allows users to provide a runtime that should be used from a given + block onwards. The `codeSubstitutes` field in the chain spec is used to force usage of a given runtime at a given block until the next runtime upgrade. It can be + used to progress chains that are stalled due to runtime bugs that prevent block-building. However, parachain usage is only possible in combination with an updated + validation function on the relay chain. crates: - name: staging-chain-spec-builder diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index a69ea1c8ff67..6c679f109a00 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -226,7 +226,12 @@ pub struct UpdateCodeCmd { /// Add a code substitute in the chain spec. /// /// The `codeSubstitute` object of the chain spec will be updated with the block height as key and -/// runtime code as value. This operation supports both plain and raw formats. +/// runtime code as value. This operation supports both plain and raw formats. The `codeSubstitute` +/// field instructs the node to use the provided runtime code at the given block height. This is +/// useful when the chain can not progress on its own due to a bug that prevents block-building. +/// +/// Note: For parachains, the validation function on the relaychain needs to be adjusted too, +/// otherwise blocks built using the substituted parachain runtime will be rejected. #[derive(Parser, Debug, Clone)] pub struct AddCodeSubstituteCmd { /// Chain spec to be updated.