mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
fix: correct effective_gas_price (#2573)
This commit is contained in:
@@ -369,7 +369,7 @@ impl Transaction {
|
||||
/// transactions is returned.
|
||||
///
|
||||
/// If the `max_fee_per_gas` is less than the base fee, `None` returned.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> Option<u128> {
|
||||
pub fn effective_gas_tip(&self, base_fee: Option<u64>) -> Option<u128> {
|
||||
if let Some(base_fee) = base_fee {
|
||||
let max_fee_per_gas = self.max_fee_per_gas();
|
||||
if max_fee_per_gas < base_fee as u128 {
|
||||
@@ -400,6 +400,19 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the effective gas price for the given base fee.
|
||||
///
|
||||
/// If the transaction is a legacy or EIP2930 transaction, the gas price is returned.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
|
||||
let dynamic_tx = match self {
|
||||
Transaction::Legacy(tx) => return tx.gas_price,
|
||||
Transaction::Eip2930(tx) => return tx.gas_price,
|
||||
Transaction::Eip1559(dynamic_tx) => dynamic_tx,
|
||||
};
|
||||
|
||||
dynamic_tx.effective_gas_price(base_fee)
|
||||
}
|
||||
|
||||
/// Returns the effective miner gas tip cap (`gasTipCap`) for the given base fee.
|
||||
///
|
||||
/// Returns `None` if the basefee is higher than the [Transaction::max_fee_per_gas].
|
||||
@@ -633,6 +646,26 @@ impl Encodable for Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl TxEip1559 {
|
||||
/// Returns the effective gas price for the given `base_fee`.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
|
||||
match base_fee {
|
||||
None => self.max_fee_per_gas,
|
||||
Some(base_fee) => {
|
||||
// if the tip is greater than the max priority fee per gas, set it to the max
|
||||
// priority fee per gas + base fee
|
||||
let tip = self.max_fee_per_gas - base_fee as u128;
|
||||
if tip > self.max_priority_fee_per_gas {
|
||||
self.max_priority_fee_per_gas + base_fee as u128
|
||||
} else {
|
||||
// otherwise return the max fee per gas
|
||||
self.max_fee_per_gas
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether or not the transaction is a contract creation.
|
||||
#[derive_arbitrary(compact, rlp)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
|
||||
|
||||
@@ -129,7 +129,7 @@ where
|
||||
let mut sorter = Vec::with_capacity(transactions.len());
|
||||
for transaction in transactions.iter() {
|
||||
let reward = transaction
|
||||
.effective_gas_price(header.base_fee_per_gas)
|
||||
.effective_gas_tip(header.base_fee_per_gas)
|
||||
.ok_or(InvalidTransactionError::FeeCapTooLow)?;
|
||||
|
||||
sorter.push(TxGasAndReward { gas_used: header.gas_used as u128, reward })
|
||||
|
||||
@@ -596,10 +596,7 @@ where
|
||||
gas_used: Some(U256::from(gas_used)),
|
||||
contract_address: None,
|
||||
logs: Vec::with_capacity(receipt.logs.len()),
|
||||
effective_gas_price: transaction
|
||||
.effective_gas_price(meta.base_fee)
|
||||
.map(U128::from)
|
||||
.unwrap_or(U128::ZERO),
|
||||
effective_gas_price: U128::from(transaction.effective_gas_price(meta.base_fee)),
|
||||
transaction_type: tx.transaction.tx_type().into(),
|
||||
// TODO pre-byzantium receipts have a post-transaction state root
|
||||
state_root: None,
|
||||
|
||||
Reference in New Issue
Block a user