difftreelog
refactor(node) use export-genesis state from cumulus
in: master
We had our implementation for some reason, however it is now broken, and I see no reason to keep it, as upstream implements exact same options
2 files changed
node/cli/src/cli.rsdiffbeforeafterboth24#[derive(Debug, Parser)]24#[derive(Debug, Parser)]25pub enum Subcommand {25pub enum Subcommand {26 /// Export the genesis state of the parachain.26 /// Export the genesis state of the parachain.27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),27 ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),292830 /// Export the genesis wasm of the parachain.29 /// Export the genesis wasm of the parachain.31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),30 ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),333134 /// Build a chain specification.32 /// Build a chain specification.35 BuildSpec(sc_cli::BuildSpecCmd),33 BuildSpec(sc_cli::BuildSpecCmd),60 TryRuntime(try_runtime_cli::TryRuntimeCmd),58 TryRuntime(try_runtime_cli::TryRuntimeCmd),61}59}6263/// Command for exporting the genesis state of the parachain64#[derive(Debug, Parser)]65pub struct ExportGenesisStateCommand {66 /// Output file name or stdout if unspecified.67 #[clap(parse(from_os_str))]68 pub output: Option<PathBuf>,6970 /// Id of the parachain this state is for.71 ///72 /// Default: 10073 #[clap(long, conflicts_with = "chain")]74 pub parachain_id: Option<u32>,7576 /// Write output in binary. Default is to write in hex.77 #[clap(short, long)]78 pub raw: bool,7980 /// The name of the chain for that the genesis state should be exported.81 #[clap(long, conflicts_with = "parachain-id")]82 pub chain: Option<String>,83}8485/// Command for exporting the genesis wasm file.86#[derive(Debug, Parser)]87pub struct ExportGenesisWasmCommand {88 /// Output file name or stdout if unspecified.89 #[clap(parse(from_os_str))]90 pub output: Option<PathBuf>,9192 /// Write output in binary. Default is to write in hex.93 #[clap(short, long)]94 pub raw: bool,9596 /// The name of the chain for that the genesis wasm file should be exported.97 #[clap(long)]98 pub chain: Option<String>,99}10060101#[derive(Debug, Parser)]61#[derive(Debug, Parser)]102#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]62#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -50,7 +50,7 @@
use codec::Encode;
use cumulus_primitives_core::ParaId;
-use cumulus_client_service::genesis::generate_genesis_block;
+use cumulus_client_cli::generate_genesis_block;
use std::{future::Future, pin::Pin};
use log::info;
use sc_cli::{
@@ -62,7 +62,7 @@
};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
-use std::{io::Write, net::SocketAddr, time::Duration};
+use std::{net::SocketAddr, time::Duration};
use up_common::types::opaque::Block;
@@ -189,16 +189,6 @@
fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
-}
-
-#[allow(clippy::borrowed_box)]
-fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
- let mut storage = chain_spec.build_storage()?;
-
- storage
- .top
- .remove(sp_core::storage::well_known_keys::CODE)
- .ok_or_else(|| "Could not find wasm file in genesis state!".into())
}
macro_rules! async_run_with_runtime {
@@ -248,6 +238,45 @@
}}
}
+macro_rules! sync_run_with_runtime {
+ (
+ $runtime_api:path, $executor:path,
+ $runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident,
+ $( $code:tt )*
+ ) => {
+ $runner.sync_run(|$config| {
+ $( $code )*
+ })
+ };
+}
+
+macro_rules! construct_sync_run {
+ (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
+ let runner = $cli.create_runner($cmd)?;
+
+ match runner.config().chain_spec.runtime_id() {
+ #[cfg(feature = "unique-runtime")]
+ RuntimeId::Unique => sync_run_with_runtime!(
+ unique_runtime::RuntimeApi, UniqueRuntimeExecutor,
+ runner, $components, $cli, $cmd, $config, $( $code )*
+ ),
+
+ #[cfg(feature = "quartz-runtime")]
+ RuntimeId::Quartz => sync_run_with_runtime!(
+ quartz_runtime::RuntimeApi, QuartzRuntimeExecutor,
+ runner, $components, $cli, $cmd, $config, $( $code )*
+ ),
+
+ RuntimeId::Opal => sync_run_with_runtime!(
+ opal_runtime::RuntimeApi, OpalRuntimeExecutor,
+ runner, $components, $cli, $cmd, $config, $( $code )*
+ ),
+
+ RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into())
+ }
+ }}
+}
+
macro_rules! start_node_using_chain_runtime {
($start_node_fn:ident($config:expr $(, $($args:expr),+)?) $($code:tt)*) => {
match $config.chain_spec.runtime_id() {
@@ -329,49 +358,18 @@
Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.backend, None))
}),
- Some(Subcommand::ExportGenesisState(params)) => {
- let mut builder = sc_cli::LoggerBuilder::new("");
- builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
- let _ = builder.init();
-
- let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;
- let state_version = Cli::native_runtime_version(&spec).state_version();
- let block: Block = generate_genesis_block(&spec, state_version)?;
- let raw_header = block.header().encode();
- let output_buf = if params.raw {
- raw_header
- } else {
- format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()
- };
-
- if let Some(output) = ¶ms.output {
- std::fs::write(output, output_buf)?;
- } else {
- std::io::stdout().write_all(&output_buf)?;
- }
-
- Ok(())
+ Some(Subcommand::ExportGenesisState(cmd)) => {
+ construct_sync_run!(|components, cli, cmd, _config| {
+ let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
+ let state_version = Cli::native_runtime_version(&spec).state_version();
+ cmd.run::<Block>(&*spec, state_version)
+ })
}
- Some(Subcommand::ExportGenesisWasm(params)) => {
- let mut builder = sc_cli::LoggerBuilder::new("");
- builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
- let _ = builder.init();
-
- let raw_wasm_blob =
- extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
- let output_buf = if params.raw {
- raw_wasm_blob
- } else {
- format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()
- };
-
- if let Some(output) = ¶ms.output {
- std::fs::write(output, output_buf)?;
- } else {
- std::io::stdout().write_all(&output_buf)?;
- }
-
- Ok(())
+ Some(Subcommand::ExportGenesisWasm(cmd)) => {
+ construct_sync_run!(|components, cli, cmd, _config| {
+ let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
+ cmd.run(&*spec)
+ })
}
Some(Subcommand::Benchmark(cmd)) => {
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
@@ -500,7 +498,7 @@
let state_version =
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
- let block: Block = generate_genesis_block(&config.chain_spec, state_version)
+ let block: Block = generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
let genesis_hash = format!("0x{:?}", HexDisplay::from(&block.header().hash().0));