diff --git a/Cargo.lock b/Cargo.lock index e532b8c0d..7c515f03f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7247,6 +7247,7 @@ dependencies = [ "futures", "itertools 0.13.0", "pin-project", + "reth-chainspec", "reth-consensus-common", "reth-engine-primitives", "reth-errors", diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 7bf509d80..cbe3a5444 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -411,17 +411,6 @@ impl ChainSpec { } } - /// Get the [`BlobParams`] for the given timestamp. - /// - /// Note: This always return [`BlobParams::cancun`] pre prague. - pub fn blob_fee_params_at_timestamp(&self, timestamp: u64) -> BlobParams { - if self.is_prague_active_at_timestamp(timestamp) { - self.blob_params.prague - } else { - self.blob_params.cancun - } - } - /// Get the hash of the genesis block. pub fn genesis_hash(&self) -> B256 { *self.genesis_hash.get_or_init(|| self.genesis_header().hash_slow()) diff --git a/crates/engine/util/Cargo.toml b/crates/engine/util/Cargo.toml index 5573c74b3..119d663ee 100644 --- a/crates/engine/util/Cargo.toml +++ b/crates/engine/util/Cargo.toml @@ -15,6 +15,7 @@ workspace = true reth-primitives.workspace = true reth-primitives-traits.workspace = true reth-errors.workspace = true +reth-chainspec.workspace = true reth-consensus-common.workspace = true reth-fs-util.workspace = true reth-rpc-types-compat.workspace = true diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 64b29958f..c4423ced8 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -1,12 +1,12 @@ //! Stream wrapper that simulates reorgs. use alloy_consensus::{Header, Transaction}; -use alloy_eips::eip7840::BlobParams; use alloy_rpc_types_engine::{ CancunPayloadFields, ExecutionPayload, ExecutionPayloadSidecar, ForkchoiceState, PayloadStatus, }; use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt}; use itertools::Either; +use reth_chainspec::EthChainSpec; use reth_engine_primitives::{ BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes, OnForkChoiceUpdated, }; @@ -109,7 +109,7 @@ where Engine: EngineTypes, Provider: BlockReader + StateProviderFactory, Evm: ConfigureEvm
, - Spec: EthereumHardforks, + Spec: EthChainSpec + EthereumHardforks, { type Item = S::Item; @@ -256,7 +256,7 @@ fn create_reorg_head( where Provider: BlockReader + StateProviderFactory, Evm: ConfigureEvm
, - Spec: EthereumHardforks, + Spec: EthChainSpec + EthereumHardforks, { let chain_spec = payload_validator.chain_spec(); @@ -380,11 +380,8 @@ where let hashed_state = state_provider.hashed_post_state(outcome.state()); let (blob_gas_used, excess_blob_gas) = - if chain_spec.is_cancun_active_at_timestamp(reorg_target.timestamp) { - ( - Some(sum_blob_gas_used), - reorg_target_parent.next_block_excess_blob_gas(BlobParams::cancun()), - ) + if let Some(blob_params) = chain_spec.blob_params_at_timestamp(reorg_target.timestamp) { + (Some(sum_blob_gas_used), reorg_target_parent.next_block_excess_blob_gas(blob_params)) } else { (None, None) }; diff --git a/crates/ethereum/consensus/src/lib.rs b/crates/ethereum/consensus/src/lib.rs index 24f81c0fc..904185c9c 100644 --- a/crates/ethereum/consensus/src/lib.rs +++ b/crates/ethereum/consensus/src/lib.rs @@ -9,7 +9,7 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use alloy_consensus::EMPTY_OMMER_ROOT_HASH; -use alloy_eips::{eip7840::BlobParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS}; +use alloy_eips::merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS; use alloy_primitives::U256; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_consensus::{ @@ -192,13 +192,7 @@ where )?; // ensure that the blob gas fields for this block - if self.chain_spec.is_cancun_active_at_timestamp(header.timestamp()) { - let blob_params = if self.chain_spec.is_prague_active_at_timestamp(header.timestamp()) { - BlobParams::prague() - } else { - BlobParams::cancun() - }; - + if let Some(blob_params) = self.chain_spec.blob_params_at_timestamp(header.timestamp()) { validate_against_parent_4844(header.header(), parent.header(), blob_params)?; } diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index c16e747d2..ac2fea59e 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -21,7 +21,7 @@ use alloc::{sync::Arc, vec::Vec}; use alloy_consensus::{BlockHeader, Header}; use alloy_primitives::{Address, U256}; use core::{convert::Infallible, fmt::Debug}; -use reth_chainspec::ChainSpec; +use reth_chainspec::{ChainSpec, EthChainSpec}; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, Database, Evm, NextBlockEnvAttributes}; use reth_primitives::TransactionSigned; use reth_primitives_traits::transaction::execute::FillTxEnv; @@ -32,7 +32,7 @@ use revm_primitives::{ }; mod config; -use alloy_eips::{eip1559::INITIAL_BASE_FEE, eip7840::BlobParams}; +use alloy_eips::eip1559::INITIAL_BASE_FEE; pub use config::{revm_spec, revm_spec_by_timestamp_and_block_number}; use reth_ethereum_forks::EthereumHardfork; @@ -188,13 +188,12 @@ impl ConfigureEvmEnv for EthEvmConfig { parent.number() + 1, ); - let blob_params = - if spec_id >= SpecId::PRAGUE { BlobParams::prague() } else { BlobParams::cancun() }; - // if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is // cancun now, we need to set the excess blob gas to the default value(0) let blob_excess_gas_and_price = parent - .next_block_excess_blob_gas(blob_params) + .maybe_next_block_excess_blob_gas( + self.chain_spec.blob_params_at_timestamp(attributes.timestamp), + ) .or_else(|| (spec_id == SpecId::CANCUN).then_some(0)) .map(|gas| BlobExcessGasAndPrice::new(gas, spec_id >= SpecId::PRAGUE)); diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 9bc89561a..814e06651 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -9,17 +9,16 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![allow(clippy::useless_let_if_seq)] -use alloy_consensus::{Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH}; +use alloy_consensus::{BlockHeader, Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH}; use alloy_eips::{ - eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, eip7840::BlobParams, - merge::BEACON_NONCE, + eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, merge::BEACON_NONCE, }; use alloy_primitives::U256; use reth_basic_payload_builder::{ commit_withdrawals, is_better_payload, BuildArguments, BuildOutcome, PayloadBuilder, PayloadConfig, }; -use reth_chainspec::{ChainSpec, ChainSpecProvider}; +use reth_chainspec::{ChainSpec, ChainSpecProvider, EthChainSpec}; use reth_errors::RethError; use reth_evm::{ env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, Evm, EvmError, InvalidTxError, @@ -419,13 +418,9 @@ where .map_err(PayloadBuilderError::other)?; excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_header.timestamp) { - let blob_params = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) { - BlobParams::prague() - } else { - // cancun - BlobParams::cancun() - }; - parent_header.next_block_excess_blob_gas(blob_params) + parent_header.maybe_next_block_excess_blob_gas( + chain_spec.blob_params_at_timestamp(attributes.timestamp), + ) } else { // for the first post-fork block, both parent.blob_gas_used and // parent.excess_blob_gas are evaluated as 0 diff --git a/crates/optimism/consensus/src/lib.rs b/crates/optimism/consensus/src/lib.rs index 5d2e002d2..93d7576fe 100644 --- a/crates/optimism/consensus/src/lib.rs +++ b/crates/optimism/consensus/src/lib.rs @@ -14,9 +14,8 @@ extern crate alloc; use alloc::sync::Arc; use alloy_consensus::{BlockHeader as _, EMPTY_OMMER_ROOT_HASH}; -use alloy_eips::eip7840::BlobParams; use alloy_primitives::{B64, U256}; -use reth_chainspec::EthereumHardforks; +use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_consensus::{ Consensus, ConsensusError, FullConsensus, HeaderValidator, PostExecutionInput, }; @@ -149,8 +148,8 @@ impl HeaderValidator for OpBeaconConsensus { } // ensure that the blob gas fields for this block - if self.chain_spec.is_cancun_active_at_timestamp(header.timestamp()) { - validate_against_parent_4844(header.header(), parent.header(), BlobParams::cancun())?; + if let Some(blob_params) = self.chain_spec.blob_params_at_timestamp(header.timestamp()) { + validate_against_parent_4844(header.header(), parent.header(), blob_params)?; } Ok(()) diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index 1270c2578..7961b1392 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -14,10 +14,10 @@ extern crate alloc; use alloc::sync::Arc; use alloy_consensus::{BlockHeader, Header}; -use alloy_eips::eip7840::BlobParams; use alloy_primitives::{Address, U256}; use core::fmt::Debug; use op_alloy_consensus::EIP1559ParamError; +use reth_chainspec::EthChainSpec; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, Database, Evm, NextBlockEnvAttributes}; use reth_optimism_chainspec::OpChainSpec; use reth_optimism_primitives::OpTransactionSigned; @@ -194,7 +194,9 @@ impl ConfigureEvmEnv for OpEvmConfig { // if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is // cancun now, we need to set the excess blob gas to the default value(0) let blob_excess_gas_and_price = parent - .next_block_excess_blob_gas(BlobParams::cancun()) + .maybe_next_block_excess_blob_gas( + self.chain_spec().blob_params_at_timestamp(attributes.timestamp), + ) .or_else(|| (spec_id.is_enabled_in(SpecId::CANCUN)).then_some(0)) .map(|gas| BlobExcessGasAndPrice::new(gas, false)); diff --git a/crates/rpc/rpc-eth-api/src/helpers/fee.rs b/crates/rpc/rpc-eth-api/src/helpers/fee.rs index 30b414859..e015364ce 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/fee.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/fee.rs @@ -165,7 +165,13 @@ pub trait EthFees: LoadFee { for header in &headers { base_fee_per_gas.push(header.base_fee_per_gas().unwrap_or_default() as u128); gas_used_ratio.push(header.gas_used() as f64 / header.gas_limit() as f64); - base_fee_per_blob_gas.push(header.blob_fee(BlobParams::cancun()).unwrap_or_default()); + + let blob_params = self.provider() + .chain_spec() + .blob_params_at_timestamp(header.timestamp()) + .unwrap_or_else(BlobParams::cancun); + + base_fee_per_blob_gas.push(header.blob_fee(blob_params).unwrap_or_default()); blob_gas_used_ratio.push( header.blob_gas_used().unwrap_or_default() as f64 / alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK as f64, @@ -206,7 +212,12 @@ pub trait EthFees: LoadFee { // Same goes for the `base_fee_per_blob_gas`: // > "[..] includes the next block after the newest of the returned range, because this value can be derived from the newest block. - base_fee_per_blob_gas.push(last_header.next_block_blob_fee(BlobParams::cancun()).unwrap_or_default()); + base_fee_per_blob_gas.push( + last_header + .maybe_next_block_blob_fee( + self.provider().chain_spec().blob_params_at_timestamp(last_header.timestamp()) + ).unwrap_or_default() + ); }; Ok(FeeHistory { @@ -331,7 +342,11 @@ pub trait LoadFee: LoadBlock { async move { self.block_with_senders(BlockNumberOrTag::Latest.into()) .await? - .and_then(|h| h.next_block_blob_fee(BlobParams::cancun())) + .and_then(|h| { + h.maybe_next_block_blob_fee( + self.provider().chain_spec().blob_params_at_timestamp(h.timestamp()), + ) + }) .ok_or(EthApiError::ExcessBlobGasNotSet.into()) .map(U256::from) } diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 7e968ce19..b61033302 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -8,7 +8,7 @@ use crate::{ BlockInfo, PoolTransaction, PoolUpdateKind, }; use alloy_consensus::{BlockHeader, Typed2718}; -use alloy_eips::{eip7840::BlobParams, BlockNumberOrTag}; +use alloy_eips::BlockNumberOrTag; use alloy_primitives::{Address, BlockHash, BlockNumber}; use alloy_rlp::Encodable; use futures_util::{ @@ -119,7 +119,9 @@ pub async fn maintain_transaction_pool( chain_spec.base_fee_params_at_timestamp(latest.timestamp() + 12), ) .unwrap_or_default(), - pending_blob_fee: latest.next_block_blob_fee(BlobParams::cancun()), + pending_blob_fee: latest.maybe_next_block_blob_fee( + chain_spec.blob_params_at_timestamp(latest.timestamp() + 12), + ), }; pool.set_block_info(info); } @@ -277,8 +279,9 @@ pub async fn maintain_transaction_pool( chain_spec.base_fee_params_at_timestamp(new_tip.timestamp() + 12), ) .unwrap_or_default(); - let pending_block_blob_fee = - new_tip.header().next_block_blob_fee(BlobParams::cancun()); + let pending_block_blob_fee = new_tip.header().maybe_next_block_blob_fee( + chain_spec.blob_params_at_timestamp(new_tip.timestamp() + 12), + ); // we know all changed account in the new chain let new_changed_accounts: HashSet<_> = @@ -382,7 +385,9 @@ pub async fn maintain_transaction_pool( chain_spec.base_fee_params_at_timestamp(tip.timestamp() + 12), ) .unwrap_or_default(); - let pending_block_blob_fee = tip.header().next_block_blob_fee(BlobParams::cancun()); + let pending_block_blob_fee = tip.header().maybe_next_block_blob_fee( + chain_spec.blob_params_at_timestamp(tip.timestamp() + 12), + ); let first_block = blocks.first(); trace!(