Skip to content

feat(txpool): add txpool_contentFrom rpc method#11048

Closed
bomanaps wants to merge 9 commits into
NethermindEth:masterfrom
bomanaps:add-txpool-contentFrom-nethermind
Closed

feat(txpool): add txpool_contentFrom rpc method#11048
bomanaps wants to merge 9 commits into
NethermindEth:masterfrom
bomanaps:add-txpool-contentFrom-nethermind

Conversation

@bomanaps
Copy link
Copy Markdown

@bomanaps bomanaps commented Apr 6, 2026

Fixes Closes Resolves #

Please choose one of the keywords above to refer to the issue this PR solves followed by the issue number (e.g. Fixes #000). If no issue number, remove the line. Also, remove everything marked optional that is not applicable. Remove this note after reading.

Changes

  • List the changes

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Optional. Remove if not applicable.

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

If yes, fill in the details here. Remove if not applicable.

Remarks

Optional. Remove if not applicable.

@bomanaps
Copy link
Copy Markdown
Author

bomanaps commented Apr 6, 2026

ethereum/execution-apis#758 in respect to this

Copy link
Copy Markdown
Contributor

@batrr batrr left a comment

Choose a reason for hiding this comment

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

This module seems allocation-heavy, but out of scope, I guess.


public ResultWrapper<TxPoolContentFrom> txpool_contentFrom(Address address)
{
var poolInfo = txPoolInfoProvider.GetInfo();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let’s avoid building the full pool here. Fetch only this sender with ITxPool.GetPendingTransactionsBySender(Address)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This means I will have to add ITxPool to TxPoolRpcModule's constructor and the replicat the nonce-sequencing logic inline, which also requires access to account state?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about TxPoolInfoProvider.GetInfo(Address)?
TxPoolInfoProvider already has ITxPool and we can reuse some code from TxPoolInfoProvider.GetInfo()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree, this is wasteful, should be passed down

TransactionForRpcContext extraData = new(chainId);
Pending = info.Pending.TryGetValue(address, out var pending)
? pending.ToDictionary(v => v.Key, v => TransactionForRpc.FromTransaction(v.Value, extraData))
: new Dictionary<ulong, TransactionForRpc>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

uuse static dictionary for empty ones to avoid allocating.

Suggested change
: new Dictionary<ulong, TransactionForRpc>();
: Empty;

public ResultWrapper<TxPoolContentFrom> txpool_contentFrom(Address address)
{
var poolInfo = txPoolInfoProvider.GetInfo();
var chainId = specProvider.ChainId;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

avoid var please


public ResultWrapper<TxPoolContentFrom> txpool_contentFrom(Address address)
{
var poolInfo = txPoolInfoProvider.GetInfo();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree, this is wasteful, should be passed down

@batrr
Copy link
Copy Markdown
Contributor

batrr commented Apr 7, 2026

@claude review

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 7, 2026

Claude Code is working…

I'll analyze this and get back to you.

View job run

@batrr
Copy link
Copy Markdown
Contributor

batrr commented Apr 7, 2026

Review findings (Claude)

# Category Location Issue
1 Bug TxPoolContentFrom.cs:697 Mutable static _emptyDictionary assigned to public Dictionary<> properties — callers can corrupt it. Change property types to IReadOnlyDictionary<ulong, TransactionForRpc>.
2 Performance TxPoolInfoProvider.cs:17 No early exit when transactions.Length == 0; allocates 4 dicts for the common case of an unknown address. Add if (transactions.Length == 0) return new TxPoolInfo([], []);.
3 Performance TxPoolInfoProvider.cs:20–21 pending/queued dicts eagerly allocated before knowing if any tx matches. Use lazy (pending ??= new()).Add(...).
5 Coding Style TxPoolInfoProvider.cs:18–21 var used for simple types (accountNonce, expectedNonce, pending, queued). Spell out types per coding-style.md.
6 Coding Style TxPoolInfoProvider.cs:23 OrderBy LINQ on a Transaction[]. Use Array.Sort + foreach instead.
7 Test Quality TxPoolInfoProvider, TxPoolRpcModule No tests for txpool_contentFrom / GetInfo(Address). Nonce-gap edge cases (e.g. nonces 5 and 7 with account nonce 5) are unverified.

Comment thread src/Nethermind/Nethermind.TxPool/TxPoolInfoProvider.cs Outdated
Comment thread src/Nethermind/Nethermind.TxPool/TxPoolInfoProvider.cs Outdated
Comment thread src/Nethermind/Nethermind.TxPool/TxPoolInfoProvider.cs Outdated
batrr
batrr previously approved these changes Apr 8, 2026
@LukaszRozmej
Copy link
Copy Markdown
Member

@claude review

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 8, 2026

Claude Code is working…

I'll analyze this and get back to you.

View job run

Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

lacks any tests

@bomanaps bomanaps requested a review from svlachakis as a code owner April 21, 2026 15:40
@svlachakis
Copy link
Copy Markdown
Contributor

Replaced by #11305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants