Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions crates/cli/commands/src/init_state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Command that initializes the node from a genesis file.

use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use alloy_consensus::Header;
use alloy_consensus::{BlockHeader as AlloyBlockHeader, Header};
use alloy_primitives::{B256, U256};
use clap::Parser;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_db_common::init::init_from_state_dump;
use reth_node_api::NodePrimitives;
use reth_primitives_traits::SealedHeader;
use reth_primitives_traits::{BlockHeader, SealedHeader};
use reth_provider::{
BlockNumReader, DatabaseProviderFactory, StaticFileProviderFactory, StaticFileWriter,
};
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
where
N: CliNodeTypes<
ChainSpec = C::ChainSpec,
Primitives: NodePrimitives<BlockHeader = alloy_consensus::Header>,
Primitives: NodePrimitives<BlockHeader: BlockHeader + From<Header>>,
>,
{
info!(target: "reth::cli", "Reth init-state starting");
Expand All @@ -85,7 +85,9 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
if self.without_evm {
// ensure header, total difficulty and header hash are provided
let header = self.header.ok_or_else(|| eyre::eyre!("Header file must be provided"))?;
let header = without_evm::read_header_from_file(header)?;
let header = without_evm::read_header_from_file::<
<N::Primitives as NodePrimitives>::BlockHeader,
>(header)?;

let header_hash =
self.header_hash.ok_or_else(|| eyre::eyre!("Header hash must be provided"))?;
Expand All @@ -103,7 +105,10 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
&provider_rw,
SealedHeader::new(header, header_hash),
total_difficulty,
|number| Header { number, ..Default::default() },
|number| {
let header = Header { number, ..Default::default() };
<<N::Primitives as NodePrimitives>::BlockHeader>::from(header)
},
)?;

// SAFETY: it's safe to commit static files, since in the event of a crash, they
Expand All @@ -112,7 +117,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
// Necessary to commit, so the header is accessible to provider_rw and
// init_state_dump
static_file_provider.commit()?;
} else if last_block_number > 0 && last_block_number < header.number {
} else if last_block_number > 0 && last_block_number < header.number() {
return Err(eyre::eyre!(
"Data directory should be empty when calling init-state with --without-evm-history."
));
Expand Down
10 changes: 6 additions & 4 deletions crates/cli/commands/src/init_state/without_evm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_consensus::{BlockHeader, Header};
use alloy_consensus::BlockHeader;
use alloy_primitives::{BlockNumber, B256, U256};
use alloy_rlp::Decodable;
use reth_codecs::Compact;
Expand All @@ -12,14 +12,16 @@ use reth_stages::{StageCheckpoint, StageId};
use reth_static_file_types::StaticFileSegment;
use std::{fs::File, io::Read, path::PathBuf};
use tracing::info;

/// Reads the header RLP from a file and returns the Header.
pub(crate) fn read_header_from_file(path: PathBuf) -> Result<Header, eyre::Error> {
pub(crate) fn read_header_from_file<H>(path: PathBuf) -> Result<H, eyre::Error>
where
H: Decodable,
{
let mut file = File::open(path)?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;

let header = Header::decode(&mut &buf[..])?;
let header = H::decode(&mut &buf[..])?;
Ok(header)
}

Expand Down
9 changes: 4 additions & 5 deletions crates/ethereum/cli/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! CLI definition and entrypoint to executable

use crate::chainspec::EthereumChainSpecParser;
use alloy_consensus::Header;
use clap::{Parser, Subcommand};
use reth_chainspec::{ChainSpec, EthChainSpec, Hardforks};
use reth_cli::chainspec::ChainSpecParser;
Expand All @@ -13,7 +14,7 @@ use reth_cli_commands::{
};
use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_node_api::NodePrimitives;
use reth_node_api::{NodePrimitives, NodeTypes};
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::{
args::LogArgs,
Expand Down Expand Up @@ -181,11 +182,9 @@ impl<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> Cli<C, Ext> {
) -> eyre::Result<()>,
) -> eyre::Result<()>
where
N: CliNodeTypes<
Primitives: NodePrimitives<BlockHeader = alloy_consensus::Header>,
ChainSpec: Hardforks,
>,
N: CliNodeTypes<Primitives: NodePrimitives, ChainSpec: Hardforks>,
C: ChainSpecParser<ChainSpec = N::ChainSpec>,
<<N as NodeTypes>::Primitives as NodePrimitives>::BlockHeader: From<Header>,
{
// Add network name if available to the logs dir
if let Some(chain_spec) = self.command.chain_spec() {
Expand Down
Loading