diff --git a/crates/block-processor/src/lib.rs b/crates/block-processor/src/lib.rs index 87341a2..d836442 100644 --- a/crates/block-processor/src/lib.rs +++ b/crates/block-processor/src/lib.rs @@ -16,6 +16,9 @@ pub(crate) mod metrics; mod alias; pub use alias::{AliasOracle, AliasOracleFactory}; +mod utils; +pub use utils::revm_spec; + mod v1; pub use v1::SignetBlockProcessor as SignetBlockProcessorV1; diff --git a/crates/block-processor/src/utils.rs b/crates/block-processor/src/utils.rs new file mode 100644 index 0000000..4341433 --- /dev/null +++ b/crates/block-processor/src/utils.rs @@ -0,0 +1,37 @@ +use reth::revm::primitives::hardfork::SpecId; +use reth_chainspec::EthereumHardforks; + +/// Equivalent to [`reth_evm_ethereum::revm_spec`], however, always starts at +/// [`SpecId::PRAGUE`] and transitions to [`SpecId::OSAKA`]. +pub fn revm_spec(chain_spec: &reth::chainspec::ChainSpec, timestamp: u64) -> SpecId { + if chain_spec.is_osaka_active_at_timestamp(timestamp) { SpecId::OSAKA } else { SpecId::PRAGUE } +} + +/// This is simply a compile-time assertion to ensure that all SpecIds are +/// covered in the match. When this fails to compile, it indicates that a new +/// hardfork has been added and [`revm_spec`] needs to be updated. +#[allow(dead_code)] +const fn assert_in_range(spec_id: SpecId) { + match spec_id { + SpecId::FRONTIER + | SpecId::FRONTIER_THAWING + | SpecId::HOMESTEAD + | SpecId::DAO_FORK + | SpecId::TANGERINE + | SpecId::SPURIOUS_DRAGON + | SpecId::BYZANTIUM + | SpecId::CONSTANTINOPLE + | SpecId::PETERSBURG + | SpecId::ISTANBUL + | SpecId::MUIR_GLACIER + | SpecId::BERLIN + | SpecId::LONDON + | SpecId::ARROW_GLACIER + | SpecId::GRAY_GLACIER + | SpecId::MERGE + | SpecId::SHANGHAI + | SpecId::CANCUN + | SpecId::PRAGUE + | SpecId::OSAKA => {} + } +} diff --git a/crates/block-processor/src/v1/processor.rs b/crates/block-processor/src/v1/processor.rs index fd5aa30..66ada78 100644 --- a/crates/block-processor/src/v1/processor.rs +++ b/crates/block-processor/src/v1/processor.rs @@ -14,7 +14,7 @@ use reth::{ }, revm::{database::StateProviderDatabase, db::StateBuilder}, }; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::ChainSpec; use reth_node_api::{FullNodeComponents, NodeTypes}; use signet_blobber::{CacheHandle, ExtractableChainShim}; use signet_constants::SignetSystemConstants; @@ -80,11 +80,7 @@ where /// Get the active spec id at the given timestamp. fn spec_id(&self, timestamp: u64) -> SpecId { - if self.chain_spec.is_prague_active_at_timestamp(timestamp) { - SpecId::PRAGUE - } else { - SpecId::CANCUN - } + crate::revm_spec(&self.chain_spec, timestamp) } /// Make a [`StateProviderDatabase`] from the read-write provider, suitable diff --git a/crates/node-config/Cargo.toml b/crates/node-config/Cargo.toml index 0842f4b..5774f5e 100644 --- a/crates/node-config/Cargo.toml +++ b/crates/node-config/Cargo.toml @@ -28,6 +28,7 @@ serde.workspace = true tracing.workspace = true trevm.workspace = true signet-genesis.workspace = true +signet-block-processor.workspace = true [features] test_utils = ["dep:reth-db", "reth-db/test-utils"] diff --git a/crates/node-config/src/core.rs b/crates/node-config/src/core.rs index d0f5aa2..3954aac 100644 --- a/crates/node-config/src/core.rs +++ b/crates/node-config/src/core.rs @@ -1,7 +1,7 @@ use alloy::genesis::Genesis; use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv}; use reth::providers::providers::StaticFileProvider; -use reth_chainspec::{ChainSpec, EthereumHardforks}; +use reth_chainspec::ChainSpec; use reth_node_api::NodePrimitives; use signet_blobber::BlobFetcherConfig; use signet_genesis::GenesisSpec; @@ -215,11 +215,7 @@ impl SignetNodeConfig { /// Get the current spec id for the Signet Node chain. pub fn spec_id(&self, timestamp: u64) -> SpecId { - if self.chain_spec().is_prague_active_at_timestamp(timestamp) { - SpecId::PRAGUE - } else { - SpecId::CANCUN - } + signet_block_processor::revm_spec(self.chain_spec(), timestamp) } } diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index c579fa0..6594a41 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -27,7 +27,6 @@ reth.workspace = true reth-chainspec.workspace = true reth-db.workspace = true reth-db-common.workspace = true -reth-evm-ethereum.workspace = true reth-node-api.workspace = true reth-rpc-eth-api.workspace = true @@ -45,6 +44,7 @@ tracing.workspace = true serde_json.workspace = true futures-util = "0.3.31" itertools.workspace = true +signet-block-processor.workspace = true [dev-dependencies] signet-zenith.workspace = true diff --git a/crates/rpc/src/ctx/signet.rs b/crates/rpc/src/ctx/signet.rs index 1a06e91..113f1af 100644 --- a/crates/rpc/src/ctx/signet.rs +++ b/crates/rpc/src/ctx/signet.rs @@ -173,7 +173,7 @@ where /// Get the EVM spec ID for a given block. pub fn evm_spec_id(&self, header: &Header) -> SpecId { - reth_evm_ethereum::revm_spec(&self.chain_spec(), header) + signet_block_processor::revm_spec(&self.chain_spec(), header.timestamp()) } /// Access the subscription manager.