Skip to content

Commit 9facbce

Browse files
committed
refactor(anvil): replace gas_price by max_fee_per_gas
1 parent cae0dad commit 9facbce

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl TypedTransaction {
663663
/// and if the transaction is EIP-4844, the result of (total blob gas cost * max fee per blob
664664
/// gas) is also added
665665
pub fn max_cost(&self) -> u128 {
666-
let mut max_cost = (self.gas_limit() as u128).saturating_mul(self.gas_price().unwrap_or(0));
666+
let mut max_cost = (self.gas_limit() as u128).saturating_mul(self.max_fee_per_gas());
667667

668668
if self.is_eip4844() {
669669
max_cost = max_cost.saturating_add(

crates/anvil/src/eth/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,10 +2780,10 @@ impl EthApi {
27802780
fn convert(tx: Arc<PoolTransaction>) -> TxpoolInspectSummary {
27812781
let tx = &tx.pending_transaction.transaction;
27822782
let to = tx.to();
2783-
let gas_price = tx.gas_price();
2783+
let gas_price = tx.max_fee_per_gas();
27842784
let value = tx.value();
27852785
let gas = tx.gas_limit();
2786-
TxpoolInspectSummary { to, value, gas, gas_price: gas_price.unwrap_or(0) }
2786+
TxpoolInspectSummary { to, value, gas, gas_price }
27872787
}
27882788

27892789
// Note: naming differs geth vs anvil:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,10 +3727,8 @@ impl TransactionValidator for Backend {
37273727

37283728
// EIP-1559 fee validation (London hard fork and later).
37293729
if env.evm_env.cfg_env.spec >= SpecId::LONDON {
3730-
if tx.gas_price().unwrap_or(0) < env.evm_env.block_env.basefee.into()
3731-
&& !is_deposit_tx
3732-
{
3733-
warn!(target: "backend", "max fee per gas={}, too low, block basefee={}", tx.gas_price().unwrap_or(0), env.evm_env.block_env.basefee);
3730+
if tx.max_fee_per_gas() < env.evm_env.block_env.basefee.into() && !is_deposit_tx {
3731+
warn!(target: "backend", "max fee per gas={}, too low, block basefee={}", tx.max_fee_per_gas(), env.evm_env.block_env.basefee);
37343732
return Err(InvalidTransactionError::FeeCapTooLow);
37353733
}
37363734

crates/anvil/src/eth/pool/transactions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TransactionOrder {
4040
pub fn priority(&self, tx: &TypedTransaction) -> TransactionPriority {
4141
match self {
4242
Self::Fifo => TransactionPriority::default(),
43-
Self::Fees => TransactionPriority(tx.gas_price().unwrap_or(0)),
43+
Self::Fees => TransactionPriority(tx.max_fee_per_gas()),
4444
}
4545
}
4646
}
@@ -95,9 +95,9 @@ impl PoolTransaction {
9595
*self.pending_transaction.hash()
9696
}
9797

98-
/// Returns the gas pric of this transaction
99-
pub fn gas_price(&self) -> Option<u128> {
100-
self.pending_transaction.transaction.gas_price()
98+
/// Returns the max fee per gas of this transaction
99+
pub fn max_fee_per_gas(&self) -> u128 {
100+
self.pending_transaction.transaction.max_fee_per_gas()
101101
}
102102

103103
/// Returns the type of the transaction
@@ -182,7 +182,7 @@ impl PendingTransactions {
182182
.and_then(|hash| self.waiting_queue.get(hash))
183183
{
184184
// check if underpriced
185-
if tx.transaction.gas_price() < replace.transaction.gas_price() {
185+
if tx.transaction.max_fee_per_gas() < replace.transaction.max_fee_per_gas() {
186186
warn!(target: "txpool", "pending replacement transaction underpriced [{:?}]", tx.transaction.hash());
187187
return Err(PoolError::ReplacementUnderpriced(Box::new(
188188
tx.transaction.as_ref().clone(),
@@ -514,7 +514,9 @@ impl ReadyTransactions {
514514
// (addr + nonce) then we check for gas price
515515
if to_remove.provides() == tx.provides {
516516
// check if underpriced
517-
if tx.pending_transaction.transaction.gas_price() <= to_remove.gas_price() {
517+
if tx.pending_transaction.transaction.max_fee_per_gas()
518+
<= to_remove.max_fee_per_gas()
519+
{
518520
warn!(target: "txpool", "ready replacement transaction underpriced [{:?}]", tx.hash());
519521
return Err(PoolError::ReplacementUnderpriced(Box::new(tx.clone())));
520522
} else {
@@ -712,8 +714,8 @@ impl ReadyTransaction {
712714
&self.transaction.transaction.provides
713715
}
714716

715-
pub fn gas_price(&self) -> Option<u128> {
716-
self.transaction.transaction.gas_price()
717+
pub fn max_fee_per_gas(&self) -> u128 {
718+
self.transaction.transaction.max_fee_per_gas()
717719
}
718720
}
719721

0 commit comments

Comments
 (0)