From 6fb25969cefd375f2d287a94e9c74835a197d1ab Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 12:41:02 -0500 Subject: [PATCH 01/50] aura AAAaaa --- cumulus/client/consensus/aura/src/collators/basic.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index dc0078b0d6a9..c7621be91cf8 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -166,6 +166,7 @@ where let parent_hash = parent_header.hash(); + println!("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaa"); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { continue } From 89e825ba1f5cb68ac0ae0a3d5bdee21148e4fafb Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 12:57:41 -0500 Subject: [PATCH 02/50] =?UTF-8?q?println=20and=20=F0=9F=A4=B5=20emojis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cumulus/client/collator/src/lib.rs | 7 +++++++ cumulus/client/consensus/aura/src/collators/basic.rs | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index f17ae4883106..92de03ea554a 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -100,10 +100,17 @@ where }; let last_head_hash = last_head.hash(); + println!("🤵🤵🤵🤵🤵🤵🤵 In Collator about to call check block status"); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", last_head); + + // Here is where we call the checks that fail. if !self.service.check_block_status(last_head_hash, &last_head) { + println!("🤵🤵🤵🤵🤵🤵🤵 In Collator returning None"); return None } + println!("🤵🤵🤵🤵🤵🤵🤵 In Collator made it past check"); + tracing::info!( target: LOG_TARGET, relay_parent = ?relay_parent, diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index c7621be91cf8..fe1241adefe7 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -166,10 +166,13 @@ where let parent_hash = parent_header.hash(); - println!("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaa"); + println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { + println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); continue } + println!("🤵🤵🤵🤵🤵🤵🤵 In Aura made it past check."); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", parent_header); let relay_parent_header = match params.relay_client.header(RBlockId::hash(*request.relay_parent())).await { From 238a7e0d3337467044e2ec7ad1844d082cb71700 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 13:14:54 -0500 Subject: [PATCH 03/50] move log line :facepalm: --- cumulus/client/consensus/aura/src/collators/basic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index fe1241adefe7..b364f355c5d7 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -167,12 +167,12 @@ where let parent_hash = parent_header.hash(); println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", parent_header); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); continue } println!("🤵🤵🤵🤵🤵🤵🤵 In Aura made it past check."); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", parent_header); let relay_parent_header = match params.relay_client.header(RBlockId::hash(*request.relay_parent())).await { From 59b2c8fce1157f7024a453f11306a37028630f78 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 13:37:00 -0500 Subject: [PATCH 04/50] hack the build-state command --- cumulus/client/cli/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 1b18ed064373..b91ceca5dfb7 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -26,7 +26,7 @@ use std::{ }; use codec::Encode; -use sc_chain_spec::ChainSpec; +use sc_chain_spec::{ChainSpec, BuildGenesisBlock}; use sc_client_api::ExecutorProvider; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, @@ -147,17 +147,19 @@ pub struct ExportGenesisStateCommand { impl ExportGenesisStateCommand { /// Run the export-genesis-state command - pub fn run( + pub fn run>( &self, chain_spec: &dyn ChainSpec, client: &impl ExecutorProvider, + genesis_block_builder: Builder, ) -> sc_cli::Result<()> { let state_version = sc_chain_spec::resolve_state_version_from_wasm( &chain_spec.build_storage()?, client.executor(), )?; - let block: Block = generate_genesis_block(chain_spec, state_version)?; + // let block: Block = generate_genesis_block(chain_spec, state_version)?; + let block: Block = genesis_block_builder.build_genesis_block()?.0; let raw_header = block.header().encode(); let output_buf = if self.raw { raw_header From f58981e60d457da1c3e62e0e0db4fe11b88c4406 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 14:05:23 -0500 Subject: [PATCH 05/50] try again --- cumulus/client/cli/src/lib.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index b91ceca5dfb7..f743e69ba6a0 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -22,12 +22,12 @@ use std::{ fs, io::{self, Write}, net::SocketAddr, - path::PathBuf, + path::PathBuf, sync::Arc, }; use codec::Encode; -use sc_chain_spec::{ChainSpec, BuildGenesisBlock}; -use sc_client_api::ExecutorProvider; +use sc_chain_spec::{ChainSpec}; +use sc_client_api::{HeaderBackend}; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, BasePath, TransactionPoolOptions, @@ -147,24 +147,19 @@ pub struct ExportGenesisStateCommand { impl ExportGenesisStateCommand { /// Run the export-genesis-state command - pub fn run>( - &self, - chain_spec: &dyn ChainSpec, - client: &impl ExecutorProvider, - genesis_block_builder: Builder, - ) -> sc_cli::Result<()> { - let state_version = sc_chain_spec::resolve_state_version_from_wasm( - &chain_spec.build_storage()?, - client.executor(), - )?; - - // let block: Block = generate_genesis_block(chain_spec, state_version)?; - let block: Block = genesis_block_builder.build_genesis_block()?.0; - let raw_header = block.header().encode(); + pub fn run(&self, client: Arc) -> sc_cli::Result<()> + where + B: BlockT, + C: HeaderBackend + 'static, + { + let genesis_hash = client.hash(Zero::zero())?.expect("Not sure what this option means."); + let genesis_header = client.header(genesis_hash)?.expect("again with the option."); + + let raw_header = genesis_header.encode(); let output_buf = if self.raw { raw_header } else { - format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() + format!("0x{:?}", HexDisplay::from(&genesis_header.encode())).into_bytes() }; if let Some(output) = &self.output { From 3caefa57863ef2fcddb3313bc2f49a876bcafe7f Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 14:27:51 -0500 Subject: [PATCH 06/50] comment the old generate_genesis_block function --- cumulus/client/cli/src/lib.rs | 70 +++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index f743e69ba6a0..c7a0658cae5b 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -172,41 +172,41 @@ impl ExportGenesisStateCommand { } } -/// Generate the genesis block from a given ChainSpec. -pub fn generate_genesis_block( - chain_spec: &dyn ChainSpec, - genesis_state_version: StateVersion, -) -> Result { - let storage = chain_spec.build_storage()?; - - let child_roots = storage.children_default.iter().map(|(sk, child_content)| { - let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( - child_content.data.clone().into_iter().collect(), - genesis_state_version, - ); - (sk.clone(), state_root.encode()) - }); - let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( - storage.top.clone().into_iter().chain(child_roots).collect(), - genesis_state_version, - ); - - let extrinsics_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( - Vec::new(), - genesis_state_version, - ); - - Ok(Block::new( - <::Header as HeaderT>::new( - Zero::zero(), - extrinsics_root, - state_root, - Default::default(), - Default::default(), - ), - Default::default(), - )) -} +// /// Generate the genesis block from a given ChainSpec. +// pub fn generate_genesis_block( +// chain_spec: &dyn ChainSpec, +// genesis_state_version: StateVersion, +// ) -> Result { +// let storage = chain_spec.build_storage()?; + +// let child_roots = storage.children_default.iter().map(|(sk, child_content)| { +// let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( +// child_content.data.clone().into_iter().collect(), +// genesis_state_version, +// ); +// (sk.clone(), state_root.encode()) +// }); +// let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( +// storage.top.clone().into_iter().chain(child_roots).collect(), +// genesis_state_version, +// ); + +// let extrinsics_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( +// Vec::new(), +// genesis_state_version, +// ); + +// Ok(Block::new( +// <::Header as HeaderT>::new( +// Zero::zero(), +// extrinsics_root, +// state_root, +// Default::default(), +// Default::default(), +// ), +// Default::default(), +// )) +// } impl sc_cli::CliConfiguration for ExportGenesisStateCommand { fn shared_params(&self) -> &sc_cli::SharedParams { From 08365ff9d9d7bcacb203d8520e0be2b3972ebb89 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 14:31:07 -0500 Subject: [PATCH 07/50] debugging in command --- cumulus/client/cli/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index c7a0658cae5b..08f282e86335 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -153,7 +153,12 @@ impl ExportGenesisStateCommand { C: HeaderBackend + 'static, { let genesis_hash = client.hash(Zero::zero())?.expect("Not sure what this option means."); + println!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:?}", genesis_hash); let genesis_header = client.header(genesis_hash)?.expect("again with the option."); + + //TODO querying the ful lblock is not necessary for the command itself, it is just for debugging purposes. + let genesis_block = client.block(genesis_hash)?.unwrap(); + println!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:#?}", genesis_block); let raw_header = genesis_header.encode(); let output_buf = if self.raw { From d456cd06a86c5c6ec1471044fb86bae97a956b81 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 14:32:33 -0500 Subject: [PATCH 08/50] duplicate error message (To test for async weirdness). --- cumulus/client/collator/src/service.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/client/collator/src/service.rs b/cumulus/client/collator/src/service.rs index c06be006fc17..48a741db2da3 100644 --- a/cumulus/client/collator/src/service.rs +++ b/cumulus/client/collator/src/service.rs @@ -152,6 +152,7 @@ where block_hash = ?hash, "Could not find the header of the genesis block in the database!", ); + println!("🤵🤵🤵🤵🤵🤵🤵 Could not find the header of the genesis block in the database!"); } else { tracing::debug!( target: LOG_TARGET, From 7c84b90fddf7c5fa63c4e27510c52a71996141f6 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 14:39:29 -0500 Subject: [PATCH 09/50] block backend --- cumulus/client/cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 08f282e86335..982018587bc5 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -27,7 +27,7 @@ use std::{ use codec::Encode; use sc_chain_spec::{ChainSpec}; -use sc_client_api::{HeaderBackend}; +use sc_client_api::{HeaderBackend, BlockBackend}; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, BasePath, TransactionPoolOptions, @@ -150,7 +150,7 @@ impl ExportGenesisStateCommand { pub fn run(&self, client: Arc) -> sc_cli::Result<()> where B: BlockT, - C: HeaderBackend + 'static, + C: HeaderBackend + BlockBackend + 'static, { let genesis_hash = client.hash(Zero::zero())?.expect("Not sure what this option means."); println!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:?}", genesis_hash); From 5e20abc87717cde32632751f2baef3b7e80ea23b Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 16:16:53 -0500 Subject: [PATCH 10/50] try to have debug output not conflict with actual exported head data --- cumulus/client/cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 982018587bc5..004e8bcede03 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -153,12 +153,12 @@ impl ExportGenesisStateCommand { C: HeaderBackend + BlockBackend + 'static, { let genesis_hash = client.hash(Zero::zero())?.expect("Not sure what this option means."); - println!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:?}", genesis_hash); + eprintln!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:?}", genesis_hash); let genesis_header = client.header(genesis_hash)?.expect("again with the option."); //TODO querying the ful lblock is not necessary for the command itself, it is just for debugging purposes. let genesis_block = client.block(genesis_hash)?.unwrap(); - println!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:#?}", genesis_block); + eprintln!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:#?}", genesis_block); let raw_header = genesis_header.encode(); let output_buf = if self.raw { From c72c161584e29ab0e75b713f586d0c3e60fc79de Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 14 Nov 2023 16:28:12 -0500 Subject: [PATCH 11/50] another log --- cumulus/client/consensus/aura/src/collators/basic.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index b364f355c5d7..e7de4fce5a4d 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -167,7 +167,8 @@ where let parent_hash = parent_header.hash(); println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", parent_header); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header is {:?}", parent_header); + println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); continue From e4ac486943524fe51fed8caaf685a91044b1710b Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 15 Nov 2023 15:04:39 -0500 Subject: [PATCH 12/50] some more random debugging lines --- cumulus/client/collator/src/lib.rs | 3 +++ cumulus/client/consensus/aura/src/collators/basic.rs | 1 + substrate/client/chain-spec/src/genesis_block.rs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index 92de03ea554a..6a5241d3d05b 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -213,6 +213,9 @@ pub mod relay_chain_driven { // unbounded. The channel is actually bounded by the block production // and consensus systems of Polkadot, which limits the amount of possible // blocks. + println!("🤵🤵🤵🤵🤵🤵🤵 We're executing this 'collator' boxed function"); + println!("🤵🤵🤵🤵🤵🤵🤵 Relay parent is: {:#?}", relay_parent); + println!("🤵🤵🤵🤵🤵🤵🤵 Validation data is: {:#?}", validation_data); let mut stream_tx = stream_tx.clone(); let validation_data = validation_data.clone(); Box::pin(async move { diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index e7de4fce5a4d..33b21ed5f984 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -168,6 +168,7 @@ where println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); println!("🤵🤵🤵🤵🤵🤵🤵 Last header is {:?}", parent_header); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is {:?}", parent_header.encode()); println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); diff --git a/substrate/client/chain-spec/src/genesis_block.rs b/substrate/client/chain-spec/src/genesis_block.rs index 6aa156a620a7..b205e255356e 100644 --- a/substrate/client/chain-spec/src/genesis_block.rs +++ b/substrate/client/chain-spec/src/genesis_block.rs @@ -119,7 +119,7 @@ impl, E: RuntimeVersionOf> GenesisBlockBuilder< _phantom: PhantomData::, }) } -} +} impl, E: RuntimeVersionOf> BuildGenesisBlock for GenesisBlockBuilder From ece683aae60a2fee3c3f7f83be8b971dfbd46879 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 15 Nov 2023 16:42:58 -0500 Subject: [PATCH 13/50] comment idea to make logs more useful --- cumulus/client/consensus/aura/src/collators/basic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index 33b21ed5f984..0250e004ed83 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -168,7 +168,7 @@ where println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); println!("🤵🤵🤵🤵🤵🤵🤵 Last header is {:?}", parent_header); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is {:?}", parent_header.encode()); + println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is {:?}", parent_header.encode()); //TODO this one needs to be hex encoded so we can compare it to the output of export-genesis-state println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); From cca6d0292e75c6cad853e71d1ae38cfe6deb5625 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 15 Nov 2023 20:57:27 -0500 Subject: [PATCH 14/50] format previous head data as hex to better compare to relay state and export-genesis-... command --- cumulus/client/consensus/aura/src/collators/basic.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index 0250e004ed83..994e51c88190 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -168,7 +168,8 @@ where println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); println!("🤵🤵🤵🤵🤵🤵🤵 Last header is {:?}", parent_header); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is {:?}", parent_header.encode()); //TODO this one needs to be hex encoded so we can compare it to the output of export-genesis-state + + println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is 0x{:?}", sp_core::hexdisplay::HexDisplay::from(&parent_header.encode())); println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); From 1b593f7babb33cee65a0630e293ae2b666b89ee6 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 10:57:06 -0500 Subject: [PATCH 15/50] Remove some logs --- cumulus/client/collator/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index 6a5241d3d05b..92de03ea554a 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -213,9 +213,6 @@ pub mod relay_chain_driven { // unbounded. The channel is actually bounded by the block production // and consensus systems of Polkadot, which limits the amount of possible // blocks. - println!("🤵🤵🤵🤵🤵🤵🤵 We're executing this 'collator' boxed function"); - println!("🤵🤵🤵🤵🤵🤵🤵 Relay parent is: {:#?}", relay_parent); - println!("🤵🤵🤵🤵🤵🤵🤵 Validation data is: {:#?}", validation_data); let mut stream_tx = stream_tx.clone(); let validation_data = validation_data.clone(); Box::pin(async move { From a8e8fb1d846ee0e8ceac19ee3314e9a1f324bc70 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 10:57:46 -0500 Subject: [PATCH 16/50] Remove some more logging --- cumulus/client/consensus/aura/src/collators/basic.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index 994e51c88190..f2adf4bcbab7 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -166,16 +166,12 @@ where let parent_hash = parent_header.hash(); - println!("🤵🤵🤵🤵🤵🤵🤵 In Aura about to call check block status"); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header is {:?}", parent_header); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is 0x{:?}", sp_core::hexdisplay::HexDisplay::from(&parent_header.encode())); println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); continue } - println!("🤵🤵🤵🤵🤵🤵🤵 In Aura made it past check."); let relay_parent_header = match params.relay_client.header(RBlockId::hash(*request.relay_parent())).await { From 439a5d4ca11cbf10db08b8da7714a1b99196cebe Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 11:09:43 -0500 Subject: [PATCH 17/50] Remove panics --- Cargo.lock | 1 + cumulus/client/cli/Cargo.toml | 1 + cumulus/client/cli/src/lib.rs | 17 +++++++---------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7854042ddbcf..13f4cadfad46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3630,6 +3630,7 @@ dependencies = [ "sc-cli", "sc-client-api", "sc-service", + "sp-blockchain", "sp-core", "sp-runtime", "url", diff --git a/cumulus/client/cli/Cargo.toml b/cumulus/client/cli/Cargo.toml index 0f942feb5952..8c6ee3605baf 100644 --- a/cumulus/client/cli/Cargo.toml +++ b/cumulus/client/cli/Cargo.toml @@ -18,3 +18,4 @@ sc-chain-spec = { path = "../../../substrate/client/chain-spec" } sc-service = { path = "../../../substrate/client/service" } sp-core = { path = "../../../substrate/primitives/core" } sp-runtime = { path = "../../../substrate/primitives/runtime" } +sp-blockchain = { path = "../../../substrate/primitives/blockchain" } diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 004e8bcede03..d1f5294e7113 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -26,7 +26,7 @@ use std::{ }; use codec::Encode; -use sc_chain_spec::{ChainSpec}; +use sc_chain_spec::ChainSpec; use sc_client_api::{HeaderBackend, BlockBackend}; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, @@ -34,8 +34,7 @@ use sc_service::{ }; use sp_core::hexdisplay::HexDisplay; use sp_runtime::{ - traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero}, - StateVersion, + traits::{Block as BlockT, Zero}, }; use url::Url; @@ -129,6 +128,7 @@ impl sc_cli::CliConfiguration for PurgeChainCmd { } } +//TODO rename this command /// Command for exporting the genesis state of the parachain #[derive(Debug, clap::Parser)] pub struct ExportGenesisStateCommand { @@ -152,13 +152,10 @@ impl ExportGenesisStateCommand { B: BlockT, C: HeaderBackend + BlockBackend + 'static, { - let genesis_hash = client.hash(Zero::zero())?.expect("Not sure what this option means."); - eprintln!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:?}", genesis_hash); - let genesis_header = client.header(genesis_hash)?.expect("again with the option."); - - //TODO querying the ful lblock is not necessary for the command itself, it is just for debugging purposes. - let genesis_block = client.block(genesis_hash)?.unwrap(); - eprintln!("🤵🤵🤵🤵🤵🤵🤵 In Command. Genesis Hash is {:#?}", genesis_block); + let genesis_hash = client.hash(Zero::zero())?.ok_or( + sc_cli::Error::Client(sp_blockchain::Error::Backend("Filed to lookup genesis block hash when exporting genesis head data.".into())))?; + let genesis_header = client.header(genesis_hash)?.ok_or( + sc_cli::Error::Client(sp_blockchain::Error::Backend("Filed to lookup genesis header by hash when exporting genesis head data.".into())))?; let raw_header = genesis_header.encode(); let output_buf = if self.raw { From 297e1bdb9b76f691ecf7ebc1391cfbe93f707b11 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 12:09:30 -0500 Subject: [PATCH 18/50] delete commented code --- cumulus/client/cli/src/lib.rs | 36 ----------------------------------- 1 file changed, 36 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index d1f5294e7113..d56ecb718b1b 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -174,42 +174,6 @@ impl ExportGenesisStateCommand { } } -// /// Generate the genesis block from a given ChainSpec. -// pub fn generate_genesis_block( -// chain_spec: &dyn ChainSpec, -// genesis_state_version: StateVersion, -// ) -> Result { -// let storage = chain_spec.build_storage()?; - -// let child_roots = storage.children_default.iter().map(|(sk, child_content)| { -// let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( -// child_content.data.clone().into_iter().collect(), -// genesis_state_version, -// ); -// (sk.clone(), state_root.encode()) -// }); -// let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( -// storage.top.clone().into_iter().chain(child_roots).collect(), -// genesis_state_version, -// ); - -// let extrinsics_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( -// Vec::new(), -// genesis_state_version, -// ); - -// Ok(Block::new( -// <::Header as HeaderT>::new( -// Zero::zero(), -// extrinsics_root, -// state_root, -// Default::default(), -// Default::default(), -// ), -// Default::default(), -// )) -// } - impl sc_cli::CliConfiguration for ExportGenesisStateCommand { fn shared_params(&self) -> &sc_cli::SharedParams { &self.shared_params From 1f6a2f3a1f3d5bd79a75dcb75eb73b6fea0dd62b Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 12:10:13 -0500 Subject: [PATCH 19/50] remove some more debugging and tracing --- cumulus/client/collator/src/service.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/client/collator/src/service.rs b/cumulus/client/collator/src/service.rs index 48a741db2da3..c06be006fc17 100644 --- a/cumulus/client/collator/src/service.rs +++ b/cumulus/client/collator/src/service.rs @@ -152,7 +152,6 @@ where block_hash = ?hash, "Could not find the header of the genesis block in the database!", ); - println!("🤵🤵🤵🤵🤵🤵🤵 Could not find the header of the genesis block in the database!"); } else { tracing::debug!( target: LOG_TARGET, From 757dc510aa8bad1128825489a089d232818a43da Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 14:57:03 -0500 Subject: [PATCH 20/50] spelling --- cumulus/client/cli/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index d56ecb718b1b..e6dcc4216062 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -128,7 +128,6 @@ impl sc_cli::CliConfiguration for PurgeChainCmd { } } -//TODO rename this command /// Command for exporting the genesis state of the parachain #[derive(Debug, clap::Parser)] pub struct ExportGenesisStateCommand { @@ -153,9 +152,9 @@ impl ExportGenesisStateCommand { C: HeaderBackend + BlockBackend + 'static, { let genesis_hash = client.hash(Zero::zero())?.ok_or( - sc_cli::Error::Client(sp_blockchain::Error::Backend("Filed to lookup genesis block hash when exporting genesis head data.".into())))?; + sc_cli::Error::Client(sp_blockchain::Error::Backend("Failed to lookup genesis block hash when exporting genesis head data.".into())))?; let genesis_header = client.header(genesis_hash)?.ok_or( - sc_cli::Error::Client(sp_blockchain::Error::Backend("Filed to lookup genesis header by hash when exporting genesis head data.".into())))?; + sc_cli::Error::Client(sp_blockchain::Error::Backend("Failed to lookup genesis header by hash when exporting genesis head data.".into())))?; let raw_header = genesis_header.encode(); let output_buf = if self.raw { From 85d39acf04b90ae8713f21e6c5b6b9e7418952b8 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 14:57:21 -0500 Subject: [PATCH 21/50] fmt --- cumulus/client/cli/src/lib.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index e6dcc4216062..791d06378c8b 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -22,20 +22,19 @@ use std::{ fs, io::{self, Write}, net::SocketAddr, - path::PathBuf, sync::Arc, + path::PathBuf, + sync::Arc, }; use codec::Encode; use sc_chain_spec::ChainSpec; -use sc_client_api::{HeaderBackend, BlockBackend}; +use sc_client_api::{BlockBackend, HeaderBackend}; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, BasePath, TransactionPoolOptions, }; use sp_core::hexdisplay::HexDisplay; -use sp_runtime::{ - traits::{Block as BlockT, Zero}, -}; +use sp_runtime::traits::{Block as BlockT, Zero}; use url::Url; /// The `purge-chain` command used to remove the whole chain: the parachain and the relay chain. @@ -151,10 +150,16 @@ impl ExportGenesisStateCommand { B: BlockT, C: HeaderBackend + BlockBackend + 'static, { - let genesis_hash = client.hash(Zero::zero())?.ok_or( - sc_cli::Error::Client(sp_blockchain::Error::Backend("Failed to lookup genesis block hash when exporting genesis head data.".into())))?; - let genesis_header = client.header(genesis_hash)?.ok_or( - sc_cli::Error::Client(sp_blockchain::Error::Backend("Failed to lookup genesis header by hash when exporting genesis head data.".into())))?; + let genesis_hash = client.hash(Zero::zero())?.ok_or(sc_cli::Error::Client( + sp_blockchain::Error::Backend( + "Failed to lookup genesis block hash when exporting genesis head data.".into(), + ), + ))?; + let genesis_header = client.header(genesis_hash)?.ok_or(sc_cli::Error::Client( + sp_blockchain::Error::Backend( + "Failed to lookup genesis header by hash when exporting genesis head data.".into(), + ), + ))?; let raw_header = genesis_header.encode(); let output_buf = if self.raw { From c187e0034ef78ac0b00428ac0693d6b67380d300 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 14:58:30 -0500 Subject: [PATCH 22/50] Rename command --- cumulus/client/cli/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 791d06378c8b..e2f4284a55c6 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -129,7 +129,7 @@ impl sc_cli::CliConfiguration for PurgeChainCmd { /// Command for exporting the genesis state of the parachain #[derive(Debug, clap::Parser)] -pub struct ExportGenesisStateCommand { +pub struct ExportGenesisHeadCommand { /// Output file name or stdout if unspecified. #[arg()] pub output: Option, @@ -143,7 +143,7 @@ pub struct ExportGenesisStateCommand { pub shared_params: sc_cli::SharedParams, } -impl ExportGenesisStateCommand { +impl ExportGenesisHeadCommand { /// Run the export-genesis-state command pub fn run(&self, client: Arc) -> sc_cli::Result<()> where @@ -178,7 +178,7 @@ impl ExportGenesisStateCommand { } } -impl sc_cli::CliConfiguration for ExportGenesisStateCommand { +impl sc_cli::CliConfiguration for ExportGenesisHeadCommand { fn shared_params(&self) -> &sc_cli::SharedParams { &self.shared_params } From 22136dc9e7d1237c345c0811a66a7f1cb6bfc036 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 14:59:52 -0500 Subject: [PATCH 23/50] update polkadot-parachain (but don't modify it's public CLI) --- cumulus/polkadot-parachain/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index 63e4baf27aeb..b48a95736119 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -45,7 +45,7 @@ pub enum Subcommand { PurgeChain(cumulus_client_cli::PurgeChainCmd), /// Export the genesis state of the parachain. - ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand), + ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), From 35d9518f03b5abf5b24922d617ce55232b825c2b Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 15:02:59 -0500 Subject: [PATCH 24/50] Update template CLI preserving backward compatability --- cumulus/parachain-template/node/src/cli.rs | 12 ++++++++++-- cumulus/parachain-template/node/src/command.rs | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index 098f59b0f373..b4015362ed2d 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -24,8 +24,16 @@ pub enum Subcommand { /// Remove the whole chain. PurgeChain(cumulus_client_cli::PurgeChainCmd), - /// Export the genesis state of the parachain. - ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand), + /// Export the genesis head data (not state!) of the parachain. + /// This command has a terrible name and we only keep it because some existing tools and scripts expect it. + /// You should use --export-genesis-head instead whenever possible. + #[clap(hide = true)] + ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), + + /// Export the genesis head data of the parachain. + /// Head data is the encoded block header. + /// This is the same as the old, poorly named, ExportGenesisState command. + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), diff --git a/cumulus/parachain-template/node/src/command.rs b/cumulus/parachain-template/node/src/command.rs index 4dd8463f6be6..ff74055b7209 100644 --- a/cumulus/parachain-template/node/src/command.rs +++ b/cumulus/parachain-template/node/src/command.rs @@ -162,6 +162,7 @@ pub fn run() -> Result<()> { cmd.run(config, polkadot_config) }) }, + Some(Subcommand::ExportGenesisHead(cmd)) | Some(Subcommand::ExportGenesisState(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { From 01dd8571035e72d08de73dfd2b22fc6401387114 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 15:04:52 -0500 Subject: [PATCH 25/50] Do all of the non-cumulus ones that copied the name --- polkadot/parachain/test-parachains/adder/collator/src/cli.rs | 4 ++-- .../parachain/test-parachains/undying/collator/src/cli.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/parachain/test-parachains/adder/collator/src/cli.rs b/polkadot/parachain/test-parachains/adder/collator/src/cli.rs index 14b259706835..92f61aaf6638 100644 --- a/polkadot/parachain/test-parachains/adder/collator/src/cli.rs +++ b/polkadot/parachain/test-parachains/adder/collator/src/cli.rs @@ -24,7 +24,7 @@ use sc_cli::SubstrateCli; pub enum Subcommand { /// Export the genesis state of the parachain. #[command(name = "export-genesis-state")] - ExportGenesisState(ExportGenesisStateCommand), + ExportGenesisState(ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. #[command(name = "export-genesis-wasm")] @@ -33,7 +33,7 @@ pub enum Subcommand { /// Command for exporting the genesis state of the parachain #[derive(Debug, Parser)] -pub struct ExportGenesisStateCommand {} +pub struct ExportGenesisHeadCommand {} /// Command for exporting the genesis wasm file. #[derive(Debug, Parser)] diff --git a/polkadot/parachain/test-parachains/undying/collator/src/cli.rs b/polkadot/parachain/test-parachains/undying/collator/src/cli.rs index cd16133dbf19..f57cf3e7bdf8 100644 --- a/polkadot/parachain/test-parachains/undying/collator/src/cli.rs +++ b/polkadot/parachain/test-parachains/undying/collator/src/cli.rs @@ -24,7 +24,7 @@ use sc_cli::SubstrateCli; pub enum Subcommand { /// Export the genesis state of the parachain. #[command(name = "export-genesis-state")] - ExportGenesisState(ExportGenesisStateCommand), + ExportGenesisState(ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. #[command(name = "export-genesis-wasm")] @@ -33,7 +33,7 @@ pub enum Subcommand { /// Command for exporting the genesis state of the parachain #[derive(Debug, Parser)] -pub struct ExportGenesisStateCommand { +pub struct ExportGenesisHeadCommand { /// Id of the parachain this collator collates for. #[arg(long, default_value_t = 100)] pub parachain_id: u32, From 68d858f73e38f902dd6e14056fb1b03396215f72 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 15:05:01 -0500 Subject: [PATCH 26/50] And the test service also copied the name --- cumulus/test/service/src/cli.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulus/test/service/src/cli.rs b/cumulus/test/service/src/cli.rs index ef1159a3c1f8..015fd1052e84 100644 --- a/cumulus/test/service/src/cli.rs +++ b/cumulus/test/service/src/cli.rs @@ -60,7 +60,7 @@ pub enum Subcommand { BuildSpec(sc_cli::BuildSpecCmd), /// Export the genesis state of the parachain. - ExportGenesisState(ExportGenesisStateCommand), + ExportGenesisState(ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(ExportGenesisWasmCommand), @@ -68,15 +68,15 @@ pub enum Subcommand { #[derive(Debug, clap::Parser)] #[group(skip)] -pub struct ExportGenesisStateCommand { +pub struct ExportGenesisHeadCommand { #[arg(default_value_t = 2000u32)] pub parachain_id: u32, #[command(flatten)] - pub base: cumulus_client_cli::ExportGenesisStateCommand, + pub base: cumulus_client_cli::ExportGenesisHeadCommand, } -impl CliConfiguration for ExportGenesisStateCommand { +impl CliConfiguration for ExportGenesisHeadCommand { fn shared_params(&self) -> &SharedParams { &self.base.shared_params } From 8f2f471df1b56debcb17163e0fef8b1731c42a0d Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 15:08:16 -0500 Subject: [PATCH 27/50] remove last remaining debugging lines --- cumulus/client/consensus/aura/src/collators/basic.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs index f2adf4bcbab7..dc0078b0d6a9 100644 --- a/cumulus/client/consensus/aura/src/collators/basic.rs +++ b/cumulus/client/consensus/aura/src/collators/basic.rs @@ -166,10 +166,7 @@ where let parent_hash = parent_header.hash(); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header Encoded is 0x{:?}", sp_core::hexdisplay::HexDisplay::from(&parent_header.encode())); - println!("🤵🤵🤵🤵🤵🤵🤵 and its hash is {:?}", parent_header.hash()); if !collator.collator_service().check_block_status(parent_hash, &parent_header) { - println!("🤵🤵🤵🤵🤵🤵🤵 In Aura continuing."); continue } From 81f5dfd42acdfe1f87f5adefd62418385a82be19 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 16 Nov 2023 15:10:00 -0500 Subject: [PATCH 28/50] lingering comments --- cumulus/client/cli/src/lib.rs | 2 +- polkadot/parachain/test-parachains/adder/collator/src/cli.rs | 2 +- polkadot/parachain/test-parachains/undying/collator/src/cli.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index e2f4284a55c6..16eb5c7bd888 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -127,7 +127,7 @@ impl sc_cli::CliConfiguration for PurgeChainCmd { } } -/// Command for exporting the genesis state of the parachain +/// Command for exporting the genesis head data of the parachain #[derive(Debug, clap::Parser)] pub struct ExportGenesisHeadCommand { /// Output file name or stdout if unspecified. diff --git a/polkadot/parachain/test-parachains/adder/collator/src/cli.rs b/polkadot/parachain/test-parachains/adder/collator/src/cli.rs index 92f61aaf6638..f81e4cc0fff6 100644 --- a/polkadot/parachain/test-parachains/adder/collator/src/cli.rs +++ b/polkadot/parachain/test-parachains/adder/collator/src/cli.rs @@ -31,7 +31,7 @@ pub enum Subcommand { ExportGenesisWasm(ExportGenesisWasmCommand), } -/// Command for exporting the genesis state of the parachain +/// Command for exporting the genesis head data of the parachain #[derive(Debug, Parser)] pub struct ExportGenesisHeadCommand {} diff --git a/polkadot/parachain/test-parachains/undying/collator/src/cli.rs b/polkadot/parachain/test-parachains/undying/collator/src/cli.rs index f57cf3e7bdf8..b14a8d5b7dc8 100644 --- a/polkadot/parachain/test-parachains/undying/collator/src/cli.rs +++ b/polkadot/parachain/test-parachains/undying/collator/src/cli.rs @@ -31,7 +31,7 @@ pub enum Subcommand { ExportGenesisWasm(ExportGenesisWasmCommand), } -/// Command for exporting the genesis state of the parachain +/// Command for exporting the genesis head data of the parachain #[derive(Debug, Parser)] pub struct ExportGenesisHeadCommand { /// Id of the parachain this collator collates for. From 554fcb31d780e690bfe13771e00848ff00cc4687 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 13:39:08 -0500 Subject: [PATCH 29/50] fmt --- cumulus/parachain-template/node/src/cli.rs | 18 +++++++++--------- .../client/chain-spec/src/genesis_block.rs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index b4015362ed2d..8c8c950d5cf2 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -25,15 +25,15 @@ pub enum Subcommand { PurgeChain(cumulus_client_cli::PurgeChainCmd), /// Export the genesis head data (not state!) of the parachain. - /// This command has a terrible name and we only keep it because some existing tools and scripts expect it. - /// You should use --export-genesis-head instead whenever possible. - #[clap(hide = true)] - ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), - - /// Export the genesis head data of the parachain. - /// Head data is the encoded block header. - /// This is the same as the old, poorly named, ExportGenesisState command. - ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), + /// This command has a terrible name and we only keep it because some existing tools and + /// scripts expect it. You should use --export-genesis-head instead whenever possible. + #[clap(hide = true)] + ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), + + /// Export the genesis head data of the parachain. + /// Head data is the encoded block header. + /// This is the same as the old, poorly named, ExportGenesisState command. + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), diff --git a/substrate/client/chain-spec/src/genesis_block.rs b/substrate/client/chain-spec/src/genesis_block.rs index b205e255356e..6aa156a620a7 100644 --- a/substrate/client/chain-spec/src/genesis_block.rs +++ b/substrate/client/chain-spec/src/genesis_block.rs @@ -119,7 +119,7 @@ impl, E: RuntimeVersionOf> GenesisBlockBuilder< _phantom: PhantomData::, }) } -} +} impl, E: RuntimeVersionOf> BuildGenesisBlock for GenesisBlockBuilder From e8d43274ab6d500ab5f65229d75900dbf872ecbf Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:00:52 -0500 Subject: [PATCH 30/50] REstore original function in test client to be used only for tests. --- cumulus/test/service/src/genesis.rs | 43 +++++++++++++++++++++++++++-- cumulus/test/service/src/main.rs | 3 +- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cumulus/test/service/src/genesis.rs b/cumulus/test/service/src/genesis.rs index d4a9a2256264..be4b0427b2ee 100644 --- a/cumulus/test/service/src/genesis.rs +++ b/cumulus/test/service/src/genesis.rs @@ -15,11 +15,50 @@ // along with Cumulus. If not, see . use codec::Encode; -use cumulus_client_cli::generate_genesis_block; use cumulus_primitives_core::ParaId; use cumulus_test_runtime::Block; use polkadot_primitives::HeadData; -use sp_runtime::traits::Block as BlockT; +use sc_chain_spec::ChainSpec; +use sp_runtime::{ + traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero}, + StateVersion, +}; + +/// Generate a simple test genesis block from a given ChainSpec. +pub fn generate_genesis_block( + chain_spec: &dyn ChainSpec, + genesis_state_version: StateVersion, +) -> Result { + let storage = chain_spec.build_storage()?; + + let child_roots = storage.children_default.iter().map(|(sk, child_content)| { + let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( + child_content.data.clone().into_iter().collect(), + genesis_state_version, + ); + (sk.clone(), state_root.encode()) + }); + let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( + storage.top.clone().into_iter().chain(child_roots).collect(), + genesis_state_version, + ); + + let extrinsics_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( + Vec::new(), + genesis_state_version, + ); + + Ok(Block::new( + <::Header as HeaderT>::new( + Zero::zero(), + extrinsics_root, + state_root, + Default::default(), + Default::default(), + ), + Default::default(), + )) +} /// Returns the initial head data for a parachain ID. pub fn initial_head_data(para_id: ParaId) -> HeadData { diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 16b68796bd39..e17ad223d066 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -19,7 +19,6 @@ mod cli; use std::{io::Write, sync::Arc}; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; -use cumulus_client_cli::generate_genesis_block; use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; use cumulus_test_service::AnnounceBlockFn; use polkadot_service::runtime_traits::AccountIdConversion; @@ -53,7 +52,7 @@ fn main() -> Result<(), sc_cli::Error> { cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; let state_version = cumulus_test_service::runtime::VERSION.state_version(); - let block: parachains_common::Block = generate_genesis_block(&*spec, state_version)?; + let block: parachains_common::Block = genesis::generate_genesis_block(&*spec, state_version)?; let raw_header = block.header().encode(); let output_buf = if params.base.raw { raw_header From babcd27010122880ff5fd20bbf1e7cb35099c804 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:02:08 -0500 Subject: [PATCH 31/50] Oops, there were still logs left --- cumulus/client/collator/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index 92de03ea554a..c180574ef91c 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -100,17 +100,12 @@ where }; let last_head_hash = last_head.hash(); - println!("🤵🤵🤵🤵🤵🤵🤵 In Collator about to call check block status"); - println!("🤵🤵🤵🤵🤵🤵🤵 Last header is\n{:?}", last_head); // Here is where we call the checks that fail. if !self.service.check_block_status(last_head_hash, &last_head) { - println!("🤵🤵🤵🤵🤵🤵🤵 In Collator returning None"); return None } - println!("🤵🤵🤵🤵🤵🤵🤵 In Collator made it past check"); - tracing::info!( target: LOG_TARGET, relay_parent = ?relay_parent, From 30a55f8d763117d6eeb248302522ef35b2e2962f Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:03:02 -0500 Subject: [PATCH 32/50] comment --- cumulus/client/cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index 16eb5c7bd888..a1b860bc7d1c 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -144,7 +144,7 @@ pub struct ExportGenesisHeadCommand { } impl ExportGenesisHeadCommand { - /// Run the export-genesis-state command + /// Run the export-genesis-head command pub fn run(&self, client: Arc) -> sc_cli::Result<()> where B: BlockT, From e1566bc7cdedb99f8af50a22bc75a005f166a69c Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:04:51 -0500 Subject: [PATCH 33/50] more stray stuff --- cumulus/client/collator/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index c180574ef91c..aa7dc4cd6570 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -101,7 +101,6 @@ where let last_head_hash = last_head.hash(); - // Here is where we call the checks that fail. if !self.service.check_block_status(last_head_hash, &last_head) { return None } From 50f7f47fd3afd3e5c99e8b742a413a706ccb125a Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:05:38 -0500 Subject: [PATCH 34/50] x --- cumulus/client/collator/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/client/collator/src/lib.rs b/cumulus/client/collator/src/lib.rs index aa7dc4cd6570..f17ae4883106 100644 --- a/cumulus/client/collator/src/lib.rs +++ b/cumulus/client/collator/src/lib.rs @@ -100,7 +100,6 @@ where }; let last_head_hash = last_head.hash(); - if !self.service.check_block_status(last_head_hash, &last_head) { return None } From 31f8a2c40aafd907b24a2d1abb8d0d2813016bda Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:06:18 -0500 Subject: [PATCH 35/50] x --- cumulus/parachain-template/node/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index 8c8c950d5cf2..d60e23211f3d 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -26,7 +26,7 @@ pub enum Subcommand { /// Export the genesis head data (not state!) of the parachain. /// This command has a terrible name and we only keep it because some existing tools and - /// scripts expect it. You should use --export-genesis-head instead whenever possible. + /// scripts expect it. You should use export-genesis-head instead whenever possible. #[clap(hide = true)] ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), From fe5b9f4755dfcb557af3f8cc828602d5b7a34d71 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:08:19 -0500 Subject: [PATCH 36/50] fmt --- cumulus/test/service/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index e17ad223d066..d6a2b3f3024a 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -52,7 +52,8 @@ fn main() -> Result<(), sc_cli::Error> { cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; let state_version = cumulus_test_service::runtime::VERSION.state_version(); - let block: parachains_common::Block = genesis::generate_genesis_block(&*spec, state_version)?; + let block: parachains_common::Block = + genesis::generate_genesis_block(&*spec, state_version)?; let raw_header = block.header().encode(); let output_buf = if params.base.raw { raw_header From df69620d346119ed54dec4759aaae4c0b69ea0f6 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:33:05 -0500 Subject: [PATCH 37/50] fix invocation --- cumulus/parachain-template/node/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachain-template/node/src/command.rs b/cumulus/parachain-template/node/src/command.rs index ff74055b7209..a4d3959c9496 100644 --- a/cumulus/parachain-template/node/src/command.rs +++ b/cumulus/parachain-template/node/src/command.rs @@ -168,7 +168,7 @@ pub fn run() -> Result<()> { runner.sync_run(|config| { let partials = new_partial(&config)?; - cmd.run(&*config.chain_spec, &*partials.client) + cmd.run(partials.client) }) }, Some(Subcommand::ExportGenesisWasm(cmd)) => { From f7c04def0414d91f7171e8ca2b75288cd6f242df Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 14:45:25 -0500 Subject: [PATCH 38/50] and fix polkadot parachain --- cumulus/polkadot-parachain/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 7bede22fea78..51ec3043fe72 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -806,7 +806,7 @@ pub fn run() -> Result<()> { Some(Subcommand::ExportGenesisState(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { - construct_partials!(config, |partials| cmd.run(&*config.chain_spec, &*partials.client)) + construct_partials!(config, |partials| cmd.run(partials.client)) }) }, Some(Subcommand::ExportGenesisWasm(cmd)) => { From 6bc796d4404b6e231f62880308771c432d0a0eef Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 15:16:29 -0500 Subject: [PATCH 39/50] x --- cumulus/test/service/src/lib.rs | 2 +- cumulus/test/service/src/main.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 6fd3e4d43d75..dd5b9aec47ef 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -22,7 +22,7 @@ pub mod bench_utils; pub mod chain_spec; -mod genesis; +pub mod genesis; use runtime::AccountId; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index d6a2b3f3024a..e27040d4f6a5 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -20,7 +20,7 @@ use std::{io::Write, sync::Arc}; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; -use cumulus_test_service::AnnounceBlockFn; +use cumulus_test_service::{genesis::generate_genesis_block, AnnounceBlockFn}; use polkadot_service::runtime_traits::AccountIdConversion; use sc_cli::{CliConfiguration, SubstrateCli}; use sp_core::{hexdisplay::HexDisplay, Encode, Pair}; @@ -52,8 +52,7 @@ fn main() -> Result<(), sc_cli::Error> { cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; let state_version = cumulus_test_service::runtime::VERSION.state_version(); - let block: parachains_common::Block = - genesis::generate_genesis_block(&*spec, state_version)?; + let block: parachains_common::Block = generate_genesis_block(&*spec, state_version)?; let raw_header = block.header().encode(); let output_buf = if params.base.raw { raw_header From 238c8742250116183e97f1d1b49f421590dc5a9a Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 17 Nov 2023 16:03:56 -0500 Subject: [PATCH 40/50] Doc comments --- cumulus/test/service/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index dd5b9aec47ef..cdefba85154d 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -22,6 +22,8 @@ pub mod bench_utils; pub mod chain_spec; + +/// Utilities for creating test genesis block and head data pub mod genesis; use runtime::AccountId; From 89511b608d77a9f1635bfe4595621cf5677462eb Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 29 Nov 2023 12:32:11 -0500 Subject: [PATCH 41/50] Basti's suggestion to use clap alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- cumulus/parachain-template/node/src/cli.rs | 9 ++------- cumulus/polkadot-parachain/src/cli.rs | 3 ++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index d60e23211f3d..393852e17a25 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -24,16 +24,11 @@ pub enum Subcommand { /// Remove the whole chain. PurgeChain(cumulus_client_cli::PurgeChainCmd), - /// Export the genesis head data (not state!) of the parachain. - /// This command has a terrible name and we only keep it because some existing tools and - /// scripts expect it. You should use export-genesis-head instead whenever possible. - #[clap(hide = true)] - ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), - /// Export the genesis head data of the parachain. /// Head data is the encoded block header. /// This is the same as the old, poorly named, ExportGenesisState command. - ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), + #[command(alias = "export-genesis-state")] + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index b48a95736119..7e0227217a1b 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -45,7 +45,8 @@ pub enum Subcommand { PurgeChain(cumulus_client_cli::PurgeChainCmd), /// Export the genesis state of the parachain. - ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand), + #[command(alias = "export-genesis-state")] + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), From c41f8a4f8fa41977dff4657e66c6b7b40e645f01 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 29 Nov 2023 12:34:23 -0500 Subject: [PATCH 42/50] fmt --- cumulus/parachain-template/node/src/cli.rs | 4 ++-- cumulus/polkadot-parachain/src/cli.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index 393852e17a25..43389057d05f 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -27,8 +27,8 @@ pub enum Subcommand { /// Export the genesis head data of the parachain. /// Head data is the encoded block header. /// This is the same as the old, poorly named, ExportGenesisState command. - #[command(alias = "export-genesis-state")] - ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), + #[command(alias = "export-genesis-state")] + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index 7e0227217a1b..fec6e144e40f 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -45,8 +45,8 @@ pub enum Subcommand { PurgeChain(cumulus_client_cli::PurgeChainCmd), /// Export the genesis state of the parachain. - #[command(alias = "export-genesis-state")] - ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), + #[command(alias = "export-genesis-state")] + ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), From c19c29d42d6c06836693cc35adf069102b27a89f Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 29 Nov 2023 12:47:33 -0500 Subject: [PATCH 43/50] Don't need Block Backend --- cumulus/client/cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/client/cli/src/lib.rs b/cumulus/client/cli/src/lib.rs index a1b860bc7d1c..4c98fdf313cc 100644 --- a/cumulus/client/cli/src/lib.rs +++ b/cumulus/client/cli/src/lib.rs @@ -28,7 +28,7 @@ use std::{ use codec::Encode; use sc_chain_spec::ChainSpec; -use sc_client_api::{BlockBackend, HeaderBackend}; +use sc_client_api::HeaderBackend; use sc_service::{ config::{PrometheusConfig, TelemetryEndpoints}, BasePath, TransactionPoolOptions, @@ -148,7 +148,7 @@ impl ExportGenesisHeadCommand { pub fn run(&self, client: Arc) -> sc_cli::Result<()> where B: BlockT, - C: HeaderBackend + BlockBackend + 'static, + C: HeaderBackend + 'static, { let genesis_hash = client.hash(Zero::zero())?.ok_or(sc_cli::Error::Client( sp_blockchain::Error::Backend( From a37a3d456868505a91c331ca82b34a535f10fb71 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 29 Nov 2023 13:04:29 -0500 Subject: [PATCH 44/50] update `command.rs`s to reflect aliases --- cumulus/parachain-template/node/src/command.rs | 3 +-- cumulus/polkadot-parachain/src/command.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cumulus/parachain-template/node/src/command.rs b/cumulus/parachain-template/node/src/command.rs index a4d3959c9496..6ddb68a359a7 100644 --- a/cumulus/parachain-template/node/src/command.rs +++ b/cumulus/parachain-template/node/src/command.rs @@ -162,8 +162,7 @@ pub fn run() -> Result<()> { cmd.run(config, polkadot_config) }) }, - Some(Subcommand::ExportGenesisHead(cmd)) | - Some(Subcommand::ExportGenesisState(cmd)) => { + Some(Subcommand::ExportGenesisHead(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { let partials = new_partial(&config)?; diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 8eddc2d22e32..d1b020cc7c90 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -530,7 +530,7 @@ pub fn run() -> Result<()> { cmd.run(config, polkadot_config) }) }, - Some(Subcommand::ExportGenesisState(cmd)) => { + Some(Subcommand::ExportGenesisHead(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { construct_partials!(config, |partials| cmd.run(partials.client)) From aa3d14a2e4810372e6e0a33b8c6d78ee955af55c Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 12 Dec 2023 15:13:21 -0500 Subject: [PATCH 45/50] update version extraction --- cumulus/test/service/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index e27040d4f6a5..62a8edbef1c6 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -50,7 +50,12 @@ fn main() -> Result<(), sc_cli::Error> { let spec = cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; - let state_version = cumulus_test_service::runtime::VERSION.state_version(); + let wasm_executor: WasmExecutor = + WasmExecutor::builder().build(); + let state_version = sc_chain_spec::resolve_state_version_from_wasm( + &spec.build_storage()?, + &wasm_executor, + )?; let block: parachains_common::Block = generate_genesis_block(&*spec, state_version)?; let raw_header = block.header().encode(); From 3c39cc97fdaf0b4d003d9406ca271c96be1bed04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Dec 2023 00:06:57 +0100 Subject: [PATCH 46/50] Remove the custom export genesis head command --- cumulus/test/service/src/cli.rs | 20 +++------------ cumulus/test/service/src/main.rs | 42 +++++++------------------------- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/cumulus/test/service/src/cli.rs b/cumulus/test/service/src/cli.rs index 015fd1052e84..64e07c8aa7e2 100644 --- a/cumulus/test/service/src/cli.rs +++ b/cumulus/test/service/src/cli.rs @@ -16,6 +16,7 @@ use std::{net::SocketAddr, path::PathBuf}; +use cumulus_client_cli::ExportGenesisHeadCommand; use polkadot_service::{ChainSpec, ParaId, PrometheusConfig}; use sc_cli::{ CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, @@ -60,28 +61,13 @@ pub enum Subcommand { BuildSpec(sc_cli::BuildSpecCmd), /// Export the genesis state of the parachain. - ExportGenesisState(ExportGenesisHeadCommand), + #[command(alias = "export-genesis-state")] + ExportGenesisHead(ExportGenesisHeadCommand), /// Export the genesis wasm of the parachain. ExportGenesisWasm(ExportGenesisWasmCommand), } -#[derive(Debug, clap::Parser)] -#[group(skip)] -pub struct ExportGenesisHeadCommand { - #[arg(default_value_t = 2000u32)] - pub parachain_id: u32, - - #[command(flatten)] - pub base: cumulus_client_cli::ExportGenesisHeadCommand, -} - -impl CliConfiguration for ExportGenesisHeadCommand { - fn shared_params(&self) -> &SharedParams { - &self.base.shared_params - } -} - /// Command for exporting the genesis wasm file. #[derive(Debug, clap::Parser)] #[group(skip)] diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 642857123216..9511d20c5439 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -16,15 +16,14 @@ mod cli; -use std::{io::Write, sync::Arc}; +use std::sync::Arc; use cli::{RelayChainCli, Subcommand, TestCollatorCli}; use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; -use cumulus_test_service::{genesis::generate_genesis_block, AnnounceBlockFn}; +use cumulus_test_service::{new_partial, AnnounceBlockFn}; use polkadot_service::runtime_traits::AccountIdConversion; use sc_cli::{CliConfiguration, SubstrateCli}; -use sp_core::{hexdisplay::HexDisplay, Encode, Pair}; -use sp_runtime::traits::Block; +use sp_core::Pair; pub fn wrap_announce_block() -> Box AnnounceBlockFn> { tracing::info!("Block announcements disabled."); @@ -43,35 +42,12 @@ fn main() -> Result<(), sc_cli::Error> { runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) }, - Some(Subcommand::ExportGenesisState(params)) => { - let mut builder = sc_cli::LoggerBuilder::new(""); - builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); - let _ = builder.init(); - - let spec = - cli.load_spec(¶ms.base.shared_params.chain.clone().unwrap_or_default())?; - let wasm_executor: WasmExecutor = - WasmExecutor::builder().build(); - let state_version = sc_chain_spec::resolve_state_version_from_wasm( - &spec.build_storage()?, - &wasm_executor, - )?; - - let block: parachains_common::Block = generate_genesis_block(&*spec, state_version)?; - let raw_header = block.header().encode(); - let output_buf = if params.base.raw { - raw_header - } else { - format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes() - }; - - if let Some(output) = ¶ms.base.output { - std::fs::write(output, output_buf)?; - } else { - std::io::stdout().write_all(&output_buf)?; - } - - Ok(()) + Some(Subcommand::ExportGenesisHead(cmd)) => { + let runner = cli.create_runner(cmd)?; + runner.sync_run(|mut config| { + let partial = new_partial(&mut config, false)?; + cmd.run(partial.client) + }) }, Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?; From 8da60f6e6ca63aab1b7569e5f629be311c808784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Dec 2023 08:40:06 +0100 Subject: [PATCH 47/50] Update cumulus/parachain-template/node/src/cli.rs --- cumulus/parachain-template/node/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachain-template/node/src/cli.rs b/cumulus/parachain-template/node/src/cli.rs index 43389057d05f..73ef996b7504 100644 --- a/cumulus/parachain-template/node/src/cli.rs +++ b/cumulus/parachain-template/node/src/cli.rs @@ -25,8 +25,8 @@ pub enum Subcommand { PurgeChain(cumulus_client_cli::PurgeChainCmd), /// Export the genesis head data of the parachain. + /// /// Head data is the encoded block header. - /// This is the same as the old, poorly named, ExportGenesisState command. #[command(alias = "export-genesis-state")] ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand), From 1e528ee1c98c52df3710c7ca8d89b9c9cfb4e150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Dec 2023 08:44:50 +0100 Subject: [PATCH 48/50] Remove the custom export genesis wasm command --- cumulus/test/service/src/cli.rs | 19 +------------------ cumulus/test/service/src/main.rs | 6 ++---- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/cumulus/test/service/src/cli.rs b/cumulus/test/service/src/cli.rs index 64e07c8aa7e2..3dc5b8e31016 100644 --- a/cumulus/test/service/src/cli.rs +++ b/cumulus/test/service/src/cli.rs @@ -16,7 +16,7 @@ use std::{net::SocketAddr, path::PathBuf}; -use cumulus_client_cli::ExportGenesisHeadCommand; +use cumulus_client_cli::{ExportGenesisHeadCommand, ExportGenesisWasmCommand}; use polkadot_service::{ChainSpec, ParaId, PrometheusConfig}; use sc_cli::{ CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, @@ -68,23 +68,6 @@ pub enum Subcommand { ExportGenesisWasm(ExportGenesisWasmCommand), } -/// Command for exporting the genesis wasm file. -#[derive(Debug, clap::Parser)] -#[group(skip)] -pub struct ExportGenesisWasmCommand { - #[arg(default_value_t = 2000u32)] - pub parachain_id: u32, - - #[command(flatten)] - pub base: cumulus_client_cli::ExportGenesisWasmCommand, -} - -impl CliConfiguration for ExportGenesisWasmCommand { - fn shared_params(&self) -> &SharedParams { - &self.base.shared_params - } -} - #[derive(Debug)] pub struct RelayChainCli { /// The actual relay chain cli object. diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 9511d20c5439..fadcb6729bc9 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -51,10 +51,8 @@ fn main() -> Result<(), sc_cli::Error> { }, Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|_config| { - let parachain_id = ParaId::from(cmd.parachain_id); - let spec = cumulus_test_service::get_chain_spec(Some(parachain_id)); - cmd.base.run(&spec) + runner.sync_run(|config| { + cmd.run(&*config.chain_spec) }) }, None => { From 4866c84e91372da6b0a34482ac17322788d6608e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Dec 2023 09:28:36 +0100 Subject: [PATCH 49/50] Adds prdoc --- prdoc/pr_2331.prdoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prdoc/pr_2331.prdoc diff --git a/prdoc/pr_2331.prdoc b/prdoc/pr_2331.prdoc new file mode 100644 index 000000000000..e3daf4c45bd4 --- /dev/null +++ b/prdoc/pr_2331.prdoc @@ -0,0 +1,17 @@ +title: Rename `ExportGenesisStateCommand` to `ExportGenesisHeadCommand` + +doc: + - audience: Node Operator + description: | + The `export-genesis-state` subcommand is now called `export-gensis-head`, but + `export-genesis-state` stays as an alias to not break any scripts. + + - audience: Node Dev + description: | + The struct `ExportGenesisStateCommand` is now called `ExportGenesisHeadCommand`. + So, you only need to rename the import and usage. The `run` function is now + taking only a `client` as argument to fetch the genesis header. This way + the exported genesis head is respecting custom genesis block builders. + +crates: + - name: "cumulus-client-cli" From 0a21af5f3f78bb129c58a145da8ac3e0b4d59d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Dec 2023 09:31:25 +0100 Subject: [PATCH 50/50] FMT --- cumulus/test/service/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index fadcb6729bc9..aace92ca965d 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -51,9 +51,7 @@ fn main() -> Result<(), sc_cli::Error> { }, Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| { - cmd.run(&*config.chain_spec) - }) + runner.sync_run(|config| cmd.run(&*config.chain_spec)) }, None => { let log_filters = cli.run.normalize().log_filters();