diff --git a/crates/chainspec/src/api.rs b/crates/chainspec/src/api.rs index 7f0b09330b..15a3a02449 100644 --- a/crates/chainspec/src/api.rs +++ b/crates/chainspec/src/api.rs @@ -1,8 +1,10 @@ use crate::{ChainSpec, DepositContract}; use alloy_chains::Chain; use alloy_eips::eip1559::BaseFeeParams; +use alloy_genesis::Genesis; use alloy_primitives::B256; -use core::fmt::Debug; +use core::fmt::{Debug, Display}; +use reth_primitives_traits::Header; /// Trait representing type configuring a chain spec. #[auto_impl::auto_impl(&, Arc)] @@ -13,6 +15,9 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug + 'static { /// Chain id. fn chain(&self) -> Chain; + /// Get the [`BaseFeeParams`] for the chain at the given block. + fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams; + /// Get the [`BaseFeeParams`] for the chain at the given timestamp. fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams; @@ -24,6 +29,18 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug + 'static { /// The delete limit for pruner, per run. fn prune_delete_limit(&self) -> usize; + + /// Returns a string representation of the hardforks. + fn display_hardforks(&self) -> impl Display; + + /// The genesis header. + fn genesis_header(&self) -> &Header; + + /// The genesis block specification. + fn genesis(&self) -> &Genesis; + + /// The block gas limit. + fn max_gas_limit(&self) -> u64; } impl EthChainSpec for ChainSpec { @@ -31,6 +48,10 @@ impl EthChainSpec for ChainSpec { self.chain } + fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams { + self.base_fee_params_at_block(block_number) + } + fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams { self.base_fee_params_at_timestamp(timestamp) } @@ -46,4 +67,20 @@ impl EthChainSpec for ChainSpec { fn prune_delete_limit(&self) -> usize { self.prune_delete_limit } + + fn display_hardforks(&self) -> impl Display { + self.display_hardforks() + } + + fn genesis_header(&self) -> &Header { + self.genesis_header() + } + + fn genesis(&self) -> &Genesis { + self.genesis() + } + + fn max_gas_limit(&self) -> u64 { + self.max_gas_limit + } } diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 6b0206135f..463501ee4d 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -616,6 +616,10 @@ impl Hardforks for ChainSpec { } impl EthereumHardforks for ChainSpec { + fn get_final_paris_total_difficulty(&self) -> Option { + self.get_final_paris_total_difficulty() + } + fn final_paris_total_difficulty(&self, block_number: u64) -> Option { self.final_paris_total_difficulty(block_number) } diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 3f338e9428..eb962a46fc 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -17,7 +17,7 @@ use alloy_primitives::{BlockHash, BlockNumber, Bloom, B256, U256}; use reth_beacon_consensus::BeaconEngineMessage; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_consensus::{Consensus, ConsensusError, PostExecutionInput}; use reth_engine_primitives::EngineTypes; use reth_execution_errors::{ @@ -34,6 +34,7 @@ use reth_transaction_pool::TransactionPool; use reth_trie::HashedPostState; use std::{ collections::HashMap, + fmt::Debug, sync::Arc, time::{SystemTime, UNIX_EPOCH}, }; @@ -52,19 +53,19 @@ pub use task::MiningTask; /// A consensus implementation intended for local development and testing purposes. #[derive(Debug, Clone)] #[allow(dead_code)] -pub struct AutoSealConsensus { +pub struct AutoSealConsensus { /// Configuration chain_spec: Arc, } -impl AutoSealConsensus { +impl AutoSealConsensus { /// Create a new instance of [`AutoSealConsensus`] pub const fn new(chain_spec: Arc) -> Self { Self { chain_spec } } } -impl Consensus for AutoSealConsensus { +impl Consensus for AutoSealConsensus { fn validate_header(&self, _header: &SealedHeader) -> Result<(), ConsensusError> { Ok(()) } @@ -100,9 +101,9 @@ impl Consensus for AutoSealConsensus { /// Builder type for configuring the setup #[derive(Debug)] -pub struct AutoSealBuilder { +pub struct AutoSealBuilder { client: Client, - consensus: AutoSealConsensus, + consensus: AutoSealConsensus, pool: Pool, mode: MiningMode, storage: Storage, @@ -112,11 +113,13 @@ pub struct AutoSealBuilder { // === impl AutoSealBuilder === -impl AutoSealBuilder +impl + AutoSealBuilder where Client: BlockReaderIdExt, Pool: TransactionPool, Engine: EngineTypes, + ChainSpec: EthChainSpec, { /// Creates a new builder instance to configure all parts. pub fn new( @@ -127,11 +130,9 @@ where mode: MiningMode, evm_config: EvmConfig, ) -> Self { - let latest_header = client - .latest_header() - .ok() - .flatten() - .unwrap_or_else(|| chain_spec.sealed_genesis_header()); + let latest_header = client.latest_header().ok().flatten().unwrap_or_else(|| { + SealedHeader::new(chain_spec.genesis_header().clone(), chain_spec.genesis_hash()) + }); Self { storage: Storage::new(latest_header), @@ -154,7 +155,11 @@ where #[track_caller] pub fn build( self, - ) -> (AutoSealConsensus, AutoSealClient, MiningTask) { + ) -> ( + AutoSealConsensus, + AutoSealClient, + MiningTask, + ) { let Self { client, consensus, pool, mode, storage, to_engine, evm_config } = self; let auto_client = AutoSealClient::new(storage.clone()); let task = MiningTask::new( @@ -259,7 +264,7 @@ impl StorageInner { /// Fills in pre-execution header fields based on the current best block and given /// transactions. - pub(crate) fn build_header_template( + pub(crate) fn build_header_template( &self, timestamp: u64, transactions: &[TransactionSigned], @@ -267,7 +272,10 @@ impl StorageInner { withdrawals: Option<&Withdrawals>, requests: Option<&Requests>, chain_spec: &ChainSpec, - ) -> Header { + ) -> Header + where + ChainSpec: EthChainSpec + EthereumHardforks, + { // check previous block for base fee let base_fee_per_gas = self.headers.get(&self.best_block).and_then(|parent| { parent.next_block_base_fee(chain_spec.base_fee_params_at_timestamp(timestamp)) @@ -292,7 +300,7 @@ impl StorageInner { withdrawals_root: withdrawals.map(|w| proofs::calculate_withdrawals_root(w)), difficulty: U256::from(2), number: self.best_block + 1, - gas_limit: chain_spec.max_gas_limit.into(), + gas_limit: chain_spec.max_gas_limit().into(), timestamp, base_fee_per_gas, blob_gas_used: blob_gas_used.map(Into::into), @@ -333,7 +341,7 @@ impl StorageInner { /// /// This returns the header of the executed block, as well as the poststate from execution. #[allow(clippy::too_many_arguments)] - pub(crate) fn build_and_execute( + pub(crate) fn build_and_execute( &mut self, transactions: Vec, ommers: Vec
, @@ -344,6 +352,7 @@ impl StorageInner { where Executor: BlockExecutorProvider, Provider: StateProviderFactory, + ChainSpec: EthChainSpec + EthereumHardforks, { let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs(); @@ -435,7 +444,7 @@ impl StorageInner { #[cfg(test)] mod tests { - use reth_chainspec::{ChainHardforks, EthereumHardfork, ForkCondition}; + use reth_chainspec::{ChainHardforks, ChainSpec, EthereumHardfork, ForkCondition}; use reth_primitives::Transaction; use super::*; diff --git a/crates/consensus/auto-seal/src/task.rs b/crates/consensus/auto-seal/src/task.rs index 2eb7914999..16c726c7a1 100644 --- a/crates/consensus/auto-seal/src/task.rs +++ b/crates/consensus/auto-seal/src/task.rs @@ -1,7 +1,7 @@ use crate::{mode::MiningMode, Storage}; use futures_util::{future::BoxFuture, FutureExt}; use reth_beacon_consensus::{BeaconEngineMessage, ForkchoiceStatus}; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_engine_primitives::EngineTypes; use reth_evm::execute::BlockExecutorProvider; use reth_primitives::IntoRecoveredTransaction; @@ -21,7 +21,7 @@ use tokio::sync::{mpsc::UnboundedSender, oneshot}; use tracing::{debug, error, warn}; /// A Future that listens for new ready transactions and puts new blocks into storage -pub struct MiningTask { +pub struct MiningTask { /// The configured chain spec chain_spec: Arc, /// The client used to interact with the state @@ -46,8 +46,8 @@ pub struct MiningTask - MiningTask +impl + MiningTask { /// Creates a new instance of the task #[allow(clippy::too_many_arguments)] @@ -80,12 +80,14 @@ impl } } -impl Future for MiningTask +impl Future + for MiningTask where Client: StateProviderFactory + CanonChainTracker + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, Engine: EngineTypes, Executor: BlockExecutorProvider, + ChainSpec: EthChainSpec + EthereumHardforks, { type Output = (); @@ -216,8 +218,8 @@ where } } -impl std::fmt::Debug - for MiningTask +impl + std::fmt::Debug for MiningTask { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("MiningTask").finish_non_exhaustive() diff --git a/crates/consensus/common/src/calc.rs b/crates/consensus/common/src/calc.rs index 88fd10f177..3f519332fe 100644 --- a/crates/consensus/common/src/calc.rs +++ b/crates/consensus/common/src/calc.rs @@ -1,5 +1,5 @@ use alloy_primitives::{BlockNumber, U256}; -use reth_chainspec::{ChainSpec, EthereumHardfork}; +use reth_chainspec::{EthereumHardfork, Hardforks}; use reth_primitives::constants::ETH_TO_WEI; /// Calculates the base block reward. @@ -22,7 +22,7 @@ use reth_primitives::constants::ETH_TO_WEI; /// /// [yp]: https://ethereum.github.io/yellowpaper/paper.pdf pub fn base_block_reward( - chain_spec: &ChainSpec, + chain_spec: impl Hardforks, block_number: BlockNumber, block_difficulty: U256, total_difficulty: U256, @@ -37,7 +37,7 @@ pub fn base_block_reward( /// Calculates the base block reward __before__ the merge (Paris hardfork). /// /// Caution: The caller must ensure that the block number is before the merge. -pub fn base_block_reward_pre_merge(chain_spec: &ChainSpec, block_number: BlockNumber) -> u128 { +pub fn base_block_reward_pre_merge(chain_spec: impl Hardforks, block_number: BlockNumber) -> u128 { if chain_spec.fork(EthereumHardfork::Constantinople).active_at_block(block_number) { ETH_TO_WEI * 2 } else if chain_spec.fork(EthereumHardfork::Byzantium).active_at_block(block_number) { @@ -66,7 +66,7 @@ pub fn base_block_reward_pre_merge(chain_spec: &ChainSpec, block_number: BlockNu /// let total_difficulty = U256::from(2_235_668_675_900usize); /// let number_of_ommers = 1; /// -/// let reward = base_block_reward(&MAINNET, block_number, block_difficulty, total_difficulty) +/// let reward = base_block_reward(&*MAINNET, block_number, block_difficulty, total_difficulty) /// .map(|reward| block_reward(reward, 1)); /// /// // The base block reward is 5 ETH, and the ommer inclusion reward is 1/32th of 5 ETH. @@ -130,7 +130,7 @@ mod tests { ]; for ((block_number, td), expected_reward) in cases { - assert_eq!(base_block_reward(&MAINNET, block_number, U256::ZERO, td), expected_reward); + assert_eq!(base_block_reward(&*MAINNET, block_number, U256::ZERO, td), expected_reward); } } diff --git a/crates/ethereum-forks/src/hardforks/ethereum.rs b/crates/ethereum-forks/src/hardforks/ethereum.rs index c8240a83e8..3069367158 100644 --- a/crates/ethereum-forks/src/hardforks/ethereum.rs +++ b/crates/ethereum-forks/src/hardforks/ethereum.rs @@ -52,6 +52,9 @@ pub trait EthereumHardforks: Hardforks { } } + /// Returns the final total difficulty if the Paris hardfork is known. + fn get_final_paris_total_difficulty(&self) -> Option; + /// Returns the final total difficulty if the given block number is after the Paris hardfork. /// /// Note: technically this would also be valid for the block before the paris upgrade, but this diff --git a/crates/ethereum-forks/src/hardforks/mod.rs b/crates/ethereum-forks/src/hardforks/mod.rs index bb6dcaed79..11851c7389 100644 --- a/crates/ethereum-forks/src/hardforks/mod.rs +++ b/crates/ethereum-forks/src/hardforks/mod.rs @@ -14,7 +14,7 @@ use alloc::{boxed::Box, vec::Vec}; /// Generic trait over a set of ordered hardforks #[auto_impl::auto_impl(&, Arc)] -pub trait Hardforks: Default + Clone { +pub trait Hardforks: Clone { /// Retrieves [`ForkCondition`] from `fork`. If `fork` is not present, returns /// [`ForkCondition::Never`]. fn fork(&self, fork: H) -> ForkCondition; diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index 8cf68c9a47..8996ac9959 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -208,7 +208,7 @@ impl ExecutionOutcome { pub fn optimism_receipts_root_slow( &self, block_number: BlockNumber, - chain_spec: &reth_chainspec::ChainSpec, + chain_spec: impl reth_chainspec::Hardforks, timestamp: u64, ) -> Option { self.receipts.optimism_root_slow( diff --git a/crates/evm/src/system_calls/eip2935.rs b/crates/evm/src/system_calls/eip2935.rs index d32a589666..4a1ec14a46 100644 --- a/crates/evm/src/system_calls/eip2935.rs +++ b/crates/evm/src/system_calls/eip2935.rs @@ -5,7 +5,7 @@ use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS; use crate::ConfigureEvm; use core::fmt::Display; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::EthereumHardforks; use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_primitives::Header; use revm::{interpreter::Host, Database, DatabaseCommit, Evm}; @@ -21,7 +21,7 @@ use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultA pub fn pre_block_blockhashes_contract_call( db: &mut DB, evm_config: &EvmConfig, - chain_spec: &ChainSpec, + chain_spec: impl EthereumHardforks, initialized_cfg: &CfgEnvWithHandlerCfg, initialized_block_env: &BlockEnv, parent_block_hash: B256, @@ -52,7 +52,7 @@ where } /// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block, -/// [`ChainSpec`], and EVM. +/// chain specification, and EVM. /// /// If Prague is not activated, or the block is the genesis block, then this is a no-op, and no /// state changes are made. @@ -66,7 +66,7 @@ where #[inline] pub fn transact_blockhashes_contract_call( evm_config: &EvmConfig, - chain_spec: &ChainSpec, + chain_spec: impl EthereumHardforks, block_timestamp: u64, block_number: u64, parent_block_hash: B256, @@ -116,7 +116,7 @@ where } /// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block, -/// [`ChainSpec`], and EVM and commits the relevant state changes. +/// chain specification, and EVM and commits the relevant state changes. /// /// If Prague is not activated, or the block is the genesis block, then this is a no-op, and no /// state changes are made. @@ -125,7 +125,7 @@ where #[inline] pub fn apply_blockhashes_contract_call( evm_config: &EvmConfig, - chain_spec: &ChainSpec, + chain_spec: impl EthereumHardforks, block_timestamp: u64, block_number: u64, parent_block_hash: B256, diff --git a/crates/evm/src/system_calls/eip4788.rs b/crates/evm/src/system_calls/eip4788.rs index 055bfb634c..d1148f6cdc 100644 --- a/crates/evm/src/system_calls/eip4788.rs +++ b/crates/evm/src/system_calls/eip4788.rs @@ -3,7 +3,7 @@ use alloc::{boxed::Box, string::ToString}; use crate::ConfigureEvm; use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::EthereumHardforks; use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_primitives::Header; use revm::{interpreter::Host, Database, DatabaseCommit, Evm}; @@ -19,7 +19,7 @@ use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultA pub fn pre_block_beacon_root_contract_call( db: &mut DB, evm_config: &EvmConfig, - chain_spec: &ChainSpec, + chain_spec: impl EthereumHardforks, initialized_cfg: &CfgEnvWithHandlerCfg, initialized_block_env: &BlockEnv, parent_beacon_block_root: Option, @@ -51,7 +51,7 @@ where } /// Applies the pre-block call to the [EIP-4788] beacon block root contract, using the given block, -/// [`ChainSpec`], EVM. +/// chain spec, EVM. /// /// Note: this does not commit the state changes to the database, it only transact the call. /// @@ -126,16 +126,16 @@ where } /// Applies the pre-block call to the [EIP-4788] beacon block root contract, using the given block, -/// [`ChainSpec`], EVM. +/// chain spec, EVM. /// /// If Cancun is not activated or the block is the genesis block, then this is a no-op, and no /// state changes are made. /// /// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788 #[inline] -pub fn apply_beacon_root_contract_call( +pub fn apply_beacon_root_contract_call( evm_config: &EvmConfig, - chain_spec: &Spec, + chain_spec: impl EthereumHardforks, block_timestamp: u64, block_number: u64, parent_beacon_block_root: Option, @@ -145,11 +145,10 @@ where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, EvmConfig: ConfigureEvm
, - Spec: EthereumHardforks, { if let Some(res) = transact_beacon_root_contract_call( evm_config, - chain_spec, + &chain_spec, block_timestamp, block_number, parent_beacon_block_root, diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 506603b84d..d7cec56cab 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -10,7 +10,7 @@ pub use states::*; use std::sync::Arc; use futures::Future; -use reth_chainspec::{ChainSpec, EthChainSpec}; +use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks}; use reth_cli_util::get_secret_key; use reth_db_api::{ database::Database, @@ -209,9 +209,10 @@ impl NodeBuilder { } } -impl NodeBuilder +impl NodeBuilder where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, + ChainSpec: EthChainSpec + EthereumHardforks, { /// Configures the types of the node. pub fn with_types(self) -> NodeBuilderWithTypes> @@ -269,9 +270,10 @@ impl WithLaunchContext> { } } -impl WithLaunchContext> +impl WithLaunchContext> where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, + ChainSpec: EthChainSpec + EthereumHardforks, { /// Configures the types of the node. pub fn with_types(self) -> WithLaunchContext>> @@ -483,7 +485,7 @@ where impl WithLaunchContext, CB, AO>> where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, - T: NodeTypesWithEngine, + T: NodeTypesWithEngine, CB: NodeComponentsBuilder>, AO: NodeAddOns< NodeAdapter, CB::Components>, diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 37bb4cc5b7..d6575d000a 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -39,7 +39,7 @@ use reth_node_metrics::{ }; use reth_primitives::Head; use reth_provider::{ - providers::{BlockchainProvider, BlockchainProvider2, StaticFileProvider}, + providers::{BlockchainProvider, BlockchainProvider2, ProviderNodeTypes, StaticFileProvider}, BlockHashReader, CanonStateNotificationSender, ChainSpecProvider, ProviderFactory, ProviderResult, StageCheckpointReader, StateProviderFactory, StaticFileProviderFactory, TreeViewer, @@ -483,7 +483,7 @@ where impl LaunchContextWith, ProviderFactory>> where - T: NodeTypesWithDB, + T: NodeTypesWithDB, { /// Returns access to the underlying database. pub const fn database(&self) -> &T::DB { @@ -523,7 +523,7 @@ where target_triple: VERGEN_CARGO_TARGET_TRIPLE, build_profile: BUILD_PROFILE_NAME, }, - ChainSpecInfo { name: self.left().config.chain.chain.to_string() }, + ChainSpecInfo { name: self.left().config.chain.chain().to_string() }, self.task_executor().clone(), Hooks::new(self.database().clone(), self.static_file_provider()), ); @@ -621,7 +621,7 @@ impl Attached::ChainSpec>, WithMeteredProviders>, > where - T: FullNodeTypes, Provider: WithTree>, + T: FullNodeTypes, { /// Returns access to the underlying database. pub const fn database(&self) -> &::DB { @@ -746,7 +746,10 @@ impl Attached::ChainSpec>, WithComponents>, > where - T: FullNodeTypes>, + T: FullNodeTypes< + Provider: WithTree, + Types: NodeTypes, + >, CB: NodeComponentsBuilder, { /// Returns the configured `ProviderFactory`. diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index eb21335433..78697056d2 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -18,7 +18,7 @@ use reth_beacon_consensus::{ BeaconConsensusEngine, }; use reth_blockchain_tree::{noop::NoopBlockchainTree, BlockchainTreeConfig}; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider}; use reth_engine_util::EngineMessageStreamExt; use reth_exex::ExExManagerHandle; @@ -106,7 +106,7 @@ impl DefaultNodeLauncher { impl LaunchNode> for DefaultNodeLauncher where - Types: NodeTypesWithDB + NodeTypesWithEngine, + Types: NodeTypesWithDB + NodeTypesWithEngine, T: FullNodeTypes, Types = Types>, CB: NodeComponentsBuilder, AO: NodeAddOns< @@ -165,7 +165,7 @@ where debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis"); }) .with_genesis()? - .inspect(|this: &LaunchContextWith, _>>| { + .inspect(|this: &LaunchContextWith, _>>| { info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks()); }) .with_metrics_task() @@ -223,7 +223,7 @@ where let (pipeline, client) = if ctx.is_dev() { info!(target: "reth::cli", "Starting Reth in dev mode"); - for (idx, (address, alloc)) in ctx.chain_spec().genesis.alloc.iter().enumerate() { + for (idx, (address, alloc)) in ctx.chain_spec().genesis().alloc.iter().enumerate() { info!(target: "reth::cli", "Allocated Genesis Account: {:02}. {} ({} ETH)", idx, address.to_string(), format_ether(alloc.balance)); } @@ -384,7 +384,7 @@ where if let Some(maybe_custom_etherscan_url) = ctx.node_config().debug.etherscan.clone() { info!(target: "reth::cli", "Using etherscan as consensus client"); - let chain = ctx.node_config().chain.chain; + let chain = ctx.node_config().chain.chain(); let etherscan_url = maybe_custom_etherscan_url.map(Ok).unwrap_or_else(|| { // If URL isn't provided, use default Etherscan URL for the chain if it is known chain diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 9affc252b9..607a33147e 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -6,10 +6,7 @@ use std::{ }; use futures::TryFutureExt; -use reth_chainspec::ChainSpec; -use reth_node_api::{ - BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, -}; +use reth_node_api::{BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithEngine}; use reth_node_core::{ node_config::NodeConfig, rpc::{ @@ -18,6 +15,7 @@ use reth_node_core::{ }, }; use reth_payload_builder::PayloadBuilderHandle; +use reth_provider::providers::ProviderNodeTypes; use reth_rpc_builder::{ auth::{AuthRpcModule, AuthServerHandle}, config::RethRpcServerConfig, @@ -298,12 +296,12 @@ where pub async fn launch_rpc_servers( node: Node, engine_api: Engine, - config: &NodeConfig, + config: &NodeConfig<::ChainSpec>, jwt_secret: JwtSecret, add_ons: RpcAddOns, ) -> eyre::Result<(RethRpcServerHandles, RpcRegistry)> where - Node: FullNodeComponents> + Clone, + Node: FullNodeComponents + Clone, Engine: EngineApiServer<::Engine>, EthApi: EthApiBuilderProvider + FullEthApiServer, { diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 61166bc7ef..403e3b8a73 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -14,7 +14,7 @@ use std::{fmt, sync::Arc}; use alloy_primitives::U256; use derive_more::Deref; use op_alloy_network::Optimism; -use reth_chainspec::ChainSpec; +use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes, NodeTypes}; @@ -110,12 +110,12 @@ where impl EthApiSpec for OpEthApi where Self: Send + Sync, - N: FullNodeComponents>, + N: FullNodeComponents>, { #[inline] fn provider( &self, - ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader + ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader { self.inner.provider() } @@ -160,12 +160,12 @@ where impl LoadFee for OpEthApi where Self: LoadBlock, - N: FullNodeComponents>, + N: FullNodeComponents>, { #[inline] fn provider( &self, - ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider { + ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider { self.inner.provider() } @@ -188,10 +188,12 @@ where impl LoadState for OpEthApi where Self: Send + Sync + Clone, - N: FullNodeComponents>, + N: FullNodeComponents>, { #[inline] - fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider { + fn provider( + &self, + ) -> impl StateProviderFactory + ChainSpecProvider { self.inner.provider() } diff --git a/crates/optimism/rpc/src/eth/pending_block.rs b/crates/optimism/rpc/src/eth/pending_block.rs index 43542baf52..c96dff40b0 100644 --- a/crates/optimism/rpc/src/eth/pending_block.rs +++ b/crates/optimism/rpc/src/eth/pending_block.rs @@ -1,7 +1,7 @@ //! Loads OP pending block for a RPC response. use alloy_primitives::{BlockNumber, B256}; -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_evm::ConfigureEvm; use reth_node_api::{FullNodeComponents, NodeTypes}; use reth_primitives::{ @@ -23,14 +23,14 @@ use crate::OpEthApi; impl LoadPendingBlock for OpEthApi where Self: SpawnBlocking, - N: FullNodeComponents>, + N: FullNodeComponents>, { #[inline] fn provider( &self, ) -> impl BlockReaderIdExt + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + StateProviderFactory { self.inner.provider() } diff --git a/crates/payload/primitives/src/lib.rs b/crates/payload/primitives/src/lib.rs index b6168f5621..5d10040513 100644 --- a/crates/payload/primitives/src/lib.rs +++ b/crates/payload/primitives/src/lib.rs @@ -49,7 +49,7 @@ pub trait PayloadTypes: Send + Sync + Unpin + core::fmt::Debug + Clone + 'static /// /// Otherwise, this will return [`EngineObjectValidationError::UnsupportedFork`]. pub fn validate_payload_timestamp( - chain_spec: &ChainSpec, + chain_spec: impl EthereumHardforks, version: EngineApiMessageVersion, timestamp: u64, ) -> Result<(), EngineObjectValidationError> { diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index 63ec5c7310..7f41fa9bd2 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -55,7 +55,7 @@ pub fn calculate_receipt_root_no_memo(receipts: &[&Receipt]) -> B256 { #[cfg(feature = "optimism")] pub fn calculate_receipt_root_no_memo_optimism( receipts: &[&Receipt], - chain_spec: &reth_chainspec::ChainSpec, + chain_spec: impl reth_chainspec::Hardforks, timestamp: u64, ) -> B256 { // There is a minor bug in op-geth and op-erigon where in the Regolith hardfork, @@ -63,6 +63,7 @@ pub fn calculate_receipt_root_no_memo_optimism( // encoding. In the Regolith Hardfork, we must strip the deposit nonce from the // receipts before calculating the receipt root. This was corrected in the Canyon // hardfork. + if chain_spec .is_fork_active_at_timestamp(reth_optimism_forks::OptimismHardfork::Regolith, timestamp) && !chain_spec.is_fork_active_at_timestamp( diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index 967dde4694..6b1b62ba6f 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -112,7 +112,7 @@ impl Receipts { pub fn optimism_root_slow( &self, index: usize, - chain_spec: &reth_chainspec::ChainSpec, + chain_spec: impl reth_chainspec::Hardforks, timestamp: u64, ) -> Option { Some(crate::proofs::calculate_receipt_root_no_memo_optimism( diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 7e97d0fcca..113cb93c46 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -167,7 +167,7 @@ use jsonrpsee::{ }, Methods, RpcModule, }; -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_engine_primitives::EngineTypes; use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm}; use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers}; @@ -842,11 +842,11 @@ impl where Network: NetworkInfo + Clone + 'static, EthApi: EthApiTypes, - Provider: ChainSpecProvider, + Provider: ChainSpecProvider, BlockExecutor: BlockExecutorProvider, { /// Instantiates `AdminApi` - pub fn admin_api(&self) -> AdminApi + pub fn admin_api(&self) -> AdminApi where Network: Peers, { diff --git a/crates/rpc/rpc-engine-api/src/engine_api.rs b/crates/rpc/rpc-engine-api/src/engine_api.rs index 431f1fd724..2b37f9d15f 100644 --- a/crates/rpc/rpc-engine-api/src/engine_api.rs +++ b/crates/rpc/rpc-engine-api/src/engine_api.rs @@ -6,7 +6,7 @@ use alloy_primitives::{BlockHash, BlockNumber, B256, U64}; use async_trait::async_trait; use jsonrpsee_core::RpcResult; use reth_beacon_consensus::BeaconConsensusEngineHandle; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthereumHardforks, Hardforks}; use reth_engine_primitives::{EngineTypes, EngineValidator}; use reth_evm::provider::EvmEnvProvider; use reth_payload_builder::PayloadStore; @@ -43,11 +43,11 @@ const MAX_BLOB_LIMIT: usize = 128; /// The Engine API implementation that grants the Consensus layer access to data and /// functions in the Execution layer that are crucial for the consensus process. -pub struct EngineApi { - inner: Arc>, +pub struct EngineApi { + inner: Arc>, } -struct EngineApiInner { +struct EngineApiInner { /// The provider to interact with the chain. provider: Provider, /// Consensus configuration @@ -70,12 +70,14 @@ struct EngineApiInner { validator: Validator, } -impl EngineApi +impl + EngineApi where Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static, EngineT: EngineTypes, Pool: TransactionPool + 'static, Validator: EngineValidator, + ChainSpec: EthereumHardforks + Send + Sync + 'static, { /// Create new instance of [`EngineApi`]. #[allow(clippy::too_many_arguments)] @@ -616,13 +618,14 @@ where } #[async_trait] -impl EngineApiServer - for EngineApi +impl EngineApiServer + for EngineApi where Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static, EngineT: EngineTypes, Pool: TransactionPool + 'static, Validator: EngineValidator, + ChainSpec: EthereumHardforks + Send + Sync + 'static, { /// Handler for `engine_newPayloadV1` /// See also @@ -932,8 +935,8 @@ where } } -impl std::fmt::Debug - for EngineApi +impl std::fmt::Debug + for EngineApi where EngineT: EngineTypes, { @@ -947,7 +950,7 @@ mod tests { use super::*; use assert_matches::assert_matches; use reth_beacon_consensus::{BeaconConsensusEngineEvent, BeaconEngineMessage}; - use reth_chainspec::MAINNET; + use reth_chainspec::{ChainSpec, MAINNET}; use reth_ethereum_engine_primitives::{EthEngineTypes, EthereumEngineValidator}; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::SealedBlock; @@ -967,6 +970,7 @@ mod tests { EthEngineTypes, NoopTransactionPool, EthereumEngineValidator, + ChainSpec, >, ) { let client = ClientVersionV1 { diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index 99e240bf37..416b29df04 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -12,7 +12,7 @@ use alloy_rpc_types::{ }; use alloy_rpc_types_eth::transaction::TransactionRequest; use futures::Future; -use reth_chainspec::MIN_TRANSACTION_GAS; +use reth_chainspec::{EthChainSpec, MIN_TRANSACTION_GAS}; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_primitives::{ basefee::calc_next_block_base_fee, @@ -782,8 +782,9 @@ pub trait Call: LoadState + SpawnBlocking { } // We can now normalize the highest gas limit to a u64 - let mut highest_gas_limit: u64 = - highest_gas_limit.try_into().unwrap_or(self.provider().chain_spec().max_gas_limit); + let mut highest_gas_limit: u64 = highest_gas_limit + .try_into() + .unwrap_or_else(|_| self.provider().chain_spec().max_gas_limit()); // If the provided gas limit is less than computed cap, use that env.tx.gas_limit = env.tx.gas_limit.min(highest_gas_limit); diff --git a/crates/rpc/rpc-eth-api/src/helpers/fee.rs b/crates/rpc/rpc-eth-api/src/helpers/fee.rs index e300ed8029..82d9e9ab4e 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/fee.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/fee.rs @@ -3,7 +3,7 @@ use alloy_primitives::U256; use alloy_rpc_types::{BlockNumberOrTag, FeeHistory}; use futures::Future; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_provider::{BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider}; use reth_rpc_eth_types::{ fee_history::calculate_reward_percentiles_for_block, EthApiError, EthStateCache, @@ -147,7 +147,7 @@ pub trait EthFees: LoadFee { // Also need to include the `base_fee_per_gas` and `base_fee_per_blob_gas` for the // next block base_fee_per_gas - .push(last_entry.next_block_base_fee(&LoadFee::provider(self).chain_spec()) + .push(last_entry.next_block_base_fee(LoadFee::provider(self).chain_spec()) as u128); base_fee_per_blob_gas.push(last_entry.next_block_blob_fee().unwrap_or_default()); @@ -247,7 +247,7 @@ pub trait LoadFee: LoadBlock { /// Data access in default (L1) trait method implementations. fn provider( &self, - ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider; + ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider; /// Returns a handle for reading data from memory. /// diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index 6593d23db2..d4d5fd23d4 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -7,7 +7,7 @@ use crate::{EthApiTypes, FromEthApiError, FromEvmError}; use alloy_primitives::{BlockNumber, B256, U256}; use alloy_rpc_types::BlockNumberOrTag; use futures::Future; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_evm::{ system_calls::{pre_block_beacon_root_contract_call, pre_block_blockhashes_contract_call}, ConfigureEvm, ConfigureEvmEnv, @@ -50,7 +50,7 @@ pub trait LoadPendingBlock: EthApiTypes { &self, ) -> impl BlockReaderIdExt + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + StateProviderFactory; /// Returns a handle for reading data from transaction pool. diff --git a/crates/rpc/rpc-eth-api/src/helpers/spec.rs b/crates/rpc/rpc-eth-api/src/helpers/spec.rs index e852a352af..5976cf29c0 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/spec.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/spec.rs @@ -1,11 +1,9 @@ //! Loads chain metadata. -use std::sync::Arc; - use alloy_primitives::{Address, U256, U64}; use alloy_rpc_types::{Stage, SyncInfo, SyncStatus}; use futures::Future; -use reth_chainspec::{ChainInfo, ChainSpec}; +use reth_chainspec::{ChainInfo, EthereumHardforks}; use reth_errors::{RethError, RethResult}; use reth_network_api::NetworkInfo; use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader}; @@ -20,7 +18,7 @@ pub trait EthApiSpec: Send + Sync { /// Returns a handle for reading data from disk. fn provider( &self, - ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader; + ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader; /// Returns a handle for reading network data summary. fn network(&self) -> impl NetworkInfo; @@ -87,9 +85,4 @@ pub trait EthApiSpec: Send + Sync { }; Ok(status) } - - /// Returns the configured [`ChainSpec`]. - fn chain_spec(&self) -> Arc { - self.provider().chain_spec() - } } diff --git a/crates/rpc/rpc-eth-api/src/helpers/state.rs b/crates/rpc/rpc-eth-api/src/helpers/state.rs index 9a72ec982e..dee4e58956 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/state.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/state.rs @@ -4,7 +4,7 @@ use alloy_primitives::{Address, Bytes, B256, U256}; use alloy_rpc_types::{serde_helpers::JsonStorageKey, Account, EIP1186AccountProofResponse}; use futures::Future; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_errors::RethError; use reth_evm::ConfigureEvmEnv; use reth_primitives::{BlockId, Header, KECCAK_EMPTY}; @@ -157,7 +157,9 @@ pub trait LoadState: EthApiTypes { /// Returns a handle for reading state from database. /// /// Data access in default trait method implementations. - fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider; + fn provider( + &self, + ) -> impl StateProviderFactory + ChainSpecProvider; /// Returns a handle for reading data from memory. /// diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index 34b7bff823..f413797682 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -14,7 +14,7 @@ use futures::{ }; use metrics::atomics::AtomicU64; use reth_chain_state::CanonStateNotification; -use reth_chainspec::{ChainSpec, ChainSpecProvider}; +use reth_chainspec::{ChainSpecProvider, EthChainSpec}; use reth_primitives::{ basefee::calc_next_block_base_fee, eip4844::{calc_blob_gasprice, calculate_excess_blob_gas}, @@ -377,7 +377,7 @@ impl FeeHistoryEntry { } /// Returns the base fee for the next block according to the EIP-1559 spec. - pub fn next_block_base_fee(&self, chain_spec: &ChainSpec) -> u64 { + pub fn next_block_base_fee(&self, chain_spec: impl EthChainSpec) -> u64 { calc_next_block_base_fee( self.gas_used as u128, self.gas_limit as u128, diff --git a/crates/rpc/rpc/src/admin.rs b/crates/rpc/rpc/src/admin.rs index 361a33eeff..311719a04e 100644 --- a/crates/rpc/rpc/src/admin.rs +++ b/crates/rpc/rpc/src/admin.rs @@ -7,7 +7,7 @@ use alloy_rpc_types_admin::{ }; use async_trait::async_trait; use jsonrpsee::core::RpcResult; -use reth_chainspec::ChainSpec; +use reth_chainspec::{EthChainSpec, EthereumHardforks, ForkCondition}; use reth_network_api::{NetworkInfo, Peers}; use reth_network_peers::{id2pk, AnyNode, NodeRecord}; use reth_network_types::PeerKind; @@ -18,14 +18,14 @@ use reth_rpc_server_types::ToRpcResult; /// `admin` API implementation. /// /// This type provides the functionality for handling `admin` related requests. -pub struct AdminApi { +pub struct AdminApi { /// An interface to interact with the network network: N, /// The specification of the blockchain's configuration. chain_spec: Arc, } -impl AdminApi { +impl AdminApi { /// Creates a new instance of `AdminApi`. pub const fn new(network: N, chain_spec: Arc) -> Self { Self { network, chain_spec } @@ -33,9 +33,10 @@ impl AdminApi { } #[async_trait] -impl AdminApiServer for AdminApi +impl AdminApiServer for AdminApi where N: NetworkInfo + Peers + 'static, + ChainSpec: EthChainSpec + EthereumHardforks + Send + Sync + 'static, { /// Handler for `admin_addPeer` fn add_peer(&self, record: NodeRecord) -> RpcResult { @@ -108,16 +109,12 @@ where let enode = self.network.local_node_record(); let status = self.network.network_status().await.to_rpc_result()?; let mut config = ChainConfig { - chain_id: self.chain_spec.chain.id(), + chain_id: self.chain_spec.chain().id(), terminal_total_difficulty_passed: self .chain_spec .get_final_paris_total_difficulty() .is_some(), - terminal_total_difficulty: self - .chain_spec - .hardforks - .fork(EthereumHardfork::Paris) - .ttd(), + terminal_total_difficulty: self.chain_spec.fork(EthereumHardfork::Paris).ttd(), ..self.chain_spec.genesis().config.clone() }; @@ -127,7 +124,12 @@ where $( // don't overwrite if already set if $config.$field.is_none() { - $config.$field = self.chain_spec.hardforks.fork_block(EthereumHardfork::$fork); + $config.$field = match self.chain_spec.fork(EthereumHardfork::$fork) { + ForkCondition::Block(block) => Some(block), + ForkCondition::TTD { fork_block, .. } => fork_block, + ForkCondition::Timestamp(ts) => Some(ts), + ForkCondition::Never => None, + }; } )* }; @@ -185,7 +187,7 @@ where } } -impl std::fmt::Debug for AdminApi { +impl std::fmt::Debug for AdminApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("AdminApi").finish_non_exhaustive() } diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 61069ad8cc..9e8ff892cc 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -12,7 +12,7 @@ use alloy_rpc_types_trace::geth::{ }; use async_trait::async_trait; use jsonrpsee::core::RpcResult; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::EthereumHardforks; use reth_evm::{ execute::{BlockExecutorProvider, Executor}, ConfigureEvmEnv, @@ -77,7 +77,7 @@ impl DebugApi where Provider: BlockReaderIdExt + HeaderProvider - + ChainSpecProvider + + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static, @@ -822,7 +822,7 @@ impl DebugApiServer for DebugApi + + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static, diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index c2999c2d30..dd8f75898b 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use alloy_primitives::{keccak256, U256}; use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult}; use jsonrpsee::core::RpcResult; +use reth_chainspec::EthChainSpec; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_primitives::{ revm_primitives::db::{DatabaseCommit, DatabaseRef}, diff --git a/crates/rpc/rpc/src/eth/core.rs b/crates/rpc/rpc/src/eth/core.rs index cc1843c233..6b258cac44 100644 --- a/crates/rpc/rpc/src/eth/core.rs +++ b/crates/rpc/rpc/src/eth/core.rs @@ -376,7 +376,7 @@ mod tests { use alloy_primitives::{B256, U64}; use alloy_rpc_types::FeeHistory; use jsonrpsee_types::error::INVALID_PARAMS_CODE; - use reth_chainspec::{BaseFeeParams, ChainSpec}; + use reth_chainspec::{BaseFeeParams, ChainSpec, EthChainSpec}; use reth_evm_ethereum::EthEvmConfig; use reth_network_api::noop::NoopNetwork; use reth_primitives::{Block, BlockBody, BlockNumberOrTag, Header, TransactionSigned}; @@ -414,7 +414,7 @@ mod tests { let fee_history_cache = FeeHistoryCache::new(cache.clone(), FeeHistoryCacheConfig::default()); - let gas_cap = provider.chain_spec().max_gas_limit; + let gas_cap = provider.chain_spec().max_gas_limit(); EthApi::new( provider.clone(), testing_pool(), diff --git a/crates/rpc/rpc/src/eth/helpers/fees.rs b/crates/rpc/rpc/src/eth/helpers/fees.rs index 70ff98ba86..a792f72895 100644 --- a/crates/rpc/rpc/src/eth/helpers/fees.rs +++ b/crates/rpc/rpc/src/eth/helpers/fees.rs @@ -1,6 +1,6 @@ //! Contains RPC handler implementations for fee history. -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_provider::{BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider}; use reth_rpc_eth_api::helpers::{EthFees, LoadBlock, LoadFee}; @@ -16,12 +16,12 @@ impl EthFees for EthApi LoadFee for EthApi where Self: LoadBlock, - Provider: BlockReaderIdExt + HeaderProvider + ChainSpecProvider, + Provider: BlockReaderIdExt + HeaderProvider + ChainSpecProvider, { #[inline] fn provider( &self, - ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider { + ) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider { self.inner.provider() } diff --git a/crates/rpc/rpc/src/eth/helpers/pending_block.rs b/crates/rpc/rpc/src/eth/helpers/pending_block.rs index 04775a718b..69d55f58bf 100644 --- a/crates/rpc/rpc/src/eth/helpers/pending_block.rs +++ b/crates/rpc/rpc/src/eth/helpers/pending_block.rs @@ -1,6 +1,6 @@ //! Support for building a pending block with transactions from local view of mempool. -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_evm::ConfigureEvm; use reth_primitives::Header; use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory}; @@ -16,7 +16,7 @@ where Self: SpawnBlocking, Provider: BlockReaderIdExt + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + StateProviderFactory, Pool: TransactionPool, EvmConfig: ConfigureEvm
, @@ -26,7 +26,7 @@ where &self, ) -> impl BlockReaderIdExt + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + StateProviderFactory { self.inner.provider() } diff --git a/crates/rpc/rpc/src/eth/helpers/spec.rs b/crates/rpc/rpc/src/eth/helpers/spec.rs index 1f42f09d77..92445bf5ed 100644 --- a/crates/rpc/rpc/src/eth/helpers/spec.rs +++ b/crates/rpc/rpc/src/eth/helpers/spec.rs @@ -1,5 +1,5 @@ use alloy_primitives::U256; -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_network_api::NetworkInfo; use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader}; use reth_rpc_eth_api::helpers::EthApiSpec; @@ -10,14 +10,16 @@ use crate::EthApi; impl EthApiSpec for EthApi where Pool: TransactionPool + 'static, - Provider: - ChainSpecProvider + BlockNumReader + StageCheckpointReader + 'static, + Provider: ChainSpecProvider + + BlockNumReader + + StageCheckpointReader + + 'static, Network: NetworkInfo + 'static, EvmConfig: Send + Sync, { fn provider( &self, - ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader + ) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader { self.inner.provider() } diff --git a/crates/rpc/rpc/src/eth/helpers/state.rs b/crates/rpc/rpc/src/eth/helpers/state.rs index cf87a1a7a8..006a0192f7 100644 --- a/crates/rpc/rpc/src/eth/helpers/state.rs +++ b/crates/rpc/rpc/src/eth/helpers/state.rs @@ -1,6 +1,6 @@ //! Contains RPC handler implementations specific to state. -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_provider::{ChainSpecProvider, StateProviderFactory}; use reth_transaction_pool::TransactionPool; @@ -21,11 +21,13 @@ where impl LoadState for EthApi where Self: Send + Sync, - Provider: StateProviderFactory + ChainSpecProvider, + Provider: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { #[inline] - fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider { + fn provider( + &self, + ) -> impl StateProviderFactory + ChainSpecProvider { self.inner.provider() } diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index 7435fde9e4..55f40fe72c 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -14,7 +14,7 @@ use alloy_rpc_types_trace::{ }; use async_trait::async_trait; use jsonrpsee::core::RpcResult; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::EthereumHardforks; use reth_consensus_common::calc::{ base_block_reward, base_block_reward_pre_merge, block_reward, ommer_reward, }; @@ -80,7 +80,7 @@ where Provider: BlockReader + StateProviderFactory + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + 'static, Eth: TraceExt + 'static, { @@ -559,7 +559,7 @@ where Provider: BlockReader + StateProviderFactory + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + 'static, Eth: TraceExt + 'static, { diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 53fd1bfee3..6e94677abf 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -2,7 +2,7 @@ use alloy_genesis::GenesisAccount; use alloy_primitives::{Address, B256, U256}; -use reth_chainspec::ChainSpec; +use reth_chainspec::{ChainSpec, EthChainSpec}; use reth_codecs::Compact; use reth_config::config::EtlConfig; use reth_db::tables; @@ -71,10 +71,7 @@ impl From for InitDatabaseError { /// Write the genesis block if it has not already been written pub fn init_genesis(factory: &PF) -> Result where - PF: DatabaseProviderFactory - + StaticFileProviderFactory - + ChainSpecProvider - + BlockHashReader, + PF: DatabaseProviderFactory + StaticFileProviderFactory + ChainSpecProvider + BlockHashReader, PF::ProviderRW: StageCheckpointWriter + HistoryWriter + HeaderProvider @@ -294,13 +291,14 @@ where } /// Inserts header for the genesis state. -pub fn insert_genesis_header( +pub fn insert_genesis_header( provider: &Provider, static_file_provider: &StaticFileProvider, - chain: &ChainSpec, + chain: &Spec, ) -> ProviderResult<()> where Provider: DBProvider, + Spec: EthChainSpec, { let (header, block_hash) = (chain.genesis_header(), chain.genesis_hash()); diff --git a/crates/storage/provider/src/traits/full.rs b/crates/storage/provider/src/traits/full.rs index 1022184d68..4998e97416 100644 --- a/crates/storage/provider/src/traits/full.rs +++ b/crates/storage/provider/src/traits/full.rs @@ -6,7 +6,7 @@ use crate::{ StaticFileProviderFactory, TransactionsProvider, }; use reth_chain_state::{CanonStateSubscriptions, ForkChoiceSubscriptions}; -use reth_chainspec::ChainSpec; +use reth_chainspec::EthereumHardforks; use reth_node_types::NodeTypesWithDB; /// Helper trait to unify all provider traits for simplicity. @@ -51,7 +51,7 @@ impl FullProvider for T where pub trait FullRpcProvider: StateProviderFactory + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + BlockReaderIdExt + HeaderProvider + TransactionsProvider @@ -65,7 +65,7 @@ pub trait FullRpcProvider: impl FullRpcProvider for T where T: StateProviderFactory + EvmEnvProvider - + ChainSpecProvider + + ChainSpecProvider + BlockReaderIdExt + HeaderProvider + TransactionsProvider