From 601528943e0c02df2f87dcb70f5ab6eb7a4c3494 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 2 May 2024 11:07:55 +0200 Subject: [PATCH 1/2] fix export genesis state Signed-off-by: Ermal Kaleci --- bin/collator/src/command.rs | 40 +++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/bin/collator/src/command.rs b/bin/collator/src/command.rs index f84315565..294b6ecab 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,32 @@ 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)?; From c739984fc61dfc9b0983f4708cc1f2515f8017e6 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 2 May 2024 12:02:00 +0200 Subject: [PATCH 2/2] fmt Signed-off-by: Ermal Kaleci --- bin/collator/src/command.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bin/collator/src/command.rs b/bin/collator/src/command.rs index 294b6ecab..cf25d589e 100644 --- a/bin/collator/src/command.rs +++ b/bin/collator/src/command.rs @@ -459,26 +459,29 @@ pub fn run() -> Result<()> { 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, - )?; + 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, - )?; + let PartialComponents { client, .. } = + parachain::new_partial::( + &config, + parachain::build_import_queue, + )?; cmd.run(config.chain_spec.as_ref(), client.as_ref()) }) } else { runner.sync_run(|config| { - let PartialComponents { client, .. } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; + let PartialComponents { client, .. } = + parachain::new_partial::( + &config, + parachain::build_import_queue, + )?; cmd.run(config.chain_spec.as_ref(), client.as_ref()) }) }