Skip to content

feat(net): optimize transaction rate limiting#6714

Open
xxo1shine wants to merge 1 commit intotronprotocol:developfrom
xxo1shine:feature/trx-rate-limiting-optimization-1
Open

feat(net): optimize transaction rate limiting#6714
xxo1shine wants to merge 1 commit intotronprotocol:developfrom
xxo1shine:feature/trx-rate-limiting-optimization-1

Conversation

@xxo1shine
Copy link
Copy Markdown
Collaborator

@xxo1shine xxo1shine commented Apr 28, 2026

What does this PR do?

Optimize transaction rate limiting with accurate cache size check.

  1. Add Manager.getCachedTransactionSize() = pushTransactionQueue + pendingTransactions + rePushTransactions to expose the true cached transaction count across all three queues.

  2. Fix isTooManyPending() to include pushTransactionQueue, which was previously omitted, causing the pending threshold to be underestimated.

  3. Update TransactionsMsgHandler.isBusy() to factor in the Manager cache size via TronNetDelegate.getCachedTransactionSize(), so the node stops accepting TRX INV messages when the full pipeline is busy.

  4. Make the busy threshold configurable via node.maxTrxCacheSize (default: 50000), replacing the hardcoded MAX_TRX_SIZE constant.

Fixes #6684

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

…e check

1. Add Manager.getCachedTransactionSize() = pushTransactionQueue +
   pendingTransactions + rePushTransactions to expose the true cached
   transaction count across all three queues.

2. Fix isTooManyPending() to include pushTransactionQueue, which was
   previously omitted, causing the pending threshold to be underestimated.

3. Update TransactionsMsgHandler.isBusy() to factor in the Manager
   cache size via TronNetDelegate.getCachedTransactionSize(), so the
   node stops accepting TRX INV messages when the full pipeline is busy.

4. Make the busy threshold configurable via node.maxTrxCacheSize
   (default: 50000), replacing the hardcoded MAX_TRX_SIZE constant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot requested a review from 317787106 April 28, 2026 08:24
@xxo1shine xxo1shine changed the title feat(net): optimize transaction rate limiting with accurate cache size check feat(net): optimize transaction rate limiting Apr 28, 2026
@halibobo1205 halibobo1205 added the topic:net p2p net work, synchronization label Apr 28, 2026
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone Apr 28, 2026
receiveTcpMinDataLength = 2048
maxTransactionPendingSize = 2000
pendingTransactionTimeout = 60000
maxTrxCacheSize = 50000 // total cached trx across handler queues + pending + rePush
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MUST] use # not //

TransactionsMsgHandler handler = new TransactionsMsgHandler();

TronNetDelegate tronNetDelegateMock = Mockito.mock(TronNetDelegate.class);
Mockito.when(tronNetDelegateMock.getCachedTransactionSize()).thenReturn(50_001);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good targeted test for the new busy logic — mocking TronNetDelegate to control the cached size is exactly the right approach 👍

Tiny nit: the magic number 50_001 couples the test to the default maxTrxCacheSize. If someone tweaks the default later, this test silently keeps passing only because 50_001 > 50_000 happens to hold. Using Args.getInstance().getMaxTrxCacheSize() + 1 would be future-proof, and adding a boundary case (e.g. exact-threshold returns false) would catch off-by-one regressions. Totally optional polish.

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

Labels

topic:net p2p net work, synchronization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize isBusy logic by incorporating mempool transactions and enabling configurable MAX_TRX_SIZE

3 participants