mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Add cli arg for pool lifetime (#14273)
Co-authored-by: Reentrancy <reentrancy@0xReentrancy.0xReentrancy> Co-authored-by: Reentrancy <osawarumitchell@gmail.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
5
book/cli/reth/node.md
vendored
5
book/cli/reth/node.md
vendored
@ -517,6 +517,11 @@ TxPool:
|
||||
|
||||
[default: 200]
|
||||
|
||||
--txpool.lifetime <DURATION>
|
||||
Maximum amount of time non-executable transaction are queued
|
||||
|
||||
[default: 10800]
|
||||
|
||||
Builder:
|
||||
--builder.extradata <EXTRA_DATA>
|
||||
Block extra data set by the payload builder
|
||||
|
||||
@ -4,8 +4,10 @@ use crate::cli::config::RethTransactionPoolConfig;
|
||||
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
|
||||
use alloy_primitives::Address;
|
||||
use clap::Args;
|
||||
use reth_cli_util::parse_duration_from_secs_or_ms;
|
||||
use reth_transaction_pool::{
|
||||
blobstore::disk::DEFAULT_MAX_CACHED_BLOBS,
|
||||
maintain::MAX_QUEUED_TRANSACTION_LIFETIME,
|
||||
pool::{NEW_TX_LISTENER_BUFFER_SIZE, PENDING_TX_LISTENER_BUFFER_SIZE},
|
||||
validate::DEFAULT_MAX_TX_INPUT_BYTES,
|
||||
LocalTransactionConfig, PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP,
|
||||
@ -13,6 +15,8 @@ use reth_transaction_pool::{
|
||||
REPLACE_BLOB_PRICE_BUMP, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
|
||||
TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
/// Parameters for debugging purposes
|
||||
#[derive(Debug, Clone, Args, PartialEq, Eq)]
|
||||
#[command(next_help_heading = "TxPool")]
|
||||
@ -98,6 +102,10 @@ pub struct TxPoolArgs {
|
||||
/// iterators.
|
||||
#[arg(long = "txpool.max-new-pending-txs-notifications", alias = "txpool.max-new-pending-txs-notifications", default_value_t = MAX_NEW_PENDING_TXS_NOTIFICATIONS)]
|
||||
pub max_new_pending_txs_notifications: usize,
|
||||
|
||||
/// Maximum amount of time non-executable transaction are queued.
|
||||
#[arg(long = "txpool.lifetime", value_parser = parse_duration_from_secs_or_ms, default_value = "10800", value_name = "DURATION")]
|
||||
pub max_queued_lifetime: Duration,
|
||||
}
|
||||
|
||||
impl Default for TxPoolArgs {
|
||||
@ -125,6 +133,7 @@ impl Default for TxPoolArgs {
|
||||
pending_tx_listener_buffer_size: PENDING_TX_LISTENER_BUFFER_SIZE,
|
||||
new_tx_listener_buffer_size: NEW_TX_LISTENER_BUFFER_SIZE,
|
||||
max_new_pending_txs_notifications: MAX_NEW_PENDING_TXS_NOTIFICATIONS,
|
||||
max_queued_lifetime: MAX_QUEUED_TRANSACTION_LIFETIME,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,6 +173,7 @@ impl RethTransactionPoolConfig for TxPoolArgs {
|
||||
pending_tx_listener_buffer_size: self.pending_tx_listener_buffer_size,
|
||||
new_tx_listener_buffer_size: self.new_tx_listener_buffer_size,
|
||||
max_new_pending_txs_notifications: self.max_new_pending_txs_notifications,
|
||||
max_queued_lifetime: self.max_queued_lifetime,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,4 +207,24 @@ mod tests {
|
||||
.args;
|
||||
assert_eq!(args.locals, vec![Address::ZERO]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn txpool_parse_max_tx_lifetime() {
|
||||
// Test with a custom duration
|
||||
let args =
|
||||
CommandParser::<TxPoolArgs>::parse_from(["reth", "--txpool.lifetime", "300"]).args;
|
||||
assert_eq!(args.max_queued_lifetime, Duration::from_secs(300));
|
||||
|
||||
// Test with the default value
|
||||
let args = CommandParser::<TxPoolArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args.max_queued_lifetime, Duration::from_secs(3 * 60 * 60)); // Default is 3h
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn txpool_parse_max_tx_lifetime_invalid() {
|
||||
let result =
|
||||
CommandParser::<TxPoolArgs>::try_parse_from(["reth", "--txpool.lifetime", "invalid"]);
|
||||
|
||||
assert!(result.is_err(), "Expected an error for invalid duration");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
use crate::{
|
||||
maintain::MAX_QUEUED_TRANSACTION_LIFETIME,
|
||||
pool::{NEW_TX_LISTENER_BUFFER_SIZE, PENDING_TX_LISTENER_BUFFER_SIZE},
|
||||
PoolSize, TransactionOrigin,
|
||||
};
|
||||
use alloy_consensus::constants::EIP4844_TX_TYPE_ID;
|
||||
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
|
||||
use alloy_primitives::Address;
|
||||
use std::{collections::HashSet, ops::Mul};
|
||||
use std::{collections::HashSet, ops::Mul, time::Duration};
|
||||
|
||||
/// Guarantees max transactions for one sender, compatible with geth/erigon
|
||||
pub const TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16;
|
||||
@ -58,6 +59,8 @@ pub struct PoolConfig {
|
||||
pub new_tx_listener_buffer_size: usize,
|
||||
/// How many new pending transactions to buffer and send iterators in progress.
|
||||
pub max_new_pending_txs_notifications: usize,
|
||||
/// Maximum lifetime for transactions in the pool
|
||||
pub max_queued_lifetime: Duration,
|
||||
}
|
||||
|
||||
impl PoolConfig {
|
||||
@ -86,6 +89,7 @@ impl Default for PoolConfig {
|
||||
pending_tx_listener_buffer_size: PENDING_TX_LISTENER_BUFFER_SIZE,
|
||||
new_tx_listener_buffer_size: NEW_TX_LISTENER_BUFFER_SIZE,
|
||||
max_new_pending_txs_notifications: MAX_NEW_PENDING_TXS_NOTIFICATIONS,
|
||||
max_queued_lifetime: MAX_QUEUED_TRANSACTION_LIFETIME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,9 @@ use tokio::{
|
||||
};
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
/// Maximum amount of time non-executable transaction are queued.
|
||||
pub const MAX_QUEUED_TRANSACTION_LIFETIME: Duration = Duration::from_secs(3 * 60 * 60);
|
||||
|
||||
/// Additional settings for maintaining the transaction pool
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MaintainPoolConfig {
|
||||
@ -59,7 +62,7 @@ impl Default for MaintainPoolConfig {
|
||||
Self {
|
||||
max_update_depth: 64,
|
||||
max_reload_accounts: 100,
|
||||
max_tx_lifetime: Duration::from_secs(3 * 60 * 60),
|
||||
max_tx_lifetime: MAX_QUEUED_TRANSACTION_LIFETIME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user