diff --git a/Cargo.lock b/Cargo.lock index 2ff1cc46db..b557d4b584 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6262,6 +6262,7 @@ dependencies = [ "reth-tokio-util", "reth-transaction-pool", "reth-trie", + "revm-primitives", "tokio", "tokio-stream", "tracing", @@ -6639,6 +6640,7 @@ dependencies = [ "reth-consensus", "reth-primitives", "reth-storage-api", + "revm-primitives", ] [[package]] @@ -7257,6 +7259,7 @@ dependencies = [ "reth-transaction-pool", "reth-trie", "revm", + "revm-primitives", "tracing", ] @@ -8111,6 +8114,7 @@ dependencies = [ "reth-transaction-pool", "reth-trie", "revm", + "revm-primitives", "sha2 0.10.8", "thiserror", "tracing", diff --git a/crates/consensus/auto-seal/Cargo.toml b/crates/consensus/auto-seal/Cargo.toml index 4e3e2db868..ca35937a47 100644 --- a/crates/consensus/auto-seal/Cargo.toml +++ b/crates/consensus/auto-seal/Cargo.toml @@ -33,6 +33,7 @@ reth-trie.workspace = true # ethereum alloy-primitives.workspace = true +revm-primitives.workspace = true # async futures-util.workspace = true diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index eb962a46fc..fea15f84d5 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -25,13 +25,14 @@ use reth_execution_errors::{ }; use reth_execution_types::ExecutionOutcome; use reth_primitives::{ - eip4844::calculate_excess_blob_gas, proofs, Block, BlockBody, BlockHashOrNumber, - BlockWithSenders, Header, Requests, SealedBlock, SealedHeader, TransactionSigned, Withdrawals, + proofs, Block, BlockBody, BlockHashOrNumber, BlockWithSenders, Header, Requests, SealedBlock, + SealedHeader, TransactionSigned, Withdrawals, }; use reth_provider::{BlockReaderIdExt, StateProviderFactory, StateRootProvider}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; use reth_trie::HashedPostState; +use revm_primitives::calc_excess_blob_gas; use std::{ collections::HashMap, fmt::Debug, @@ -326,11 +327,8 @@ impl StorageInner { _ => (0, 0), }; header.excess_blob_gas = Some( - calculate_excess_blob_gas( - parent_excess_blob_gas as u64, - parent_blob_gas_used as u64, - ) - .into(), + calc_excess_blob_gas(parent_excess_blob_gas as u64, parent_blob_gas_used as u64) + .into(), ) } diff --git a/crates/consensus/common/Cargo.toml b/crates/consensus/common/Cargo.toml index 0c622245f3..c9fea9789b 100644 --- a/crates/consensus/common/Cargo.toml +++ b/crates/consensus/common/Cargo.toml @@ -18,6 +18,7 @@ reth-consensus.workspace = true # ethereum alloy-primitives.workspace = true +revm-primitives.workspace = true [dev-dependencies] reth-storage-api.workspace = true diff --git a/crates/consensus/common/src/validation.rs b/crates/consensus/common/src/validation.rs index 646ab7b473..66a953a508 100644 --- a/crates/consensus/common/src/validation.rs +++ b/crates/consensus/common/src/validation.rs @@ -7,9 +7,9 @@ use reth_primitives::{ eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK}, MAXIMUM_EXTRA_DATA_SIZE, }, - eip4844::calculate_excess_blob_gas, EthereumHardfork, GotExpected, Header, SealedBlock, SealedHeader, }; +use revm_primitives::calc_excess_blob_gas; /// Gas used needs to be less than gas limit. Gas used is going to be checked after execution. #[inline] @@ -166,7 +166,7 @@ pub fn validate_4844_header_standalone(header: &Header) -> Result<(), ConsensusE } // `excess_blob_gas` must also be a multiple of `DATA_GAS_PER_BLOB`. This will be checked later - // (via `calculate_excess_blob_gas`), but it doesn't hurt to catch the problem sooner. + // (via `calc_excess_blob_gas`), but it doesn't hurt to catch the problem sooner. if excess_blob_gas as u64 % DATA_GAS_PER_BLOB != 0 { return Err(ConsensusError::ExcessBlobGasNotMultipleOfBlobGasPerBlob { excess_blob_gas: excess_blob_gas as u64, @@ -276,7 +276,7 @@ pub fn validate_against_parent_4844( // > For the first post-fork block, both parent.blob_gas_used and parent.excess_blob_gas // > are evaluated as 0. // - // This means in the first post-fork block, calculate_excess_blob_gas will return 0. + // This means in the first post-fork block, calc_excess_blob_gas will return 0. let parent_blob_gas_used = parent.blob_gas_used.unwrap_or(0) as u64; let parent_excess_blob_gas = parent.excess_blob_gas.unwrap_or(0) as u64; @@ -287,7 +287,7 @@ pub fn validate_against_parent_4844( header.excess_blob_gas.ok_or(ConsensusError::ExcessBlobGasMissing)? as u64; let expected_excess_blob_gas = - calculate_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used); + calc_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used); if expected_excess_blob_gas != excess_blob_gas { return Err(ConsensusError::ExcessBlobGasDiff { diff: GotExpected { got: excess_blob_gas, expected: expected_excess_blob_gas }, diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 5c775ce7c8..8b7b2c0362 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -9,9 +9,7 @@ use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResu use reth_ethereum_forks::EthereumHardforks; use reth_evm::{system_calls::apply_beacon_root_contract_call, ConfigureEvm}; use reth_payload_validator::ExecutionPayloadValidator; -use reth_primitives::{ - eip4844::calculate_excess_blob_gas, proofs, Block, BlockBody, Header, Receipt, Receipts, -}; +use reth_primitives::{proofs, Block, BlockBody, Header, Receipt, Receipts}; use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory}; use reth_revm::{ database::StateProviderDatabase, @@ -25,7 +23,9 @@ use reth_rpc_types::{ }; use reth_rpc_types_compat::engine::payload::block_to_payload; use reth_trie::HashedPostState; -use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg}; +use revm_primitives::{ + calc_excess_blob_gas, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, +}; use std::{ collections::VecDeque, future::Future, @@ -371,7 +371,7 @@ where if chain_spec.is_cancun_active_at_timestamp(reorg_target.timestamp) { ( Some(sum_blob_gas_used), - Some(calculate_excess_blob_gas( + Some(calc_excess_blob_gas( reorg_target_parent.excess_blob_gas.unwrap_or_default() as u64, reorg_target_parent.blob_gas_used.unwrap_or_default() as u64, )), diff --git a/crates/ethereum/payload/Cargo.toml b/crates/ethereum/payload/Cargo.toml index 5438902b4d..f169d58f7e 100644 --- a/crates/ethereum/payload/Cargo.toml +++ b/crates/ethereum/payload/Cargo.toml @@ -30,6 +30,7 @@ reth-chainspec.workspace = true # ethereum revm.workspace = true +revm-primitives.workspace = true # alloy alloy-primitives.workspace = true diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index fcaa6cd593..ecce558f1a 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -31,7 +31,6 @@ use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes}; use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError}; use reth_primitives::{ constants::{eip4844::MAX_DATA_GAS_PER_BLOCK, BEACON_NONCE}, - eip4844::calculate_excess_blob_gas, proofs::{self, calculate_requests_root}, revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg}, Block, BlockBody, EthereumHardforks, Header, IntoRecoveredTransaction, Receipt, @@ -48,6 +47,7 @@ use revm::{ primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState}, DatabaseCommit, State, }; +use revm_primitives::calc_excess_blob_gas; use std::sync::Arc; use tracing::{debug, trace, warn}; @@ -391,14 +391,11 @@ where excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_block.timestamp) { let parent_excess_blob_gas = parent_block.excess_blob_gas.unwrap_or_default(); let parent_blob_gas_used = parent_block.blob_gas_used.unwrap_or_default(); - Some(calculate_excess_blob_gas( - parent_excess_blob_gas as u64, - parent_blob_gas_used as u64, - )) + Some(calc_excess_blob_gas(parent_excess_blob_gas as u64, parent_blob_gas_used as u64)) } else { // for the first post-fork block, both parent.blob_gas_used and // parent.excess_blob_gas are evaluated as 0 - Some(calculate_excess_blob_gas(0, 0)) + Some(calc_excess_blob_gas(0, 0)) }; blob_gas_used = Some(sum_blob_gas_used); diff --git a/crates/optimism/payload/Cargo.toml b/crates/optimism/payload/Cargo.toml index 7d2e320b52..8fba06f228 100644 --- a/crates/optimism/payload/Cargo.toml +++ b/crates/optimism/payload/Cargo.toml @@ -37,6 +37,7 @@ revm.workspace = true alloy-primitives.workspace = true alloy-rlp.workspace = true op-alloy-rpc-types-engine.workspace = true +revm-primitives.workspace = true # misc tracing.workspace = true diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 59f1e38d3a..5e443a4f5a 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -15,7 +15,6 @@ use reth_optimism_forks::OptimismHardfork; use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError}; use reth_primitives::{ constants::BEACON_NONCE, - eip4844::calculate_excess_blob_gas, proofs, revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg}, Block, BlockBody, Header, IntoRecoveredTransaction, Receipt, TxType, EMPTY_OMMER_ROOT_HASH, @@ -31,6 +30,7 @@ use revm::{ primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState}, DatabaseCommit, State, }; +use revm_primitives::calc_excess_blob_gas; use tracing::{debug, trace, warn}; use crate::{ @@ -477,14 +477,11 @@ where excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_block.timestamp) { let parent_excess_blob_gas = parent_block.excess_blob_gas.unwrap_or_default(); let parent_blob_gas_used = parent_block.blob_gas_used.unwrap_or_default(); - Some(calculate_excess_blob_gas( - parent_excess_blob_gas as u64, - parent_blob_gas_used as u64, - )) + Some(calc_excess_blob_gas(parent_excess_blob_gas as u64, parent_blob_gas_used as u64)) } else { // for the first post-fork block, both parent.blob_gas_used and // parent.excess_blob_gas are evaluated as 0 - Some(calculate_excess_blob_gas(0, 0)) + Some(calc_excess_blob_gas(0, 0)) }; blob_gas_used = Some(0); diff --git a/crates/primitives/src/eip4844.rs b/crates/primitives/src/eip4844.rs deleted file mode 100644 index 9c0054ac95..0000000000 --- a/crates/primitives/src/eip4844.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Helpers for working with EIP-4844 blob fee. - -// re-exports from revm for calculating blob fee -pub use crate::revm_primitives::{ - calc_blob_gasprice, calc_excess_blob_gas as calculate_excess_blob_gas, -}; diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 4996cff67f..5a17347a84 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -27,7 +27,6 @@ mod block; #[cfg(feature = "reth-codec")] mod compression; pub mod constants; -pub mod eip4844; pub mod proofs; mod receipt; pub use reth_static_file_types as static_file; diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index c5afa2013a..3f6f3ee74b 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -16,11 +16,9 @@ use futures::{ use metrics::atomics::AtomicU64; use reth_chain_state::CanonStateNotification; use reth_chainspec::{ChainSpecProvider, EthChainSpec}; -use reth_primitives::{ - eip4844::{calc_blob_gasprice, calculate_excess_blob_gas}, - Receipt, SealedBlock, TransactionSigned, -}; +use reth_primitives::{Receipt, SealedBlock, TransactionSigned}; use reth_storage_api::BlockReaderIdExt; +use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas}; use serde::{Deserialize, Serialize}; use tracing::trace; @@ -399,6 +397,6 @@ impl FeeHistoryEntry { /// /// Returns a `None` if no excess blob gas is set, no EIP-4844 support pub fn next_block_excess_blob_gas(&self) -> Option { - Some(calculate_excess_blob_gas(self.excess_blob_gas?, self.blob_gas_used?)) + Some(calc_excess_blob_gas(self.excess_blob_gas?, self.blob_gas_used?)) } }