mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 06:57:58 +00:00
chain-spec: getting ready for native-runtime-free world (#1256)
This PR prepares chains specs for _native-runtime-free_ world. This PR has following changes: - `substrate`: - adds support for: - JSON based `GenesisConfig` to `ChainSpec` allowing interaction with runtime `GenesisBuilder` API. - interacting with arbitrary runtime wasm blob to[ `chain-spec-builder`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/bin/utils/chain-spec-builder/src/lib.rs#L46) command line util, - removes [`code`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/frame/system/src/lib.rs#L660) from `system_pallet` - adds `code` to the `ChainSpec` - deprecates [`ChainSpec::from_genesis`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/client/chain-spec/src/chain_spec.rs#L263), but also changes the signature of this method extending it with `code` argument. [`ChainSpec::builder()`](https://github.com/paritytech/substrate/blob/20bee680ed098be7239cf7a6b804cd4de267983e/client/chain-spec/src/chain_spec.rs#L507) should be used instead. - `polkadot`: - all references to `RuntimeGenesisConfig` in `node/service` are removed, - all `(kusama|polkadot|versi|rococo|wococo)_(staging|dev)_genesis_config` functions now return the JSON patch for default runtime `GenesisConfig`, - `ChainSpecBuilder` is used, `ChainSpec::from_genesis` is removed, - `cumulus`: - `ChainSpecBuilder` is used, `ChainSpec::from_genesis` is removed, - _JSON_ patch configuration used instead of `RuntimeGenesisConfig struct` in all chain specs. --------- Co-authored-by: command-bot <> Co-authored-by: Javier Viola <javier@parity.io> Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: Kevin Krone <kevin@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
committed by
GitHub
parent
c46a7dbb61
commit
8ba7a6aba8
@@ -17,28 +17,40 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use chain_spec_builder::{
|
||||
generate_authority_keys_and_store, generate_chain_spec, print_seeds, ChainSpecBuilder,
|
||||
generate_authority_keys_and_store, generate_chain_spec, generate_chain_spec_for_runtime,
|
||||
print_seeds, ChainSpecBuilder, ChainSpecBuilderCmd, EditCmd, GenerateCmd, NewCmd, VerifyCmd,
|
||||
};
|
||||
use clap::Parser;
|
||||
use node_cli::chain_spec;
|
||||
use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
|
||||
use sc_chain_spec::{update_code_in_json_chain_spec, GenericChainSpec};
|
||||
use sp_core::{crypto::Ss58Codec, sr25519};
|
||||
use staging_chain_spec_builder as chain_spec_builder;
|
||||
use std::fs;
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
#[cfg(build_type = "debug")]
|
||||
println!(
|
||||
"The chain spec builder builds a chain specification that includes a Substrate runtime \
|
||||
compiled as WASM. To ensure proper functioning of the included runtime compile (or run) \
|
||||
the chain spec builder binary in `--release` mode.\n",
|
||||
);
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
let builder = ChainSpecBuilder::parse();
|
||||
let chain_spec_path = builder.chain_spec_path().to_path_buf();
|
||||
#[cfg(build_type = "debug")]
|
||||
if matches!(builder.command, ChainSpecBuilderCmd::Generate(_) | ChainSpecBuilderCmd::New(_)) {
|
||||
println!(
|
||||
"The chain spec builder builds a chain specification that includes a Substrate runtime \
|
||||
compiled as WASM. To ensure proper functioning of the included runtime compile (or run) \
|
||||
the chain spec builder binary in `--release` mode.\n",
|
||||
);
|
||||
}
|
||||
|
||||
let (authority_seeds, nominator_accounts, endowed_accounts, sudo_account) = match builder {
|
||||
ChainSpecBuilder::Generate { authorities, nominators, endowed, keystore_path, .. } => {
|
||||
let chain_spec_path = builder.chain_spec_path.to_path_buf();
|
||||
let mut write_chain_spec = true;
|
||||
|
||||
let chain_spec_json = match builder.command {
|
||||
ChainSpecBuilderCmd::Generate(GenerateCmd {
|
||||
authorities,
|
||||
nominators,
|
||||
endowed,
|
||||
keystore_path,
|
||||
}) => {
|
||||
let authorities = authorities.max(1);
|
||||
let rand_str = || -> String {
|
||||
OsRng.sample_iter(&Alphanumeric).take(32).map(char::from).collect()
|
||||
@@ -72,19 +84,58 @@ fn main() -> Result<(), String> {
|
||||
let sudo_account =
|
||||
chain_spec::get_account_id_from_seed::<sr25519::Public>(&sudo_seed).to_ss58check();
|
||||
|
||||
(authority_seeds, nominator_accounts, endowed_accounts, sudo_account)
|
||||
generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account)
|
||||
},
|
||||
ChainSpecBuilder::New {
|
||||
ChainSpecBuilderCmd::New(NewCmd {
|
||||
authority_seeds,
|
||||
nominator_accounts,
|
||||
endowed_accounts,
|
||||
sudo_account,
|
||||
..
|
||||
} => (authority_seeds, nominator_accounts, endowed_accounts, sudo_account),
|
||||
};
|
||||
}) =>
|
||||
generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account),
|
||||
ChainSpecBuilderCmd::Runtime(cmd) => generate_chain_spec_for_runtime(&cmd),
|
||||
ChainSpecBuilderCmd::Edit(EditCmd {
|
||||
ref input_chain_spec,
|
||||
ref runtime_wasm_path,
|
||||
convert_to_raw,
|
||||
}) => {
|
||||
let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?;
|
||||
|
||||
let json =
|
||||
generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account)?;
|
||||
let mut chain_spec_json =
|
||||
serde_json::from_str::<serde_json::Value>(&chain_spec.as_json(convert_to_raw)?)
|
||||
.map_err(|e| format!("Conversion to json failed: {e}"))?;
|
||||
if let Some(path) = runtime_wasm_path {
|
||||
update_code_in_json_chain_spec(
|
||||
&mut chain_spec_json,
|
||||
&fs::read(path.as_path())
|
||||
.map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..],
|
||||
);
|
||||
}
|
||||
|
||||
fs::write(chain_spec_path, json).map_err(|err| err.to_string())
|
||||
serde_json::to_string_pretty(&chain_spec_json)
|
||||
.map_err(|e| format!("to pretty failed: {e}"))
|
||||
},
|
||||
ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec, ref runtime_wasm_path }) => {
|
||||
write_chain_spec = false;
|
||||
let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?;
|
||||
let mut chain_spec_json =
|
||||
serde_json::from_str::<serde_json::Value>(&chain_spec.as_json(true)?)
|
||||
.map_err(|e| format!("Conversion to json failed: {e}"))?;
|
||||
if let Some(path) = runtime_wasm_path {
|
||||
update_code_in_json_chain_spec(
|
||||
&mut chain_spec_json,
|
||||
&fs::read(path.as_path())
|
||||
.map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..],
|
||||
);
|
||||
};
|
||||
serde_json::to_string_pretty(&chain_spec_json)
|
||||
.map_err(|e| format!("to pretty failed: {e}"))
|
||||
},
|
||||
}?;
|
||||
|
||||
if write_chain_spec {
|
||||
fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user