feat: added closure and relaxed setup_without_evm function (#16720)

This commit is contained in:
Odinson
2025-06-08 14:51:29 +05:30
committed by GitHub
parent b767ffbda2
commit e1a5ecd3bf
3 changed files with 12 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
//! Command that initializes the node from a genesis file.
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use alloy_consensus::Header;
use alloy_primitives::{B256, U256};
use clap::Parser;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
@@ -102,6 +103,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
&provider_rw,
SealedHeader::new(header, header_hash),
total_difficulty,
|number| Header { number, ..Default::default() },
)?;
// SAFETY: it's safe to commit static files, since in the event of a crash, they

View File

@@ -25,24 +25,26 @@ pub(crate) fn read_header_from_file(path: PathBuf) -> Result<Header, eyre::Error
/// Creates a dummy chain (with no transactions) up to the last EVM block and appends the
/// first valid block.
pub fn setup_without_evm<Provider>(
pub fn setup_without_evm<Provider, F>(
provider_rw: &Provider,
header: SealedHeader<<Provider::Primitives as NodePrimitives>::BlockHeader>,
total_difficulty: U256,
header_factory: F,
) -> ProviderResult<()>
where
Provider: StaticFileProviderFactory<Primitives: NodePrimitives<BlockHeader = Header>>
Provider: StaticFileProviderFactory
+ StageCheckpointWriter
+ BlockWriter<Block = <Provider::Primitives as NodePrimitives>::Block>,
F: Fn(BlockNumber) -> <Provider::Primitives as NodePrimitives>::BlockHeader
+ Send
+ Sync
+ 'static,
{
info!(target: "reth::cli", new_tip = ?header.num_hash(), "Setting up dummy EVM chain before importing state.");
let static_file_provider = provider_rw.static_file_provider();
// Write EVM dummy data up to `header - 1` block
append_dummy_chain(&static_file_provider, header.number() - 1, |number| Header {
number,
..Default::default()
})?;
append_dummy_chain(&static_file_provider, header.number() - 1, header_factory)?;
info!(target: "reth::cli", "Appending first valid block.");

View File

@@ -1,5 +1,6 @@
//! Command that initializes the node from a genesis file.
use alloy_consensus::Header;
use clap::Parser;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment};
@@ -58,6 +59,7 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> InitStateCommandOp<C> {
&provider_rw,
SealedHeader::new(BEDROCK_HEADER, BEDROCK_HEADER_HASH),
BEDROCK_HEADER_TTD,
|number| Header { number, ..Default::default() },
)?;
// SAFETY: it's safe to commit static files, since in the event of a crash, they