Skip to content

Commit 9b22631

Browse files
authored
refactor(anvil): remove TypedTransaction::blob_gas() method (#12632)
* refactor(anvil): remove `TypedTransaction::blob_gas()` method * refactor(anvil): remove `TypedTransaction::max_cost()` method
1 parent 91cc693 commit 9b22631

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

crates/anvil/core/src/eth/transaction/mod.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use op_alloy_consensus::{
2727
use op_revm::{OpTransaction, transaction::deposit::DepositTransactionParts};
2828
use revm::{context::TxEnv, interpreter::InstructionResult};
2929
use serde::{Deserialize, Serialize};
30-
use std::ops::{Deref, Mul};
30+
use std::ops::Deref;
3131

3232
/// Converts a [TransactionRequest] into a [TypedTransactionRequest].
3333
/// Should be removed once the call builder abstraction for providers is in place.
@@ -456,32 +456,6 @@ impl TypedTransaction {
456456
}
457457
}
458458

459-
/// Max cost of the transaction
460-
/// It is the gas limit multiplied by the gas price,
461-
/// and if the transaction is EIP-4844, the result of (total blob gas cost * max fee per blob
462-
/// gas) is also added
463-
pub fn max_cost(&self) -> u128 {
464-
let mut max_cost = (self.gas_limit() as u128).saturating_mul(self.max_fee_per_gas());
465-
466-
if self.is_eip4844() {
467-
max_cost = max_cost.saturating_add(
468-
self.blob_gas()
469-
.map(|g| g as u128)
470-
.unwrap_or(0)
471-
.mul(self.max_fee_per_blob_gas().unwrap_or(0)),
472-
)
473-
}
474-
475-
max_cost
476-
}
477-
478-
pub fn blob_gas(&self) -> Option<u64> {
479-
match self {
480-
Self::EIP4844(tx) => Some(tx.tx().tx().blob_gas()),
481-
_ => None,
482-
}
483-
}
484-
485459
pub fn sidecar(&self) -> Option<&TxEip4844WithSidecar> {
486460
match self {
487461
Self::EIP4844(signed_variant) => match signed_variant.tx() {

crates/anvil/src/eth/backend/executor.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> TransactionExecutor<'_, DB, V> {
183183
continue;
184184
}
185185
TransactionExecutionOutcome::BlobGasExhausted(tx) => {
186-
trace!(target: "backend", blob_gas = %tx.pending_transaction.transaction.blob_gas().unwrap_or_default(), ?tx, "block blob gas limit exhausting, skipping transaction");
186+
trace!(target: "backend", blob_gas = %tx.pending_transaction.transaction.blob_gas_used().unwrap_or_default(), ?tx, "block blob gas limit exhausting, skipping transaction");
187187
continue;
188188
}
189189
TransactionExecutionOutcome::TransactionGasExhausted(tx) => {
@@ -208,7 +208,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> TransactionExecutor<'_, DB, V> {
208208
.pending_transaction
209209
.transaction
210210
.transaction
211-
.blob_gas()
211+
.blob_gas_used()
212212
.unwrap_or(0);
213213
cumulative_blob_gas_used =
214214
Some(cumulative_blob_gas_used.unwrap_or(0u64).saturating_add(tx_blob_gas));
@@ -365,7 +365,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> Iterator for &mut TransactionExec
365365

366366
// check that we comply with the block's blob gas limit
367367
let max_blob_gas = self.blob_gas_used.saturating_add(
368-
transaction.pending_transaction.transaction.transaction.blob_gas().unwrap_or(0),
368+
transaction.pending_transaction.transaction.transaction.blob_gas_used().unwrap_or(0),
369369
);
370370
if max_blob_gas > self.blob_params.max_blob_gas_per_block() {
371371
return Some(TransactionExecutionOutcome::BlobGasExhausted(transaction));
@@ -468,7 +468,9 @@ impl<DB: Db + ?Sized, V: TransactionValidator> Iterator for &mut TransactionExec
468468
self.gas_used = self.gas_used.saturating_add(gas_used);
469469

470470
// Track the total blob gas used for total blob gas per blob checks
471-
if let Some(blob_gas) = transaction.pending_transaction.transaction.transaction.blob_gas() {
471+
if let Some(blob_gas) =
472+
transaction.pending_transaction.transaction.transaction.blob_gas_used()
473+
{
472474
self.blob_gas_used = self.blob_gas_used.saturating_add(blob_gas);
473475
}
474476

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ use std::{
131131
collections::BTreeMap,
132132
fmt::Debug,
133133
io::{Read, Write},
134-
ops::Not,
134+
ops::{Mul, Not},
135135
path::PathBuf,
136136
sync::Arc,
137137
time::Duration,
@@ -3118,7 +3118,7 @@ impl Backend {
31183118
let excess_blob_gas = block.header.excess_blob_gas;
31193119
let blob_gas_price =
31203120
alloy_eips::eip4844::calc_blob_gasprice(excess_blob_gas.unwrap_or_default());
3121-
let blob_gas_used = transaction.blob_gas();
3121+
let blob_gas_used = transaction.blob_gas_used();
31223122

31233123
let effective_gas_price = match transaction.transaction {
31243124
TypedTransaction::Legacy(t) => t.tx().gas_price,
@@ -3775,7 +3775,13 @@ impl TransactionValidator for Backend {
37753775
));
37763776
}
37773777

3778-
let max_cost = tx.max_cost();
3778+
let max_cost =
3779+
(tx.gas_limit() as u128).saturating_mul(tx.max_fee_per_gas()).saturating_add(
3780+
tx.blob_gas_used()
3781+
.map(|g| g as u128)
3782+
.unwrap_or(0)
3783+
.mul(tx.max_fee_per_blob_gas().unwrap_or(0)),
3784+
);
37793785
let value = tx.value();
37803786
match &tx.transaction {
37813787
TypedTransaction::Deposit(deposit_tx) => {

0 commit comments

Comments
 (0)