Skip to content
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

fix export genesis state #1233

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<astar::RuntimeApi, astar::Executor, _>(
&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::<shiden::RuntimeApi, shiden::Executor, _>(
&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::<shibuya::RuntimeApi, shibuya::Executor, _>(
&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)?;
Expand Down
Loading