diff --git a/crates/anvil/core/src/eth/transaction/mod.rs b/crates/anvil/core/src/eth/transaction/mod.rs index 2692c96815e36..7a55baa783a3f 100644 --- a/crates/anvil/core/src/eth/transaction/mod.rs +++ b/crates/anvil/core/src/eth/transaction/mod.rs @@ -27,7 +27,7 @@ use op_alloy_consensus::{ use op_revm::{OpTransaction, transaction::deposit::DepositTransactionParts}; use revm::{context::TxEnv, interpreter::InstructionResult}; use serde::{Deserialize, Serialize}; -use std::ops::{Deref, Mul}; +use std::ops::Deref; /// Converts a [TransactionRequest] into a [TypedTransactionRequest]. /// Should be removed once the call builder abstraction for providers is in place. @@ -456,32 +456,6 @@ impl TypedTransaction { } } - /// Max cost of the transaction - /// It is the gas limit multiplied by the gas price, - /// and if the transaction is EIP-4844, the result of (total blob gas cost * max fee per blob - /// gas) is also added - pub fn max_cost(&self) -> u128 { - let mut max_cost = (self.gas_limit() as u128).saturating_mul(self.max_fee_per_gas()); - - if self.is_eip4844() { - max_cost = max_cost.saturating_add( - self.blob_gas() - .map(|g| g as u128) - .unwrap_or(0) - .mul(self.max_fee_per_blob_gas().unwrap_or(0)), - ) - } - - max_cost - } - - pub fn blob_gas(&self) -> Option { - match self { - Self::EIP4844(tx) => Some(tx.tx().tx().blob_gas()), - _ => None, - } - } - pub fn sidecar(&self) -> Option<&TxEip4844WithSidecar> { match self { Self::EIP4844(signed_variant) => match signed_variant.tx() { diff --git a/crates/anvil/src/eth/backend/executor.rs b/crates/anvil/src/eth/backend/executor.rs index f986c83fa4ed8..cf5b4b2f93591 100644 --- a/crates/anvil/src/eth/backend/executor.rs +++ b/crates/anvil/src/eth/backend/executor.rs @@ -183,7 +183,7 @@ impl TransactionExecutor<'_, DB, V> { continue; } TransactionExecutionOutcome::BlobGasExhausted(tx) => { - trace!(target: "backend", blob_gas = %tx.pending_transaction.transaction.blob_gas().unwrap_or_default(), ?tx, "block blob gas limit exhausting, skipping transaction"); + trace!(target: "backend", blob_gas = %tx.pending_transaction.transaction.blob_gas_used().unwrap_or_default(), ?tx, "block blob gas limit exhausting, skipping transaction"); continue; } TransactionExecutionOutcome::TransactionGasExhausted(tx) => { @@ -208,7 +208,7 @@ impl TransactionExecutor<'_, DB, V> { .pending_transaction .transaction .transaction - .blob_gas() + .blob_gas_used() .unwrap_or(0); cumulative_blob_gas_used = Some(cumulative_blob_gas_used.unwrap_or(0u64).saturating_add(tx_blob_gas)); @@ -365,7 +365,7 @@ impl Iterator for &mut TransactionExec // check that we comply with the block's blob gas limit let max_blob_gas = self.blob_gas_used.saturating_add( - transaction.pending_transaction.transaction.transaction.blob_gas().unwrap_or(0), + transaction.pending_transaction.transaction.transaction.blob_gas_used().unwrap_or(0), ); if max_blob_gas > self.blob_params.max_blob_gas_per_block() { return Some(TransactionExecutionOutcome::BlobGasExhausted(transaction)); @@ -468,7 +468,9 @@ impl Iterator for &mut TransactionExec self.gas_used = self.gas_used.saturating_add(gas_used); // Track the total blob gas used for total blob gas per blob checks - if let Some(blob_gas) = transaction.pending_transaction.transaction.transaction.blob_gas() { + if let Some(blob_gas) = + transaction.pending_transaction.transaction.transaction.blob_gas_used() + { self.blob_gas_used = self.blob_gas_used.saturating_add(blob_gas); } diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index a86f1b00c5b7a..a63582960c5d0 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -131,7 +131,7 @@ use std::{ collections::BTreeMap, fmt::Debug, io::{Read, Write}, - ops::Not, + ops::{Mul, Not}, path::PathBuf, sync::Arc, time::Duration, @@ -3118,7 +3118,7 @@ impl Backend { let excess_blob_gas = block.header.excess_blob_gas; let blob_gas_price = alloy_eips::eip4844::calc_blob_gasprice(excess_blob_gas.unwrap_or_default()); - let blob_gas_used = transaction.blob_gas(); + let blob_gas_used = transaction.blob_gas_used(); let effective_gas_price = match transaction.transaction { TypedTransaction::Legacy(t) => t.tx().gas_price, @@ -3775,7 +3775,13 @@ impl TransactionValidator for Backend { )); } - let max_cost = tx.max_cost(); + let max_cost = + (tx.gas_limit() as u128).saturating_mul(tx.max_fee_per_gas()).saturating_add( + tx.blob_gas_used() + .map(|g| g as u128) + .unwrap_or(0) + .mul(tx.max_fee_per_blob_gas().unwrap_or(0)), + ); let value = tx.value(); match &tx.transaction { TypedTransaction::Deposit(deposit_tx) => {