Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<u64> {
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() {
Expand Down
10 changes: 6 additions & 4 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> 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) => {
Expand All @@ -208,7 +208,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> 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));
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> 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));
Expand Down Expand Up @@ -468,7 +468,9 @@ impl<DB: Db + ?Sized, V: TransactionValidator> 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);
}

Expand Down
12 changes: 9 additions & 3 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ use std::{
collections::BTreeMap,
fmt::Debug,
io::{Read, Write},
ops::Not,
ops::{Mul, Not},
path::PathBuf,
sync::Arc,
time::Duration,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
Loading