diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index ade66d1d9a75..4d2e5d06c32c 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1,6 +1,5 @@ use crate::{ compression::{TRANSACTION_COMPRESSOR, TRANSACTION_DECOMPRESSOR}, - constants::eip4844::DATA_GAS_PER_BLOB, keccak256, Address, Bytes, TxHash, H256, }; pub use access_list::{AccessList, AccessListItem, AccessListWithGasUsed}; @@ -236,10 +235,10 @@ impl Transaction { /// Returns the blob gas used for all blobs of the EIP-4844 transaction if it is an EIP-4844 /// transaction. /// - /// This is the number of blobs times the [DATA_GAS_PER_BLOB] a single blob consumes. - pub fn blob_gas_used(&self) -> Option { - let tx = self.as_eip4844()?; - Some(tx.blob_versioned_hashes.len() as u128 * DATA_GAS_PER_BLOB as u128) + /// This is the number of blobs times the + /// [DATA_GAS_PER_BLOB](crate::constants::eip4844::DATA_GAS_PER_BLOB) a single blob consumes. + pub fn blob_gas_used(&self) -> Option { + self.as_eip4844().map(TxEip4844::blob_gas) } /// Return the max priority fee per gas if the transaction is an EIP-1559 transaction, and diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 49badfd050aa..71ec7c03a46f 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -629,6 +629,8 @@ pub trait PoolTransaction: /// /// For EIP-1559 transactions: `max_fee_per_gas * gas_limit + tx_value`. /// For legacy transactions: `gas_price * gas_limit + tx_value`. + /// For EIP-4844 blob transactions: `max_fee_per_gas * gas_limit + tx_value + + /// max_blob_fee_per_gas * blob_gas_used`. fn cost(&self) -> U256; /// Amount of gas that should be used in executing this transaction. This is paid up-front. @@ -721,6 +723,8 @@ pub struct EthPooledTransaction { /// For EIP-1559 transactions: `max_fee_per_gas * gas_limit + tx_value`. /// For legacy transactions: `gas_price * gas_limit + tx_value`. + /// For EIP-4844 blob transactions: `max_fee_per_gas * gas_limit + tx_value + + /// max_blob_fee_per_gas * blob_gas_used`. pub(crate) cost: U256, /// The blob side car this transaction @@ -754,7 +758,12 @@ impl EthPooledTransaction { U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit) } }; - let cost = gas_cost + U256::from(transaction.value()); + let mut cost = gas_cost + U256::from(transaction.value()); + + if let Some(blob_tx) = transaction.as_eip4844() { + // add max blob cost + cost += U256::from(blob_tx.max_fee_per_gas * blob_tx.blob_gas() as u128); + } Self { transaction, cost, blob_sidecar } } @@ -806,6 +815,8 @@ impl PoolTransaction for EthPooledTransaction { /// /// For EIP-1559 transactions: `max_fee_per_gas * gas_limit + tx_value`. /// For legacy transactions: `gas_price * gas_limit + tx_value`. + /// For EIP-4844 blob transactions: `max_fee_per_gas * gas_limit + tx_value + + /// max_blob_fee_per_gas * blob_gas_used`. fn cost(&self) -> U256 { self.cost }