From 8b365134d43d450ce90b52f67547a5df022c8e19 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 13:11:44 +0100 Subject: [PATCH 1/7] refactor: :recycle: use `cumulus_client_cli::ExportGenesisHeadCommand` instead of a custom implementation --- node/cli/src/cli.rs | 22 +--------------------- node/cli/src/command.rs | 9 +++------ scripts/generate-parachain-specs.sh | 2 -- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/node/cli/src/cli.rs b/node/cli/src/cli.rs index c93fcce207b..362a3efcbec 100644 --- a/node/cli/src/cli.rs +++ b/node/cli/src/cli.rs @@ -49,7 +49,7 @@ fn validate_url(arg: &str) -> Result { pub enum Subcommand { /// Export the genesis state of the parachain. #[clap(name = "export-genesis-state")] - ExportGenesisHead(ExportGenesisHeadCommand), + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. #[clap(name = "export-genesis-wasm")] @@ -108,26 +108,6 @@ pub struct BuildSpecCommand { pub mnemonic: Option, } -/// Command for exporting the genesis state of the parachain -#[derive(Debug, Parser)] -pub struct ExportGenesisHeadCommand { - /// Output file name or stdout if unspecified. - #[clap(value_parser)] - pub output: Option, - - /// Id of the parachain this state is for. - #[clap(long)] - pub parachain_id: Option, - - /// Write output in binary. Default is to write in hex. - #[clap(short, long)] - pub raw: bool, - - /// The name of the chain for that the genesis state should be exported. - #[clap(long)] - pub chain: Option, -} - /// Command for exporting the genesis wasm file. #[derive(Debug, Parser)] pub struct ExportGenesisWasmCommand { diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 4056b32afe4..60c2ab1f5dd 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -419,16 +419,13 @@ pub fn run() -> Result<()> { } } Some(Subcommand::ExportGenesisHead(params)) => { + let runner = cli.create_runner(params)?; + let chain_spec = (runner.config().chain_spec).cloned_box(); + let mut builder = sc_cli::LoggerBuilder::new(""); builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); let _ = builder.init(); - // Cumulus approach here, we directly call the generic load_spec func - let chain_spec = load_spec( - params.chain.as_deref().unwrap_or_default(), - params.parachain_id.unwrap_or(1000).into(), - &cli.run, - )?; let state_version = Cli::runtime_version(&chain_spec).state_version(); let output_buf = match chain_spec { diff --git a/scripts/generate-parachain-specs.sh b/scripts/generate-parachain-specs.sh index c3792ad825b..b6558387eaf 100755 --- a/scripts/generate-parachain-specs.sh +++ b/scripts/generate-parachain-specs.sh @@ -28,8 +28,6 @@ $MOONBEAM_BINARY export-genesis-wasm \ echo $ALPHANET_WASM generated $MOONBEAM_BINARY export-genesis-state \ - --parachain-id $ALPHANET_PARACHAIN_ID \ - --chain $ALPHANET_PARACHAIN_SPEC_RAW \ > $ALPHANET_GENESIS; echo $ALPHANET_GENESIS generated From 9c976bfa5c25e4d3a01463149f571a2e24028398 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 13:30:40 +0100 Subject: [PATCH 2/7] refactor: :recycle: retrieve state version from WASM blob --- Cargo.lock | 1 + node/cli/Cargo.toml | 1 + node/cli/src/command.rs | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d33bada812..d71a74c0f93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6382,6 +6382,7 @@ dependencies = [ "sc-cli", "sc-client-api", "sc-consensus-grandpa", + "sc-executor", "sc-network", "sc-service", "sc-sysinfo", diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 600984f1859..8dd2b29d4ea 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -21,6 +21,7 @@ sc-chain-spec = { workspace = true } sc-cli = { workspace = true } sc-client-api = { workspace = true } sc-consensus-grandpa = { workspace = true } +sc-executor = { workspace = true } sc-network = { workspace = true } sc-service = { workspace = true } sc-sysinfo = { workspace = true } diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 60c2ab1f5dd..9bee8407e72 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -30,7 +30,7 @@ use moonbeam_service::moonbeam_runtime; #[cfg(feature = "moonriver-native")] use moonbeam_service::moonriver_runtime; -use moonbeam_service::{chain_spec, frontier_database_dir, HostFunctions, IdentifyVariant}; +use moonbeam_service::{chain_spec, frontier_database_dir, Block, HostFunctions, IdentifyVariant}; use parity_scale_codec::Encode; #[cfg(feature = "westend-native")] use polkadot_service::WestendChainSpec; @@ -38,6 +38,7 @@ use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, RpcEndpoint, RuntimeVersion, SharedParams, SubstrateCli, }; +use sc_executor::WasmtimeInstantiationStrategy; use sc_service::{ config::{BasePath, PrometheusConfig}, DatabaseSource, PartialComponents, @@ -420,13 +421,24 @@ pub fn run() -> Result<()> { } Some(Subcommand::ExportGenesisHead(params)) => { let runner = cli.create_runner(params)?; - let chain_spec = (runner.config().chain_spec).cloned_box(); + let chain_spec = runner.config().chain_spec.cloned_box(); let mut builder = sc_cli::LoggerBuilder::new(""); builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); let _ = builder.init(); - let state_version = Cli::runtime_version(&chain_spec).state_version(); + let storage = chain_spec.build_storage()?; + let executor = sc_executor::WasmExecutor::::builder() + .with_execution_method(sc_executor::WasmExecutionMethod::Compiled { + instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, + }) + .with_max_runtime_instances(1024) + .build(); + + let state_version = sc_chain_spec::resolve_state_version_from_wasm::< + _, + HashingFor, + >(&storage, &executor)?; let output_buf = match chain_spec { #[cfg(feature = "moonriver-native")] From a1564915cde7decf5c0da40bd41ae1af0e3b64a0 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 13:44:13 +0100 Subject: [PATCH 3/7] revert: :rewind: revert changes to generate-parachain-specs.sh --- scripts/generate-parachain-specs.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/generate-parachain-specs.sh b/scripts/generate-parachain-specs.sh index b6558387eaf..c3792ad825b 100755 --- a/scripts/generate-parachain-specs.sh +++ b/scripts/generate-parachain-specs.sh @@ -28,6 +28,8 @@ $MOONBEAM_BINARY export-genesis-wasm \ echo $ALPHANET_WASM generated $MOONBEAM_BINARY export-genesis-state \ + --parachain-id $ALPHANET_PARACHAIN_ID \ + --chain $ALPHANET_PARACHAIN_SPEC_RAW \ > $ALPHANET_GENESIS; echo $ALPHANET_GENESIS generated From 76f6a07afd860a50d02d2acb276c6c58f48d8972 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 14:13:09 +0100 Subject: [PATCH 4/7] fix: :bug: remove unsupported option in export-genesis-state invocation --- scripts/generate-parachain-specs.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate-parachain-specs.sh b/scripts/generate-parachain-specs.sh index c3792ad825b..1feceb3e8c0 100755 --- a/scripts/generate-parachain-specs.sh +++ b/scripts/generate-parachain-specs.sh @@ -28,7 +28,6 @@ $MOONBEAM_BINARY export-genesis-wasm \ echo $ALPHANET_WASM generated $MOONBEAM_BINARY export-genesis-state \ - --parachain-id $ALPHANET_PARACHAIN_ID \ --chain $ALPHANET_PARACHAIN_SPEC_RAW \ > $ALPHANET_GENESIS; echo $ALPHANET_GENESIS generated From 38087045d95c169df8c104deae629d6304c5a405 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 15:27:22 +0100 Subject: [PATCH 5/7] refactor: :fire: remove dead code runtime_version --- node/cli/src/command.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 9bee8407e72..f831b417bbe 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -149,21 +149,6 @@ impl SubstrateCli for Cli { } } -impl Cli { - fn runtime_version(spec: &Box) -> &'static RuntimeVersion { - match spec { - #[cfg(feature = "moonriver-native")] - spec if spec.is_moonriver() => return &moonbeam_service::moonriver_runtime::VERSION, - #[cfg(feature = "moonbeam-native")] - spec if spec.is_moonbeam() => return &moonbeam_service::moonbeam_runtime::VERSION, - #[cfg(feature = "moonbase-native")] - _ => return &moonbeam_service::moonbase_runtime::VERSION, - #[cfg(not(feature = "moonbase-native"))] - _ => panic!("invalid chain spec"), - } - } -} - impl SubstrateCli for RelayChainCli { fn impl_name() -> String { "Moonbeam Parachain Collator".into() From 030ba8c3688ffd5e194c04df4f4bd41b1950e6d7 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 30 Jan 2025 16:08:24 +0100 Subject: [PATCH 6/7] refactor: :fire: remove unused import --- node/cli/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index f831b417bbe..c2aae45e784 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -36,7 +36,7 @@ use parity_scale_codec::Encode; use polkadot_service::WestendChainSpec; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, RpcEndpoint, RuntimeVersion, SharedParams, SubstrateCli, + NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, }; use sc_executor::WasmtimeInstantiationStrategy; use sc_service::{ From 8f44f475040613ec34cd0dc96ddfb0c532b9603e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 3 Feb 2025 11:23:47 +0100 Subject: [PATCH 7/7] feat: :sparkles: retrieve max_runtime_instances from executor config --- node/cli/src/command.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index c2aae45e784..ce92a597f14 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -404,8 +404,8 @@ pub fn run() -> Result<()> { _ => panic!("invalid chain spec"), } } - Some(Subcommand::ExportGenesisHead(params)) => { - let runner = cli.create_runner(params)?; + Some(Subcommand::ExportGenesisHead(cmd)) => { + let runner = cli.create_runner(cmd)?; let chain_spec = runner.config().chain_spec.cloned_box(); let mut builder = sc_cli::LoggerBuilder::new(""); @@ -417,7 +417,7 @@ pub fn run() -> Result<()> { .with_execution_method(sc_executor::WasmExecutionMethod::Compiled { instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, }) - .with_max_runtime_instances(1024) + .with_max_runtime_instances(runner.config().executor.max_runtime_instances) .build(); let state_version = sc_chain_spec::resolve_state_version_from_wasm::< @@ -431,7 +431,7 @@ pub fn run() -> Result<()> { let block: moonbeam_service::moonriver_runtime::Block = generate_genesis_block(&*chain_spec, state_version)?; let raw_header = block.header().encode(); - let output_buf = if params.raw { + let output_buf = if cmd.raw { raw_header } else { format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() @@ -443,7 +443,7 @@ pub fn run() -> Result<()> { let block: moonbeam_service::moonbeam_runtime::Block = generate_genesis_block(&*chain_spec, state_version)?; let raw_header = block.header().encode(); - let output_buf = if params.raw { + let output_buf = if cmd.raw { raw_header } else { format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() @@ -455,7 +455,7 @@ pub fn run() -> Result<()> { let block: moonbeam_service::moonbase_runtime::Block = generate_genesis_block(&*chain_spec, state_version)?; let raw_header = block.header().encode(); - let output_buf = if params.raw { + let output_buf = if cmd.raw { raw_header } else { format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() @@ -466,7 +466,7 @@ pub fn run() -> Result<()> { _ => panic!("invalid chain spec"), }; - if let Some(output) = ¶ms.output { + if let Some(output) = &cmd.output { std::fs::write(output, output_buf)?; } else { std::io::stdout().write_all(&output_buf)?;