Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): txpool args #3575

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bin/reth/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ 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;

/// Stage related arguments
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;
57 changes: 57 additions & 0 deletions bin/reth/src/args/txpool_args.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
7 changes: 5 additions & 2 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -132,6 +132,9 @@ pub struct Command {
#[clap(flatten)]
rpc: RpcServerArgs,

#[clap(flatten)]
txpool: TxPoolArgs,

#[clap(flatten)]
builder: PayloadBuilderArgs,

Expand Down Expand Up @@ -220,7 +223,7 @@ impl Command {
ctx.task_executor.clone(),
1,
),
Default::default(),
self.txpool.pool_config(),
);
info!(target: "reth::cli", "Transaction pool initialized");

Expand Down
15 changes: 12 additions & 3 deletions crates/transaction-pool/src/config.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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,
}
}
}
Expand All @@ -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,
}
}
}
5 changes: 4 additions & 1 deletion crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -1191,7 +1191,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
impl<T: PoolTransaction> Default for AllTransactions<T> {
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(),
Expand Down