From 36e31f43c9d1afb278cad238fc981e017347526b Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Tue, 4 Jul 2023 13:10:38 +0300 Subject: [PATCH] feat(cli): txpool args --- bin/reth/src/args/mod.rs | 11 +++-- bin/reth/src/args/txpool_args.rs | 57 ++++++++++++++++++++++ bin/reth/src/node/mod.rs | 7 ++- crates/transaction-pool/src/config.rs | 15 ++++-- crates/transaction-pool/src/lib.rs | 5 +- crates/transaction-pool/src/pool/txpool.rs | 4 +- 6 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 bin/reth/src/args/txpool_args.rs diff --git a/bin/reth/src/args/mod.rs b/bin/reth/src/args/mod.rs index ba26ce04bbc4..0360adf41398 100644 --- a/bin/reth/src/args/mod.rs +++ b/bin/reth/src/args/mod.rs @@ -15,7 +15,7 @@ pub use debug_args::DebugArgs; mod secret_key; pub use secret_key::{get_secret_key, SecretKeyError}; -/// MinerArgs struct for configuring the miner +/// PayloadBuilderArgs struct for configuring the payload builder mod payload_builder_args; pub use payload_builder_args::PayloadBuilderArgs; @@ -23,7 +23,12 @@ pub use payload_builder_args::PayloadBuilderArgs; mod stage_args; pub use stage_args::StageEnum; +/// Gas price oracle related arguments mod gas_price_oracle_args; -pub mod utils; - pub use gas_price_oracle_args::GasPriceOracleArgs; + +/// TxPoolArgs for congiguring the transaction pool +mod txpool_args; +pub use txpool_args::TxPoolArgs; + +pub mod utils; diff --git a/bin/reth/src/args/txpool_args.rs b/bin/reth/src/args/txpool_args.rs new file mode 100644 index 000000000000..d1bd2326b692 --- /dev/null +++ b/bin/reth/src/args/txpool_args.rs @@ -0,0 +1,57 @@ +//! Transaction pool arguments + +use clap::Args; +use reth_transaction_pool::{ + PoolConfig, SubPoolLimit, 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, Default)] +pub struct TxPoolArgs { + /// Max number of transaction in the pending sub-pool. + #[arg(long = "txpool.pending_max_count", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_TXS_DEFAULT)] + pub pending_max_count: usize, + /// Max size of the pending sub-pool in megabytes. + #[arg(long = "txpool.pending_max_size", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT)] + pub pending_max_size: usize, + + /// Max number of transaction in the basefee sub-pool + #[arg(long = "txpool.basefee_max_count", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_TXS_DEFAULT)] + pub basefee_max_count: usize, + /// Max size of the basefee sub-pool in megabytes. + #[arg(long = "txpool.basefee_max_size", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT)] + pub basefee_max_size: usize, + + /// Max number of transaction in the queued sub-pool + #[arg(long = "txpool.queued_max_count", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_TXS_DEFAULT)] + pub queued_max_count: usize, + /// Max size of the queued sub-pool in megabytes. + #[arg(long = "txpool.queued_max_size", help_heading = "TxPool", default_value_t = TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT)] + pub queued_max_size: usize, + + /// Max number of executable transaction slots guaranteed per account + #[arg(long = "txpool.max_account_slots", help_heading = "TxPool", default_value_t = TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER)] + pub max_account_slots: usize, +} + +impl TxPoolArgs { + /// Returns transaction pool configuration. + pub fn pool_config(&self) -> PoolConfig { + PoolConfig { + pending_limit: SubPoolLimit { + max_txs: self.pending_max_count, + max_size: self.pending_max_size * 1024 * 1024, + }, + basefee_limit: SubPoolLimit { + max_txs: self.basefee_max_count, + max_size: self.basefee_max_size * 1024 * 1024, + }, + queued_limit: SubPoolLimit { + max_txs: self.queued_max_count, + max_size: self.queued_max_size * 1024 * 1024, + }, + max_account_slots: self.max_account_slots, + } + } +} diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 905bf32d0449..b4e3f8d13d67 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -2,7 +2,7 @@ //! //! Starts the client use crate::{ - args::{get_secret_key, DebugArgs, NetworkArgs, RpcServerArgs}, + args::{get_secret_key, DebugArgs, NetworkArgs, RpcServerArgs, TxPoolArgs}, dirs::DataDirPath, prometheus_exporter, runner::CliContext, @@ -132,6 +132,9 @@ pub struct Command { #[clap(flatten)] rpc: RpcServerArgs, + #[clap(flatten)] + txpool: TxPoolArgs, + #[clap(flatten)] builder: PayloadBuilderArgs, @@ -220,7 +223,7 @@ impl Command { ctx.task_executor.clone(), 1, ), - Default::default(), + self.txpool.pool_config(), ); info!(target: "reth::cli", "Transaction pool initialized"); diff --git a/crates/transaction-pool/src/config.rs b/crates/transaction-pool/src/config.rs index 285b2032c4f2..faf0c0156b41 100644 --- a/crates/transaction-pool/src/config.rs +++ b/crates/transaction-pool/src/config.rs @@ -1,5 +1,11 @@ /// Guarantees max transactions for one sender, compatible with geth/erigon -pub(crate) const MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16; +pub const TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16; + +/// The default maximum allowed number of transactions in the given subpool. +pub const TXPOOL_SUBPOOL_MAX_TXS_DEFAULT: usize = 10_000; + +/// The default maximum allowed size of the given subpool. +pub const TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT: usize = 20; /// Configuration options for the Transaction pool. #[derive(Debug, Clone)] @@ -20,7 +26,7 @@ impl Default for PoolConfig { pending_limit: Default::default(), basefee_limit: Default::default(), queued_limit: Default::default(), - max_account_slots: MAX_ACCOUNT_SLOTS_PER_SENDER, + max_account_slots: TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, } } } @@ -45,6 +51,9 @@ impl SubPoolLimit { impl Default for SubPoolLimit { fn default() -> Self { // either 10k transactions or 20MB - Self { max_txs: 10_000, max_size: 20 * 1024 * 1024 } + Self { + max_txs: TXPOOL_SUBPOOL_MAX_TXS_DEFAULT, + max_size: TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT * 1024 * 1024, + } } } diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index b56bb2042d04..d4c9de5b9dac 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -100,7 +100,10 @@ use tracing::{instrument, trace}; use traits::TransactionPoolExt; pub use crate::{ - config::PoolConfig, + config::{ + PoolConfig, SubPoolLimit, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, + TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT, + }, error::PoolResult, ordering::{GasCostOrdering, TransactionOrdering}, pool::TransactionEvents, diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index aba3e1e698d4..4368a240f26c 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1,6 +1,6 @@ //! The internal transaction pool implementation. use crate::{ - config::MAX_ACCOUNT_SLOTS_PER_SENDER, + config::TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, error::{InvalidPoolTransactionError, PoolError}, identifier::{SenderId, TransactionId}, metrics::TxPoolMetrics, @@ -1191,7 +1191,7 @@ impl AllTransactions { impl Default for AllTransactions { fn default() -> Self { Self { - max_account_slots: MAX_ACCOUNT_SLOTS_PER_SENDER, + max_account_slots: TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, minimal_protocol_basefee: MIN_PROTOCOL_BASE_FEE, block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, by_hash: Default::default(),