mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: add Header AT to EthChainSpec (#13046)
This commit is contained in:
@ -14,6 +14,9 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug {
|
|||||||
// todo: make chain spec type generic over hardfork
|
// todo: make chain spec type generic over hardfork
|
||||||
//type Hardfork: Clone + Copy + 'static;
|
//type Hardfork: Clone + Copy + 'static;
|
||||||
|
|
||||||
|
/// The header type of the network.
|
||||||
|
type Header;
|
||||||
|
|
||||||
/// Returns the [`Chain`] object this spec targets.
|
/// Returns the [`Chain`] object this spec targets.
|
||||||
fn chain(&self) -> Chain;
|
fn chain(&self) -> Chain;
|
||||||
|
|
||||||
@ -41,7 +44,7 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug {
|
|||||||
fn display_hardforks(&self) -> Box<dyn Display>;
|
fn display_hardforks(&self) -> Box<dyn Display>;
|
||||||
|
|
||||||
/// The genesis header.
|
/// The genesis header.
|
||||||
fn genesis_header(&self) -> &Header;
|
fn genesis_header(&self) -> &Self::Header;
|
||||||
|
|
||||||
/// The genesis block specification.
|
/// The genesis block specification.
|
||||||
fn genesis(&self) -> &Genesis;
|
fn genesis(&self) -> &Genesis;
|
||||||
@ -64,6 +67,8 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EthChainSpec for ChainSpec {
|
impl EthChainSpec for ChainSpec {
|
||||||
|
type Header = Header;
|
||||||
|
|
||||||
fn chain(&self) -> Chain {
|
fn chain(&self) -> Chain {
|
||||||
self.chain
|
self.chain
|
||||||
}
|
}
|
||||||
@ -92,7 +97,7 @@ impl EthChainSpec for ChainSpec {
|
|||||||
Box::new(Self::display_hardforks(self))
|
Box::new(Self::display_hardforks(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn genesis_header(&self) -> &Header {
|
fn genesis_header(&self) -> &Self::Header {
|
||||||
self.genesis_header()
|
self.genesis_header()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use reth_beacon_consensus::EthBeaconConsensus;
|
use reth_beacon_consensus::EthBeaconConsensus;
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_cli::chainspec::ChainSpecParser;
|
use reth_cli::chainspec::ChainSpecParser;
|
||||||
use reth_config::{config::EtlConfig, Config};
|
use reth_config::{config::EtlConfig, Config};
|
||||||
use reth_db::{init_db, open_db_read_only, DatabaseEnv};
|
use reth_db::{init_db, open_db_read_only, DatabaseEnv};
|
||||||
@ -54,13 +54,13 @@ pub struct EnvironmentArgs<C: ChainSpecParser> {
|
|||||||
pub db: DatabaseArgs,
|
pub db: DatabaseArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> EnvironmentArgs<C> {
|
impl<C: ChainSpecParser> EnvironmentArgs<C> {
|
||||||
/// Initializes environment according to [`AccessRights`] and returns an instance of
|
/// Initializes environment according to [`AccessRights`] and returns an instance of
|
||||||
/// [`Environment`].
|
/// [`Environment`].
|
||||||
pub fn init<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
|
pub fn init<N: CliNodeTypes>(&self, access: AccessRights) -> eyre::Result<Environment<N>>
|
||||||
&self,
|
where
|
||||||
access: AccessRights,
|
C: ChainSpecParser<ChainSpec = N::ChainSpec>,
|
||||||
) -> eyre::Result<Environment<N>> {
|
{
|
||||||
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain());
|
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain());
|
||||||
let db_path = data_dir.db();
|
let db_path = data_dir.db();
|
||||||
let sf_path = data_dir.static_files();
|
let sf_path = data_dir.static_files();
|
||||||
@ -109,12 +109,15 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Environmen
|
|||||||
/// If it's a read-write environment and an issue is found, it will attempt to heal (including a
|
/// If it's a read-write environment and an issue is found, it will attempt to heal (including a
|
||||||
/// pipeline unwind). Otherwise, it will print out an warning, advising the user to restart the
|
/// pipeline unwind). Otherwise, it will print out an warning, advising the user to restart the
|
||||||
/// node to heal.
|
/// node to heal.
|
||||||
fn create_provider_factory<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
|
fn create_provider_factory<N: CliNodeTypes>(
|
||||||
&self,
|
&self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db: Arc<DatabaseEnv>,
|
db: Arc<DatabaseEnv>,
|
||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
) -> eyre::Result<ProviderFactory<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>> {
|
) -> eyre::Result<ProviderFactory<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>>
|
||||||
|
where
|
||||||
|
C: ChainSpecParser<ChainSpec = N::ChainSpec>,
|
||||||
|
{
|
||||||
let has_receipt_pruning = config.prune.as_ref().is_some_and(|a| a.has_receipts_pruning());
|
let has_receipt_pruning = config.prune.as_ref().is_some_and(|a| a.has_receipts_pruning());
|
||||||
let prune_modes =
|
let prune_modes =
|
||||||
config.prune.as_ref().map(|prune| prune.segments.clone()).unwrap_or_default();
|
config.prune.as_ref().map(|prune| prune.segments.clone()).unwrap_or_default();
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
|
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_cli::chainspec::ChainSpecParser;
|
use reth_cli::chainspec::ChainSpecParser;
|
||||||
use reth_db::{mdbx::tx::Tx, static_file::iter_static_files, tables, DatabaseError};
|
use reth_db::{mdbx::tx::Tx, static_file::iter_static_files, tables, DatabaseError};
|
||||||
use reth_db_api::transaction::{DbTx, DbTxMut};
|
use reth_db_api::transaction::{DbTx, DbTxMut};
|
||||||
@ -27,9 +27,12 @@ pub struct Command<C: ChainSpecParser> {
|
|||||||
stage: StageEnum,
|
stage: StageEnum,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C> {
|
impl<C: ChainSpecParser> Command<C> {
|
||||||
/// Execute `db` command
|
/// Execute `db` command
|
||||||
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(self) -> eyre::Result<()> {
|
pub async fn execute<N: CliNodeTypes>(self) -> eyre::Result<()>
|
||||||
|
where
|
||||||
|
C: ChainSpecParser<ChainSpec = N::ChainSpec>,
|
||||||
|
{
|
||||||
let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RW)?;
|
let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RW)?;
|
||||||
|
|
||||||
let tool = DbTool::new(provider_factory)?;
|
let tool = DbTool::new(provider_factory)?;
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use reth_chainspec::{EthChainSpec, Head};
|
use reth_chainspec::{EthChainSpec, Head};
|
||||||
use reth_node_api::{FullNodeComponents, NodePrimitives, NodeTypes};
|
use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, NodeTypes};
|
||||||
use reth_node_core::node_config::NodeConfig;
|
use reth_node_core::node_config::NodeConfig;
|
||||||
use reth_primitives::EthPrimitives;
|
use reth_primitives::EthPrimitives;
|
||||||
use reth_provider::BlockReader;
|
use reth_provider::BlockReader;
|
||||||
@ -18,7 +18,7 @@ pub struct ExExContextDyn<N: NodePrimitives = EthPrimitives> {
|
|||||||
/// The current head of the blockchain at launch.
|
/// The current head of the blockchain at launch.
|
||||||
pub head: Head,
|
pub head: Head,
|
||||||
/// The config of the node
|
/// The config of the node
|
||||||
pub config: NodeConfig<Box<dyn EthChainSpec + 'static>>,
|
pub config: NodeConfig<Box<dyn EthChainSpec<Header = N::BlockHeader> + 'static>>,
|
||||||
/// The loaded node config
|
/// The loaded node config
|
||||||
pub reth_config: reth_config::Config,
|
pub reth_config: reth_config::Config,
|
||||||
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
||||||
@ -57,8 +57,9 @@ where
|
|||||||
Node::Executor: Debug,
|
Node::Executor: Debug,
|
||||||
{
|
{
|
||||||
fn from(ctx: ExExContext<Node>) -> Self {
|
fn from(ctx: ExExContext<Node>) -> Self {
|
||||||
let config =
|
let config = ctx.config.map_chainspec(|chainspec| {
|
||||||
ctx.config.map_chainspec(|chainspec| Box::new(chainspec) as Box<dyn EthChainSpec>);
|
Box::new(chainspec) as Box<dyn EthChainSpec<Header = HeaderTy<Node::Types>>>
|
||||||
|
});
|
||||||
let notifications = Box::new(ctx.notifications) as Box<_>;
|
let notifications = Box::new(ctx.notifications) as Box<_>;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ pub trait NodeTypes: Send + Sync + Unpin + 'static {
|
|||||||
/// The node's primitive types, defining basic operations and structures.
|
/// The node's primitive types, defining basic operations and structures.
|
||||||
type Primitives: NodePrimitives;
|
type Primitives: NodePrimitives;
|
||||||
/// The type used for configuration of the EVM.
|
/// The type used for configuration of the EVM.
|
||||||
type ChainSpec: EthChainSpec;
|
type ChainSpec: EthChainSpec<Header = <Self::Primitives as NodePrimitives>::BlockHeader>;
|
||||||
/// The type used to perform state commitment operations.
|
/// The type used to perform state commitment operations.
|
||||||
type StateCommitment: StateCommitment;
|
type StateCommitment: StateCommitment;
|
||||||
/// The type responsible for writing chain primitives to storage.
|
/// The type responsible for writing chain primitives to storage.
|
||||||
@ -151,7 +151,7 @@ impl<P, C, SC, S> AnyNodeTypes<P, C, SC, S> {
|
|||||||
impl<P, C, SC, S> NodeTypes for AnyNodeTypes<P, C, SC, S>
|
impl<P, C, SC, S> NodeTypes for AnyNodeTypes<P, C, SC, S>
|
||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec<Header = P::BlockHeader> + 'static,
|
||||||
SC: StateCommitment,
|
SC: StateCommitment,
|
||||||
S: Default + Send + Sync + Unpin + Debug + 'static,
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
@ -212,7 +212,7 @@ impl<P, E, C, SC, S> NodeTypes for AnyNodeTypesWithEngine<P, E, C, SC, S>
|
|||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
E: EngineTypes + Send + Sync + Unpin,
|
E: EngineTypes + Send + Sync + Unpin,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec<Header = P::BlockHeader> + 'static,
|
||||||
SC: StateCommitment,
|
SC: StateCommitment,
|
||||||
S: Default + Send + Sync + Unpin + Debug + 'static,
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
@ -226,7 +226,7 @@ impl<P, E, C, SC, S> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C, SC,
|
|||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
E: EngineTypes + Send + Sync + Unpin,
|
E: EngineTypes + Send + Sync + Unpin,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec<Header = P::BlockHeader> + 'static,
|
||||||
SC: StateCommitment,
|
SC: StateCommitment,
|
||||||
S: Default + Send + Sync + Unpin + Debug + 'static,
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -253,6 +253,8 @@ pub fn decode_holocene_1559_params(extra_data: Bytes) -> Result<(u32, u32), Deco
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EthChainSpec for OpChainSpec {
|
impl EthChainSpec for OpChainSpec {
|
||||||
|
type Header = Header;
|
||||||
|
|
||||||
fn chain(&self) -> alloy_chains::Chain {
|
fn chain(&self) -> alloy_chains::Chain {
|
||||||
self.inner.chain()
|
self.inner.chain()
|
||||||
}
|
}
|
||||||
@ -281,7 +283,7 @@ impl EthChainSpec for OpChainSpec {
|
|||||||
Box::new(ChainSpec::display_hardforks(self))
|
Box::new(ChainSpec::display_hardforks(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn genesis_header(&self) -> &Header {
|
fn genesis_header(&self) -> &Self::Header {
|
||||||
self.inner.genesis_header()
|
self.inner.genesis_header()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ impl From<DatabaseError> for InitDatabaseError {
|
|||||||
pub fn init_genesis<PF>(factory: &PF) -> Result<B256, InitDatabaseError>
|
pub fn init_genesis<PF>(factory: &PF) -> Result<B256, InitDatabaseError>
|
||||||
where
|
where
|
||||||
PF: DatabaseProviderFactory + StaticFileProviderFactory + ChainSpecProvider + BlockHashReader,
|
PF: DatabaseProviderFactory + StaticFileProviderFactory + ChainSpecProvider + BlockHashReader,
|
||||||
PF::ProviderRW: StaticFileProviderFactory
|
PF::ProviderRW: StaticFileProviderFactory<Primitives = PF::Primitives>
|
||||||
+ StageCheckpointWriter
|
+ StageCheckpointWriter
|
||||||
+ HistoryWriter
|
+ HistoryWriter
|
||||||
+ HeaderProvider
|
+ HeaderProvider
|
||||||
@ -78,6 +78,7 @@ where
|
|||||||
+ StateWriter
|
+ StateWriter
|
||||||
+ StateWriter
|
+ StateWriter
|
||||||
+ AsRef<PF::ProviderRW>,
|
+ AsRef<PF::ProviderRW>,
|
||||||
|
PF::ChainSpec: EthChainSpec<Header = reth_primitives::Header>,
|
||||||
{
|
{
|
||||||
let chain = factory.chain_spec();
|
let chain = factory.chain_spec();
|
||||||
|
|
||||||
@ -307,7 +308,7 @@ pub fn insert_genesis_header<Provider, Spec>(
|
|||||||
) -> ProviderResult<()>
|
) -> ProviderResult<()>
|
||||||
where
|
where
|
||||||
Provider: StaticFileProviderFactory + DBProvider<Tx: DbTxMut>,
|
Provider: StaticFileProviderFactory + DBProvider<Tx: DbTxMut>,
|
||||||
Spec: EthChainSpec,
|
Spec: EthChainSpec<Header = reth_primitives::Header>,
|
||||||
{
|
{
|
||||||
let (header, block_hash) = (chain.genesis_header(), chain.genesis_hash());
|
let (header, block_hash) = (chain.genesis_header(), chain.genesis_hash());
|
||||||
let static_file_provider = provider.static_file_provider();
|
let static_file_provider = provider.static_file_provider();
|
||||||
|
|||||||
Reference in New Issue
Block a user