Skip to content

fix(net): precheck id counts of inventory and sync messages - #7145

Closed
SeriousCoding789 wants to merge 1 commit into
tronprotocol:release_v4.8.3from
Little-Peony:fix/net-inventory-id-precheck
Closed

SeriousCoding789 wants to merge 1 commit into
tronprotocol:release_v4.8.3from
Little-Peony:fix/net-inventory-id-precheck

Conversation

@SeriousCoding789

@SeriousCoding789 SeriousCoding789 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • INVENTORY / FETCH_INV_DATA: limit is InventoryMessage.MAX_IDS_COUNT, which is SENDER_LIMIT_MARGIN times the largest of MAX_SPREAD_SIZE, MAX_TRX_FETCH_PER_PEER and MAX_BLOCK_FETCH_PER_PEER. MAX_SPREAD_SIZE moves from AdvService to NetConstants.
  • BLOCK_CHAIN_INVENTORY: limit is ChainInventoryMessage.MAX_IDS_COUNT (SYNC_FETCH_BATCH_NUM + 1). ChainInventoryMsgHandler now uses the same constant.
  • SYNC_BLOCK_CHAIN: limit is MAX_SYNC_CHAIN_IDS, the limit SyncBlockChainMsgHandler already uses.
  • Shared counting loop: the loop that BlockMessage and TransactionsMessage used for the same kind of check moves to TronMessage.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:

  • An inventory carries about MAX_SPREAD_SIZE ids, the size of the AdvService spread queue. The margin covers concurrent broadcasts.
  • A fetch asks for at most MAX_TRX_FETCH_PER_PEER advertised ids or MAX_BLOCK_FETCH_PER_PEER sync blocks.
  • A chain inventory reply lists the common block and at most SYNC_FETCH_BATCH_NUM blocks after it.
  • A chain summary grows with the logarithm of the chain length.

These bounds hold from GreatVoyage-v4.1.2 onward.

This PR has been tested by:

  • Unit tests:
    • New InventoryPrecheckTest covers limit boundaries, rejection before decoding, and outcomes identical to the parser within the limits.
    • New case in P2pEventHandlerImplTest.
    • The existing net message, message handler and AdvService tests pass.
  • Static checks: checkstyleMain, checkstyleTest and 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.

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.
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.

2 participants