From 34f8e37a48a5758cd649bc9774ef7a653c029781 Mon Sep 17 00:00:00 2001 From: Ivan Wang <314130948@qq.com> Date: Fri, 13 Nov 2026 11:16:33 +0000 Subject: [PATCH] feat(txpool): add --txpool.enforce-tracked-nonce (#28526) Co-authored-by: raz-glm <178501331+raz-glm@users.noreply.github.com> (cherry picked from commit 3e88af42a04264f1ad32d1bde14f67025de152be) --- crates/node/core/src/args/txpool.rs | 33 +++++++++++++++++++++++++- docs/vocs/docs/pages/cli/reth/node.mdx | 5 ++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/node/core/src/args/txpool.rs b/crates/node/core/src/args/txpool.rs index 9b7fea97baf..09997399c0a 100644 --- a/crates/node/core/src/args/txpool.rs +++ b/crates/node/core/src/args/txpool.rs @@ -58,6 +58,7 @@ pub struct DefaultTxPoolValues { transactions_backup_path: Option, disable_transactions_backup: bool, max_batch_size: usize, + enforce_tracked_nonce: bool, } impl DefaultTxPoolValues { @@ -250,6 +251,12 @@ impl DefaultTxPoolValues { self.max_batch_size = v; self } + + /// Set whether to enforce the sender nonce tracked from canonical updates by default + pub const fn with_enforce_tracked_nonce(mut self, v: bool) -> Self { + self.enforce_tracked_nonce = v; + self + } } impl Default for DefaultTxPoolValues { @@ -285,6 +292,7 @@ impl Default for DefaultTxPoolValues { transactions_backup_path: None, disable_transactions_backup: false, max_batch_size: 1, + enforce_tracked_nonce: false, } } } @@ -414,6 +422,14 @@ pub struct TxPoolArgs { /// Max batch size for transaction pool insertions #[arg(long = "txpool.max-batch-size", value_parser = RangedU64ValueParser::::new().range(1..), default_value_t = DefaultTxPoolValues::get_global().max_batch_size)] pub max_batch_size: usize, + + /// Reject transactions whose nonce is below the sender nonce tracked from canonical updates. + /// + /// Closes the window in which a validation result that predates a block inserts an already + /// mined nonce as pending. Assumes sender nonces only move forward, so this is meant for + /// chains without reorgs and very low block times. + #[arg(long = "txpool.enforce-tracked-nonce", default_value_t = DefaultTxPoolValues::get_global().enforce_tracked_nonce)] + pub enforce_tracked_nonce: bool, } impl TxPoolArgs { @@ -467,6 +483,7 @@ impl Default for TxPoolArgs { transactions_backup_path, disable_transactions_backup, max_batch_size, + enforce_tracked_nonce, } = DefaultTxPoolValues::get_global().clone(); Self { pending_max_count, @@ -499,6 +516,7 @@ impl Default for TxPoolArgs { transactions_backup_path, disable_transactions_backup, max_batch_size, + enforce_tracked_nonce, } } } @@ -543,7 +561,7 @@ impl RethTransactionPoolConfig for TxPoolArgs { max_new_pending_txs_notifications: self.max_new_pending_txs_notifications, max_queued_lifetime: self.max_queued_lifetime, max_inflight_delegated_slot_limit: default_config.max_inflight_delegated_slot_limit, - enforce_tracked_nonce: default_config.enforce_tracked_nonce, + enforce_tracked_nonce: self.enforce_tracked_nonce, } } @@ -604,6 +622,17 @@ mod tests { assert_eq!(valid.args.max_batch_size, 1); } + #[test] + fn txpool_enforce_tracked_nonce_reaches_the_pool_config() { + let args = CommandParser::::parse_from(["reth"]).args; + assert!(!args.pool_config().enforce_tracked_nonce); + + let args = + CommandParser::::parse_from(["reth", "--txpool.enforce-tracked-nonce"]) + .args; + assert!(args.pool_config().enforce_tracked_nonce); + } + #[test] fn txpool_args() { let args = TxPoolArgs { @@ -640,6 +669,7 @@ mod tests { transactions_backup_path: Some(PathBuf::from("/tmp/txpool-backup")), disable_transactions_backup: false, max_batch_size: 10, + enforce_tracked_nonce: true, }; let parsed_args = CommandParser::::parse_from([ @@ -700,6 +730,7 @@ mod tests { "/tmp/txpool-backup", "--txpool.max-batch-size", "10", + "--txpool.enforce-tracked-nonce", ]) .args; diff --git a/docs/vocs/docs/pages/cli/reth/node.mdx b/docs/vocs/docs/pages/cli/reth/node.mdx index dbe3487dce3..a5f9ebb4059 100644 --- a/docs/vocs/docs/pages/cli/reth/node.mdx +++ b/docs/vocs/docs/pages/cli/reth/node.mdx @@ -761,6 +761,11 @@ TxPool: [default: 1] + --txpool.enforce-tracked-nonce + Reject transactions whose nonce is below the sender nonce tracked from canonical updates. + + Closes the window in which a validation result that predates a block inserts an already mined nonce as pending. Assumes sender nonces only move forward, so this is meant for chains without reorgs and very low block times. + Builder: --builder.extradata Block extra data set by the payload builder.