Skip to content

Add txpool_inspect JSON-RPC method#10121

Merged
fab-10 merged 7 commits into
besu-eth:mainfrom
fab-10:txpool-inspect
Mar 31, 2026
Merged

Add txpool_inspect JSON-RPC method#10121
fab-10 merged 7 commits into
besu-eth:mainfrom
fab-10:txpool-inspect

Conversation

@fab-10
Copy link
Copy Markdown
Contributor

@fab-10 fab-10 commented Mar 27, 2026

Summary

Stacks on top of #10120 (txpool_content), please review it first

Implements the spec-defined txpool_inspect JSON-RPC method. Returns a textual summary of all pending and queued transactions in the pool, grouped by sender address and nonce.
Some duplicated code was removed as part of this PR.

Since the content is free form and implementation dependent, Besu chose to return this output

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "pending": {
      "0x67ee9a8c19f7873125a875f61add461b4a505d8c": {
        "5": "{sequence: 68178, addedAt: 1775837774160, isLocal=false, hasPriority=false, score=127, 0xfbee0231c6140f9db3bbcef774b3626556f6f5528a6a49dcd38e1f7f86c79368={MessageCall, 5, 0x67ee9a8c19f7873125a875f61add461b4a505d8c, EIP1559, mf: 300.00 kwei, pf: 300.00 kwei, gl: 70926, v: 0 wei, to: 0xe9f8133e47d42bc9962e469721faaf75e385af31}}",
        "6": "{sequence: 68179, addedAt: 1775837774160, isLocal=false, hasPriority=false, score=127, 0x3474c0582722ed751dba809363f58c8d1acea415831b81bc0b0b9f29afb19c19={MessageCall, 6, 0x67ee9a8c19f7873125a875f61add461b4a505d8c, EIP1559, mf: 2.00 mwei, pf: 2.00 mwei, gl: 90617, v: 0 wei, to: 0x1eb4a2620b909a8838e0e24a8e912bd32f4a47a3}}"
      }
    },
    "queued": {
      "0x5fa84846743cc07ab16106ceabad8e4e0ec1c1b6": {
        "29": "{sequence: 2208499, addedAt: 1775952461706, isLocal=false, hasPriority=false, score=127, 0x2bb5f69f2b9737a99a3674018cd2aac5035b907a753a0c797051bc9df0b2a152={MessageCall, 29, 0x5fa84846743cc07ab16106ceabad8e4e0ec1c1b6, EIP1559, mf: 1.40 gwei, pf: 417.90 mwei, gl: 63209, v: 0 wei, to: 0xdac17f958d2ee523a2206206994597c13d831ec7}}",
        "31": "{sequence: 1766002, addedAt: 1775931135467, isLocal=false, hasPriority=false, score=127, 0xdd250f166c086412fae187ef52dfbe1c4ff9405818781ac50f89d67a77a2d432={MessageCall, 31, 0x5fa84846743cc07ab16106ceabad8e4e0ec1c1b6, EIP1559, mf: 47.74 gwei, pf: 9.28 gwei, gl: 21000, v: 0 wei, to: 0x5fa84846743cc07ab16106ceabad8e4e0ec1c1b6}}"
      }
    }
  }
}

Changes

  • TxPoolInspect: RPC handler, extends AbstractTxPoolContent<String>; delegates the per-transaction summary to PendingTransaction.toTraceLog() (the spec does not enforce a specific free-text format)
  • RpcMethod: added TX_POOL_INSPECT("txpool_inspect")
  • TxPoolJsonRpcMethods: registered TxPoolInspect

The humanReadableView helper is static to allow the unbound method reference TxPoolInspect::humanReadableView, and package-private to allow direct unit testing.

Test plan

  • TxPoolInspectTest — 6 unit tests: empty pool, humanReadableView delegation to toTraceLog(), all-pending, pending/queued split, result values are non-empty strings

🤖 Generated with Claude Code

@fab-10 fab-10 force-pushed the txpool-inspect branch 2 times, most recently from 97296fc to dc42323 Compare March 30, 2026 13:22
@fab-10 fab-10 added doc-change-required Indicates an issue or PR that requires doc to be updated RPC labels Mar 30, 2026
@fab-10 fab-10 marked this pull request as ready for review March 30, 2026 13:37
Copilot AI review requested due to automatic review settings March 30, 2026 13:37
Copy link
Copy Markdown
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

couple of nits and a query about TransactionPoolStatusResult class change

fab-10 and others added 7 commits March 31, 2026 11:48
Implements the spec-defined `txpool_content` endpoint that returns all
pending and queued transactions in the pool, grouped by sender address
and nonce.

- Add `TxPoolContent` RPC handler and `TransactionPoolContentResult`
- Add `getPendingTransactionsBySender()` to `PendingTransactions` interface
- Add `getAllBySender()` to `TransactionsLayer` interface
- Implement in `LayeredPendingTransactions` and `AbstractPendingTransactionsSorter`
- Unit tests: 8 cases covering empty pool, all-pending, all-queued,
  mixed split, multiple senders, and nonce ordering

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements the spec-defined txpool_inspect endpoint that returns a
textual summary of all pending and queued transactions, grouped by
sender address and nonce.

Each transaction is summarised as:
  "<to>: <value> wei + <gasLimit> gas × <gasPrice> wei"
For contract creation the destination is "contract creation".
EIP-1559 transactions use maxFeePerGas as the price field.

Reuses AbstractTxPoolContent<String> so the pending/queued split and
nonce-keyed map building are shared with txpool_content.

Bug fixed: the original humanReadableView delegated to
PendingTransaction.toTraceLog() which produces an internal debug
format, not the spec-defined summary string.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The spec does not enforce the free-text format of the summary string,
so use PendingTransaction.toTraceLog() as the implementation.
Update tests accordingly.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
… consistently

- Extract `contentMap()` into `AbstractTxPoolContent` to eliminate duplication
  between `TxPoolContent` and `TxPoolInspect`
- Use `ptx.getNonce()` in `renderPendingTransactions()` instead of
  `ptx.getTransaction().getNonce()` for consistency with the rest of the class
- Fix `TxPoolInspectTest` to not stub `getTransaction()` since `TxPoolInspect`
  only uses `toTraceLog()` and `getNonce()`

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
…sResult

- Remove `humanReadableView()` wrapper from `TxPoolInspect`; use
  `PendingTransaction::toTraceLog` directly as the method reference adds no value
- Restore dedicated `TransactionPoolStatusResult` for `txpool_status` with
  hex-encoded getters, keeping `TransactionPoolResult<T>` for content/inspect
  methods only

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 requested a review from macfarla March 31, 2026 10:23
@fab-10 fab-10 merged commit 5873f56 into besu-eth:main Mar 31, 2026
46 checks passed
@fab-10 fab-10 deleted the txpool-inspect branch March 31, 2026 10:49
@bgravenorst bgravenorst removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants