fix(p2p): penalize peers for errors during response reading#21680
Merged
mralj merged 1 commit intomerge-train/spartanfrom Mar 17, 2026
Merged
fix(p2p): penalize peers for errors during response reading#21680mralj merged 1 commit intomerge-train/spartanfrom
mralj merged 1 commit intomerge-train/spartanfrom
Conversation
Errors in readMessage (invalid status bytes, oversized snappy responses, corrupt data) were caught and silently converted to UNKNOWN status returns. Since sendRequestToPeer only calls handleResponseError in its own catch block, none of these errors resulted in peer penalties. The request was simply retried with another peer, allowing a malicious peer to waste bandwidth indefinitely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
14a8239 to
34ee6a4
Compare
Collaborator
Flakey Tests🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
mralj
approved these changes
Mar 17, 2026
Contributor
mralj
left a comment
There was a problem hiding this comment.
@spalladino I cannot find anything wrong with the reasoning/implementation - I think this is good callout
AztecBot
pushed a commit
that referenced
this pull request
Mar 17, 2026
## Motivation
Errors during `readMessage` (oversized snappy responses, corrupt data,
etc.) were caught and silently converted to `{ status: UNKNOWN }` return
values instead of re-throwing. Since `sendRequestToPeer` only calls
`handleResponseError` in its own catch block, none of these errors
resulted in peer penalties. The request was simply retried with another
peer, allowing a malicious peer to waste bandwidth indefinitely.
## Approach
Re-throw non-protocol errors from `readMessage` so they propagate to
`sendRequestToPeer`'s catch block where `handleResponseError` applies
peer penalties. Additionally, introduce a dedicated
`OversizedSnappyResponseError` class so oversized responses get a
harsher `LowToleranceError` penalty (score -50, banned after 2 offenses)
instead of falling through to the generic `HighToleranceError`
catch-all.
## Changes
- **p2p (reqresp)**: Changed `readMessage` catch block to only return
status for `ReqRespStatusError` and re-throw all other errors, so they
reach `handleResponseError` for penalization
- **p2p (encoding)**: Added `OversizedSnappyResponseError` class for
explicit categorization
- **p2p (reqresp)**: Added `OversizedSnappyResponseError` handling in
`categorizeResponseError` with `LowToleranceError` severity
Collaborator
|
✅ Successfully backported to backport-to-v4-next-staging #21654. |
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.
Motivation
Errors during
readMessage(oversized snappy responses, corrupt data, etc.) were caught and silently converted to{ status: UNKNOWN }return values instead of re-throwing. SincesendRequestToPeeronly callshandleResponseErrorin its own catch block, none of these errors resulted in peer penalties. The request was simply retried with another peer, allowing a malicious peer to waste bandwidth indefinitely.Approach
Re-throw non-protocol errors from
readMessageso they propagate tosendRequestToPeer's catch block wherehandleResponseErrorapplies peer penalties. Additionally, introduce a dedicatedOversizedSnappyResponseErrorclass so oversized responses get a harsherLowToleranceErrorpenalty (score -50, banned after 2 offenses) instead of falling through to the genericHighToleranceErrorcatch-all.Changes
readMessagecatch block to only return status forReqRespStatusErrorand re-throw all other errors, so they reachhandleResponseErrorfor penalizationOversizedSnappyResponseErrorclass for explicit categorizationOversizedSnappyResponseErrorhandling incategorizeResponseErrorwithLowToleranceErrorseverity