mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
fix: pick 1559 fees correctly for dynamic fee (#15605)
This commit is contained in:
@@ -263,11 +263,19 @@ pub trait BlockBuilder {
|
||||
/// Provides mutable access to the inner [`BlockExecutor`].
|
||||
fn executor_mut(&mut self) -> &mut Self::Executor;
|
||||
|
||||
/// Helper to access inner [`BlockExecutor::Evm`].
|
||||
/// Provides access to the inner [`BlockExecutor`].
|
||||
fn executor(&self) -> &Self::Executor;
|
||||
|
||||
/// Helper to access inner [`BlockExecutor::Evm`] mutably.
|
||||
fn evm_mut(&mut self) -> &mut <Self::Executor as BlockExecutor>::Evm {
|
||||
self.executor_mut().evm_mut()
|
||||
}
|
||||
|
||||
/// Helper to access inner [`BlockExecutor::Evm`].
|
||||
fn evm(&self) -> &<Self::Executor as BlockExecutor>::Evm {
|
||||
self.executor().evm()
|
||||
}
|
||||
|
||||
/// Consumes the type and returns the underlying [`BlockExecutor`].
|
||||
fn into_executor(self) -> Self::Executor;
|
||||
}
|
||||
@@ -388,6 +396,10 @@ where
|
||||
&mut self.executor
|
||||
}
|
||||
|
||||
fn executor(&self) -> &Self::Executor {
|
||||
&self.executor
|
||||
}
|
||||
|
||||
fn into_executor(self) -> Self::Executor {
|
||||
self.executor
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ where
|
||||
let tx = resolve_transaction(
|
||||
call,
|
||||
default_gas_limit,
|
||||
builder.evm().block().basefee,
|
||||
chain_id,
|
||||
builder.evm_mut().db_mut(),
|
||||
tx_resp_builder,
|
||||
@@ -113,6 +114,7 @@ where
|
||||
pub fn resolve_transaction<DB: Database, Tx, T: TransactionCompat<Tx>>(
|
||||
mut tx: TransactionRequest,
|
||||
default_gas_limit: u64,
|
||||
block_base_fee_per_gas: u64,
|
||||
chain_id: u64,
|
||||
db: &mut DB,
|
||||
tx_resp_builder: &T,
|
||||
@@ -153,13 +155,19 @@ where
|
||||
match tx_type {
|
||||
TxType::Legacy | TxType::Eip2930 => {
|
||||
if tx.gas_price.is_none() {
|
||||
tx.gas_price = Some(0);
|
||||
tx.gas_price = Some(block_base_fee_per_gas as u128);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// set dynamic 1559 fees
|
||||
if tx.max_fee_per_gas.is_none() {
|
||||
tx.max_fee_per_gas = Some(0);
|
||||
let mut max_fee_per_gas = block_base_fee_per_gas as u128;
|
||||
if let Some(prio_fee) = tx.max_priority_fee_per_gas {
|
||||
// if a prio fee is provided we need to select the max fee accordingly
|
||||
// because the base fee must be higher than the prio fee.
|
||||
max_fee_per_gas = prio_fee.max(max_fee_per_gas);
|
||||
}
|
||||
tx.max_fee_per_gas = Some(max_fee_per_gas);
|
||||
}
|
||||
if tx.max_priority_fee_per_gas.is_none() {
|
||||
tx.max_priority_fee_per_gas = Some(0);
|
||||
|
||||
@@ -96,7 +96,7 @@ mod tests {
|
||||
let builder = EthTxBuilder::default();
|
||||
let mut db = CacheDB::<reth_revm::db::EmptyDBTyped<reth_errors::ProviderError>>::default();
|
||||
let tx = TransactionRequest::default();
|
||||
let result = resolve_transaction(tx, 21000, 1, &mut db, &builder).unwrap();
|
||||
let result = resolve_transaction(tx, 21000, 0, 1, &mut db, &builder).unwrap();
|
||||
|
||||
// For an empty request, we should get a valid transaction with defaults
|
||||
let tx = result.into_inner();
|
||||
@@ -112,7 +112,7 @@ mod tests {
|
||||
|
||||
let tx = TransactionRequest { gas_price: Some(100), ..Default::default() };
|
||||
|
||||
let tx = resolve_transaction(tx, 21000, 1, &mut db, &builder).unwrap();
|
||||
let tx = resolve_transaction(tx, 21000, 0, 1, &mut db, &builder).unwrap();
|
||||
|
||||
assert_eq!(tx.tx_type(), TxType::Legacy);
|
||||
|
||||
@@ -132,7 +132,7 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = resolve_transaction(tx, 21000, 1, &mut db, &builder).unwrap();
|
||||
let result = resolve_transaction(tx, 21000, 0, 1, &mut db, &builder).unwrap();
|
||||
|
||||
assert_eq!(result.tx_type(), TxType::Eip1559);
|
||||
let tx = result.into_inner();
|
||||
|
||||
Reference in New Issue
Block a user