Repository navigation
Conversation
Reject decompressed BLOCK payloads above the existing block size limit before parsing. Scan top-level transaction fields without allocating message objects and bound their count using the existing 80-byte minimum transaction size to prevent excessive allocations before rejection. Share the limits with existing validation and cover size/count boundaries, opaque bytes, unknown groups and malformed wire data in regression tests.
Reject inbound TRXS messages above MAX_TRX_FETCH_PER_PEER transaction entries before protobuf parsing. Count only top-level transaction fields and skip their contents without constructing messages. Keep EOF validation in the precheck and add regression coverage for count boundaries, rejection before parsing, opaque bytes, unknown groups, wrong wire types and malformed input.
Reject TRX messages in the P2P message factory before copying payload bytes or constructing TransactionMessage. Preserve the NO_SUCH_MESSAGE category already used by the dispatcher for this unsupported message type. Cover early rejection of canonical, malformed and near-frame-limit inputs, the P2P disconnect reason, supported message decoding and direct TransactionMessage construction for API and internal callers.
Let unsupported TRX messages fall through the private factory dispatch instead of handling them specially in the public entry point. Continue rejecting before TransactionMessage construction or transaction parsing, and align regression tests with that guarantee rather than requiring rejection before the payload copy.
SeriousCoding789
left a comment
There was a problem hiding this comment.
Thanks for this. Overall the change looks correct to me, and I don't see it affecting honest traffic. I also ran the network tests on the PR head locally, and they pass.
- BLOCK: the size limit is the one the handler already applied, now enforced before parsing, and the transaction-count limit sits above anything a valid block can contain. This removes most of the cost a peer could cause on this path before its block is rejected.
- TRX: nothing handled it before, so rejecting it before decoding keeps the same outcome without the parse.
- TRXS: the 1,000-entry limit matches the most a node asks for in one fetch, so honest replies should not be affected, including those from older versions.
My one concern is how much the TRXS check covers. It limits the number of top-level entries but not what each entry carries, so a frame within the limit can still cost about as much to parse as before. The description lists nested budgets as out of scope, while "Follow up: None" reads as if nothing is left on this path. As far as I can see, the remaining cost can be bounded before parsing without touching honest traffic: reject TRXS from a peer the node has no outstanding transaction request to, limit the frame size to what honest replies use, and give each entry a size and structure budget. Whether that goes into this PR or a follow-up is the team's call, but noting it in the description would make the remaining scope clear.
On BLOCK, the size limit now bounds the work, though nested content within that limit is still parsed before the request check.
|
@SeriousCoding789 Thanks for the review. We agree that the top-level TRXS count check does not bound all nested parsing work. The current checks provide early rejection of oversized BLOCK payloads, excessive transaction counts, and unsupported TRX messages, while retaining the existing transport frame-size limit. Deeper TRXS content inspection would add CPU work to normal message processing, and tighter size or structure limits would require separate compatibility validation. Given the existing constraints, the incremental benefit of those restrictions has not yet been established. We prefer to keep this PR focused and revisit additional hardening when profiling or operational evidence justifies it. I’ve updated Follow up to make this deferral explicit and acknowledge the remaining nested parsing costs. |
Thanks for updating the Follow up. I agree the per-entry structure budget can wait: it is the one check that reads every entry, and its limit needs care so that no valid transaction falls outside it. The other two checks don't carry those costs, though:
On the benefit: in my local runs, a frame that stays under the entry cap can cost more to parse than the frames the cap rejects, so on TRXS the count check alone does not lower the worst case. With the two checks above, only peers the node is fetching from could send TRXS, and the largest frame would drop from 5 MiB to about 1.5 MB. Both are a few lines on the receive path and leave honest traffic unchanged, so they seem worth including in this PR, with the per-entry budget left for the follow-up. |
|
What does this PR do?
Add read-only wire-format prechecks to inbound BLOCK and TRXS messages, and reject unsupported P2P TRX messages before transaction parsing:
BLOCK_SIZE + 1000(2,001,000 bytes), or more thanMAX_BLOCK_SIZE / MIN_TRANSACTION_SIZEtop-level transaction entries (currently 25,012), beforeBlockCapsuleconstruction.MAX_TRX_FETCH_PER_PEERtop-level transaction entries (currently 1,000), beforeProtocol.Transactions.parseFrom().TronMessageFactory. The private dispatch now rejects it throughdefaultwithNO_SUCH_MESSAGE, beforeTransactionMessageconstruction or transaction parsing.Why are these changes required?
BLOCK and TRXS messages are parsed before handler-level request and size checks. BLOCK also creates a capsule for every transaction before those checks. Inputs that are ultimately rejected can therefore incur substantial allocation and parsing work.
P2P TRX messages were already unsupported by the event dispatcher, but the factory still parsed them first. Removing that factory branch rejects them before transaction decoding while preserving the existing unsupported-message disconnect reason.
The BLOCK count bound follows the existing 80-byte minimum enforced by
validBlock()on advertisement and sync paths. Header and repeated-field encoding overhead make this a conservative upper bound. The TRXS count bound follows our existing maximum of 1,000 entries per TRX fetch request; responses may split that request into smaller batches.This PR has been tested by:
Local validation on macOS ARM64 / JDK 17:
TronMessageFactoryTest(5),BlockMessageTest(11),TransactionsMessageTest(9),TransactionsMsgHandlerTest(30), andMessageHandlerTest(2).TransactionMessageconstruction, and supported message decoding.The full regression suite was not completed.
Follow up
Further TRXS hardening is deferred. The current early checks address outer message/list amplification while retaining the existing transport frame-size limit; nested transaction and unknown-field contents can still incur parsing costs.
Deeper content prechecks would add CPU work to normal message processing, and tighter admission limits would require separate compatibility validation. The incremental benefit of additional restrictions under the current limits has not yet been established. Revisit request-state gating, tighter size limits, or per-entry structure budgets when profiling or operational evidence justifies them.
Extra details
The BLOCK size check applies to the decompressed protobuf payload, excluding the message-type byte and transport framing. The existing handler checks parsed
getSerializedSize(); the new raw-size limit also rejects oversized noncanonical encodings that normalize to a smaller parsed message. This stricter admission behavior is covered by a regression test.TRXS receives only a top-level transaction-count precheck and retains the existing transport frame-size limit. These checks address outer transaction-list amplification; nested transaction and unknown-field structure budgets are outside this scope.
Unsupported P2P TRX messages are rejected in the private factory dispatch after the existing payload slice, before transaction decoding. Direct
TransactionMessageconstruction for API and internal callers remains available.Different peer fetch limits
Nodes do not need identical
MAX_TRX_FETCH_PER_PEERvalues. Under the current per-request response flow, different values alone do not cause a disconnect: each requester limits its own fetch batch and accepts up to that same local limit, while the responder returns only transactions from that request, possibly split into smaller TRXS messages. The responder's own fetch limit does not cap its outgoing responses.For example, A with a limit of 2,000 can request 2,000 transactions from B with a limit of 1,000 and accept B's responses. In the reverse direction, B requests at most 1,000 from A and receives at most 1,000 per response. This reasoning relies on the current behavior of replying per request without merging responses across fetch requests.
BLOCK precheck cost
The precheck reads top-level field tags and lengths, counts transaction entries and skips their payloads. It does not parse transaction contents or create per-transaction protobuf/capsule objects. Cost therefore depends mainly on field count, length encoding and cache layout.
In a warmed local microbenchmark on macOS ARM64 / OpenJDK 17.0.19 with three independent JVMs, the slowest tested scenario (8,500 synthetic transactions, approximately 1.90 MB) had a precheck median of approximately 75 µs per block. The highest observed batch-average was approximately 80 µs per block. For the same scenario, parsing plus capsule construction changed from approximately 1.91 ms to 2.19 ms across JVM medians, with per-JVM increases of 14–24%.
These are synthetic microbenchmark observations, not a worst-case latency bound or a production throughput estimate. Measurements exclude protobuf-filter work, networking, signature verification and database operations.
The timing figures above cover BLOCK precheck only.