Skip to content

fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport #5959) - #6003

Merged
swift1337 merged 4 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5959
Jul 27, 2026
Merged

swift1337 merged 4 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5959

Conversation

@mergify

@mergify mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

This is an automatic backport of pull request #5959 done by [Mergify](https://mergify.com).

…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
@mergify mergify Bot added the conflicts label Jul 27, 2026
@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 17bb385 has failed:

On branch mergify/bp/v0.38.x/pr-5959
Your branch is up to date with 'origin/v0.38.x'.

You are currently cherry-picking commit 17bb3853.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   CHANGELOG.md
	both modified:   blocksync/reactor.go
	both modified:   blocksync/reactor_test.go

no changes added to commit (use "git add" and/or "git commit -a")

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

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@swift1337
swift1337 merged commit e9ffcb9 into v0.38.x Jul 27, 2026
17 checks passed
@swift1337
swift1337 deleted the mergify/bp/v0.38.x/pr-5959 branch July 27, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants