-
Notifications
You must be signed in to change notification settings - Fork 707
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
chain-spec-builder: Add support for codeSubstitutes
#4685
Changes from 6 commits
c8e76ad
c45be3a
7559188
ae2d7c1
fb588ea
cc978aa
b50a2c5
4259adb
728304c
79155a9
2f0a4e4
49ddf11
b078a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
|
||
//! 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()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,18 @@ | |
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
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, ListPresetsCmd, OptionalParaFieldsExtension, 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; | ||
type ChainSpec = GenericChainSpec<OptionalParaFieldsExtension, ()>; | ||
|
||
//avoid error message escaping | ||
fn main() { | ||
|
@@ -50,7 +53,7 @@ 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 = ChainSpec::from_json_file(input_chain_spec.clone())?; | ||
|
||
let mut chain_spec_json = | ||
serde_json::from_str::<serde_json::Value>(&chain_spec.as_json(false)?) | ||
|
@@ -65,8 +68,29 @@ 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 = ChainSpec::from_json_file(input_chain_spec.clone())?; | ||
|
||
let mut chain_spec_json = | ||
serde_json::from_str::<serde_json::Value>(&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())?; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: to avoid code duplication in |
||
ChainSpecBuilderCmd::ConvertToRaw(ConvertToRawCmd { ref input_chain_spec }) => { | ||
let chain_spec = GenericChainSpec::<()>::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::<serde_json::Value>(&chain_spec.as_json(true)?) | ||
|
@@ -77,7 +101,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::<()>::from_json_file(input_chain_spec.clone())?; | ||
let chain_spec = ChainSpec::from_json_file(input_chain_spec.clone())?; | ||
let _ = serde_json::from_str::<serde_json::Value>(&chain_spec.as_json(true)?) | ||
.map_err(|e| format!("Conversion to json failed: {e}"))?; | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a new crate for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that we can refer to this crate from small tools like chain-spec-builder without pulling in the whole world of dependencies. Which would be the case if I put it in some other bigger crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be also done with features, one of which could be 'api' exposing necessary types only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe move it to sc_chain_spec::common, as it is typical/common of parachains?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#4685 (comment) given this, we should revert these changes. Merge the pr with the
codeSubstitute
support and add a new one that ignores the unknown fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking of follow up #4873