-
Notifications
You must be signed in to change notification settings - Fork 615
fix: marking peer as dumb on failed responses #21316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
dcde849
ba4b9da
790dd3c
dcfe010
3f3c218
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,9 +463,18 @@ export class BatchTxRequester { | |
| * this implies we will query these peers couple of more times and give them a chance to "redeem" themselves before completely ignoring them | ||
| */ | ||
| private handleFailResponseFromPeer(peerId: PeerId, responseStatus: ReqRespStatus) { | ||
| //TODO: Should we ban these peers? | ||
| if (responseStatus === ReqRespStatus.FAILURE || responseStatus === ReqRespStatus.UNKNOWN) { | ||
| this.peers.penalisePeer(peerId, PeerErrorSeverity.HighToleranceError); | ||
| this.peers.markPeerDumb(peerId); | ||
| this.txsMetadata.clearPeerData(peerId); | ||
| return; | ||
| } | ||
|
|
||
| // NOT_FOUND means the peer pruned its block proposal — it can no longer serve | ||
| // index-based requests, but this is a legitimate state so we don't penalize. | ||
| if (responseStatus === ReqRespStatus.NOT_FOUND) { | ||
| this.peers.markPeerDumb(peerId); | ||
| this.txsMetadata.clearPeerData(peerId); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -555,10 +564,7 @@ export class BatchTxRequester { | |
| return; | ||
| } | ||
|
|
||
| // If block response is invalid we still want to query this peer in the future | ||
| // Because they sent successful response, so they might become smart peer in the future | ||
| // Or send us needed txs | ||
| if (!this.isBlockResponseValid(response)) { | ||
| if (this.handleArchiveRootFromResponse(peerId, response)) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -576,13 +582,33 @@ export class BatchTxRequester { | |
| this.smartRequesterSemaphore.release(); | ||
| } | ||
|
|
||
| private isBlockResponseValid(response: BlockTxsResponse): boolean { | ||
| /** | ||
| * Validates the archive root in the response and handles any mismatch. | ||
| * Returns true if the caller should stop processing (i.e., there was a mismatch). | ||
| * | ||
| * - Archives match: returns false (continue processing). | ||
| * - Response archive is Fr.ZERO (peer pruned proposal, legitimate): marks peer dumb, returns true. | ||
| * - Non-zero archive mismatch (malicious response): penalises + marks dumb, returns true. | ||
| */ | ||
| private handleArchiveRootFromResponse(peerId: PeerId, response: BlockTxsResponse): boolean { | ||
| const archiveRootsMatch = this.blockTxsSource.archive.toString() === response.archiveRoot.toString(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deffrian @mrzeszutko let's penalise peer in case of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deffrian @mrzeszutko actually let me think bit more on this, not sure it's as simple as this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree here with amp P.S.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| const peerHasSomeTxsFromProposal = !response.txIndices.isEmpty(); | ||
| return archiveRootsMatch && peerHasSomeTxsFromProposal; | ||
| if (archiveRootsMatch) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!response.archiveRoot.isZero()) { | ||
| this.peers.penalisePeer(peerId, PeerErrorSeverity.LowToleranceError); | ||
| } | ||
|
|
||
| this.peers.markPeerDumb(peerId); | ||
| this.txsMetadata.clearPeerData(peerId); | ||
| return true; | ||
| } | ||
|
|
||
| private peerHasSomeTxsWeAreMissing(_peerId: PeerId, response: BlockTxsResponse): boolean { | ||
| if (response.txIndices.isEmpty()) { | ||
| return false; | ||
| } | ||
| const txsPeerHas = new Set(this.extractHashesPeerHasFromResponse(response).map(h => h.toString())); | ||
| return this.txsMetadata.getMissingTxHashes().intersection(txsPeerHas).size > 0; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being nitpicky, this now reads weird, you have
And if it returns
falsethen it singals everytihg being ok, otherwise it's not ok.Why not rename it to
responseArchiveRootIsBador something like that?So it reads better and returns
trueif badThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored - did not really like just changing the name as the method had some side effects apart of the mismatch check