From e2d0097a120f03a625c0739dac1d19beac73cf5f Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Mon, 6 May 2024 09:58:07 +0200 Subject: [PATCH] fix export genesis state (#1233) * fix export genesis state Signed-off-by: Ermal Kaleci --- bin/collator/src/command.rs | 43 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/bin/collator/src/command.rs b/bin/collator/src/command.rs index f84315565e..cf25d589e3 100644 --- a/bin/collator/src/command.rs +++ b/bin/collator/src/command.rs @@ -41,7 +41,7 @@ use sc_service::{ use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::AccountIdConversion; use sp_runtime::traits::Block as BlockT; -use std::{io::Write, net::SocketAddr}; +use std::net::SocketAddr; #[cfg(feature = "runtime-benchmarks")] use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; @@ -456,22 +456,35 @@ pub fn run() -> Result<()> { } } Some(Subcommand::ExportGenesisState(cmd)) => { - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - let state_version = Cli::runtime_version(&spec).state_version(); - - let block: Block = generate_genesis_block(&*spec, state_version)?; - let raw_header = block.header().encode(); - let output_buf = if cmd.raw { - raw_header - } else { - format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() - }; - if let Some(output) = &cmd.output { - std::fs::write(output, output_buf)?; + let runner = cli.create_runner(cmd)?; + if runner.config().chain_spec.is_astar() { + runner.sync_run(|config| { + let PartialComponents { client, .. } = + parachain::new_partial::( + &config, + parachain::build_import_queue, + )?; + cmd.run(config.chain_spec.as_ref(), client.as_ref()) + }) + } else if runner.config().chain_spec.is_shiden() { + runner.sync_run(|config| { + let PartialComponents { client, .. } = + parachain::new_partial::( + &config, + parachain::build_import_queue, + )?; + cmd.run(config.chain_spec.as_ref(), client.as_ref()) + }) } else { - std::io::stdout().write_all(&output_buf)?; + runner.sync_run(|config| { + let PartialComponents { client, .. } = + parachain::new_partial::( + &config, + parachain::build_import_queue, + )?; + cmd.run(config.chain_spec.as_ref(), client.as_ref()) + }) } - Ok(()) } Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?;