Skip to content
Merged
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
40 changes: 10 additions & 30 deletions crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use std::{
task::{Context, Poll},
};

use alloy_consensus::Header;
use alloy_consensus::{Header, Transaction};
use alloy_eips::{
calc_next_block_base_fee, eip1559::BaseFeeParams, eip7691::MAX_BLOBS_PER_BLOCK_ELECTRA,
eip7840::BlobParams,
};
use alloy_primitives::B256;
use anvil_core::eth::transaction::TypedTransaction;
use futures::StreamExt;
use parking_lot::{Mutex, RwLock};
use revm::{context_interface::block::BlobExcessGasAndPrice, primitives::hardfork::SpecId};
Expand Down Expand Up @@ -252,13 +251,13 @@ impl FeeHistoryService {
};

let mut block_number: Option<u64> = None;
let base_fee = header.base_fee_per_gas.map(|g| g as u128).unwrap_or_default();
let base_fee = header.base_fee_per_gas.unwrap_or_default();
let excess_blob_gas = header.excess_blob_gas.map(|g| g as u128);
let blob_gas_used = header.blob_gas_used.map(|g| g as u128);
let base_fee_per_blob_gas = header.blob_fee(self.blob_params);

let mut item = FeeHistoryCacheItem {
base_fee,
base_fee: base_fee as u128,
gas_used_ratio: 0f64,
blob_gas_used_ratio: 0f64,
rewards: Vec::new(),
Expand All @@ -285,31 +284,12 @@ impl FeeHistoryService {
.enumerate()
.map(|(i, receipt)| {
let gas_used = receipt.cumulative_gas_used();
let effective_reward =
match block.body.transactions.get(i).map(|tx| &tx.transaction) {
Some(TypedTransaction::Legacy(t)) => {
t.tx().gas_price.saturating_sub(base_fee)
}
Some(TypedTransaction::EIP2930(t)) => {
t.tx().gas_price.saturating_sub(base_fee)
}
Some(TypedTransaction::EIP1559(t)) => t
.tx()
.max_priority_fee_per_gas
.min(t.tx().max_fee_per_gas.saturating_sub(base_fee)),
// TODO: This probably needs to be extended to extract 4844 info.
Some(TypedTransaction::EIP4844(t)) => t
.tx()
.tx()
.max_priority_fee_per_gas
.min(t.tx().tx().max_fee_per_gas.saturating_sub(base_fee)),
Some(TypedTransaction::EIP7702(t)) => t
.tx()
.max_priority_fee_per_gas
.min(t.tx().max_fee_per_gas.saturating_sub(base_fee)),
Some(TypedTransaction::Deposit(_)) => 0,
None => 0,
};
let effective_reward = block
.body
.transactions
.get(i)
.map(|tx| tx.as_ref().effective_tip_per_gas(base_fee).unwrap_or(0))
.unwrap_or(0);

(gas_used, effective_reward)
})
Expand All @@ -334,7 +314,7 @@ impl FeeHistoryService {
})
.collect();
} else {
item.rewards = reward_percentiles.iter().map(|_| 0).collect();
item.rewards = vec![0; reward_percentiles.len()];
}
(item, block_number)
}
Expand Down
Loading