feat: Support txpool.locals in txpool.cli (#5971)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Supernovahs.eth
2024-01-09 20:02:55 +05:30
committed by GitHub
parent a3d2b224ea
commit 7cd659f406
4 changed files with 33 additions and 6 deletions

View File

@ -2,12 +2,12 @@
use crate::cli::config::RethTransactionPoolConfig;
use clap::Args;
use reth_primitives::Address;
use reth_transaction_pool::{
LocalTransactionConfig, PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP,
REPLACE_BLOB_PRICE_BUMP, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
};
/// Parameters for debugging purposes
#[derive(Debug, Args, PartialEq)]
#[clap(next_help_heading = "TxPool")]
@ -47,6 +47,9 @@ pub struct TxPoolArgs {
/// Flag to disable local transaction exemptions.
#[arg(long = "txpool.nolocals")]
pub no_locals: bool,
/// Flag to allow certain addresses as local
#[arg(long = "txpool.locals")]
pub locals: Vec<Address>,
}
impl Default for TxPoolArgs {
@ -62,6 +65,7 @@ impl Default for TxPoolArgs {
price_bump: DEFAULT_PRICE_BUMP,
blob_transaction_price_bump: REPLACE_BLOB_PRICE_BUMP,
no_locals: false,
locals: Default::default(),
}
}
}
@ -70,7 +74,10 @@ impl RethTransactionPoolConfig for TxPoolArgs {
/// Returns transaction pool configuration.
fn pool_config(&self) -> PoolConfig {
PoolConfig {
local_transactions_config: LocalTransactionConfig { no_exemptions: self.no_locals },
local_transactions_config: LocalTransactionConfig {
no_exemptions: self.no_locals,
local_addresses: self.locals.clone().into_iter().collect(),
},
pending_limit: SubPoolLimit {
max_txs: self.pending_max_count,
max_size: self.pending_max_size * 1024 * 1024,

View File

@ -1,5 +1,6 @@
use reth_primitives::EIP4844_TX_TYPE_ID;
use crate::TransactionOrigin;
use reth_primitives::{Address, EIP4844_TX_TYPE_ID};
use std::collections::HashSet;
/// Guarantees max transactions for one sender, compatible with geth/erigon
pub const TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16;
@ -118,6 +119,8 @@ pub struct LocalTransactionConfig {
/// - no price exemptions
/// - no eviction exemptions
pub no_exemptions: bool,
/// Addresses that will be considered as local . Above exemptions apply
pub local_addresses: HashSet<Address>,
}
impl LocalTransactionConfig {
@ -126,4 +129,21 @@ impl LocalTransactionConfig {
pub fn no_local_exemptions(&self) -> bool {
self.no_exemptions
}
/// Returns whether the local addresses vector contains the given address.
#[inline]
pub fn contains_local_address(&self, address: Address) -> bool {
self.local_addresses.contains(&address)
}
/// Returns whether the particular transaction should be considered local.
///
/// This always returns false if the local exemptions are disabled.
#[inline]
pub fn is_local(&self, origin: TransactionOrigin, sender: Address) -> bool {
if self.no_local_exemptions() {
return false
}
origin.is_local() || self.contains_local_address(sender)
}
}

View File

@ -1253,7 +1253,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
&self,
transaction: ValidPoolTransaction<T>,
) -> Result<ValidPoolTransaction<T>, InsertErr<T>> {
if !transaction.origin.is_local() || self.local_transactions_config.no_local_exemptions() {
if !self.local_transactions_config.is_local(transaction.origin, transaction.sender()) {
let current_txs =
self.tx_counter.get(&transaction.sender_id()).copied().unwrap_or_default();
if current_txs >= self.max_account_slots {

View File

@ -237,7 +237,7 @@ where
// Drop non-local transactions with a fee lower than the configured fee for acceptance into
// the pool.
if (!origin.is_local() || self.local_transactions_config.no_local_exemptions()) &&
if !self.local_transactions_config.is_local(origin, transaction.sender()) &&
transaction.is_eip1559() &&
transaction.max_priority_fee_per_gas() < self.minimum_priority_fee
{