Repository navigation
fix(net): precheck id counts of inventory and sync messages - #7145
Closed
SeriousCoding789 wants to merge 1 commit into
Closed
SeriousCoding789 wants to merge 1 commit into
SeriousCoding789 wants to merge 1 commit into
Conversation
Reject INVENTORY, FETCH_INV_DATA, BLOCK_CHAIN_INVENTORY and SYNC_BLOCK_CHAIN messages whose id lists exceed what senders produce before decoding them. Move the counting loop used by BLOCK and TRXS into TronMessage.checkRepeatedCount() and reuse it, and move MAX_SPREAD_SIZE into NetConstants so the inventory limit can refer to it.
Little-Peony
force-pushed
the
fix/net-inventory-id-precheck
branch
from
December 4, 2026 13:47
2f901f1 to
6bc9d22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Inbound INVENTORY, FETCH_INV_DATA, BLOCK_CHAIN_INVENTORY and SYNC_BLOCK_CHAIN messages whose id lists exceed a limit are now rejected before they are decoded:
InventoryMessage.MAX_IDS_COUNT, which isSENDER_LIMIT_MARGINtimes the largest ofMAX_SPREAD_SIZE,MAX_TRX_FETCH_PER_PEERandMAX_BLOCK_FETCH_PER_PEER.MAX_SPREAD_SIZEmoves fromAdvServicetoNetConstants.ChainInventoryMessage.MAX_IDS_COUNT(SYNC_FETCH_BATCH_NUM + 1).ChainInventoryMsgHandlernow uses the same constant.MAX_SYNC_CHAIN_IDS, the limitSyncBlockChainMsgHandleralready uses.BlockMessageandTransactionsMessageused for the same kind of check moves toTronMessage.checkRepeatedCount(), and all of these messages now call it. BLOCK and TRXS behave as before.Why are these changes required?
BLOCK and TRXS already check their entry counts before decoding (#7115). These four message types were decoded first and their counts checked afterwards. The limits follow what senders produce, so honest peers are not affected:
MAX_SPREAD_SIZEids, the size of the AdvService spread queue. The margin covers concurrent broadcasts.MAX_TRX_FETCH_PER_PEERadvertised ids orMAX_BLOCK_FETCH_PER_PEERsync blocks.SYNC_FETCH_BATCH_NUMblocks after it.These bounds hold from GreatVoyage-v4.1.2 onward.
This PR has been tested by:
InventoryPrecheckTestcovers limit boundaries, rejection before decoding, and outcomes identical to the parser within the limits.P2pEventHandlerImplTest.AdvServicetests pass.checkstyleMain,checkstyleTestand the Math usage check pass.The full regression suite was not run.
Follow up
None.
Extra details
A message over its limit is rejected with BAD_MESSAGE (BAD_PROTOCOL disconnect), as other malformed inventory and sync messages are. For BLOCK_CHAIN_INVENTORY and SYNC_BLOCK_CHAIN the outcome is unchanged; only the point where the check runs moves to before decoding.