mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Rename ExportGenesisStateCommand to ExportGenesisHeadCommand and make it respect custom genesis block builders (#2331)
Closes #2326. This PR both fixes a logic bug and replaces an incorrect name. ## Bug Fix: Respecting custom genesis builder Prior to this PR the standard logic for creating a genesis block was repeated inside of cumulus. This PR removes that duplicated logic, and calls into the proper `BuildGenesisBlock` implementation. One consequence is that if the genesis block has already been initialized, it will not be re-created, but rather read from the database like it is for other node invocations. So you need to watch out for old unpurged data during the development process. Offchain tools may need to be updated accordingly. I've already filed https://github.com/paritytech/zombienet/issues/1519 ## Rename: It doesn't export state. It exports head data. The name export-genesis-state was always wrong, nad it's never too late to right a wrong. I've changed the name of the struct to `ExportGenesisHeadCommand`. There is still the question of what to do with individual nodes' public CLIs. I have updated the parachain template to a reasonable default that preserves compatibility with tools that will expect `export-genesis-state` to still work. And I've chosen not to modify the public CLIs of any other nodes in the repo. I'll leave it up to their individual owners/maintains to decide whether that is appropriate. --------- Co-authored-by: Joshy Orndorff <git-user-email.h0ly5@simplelogin.com> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
use std::{net::SocketAddr, path::PathBuf};
|
||||
|
||||
use cumulus_client_cli::{ExportGenesisHeadCommand, ExportGenesisWasmCommand};
|
||||
use polkadot_service::{ChainSpec, ParaId, PrometheusConfig};
|
||||
use sc_cli::{
|
||||
CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
|
||||
@@ -60,45 +61,13 @@ pub enum Subcommand {
|
||||
BuildSpec(sc_cli::BuildSpecCmd),
|
||||
|
||||
/// Export the genesis state of the parachain.
|
||||
ExportGenesisState(ExportGenesisStateCommand),
|
||||
#[command(alias = "export-genesis-state")]
|
||||
ExportGenesisHead(ExportGenesisHeadCommand),
|
||||
|
||||
/// Export the genesis wasm of the parachain.
|
||||
ExportGenesisWasm(ExportGenesisWasmCommand),
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
#[group(skip)]
|
||||
pub struct ExportGenesisStateCommand {
|
||||
#[arg(default_value_t = 2000u32)]
|
||||
pub parachain_id: u32,
|
||||
|
||||
#[command(flatten)]
|
||||
pub base: cumulus_client_cli::ExportGenesisStateCommand,
|
||||
}
|
||||
|
||||
impl CliConfiguration for ExportGenesisStateCommand {
|
||||
fn shared_params(&self) -> &SharedParams {
|
||||
&self.base.shared_params
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
||||
@@ -15,11 +15,50 @@
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<Block: BlockT>(
|
||||
chain_spec: &dyn ChainSpec,
|
||||
genesis_state_version: StateVersion,
|
||||
) -> Result<Block, String> {
|
||||
let storage = chain_spec.build_storage()?;
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<Block as BlockT>::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 = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||
genesis_state_version,
|
||||
);
|
||||
|
||||
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
Vec::new(),
|
||||
genesis_state_version,
|
||||
);
|
||||
|
||||
Ok(Block::new(
|
||||
<<Block as BlockT>::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 {
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
pub mod bench_utils;
|
||||
|
||||
pub mod chain_spec;
|
||||
mod genesis;
|
||||
|
||||
/// Utilities for creating test genesis block and head data
|
||||
pub mod genesis;
|
||||
|
||||
use runtime::AccountId;
|
||||
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
|
||||
mod cli;
|
||||
|
||||
use std::{io::Write, sync::Arc};
|
||||
use std::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 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<dyn FnOnce(AnnounceBlockFn) -> AnnounceBlockFn> {
|
||||
tracing::info!("Block announcements disabled.");
|
||||
@@ -44,38 +42,16 @@ 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 state_version = cumulus_test_service::runtime::VERSION.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
|
||||
} 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)?;
|
||||
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 => {
|
||||
let log_filters = cli.run.normalize().log_filters();
|
||||
|
||||
Reference in New Issue
Block a user