feat(net): add P2P message deduplication and length validation#6712
Open
xxo1shine wants to merge 1 commit intotronprotocol:developfrom
Open
feat(net): add P2P message deduplication and length validation#6712xxo1shine wants to merge 1 commit intotronprotocol:developfrom
xxo1shine wants to merge 1 commit intotronprotocol:developfrom
Conversation
- FetchInvDataMsgHandler: reject messages with duplicate hashes - TransactionsMsgHandler: reject messages with duplicate transactions - SyncBlockChainMsgHandler: reject blockIds list exceeding 30 entries - Add MAX_SYNC_CHAIN_IDS = 30 constant to NetConstants - Add unit tests covering duplicate rejection and boundary values All violations throw P2pException(BAD_MESSAGE), triggering peer disconnect via existing P2pEventHandlerImpl error path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
alan-eth
reviewed
Apr 28, 2026
| public static final int MSG_CACHE_DURATION_IN_BLOCKS = 5; | ||
| public static final int MAX_BLOCK_FETCH_PER_PEER = 100; | ||
| public static final int MAX_TRX_FETCH_PER_PEER = 1000; | ||
| public static final int MAX_SYNC_CHAIN_IDS = 30; |
There was a problem hiding this comment.
Nice to have a named constant here instead of a magic number! 👍
Quick question — how was 30 chosen? Observed from real traffic, or estimated from getBlockChainSummary()'s log-step algorithm?
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?
Add P2P message deduplication and length validation:
All violations throw
P2pException(BAD_MESSAGE), triggering peer disconnect via existingP2pEventHandlerImplerror path.Fixes #6667
Why are these changes required?
This PR has been tested by:
Follow up
Extra details