Repository navigation
fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport #5959) - #6003
Merged
Merged
Conversation
…witching to consensus (#5959) ### Problem `FilterMsgBytes` returned an error for any `BlockResponse` once the block pool had stopped (`!r.pool.IsRunning()`). That error panicked inside `p2p/peer.go`'s `onReceive` and was recovered into `StopPeerForError` — a hard disconnect. Because requests for the last blocks are typically still in-flight when the catch-up ticker fires and `pool.Stop()` is called, both request targets (primary and secondary peer) were disconnected on every normal sync completion, exactly when the node needs them for consensus gossip. Root cause introduced by #5860 (`FilterMsgBytes`). Not covered by #5950, which handles the second-peer race while the pool is still running. ### Fix Split the single `||` guard into two branches: - `!r.enabled.Load()` — node never ran blocksync; any `BlockResponse` is genuinely unsolicited → reject (unchanged behaviour) - `!r.pool.IsRunning()` — pool stopped for consensus switch; requests we sent before the transition are still in-flight; the peers are honest → allow, but still run `validateMaxVotes` on the response The `AddBlock` call that follows returns `"already committed block"` and logs it; no peer state is mutated and no disconnect occurs. `pool.sendError` is already a no-op once the pool is stopped (it guards on `!pool.IsRunning()`), so the pre-fix punishment for genuinely out-of-window responses in this window was already silently dropped the moment `poolEventsRoutine` exited. The post-stop branch skips the `HasPendingRequestFrom` peer-identity check (any peer, not just the one we solicited, may legitimately answer a stale request) but still enforces `validateMaxVotes` — once the pool stops, any connected peer can reach this path, and the commit-signature cap exists to prevent a heap-amplification DoS regardless of sender. Caught by review on this PR; added a dedicated regression test (`rejects oversized BlockResponse after pool stops for consensus switch`) so an oversized response is still rejected in this window. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: dianab-cl <[email protected]> (cherry picked from commit 17bb385) # Conflicts: # CHANGELOG.md # blocksync/reactor.go # blocksync/reactor_test.go
Contributor
Author
|
Cherry-pick of 17bb385 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
Contributor
|
PR author is not in the allowed authors list. |
swift1337
approved these changes
Jul 27, 2026
Contributor
Author
|
Tick the box to add this pull request to the merge queue (same as
|
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.
Problem
FilterMsgBytesreturned an error for anyBlockResponseonce the block pool had stopped (!r.pool.IsRunning()). That error panicked insidep2p/peer.go'sonReceiveand was recovered intoStopPeerForError— a hard disconnect. Because requests for the last blocks are typically still in-flight when the catch-up ticker fires andpool.Stop()is called, both request targets (primary and secondary peer) were disconnected on every normal sync completion, exactly when the node needs them for consensus gossip.Root cause introduced by #5860 (
FilterMsgBytes). Not covered by #5950, which handles the second-peer race while the pool is still running.Fix
Split the single
||guard into two branches:!r.enabled.Load()— node never ran blocksync; anyBlockResponseis genuinely unsolicited → reject (unchanged behaviour)!r.pool.IsRunning()— pool stopped for consensus switch; requests we sent before the transition are still in-flight; the peers are honest → allow, but still runvalidateMaxVoteson the responseThe
AddBlockcall that follows returns"already committed block"and logs it; no peer state is mutated and no disconnect occurs.pool.sendErroris already a no-op once the pool is stopped (it guards on!pool.IsRunning()), so the pre-fix punishment for genuinely out-of-window responses in this window was already silently dropped the momentpoolEventsRoutineexited.The post-stop branch skips the
HasPendingRequestFrompeer-identity check (any peer, not just the one we solicited, may legitimately answer a stale request) but still enforcesvalidateMaxVotes— once the pool stops, any connected peer can reach this path, and the commit-signature cap exists to prevent a heap-amplification DoS regardless of sender. Caught by review on this PR; added a dedicated regression test (rejects oversized BlockResponse after pool stops for consensus switch) so an oversized response is still rejected in this window.PR checklist
CHANGELOG.mddocs/orspec/) and code commentsThis is an automatic backport of pull request #5959 done by [Mergify](https://mergify.com).