Skip to content

feat(txpool): Batch insertions into the Tx Pool#17670

Merged
mattsse merged 62 commits intoparadigmxyz:mainfrom
0xKitsune:kit/batch-insert
Aug 13, 2025
Merged

feat(txpool): Batch insertions into the Tx Pool#17670
mattsse merged 62 commits intoparadigmxyz:mainfrom
0xKitsune:kit/batch-insert

Conversation

@0xKitsune
Copy link
Contributor

@0xKitsune 0xKitsune commented Jul 29, 2025

Addresses #12811

This PR adds support for batch transaction insertions into the TxPool to reduce lock contention and improve throughput under high-load scenarios.

When enabled, transactions are funneled through a TxBatcher, which accumulates txs in an internal buffer. Insertions are triggered either on a fixed interval or when a threshold is reached, whichever comes first. This avoids excessive locking and per-tx overhead during highly concurrent send_raw_transaction calls.

The Batcher configuration is exposed via CLI flags:

  • --txpool.max-batch-size: Enables batch insertion and sets the maximum number of transactions that will be processed in a batch.

When batching is enabled, the EthApi routes transactions through the batcher. Otherwise, it will falls back to the default logic executing each tx indivudally.

Internally, the batcher uses a channel and a background task to process batches. Batched transactions are marked as TransactionOrigin::Local and validated before being added.

Opening a draft PR for initial feedback. I am still writing benchmarks as well as adding logging/metrics. Also happy to adjust if there is a preferred approach different than the current implementation.

Comment on lines +306 to +307
/// Optional transaction batcher for batching tx insertions
tx_batcher: Option<TxBatcher<N::Pool>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we just make this behaviour default, wdyt @klkvr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with that, can make the default batch size 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR to use tx batching by default for transactions submitted via send_raw_transaction. The default batch size has been updated to 1.

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jul 29, 2025
0xKitsune and others added 5 commits July 29, 2025 13:56
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
@0xKitsune 0xKitsune requested a review from fgimenez as a code owner August 7, 2025 00:58
klkvr
klkvr previously requested changes Aug 7, 2025
@mattsse mattsse added the A-rpc Related to the RPC implementation label Aug 13, 2025
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm,

we probably want to increase the max batch size but let's start with 1 for now, the overhead for a single 1 should be negligible here

@mattsse mattsse added the C-perf A change motivated by improving speed, memory usage or disk footprint label Aug 13, 2025
@mattsse mattsse enabled auto-merge August 13, 2025 19:23
@mattsse mattsse added this pull request to the merge queue Aug 13, 2025
Merged via the queue into paradigmxyz:main with commit e12e6c0 Aug 13, 2025
41 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Aug 13, 2025
lwedge99 pushed a commit to sentioxyz/reth that referenced this pull request Sep 16, 2025
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Jan 22, 2026
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Feb 11, 2026
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation C-perf A change motivated by improving speed, memory usage or disk footprint

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants