Skip to content

fix(net): reduce memory usage in transaction queues - #7011

Open
317787106 wants to merge 2 commits into
tronprotocol:release_v4.8.3from
317787106:fix/restrict_queue_memory
Open

317787106 wants to merge 2 commits into
tronprotocol:release_v4.8.3from
317787106:fix/restrict_queue_memory

Conversation

@317787106

Copy link
Copy Markdown
Collaborator

What does this PR do?

Reduce memory retained by incoming transaction queues and avoid unnecessary serialization allocations in TransactionsMsgHandler.

  • Strip transaction-level unknown fields and redundant ret entries before admission. Both smart-contract events and ordinary transaction tasks retain the cleaned transaction.
  • Drop transactions whose serialized size still exceeds 500 KiB after cleanup, before either queue retains them.
  • Calculate transaction IDs through TransactionCapsule, avoiding the full transaction byte arrays created by temporary TransactionMessage objects during request checks and cleanup.

Why are these changes required?

Queued transactions could retain removable padding or oversized payloads until worker processing and downstream validation. During a backlog, these bytes accumulate in protobuf objects and, for smart-contract messages, cached serialized data. Cleaning and checking transactions before admission reduces this retained memory, while avoiding temporary message construction reduces allocation pressure.

The cleanup preserves signed raw_data and transaction IDs. The size check is an early admission guard; full transaction validation still runs downstream.

This PR has been tested by:

  • 25 targeted tests passed locally, including four new tests covering both transaction paths: padding removal, oversized payload rejection, the exact 500 KiB boundary, and redundant-result cleanup. Assertions also verify retained message bytes and transaction IDs.
  • checkstyleMain, checkstyleTest, and git diff --check passed.

@github-actions
github-actions Bot requested a review from xxo1shine October 8, 2026 03:08
Comment on lines +94 to +95
for (Transaction trx : transactionsMessage.getTransactions().getTransactionsList()) {
Item item = new Item(new TransactionMessage(trx).getMessageId(), InventoryType.TRX);
Item item = new Item(new TransactionCapsule(trx).getTransactionId(), InventoryType.TRX);

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.

[NIT] check() and the request-cleanup loop each create a new capsule and compute the transaction ID. Accepted transactions later compute the ID again in the worker using another capsule. Oversized transactions undergo at least two raw-data hash computations before being dropped, which could be optimized.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in bdafbed. check() now returns its existing ID set for reuse during request cleanup, eliminating the second raw-data serialization and hash computation. Cleanup still happens only after the entire batch passes validation, with regression tests covering this behavior.

Worker-side hashing remains unchanged. Given its low CPU overhead in load tests and production, and expected throughput of at most 10,000 TPS, further optimization is deferred to keep this PR focused on reducing memory usage.

@lvs0075 lvs0075 added this to the GreatVoyage-v4.8.3 milestone Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants