fix(txpool): enforce minimum priority fee (#2212)

This commit is contained in:
Matthias Seitz
2023-04-12 17:41:10 +02:00
committed by GitHub
parent cf93d642f6
commit 15ad63f8c2
3 changed files with 23 additions and 11 deletions

View File

@@ -121,4 +121,7 @@ pub enum InvalidPoolTransactionError {
/// making the transaction invalid, rather a DOS protection.
#[error("Input data too large")]
OversizedData(usize, usize),
/// Thrown if the transaction's fee is below the minimum fee
#[error("transaction underpriced")]
Underpriced,
}

View File

@@ -1,7 +1,7 @@
use crate::{error::PoolResult, pool::state::SubPool, validate::ValidPoolTransaction};
use reth_primitives::{
Address, FromRecoveredTransaction, IntoRecoveredTransaction, PeerId, Transaction,
TransactionKind, TransactionSignedEcRecovered, TxHash, H256, U256,
TransactionKind, TransactionSignedEcRecovered, TxHash, EIP1559_TX_TYPE_ID, H256, U256,
};
use reth_rlp::Encodable;
use std::{collections::HashMap, fmt, sync::Arc};
@@ -314,6 +314,11 @@ pub trait PoolTransaction:
/// Returns the transaction type
fn tx_type(&self) -> u8;
/// Returns true if the transaction is an EIP-1559 transaction.
fn is_eip1559(&self) -> bool {
self.tx_type() == EIP1559_TX_TYPE_ID
}
/// Returns the length of the rlp encoded object
fn encoded_length(&self) -> usize;

View File

@@ -96,9 +96,9 @@ pub struct EthTransactionValidator<Client, T> {
/// Fork indicator whether we are using EIP-1559 type transactions.
eip1559: bool,
/// The current max gas limit
current_max_gas_limit: u64,
/// Current base fee.
base_fee: Option<u128>,
block_gas_limit: u64,
/// Minimum priority fee to enforce for acceptance into the pool.
minimum_priority_fee: Option<u128>,
/// Marker for the transaction type
_marker: PhantomData<T>,
}
@@ -116,8 +116,8 @@ impl<Client, Tx> EthTransactionValidator<Client, Tx> {
shanghai: true,
eip2718: true,
eip1559: true,
current_max_gas_limit: 30_000_000,
base_fee: None,
block_gas_limit: 30_000_000,
minimum_priority_fee: None,
_marker: Default::default(),
}
}
@@ -191,11 +191,11 @@ where
}
// Checks for gas limit
if transaction.gas_limit() > self.current_max_gas_limit {
if transaction.gas_limit() > self.block_gas_limit {
let gas_limit = transaction.gas_limit();
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::ExceedsGasLimit(gas_limit, self.current_max_gas_limit),
InvalidPoolTransactionError::ExceedsGasLimit(gas_limit, self.block_gas_limit),
)
}
@@ -207,11 +207,15 @@ where
)
}
// Drop non-local transactions under our own minimal accepted gas price or tip
if !origin.is_local() && transaction.max_fee_per_gas() < self.base_fee {
// Drop non-local transactions with a fee lower than the configured fee for acceptance into
// the pool.
if !origin.is_local() &&
transaction.is_eip1559() &&
transaction.max_priority_fee_per_gas() < self.minimum_priority_fee
{
return TransactionValidationOutcome::Invalid(
transaction,
InvalidTransactionError::MaxFeeLessThenBaseFee.into(),
InvalidPoolTransactionError::Underpriced,
)
}