Repository navigation
fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport #5959) - #6002
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_test.go
|
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 |
|
PR author is not in the allowed authors list. |
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Unsigned commits:
|
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Unsigned commits:
|
|
Tick the box to add this pull request to the merge queue (same as
|
# Conflicts: # CHANGELOG.md
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Unsigned commits:
|
…witching to consensus (backport cometbft#5959) (cometbft#6002) `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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#5950, which handles the second-peer race while the pool is still running. 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. --- - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <hr>This is an automatic backport of pull request cometbft#5959 done by [Mergify](https://mergify.com). --------- Co-authored-by: JayT106 <[email protected]> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 6ed1d96)
* fix(consensus): release cs.mtx before sending to statsMsgQueue (backport cometbft#5813) (cometbft#5999) ## Problem `handleMsg` sent to `cs.statsMsgQueue` while holding `cs.mtx`. If the buffer fills, the send blocks indefinitely — stalling the entire consensus state machine. ## Fix Hoist the `statsMsgQueue` send outside the `switch`, release `cs.mtx` before the send and re-acquire after. This also removes the duplicated `added` checks inside each `case` block, replacing them with a single check at the bottom. ## Testing - `TestHandleMsgReleasesLockBeforeStatsMsgQueueSend`: verifies `GetRoundState()` is not blocked while `handleMsg` is blocked on the send. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5813 done by [Mergify](https://mergify.com). Co-authored-by: songgaoye <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 4f1535b) * fix(consensus): correct loop condition in checkDoubleSigningRisk for height=1 (backport cometbft#5668) (cometbft#6000) Fixes: cometbft#5435 When `double_sign_check_height` is set to `1`, the loop condition `i := int64(1); i < 1` is never satisfied, resulting in zero iterations and no double sign checks being performed. This makes the setting functionally equivalent to `0` (disabled), silently giving validators false confidence in their double-sign protection. Changed the loop condition from `i < doubleSignCheckHeight` to `i <= doubleSignCheckHeight` so that a value of `1` correctly checks `height - 1`, matching the documented intent of the configuration parameter. The existing guard `if doubleSignCheckHeight > height` already prevents out-of-bounds lookups on short chains, so no additional bounds protection is needed. - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5668 done by [Mergify](https://mergify.com). --------- Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 222949a) * fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport cometbft#5959) (cometbft#6002) `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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#5950, which handles the second-peer race while the pool is still running. 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. --- - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <hr>This is an automatic backport of pull request cometbft#5959 done by [Mergify](https://mergify.com). --------- Co-authored-by: JayT106 <[email protected]> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 6ed1d96) * ci: run e2e-test on ubuntu-latest, not unavailable Depot runner Fork has no Depot runner registered, so depot-ubuntu-24.04-4 jobs queue indefinitely and get cancelled at the 24h timeout. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: songgaoye <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: jay.tseng <[email protected]>
* fix(consensus): release cs.mtx before sending to statsMsgQueue (backport cometbft#5813) (cometbft#5999) `handleMsg` sent to `cs.statsMsgQueue` while holding `cs.mtx`. If the buffer fills, the send blocks indefinitely — stalling the entire consensus state machine. Hoist the `statsMsgQueue` send outside the `switch`, release `cs.mtx` before the send and re-acquire after. This also removes the duplicated `added` checks inside each `case` block, replacing them with a single check at the bottom. - `TestHandleMsgReleasesLockBeforeStatsMsgQueueSend`: verifies `GetRoundState()` is not blocked while `handleMsg` is blocked on the send. --- - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5813 done by [Mergify](https://mergify.com). Co-authored-by: songgaoye <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dmitry S <[email protected]> On v0.40.0 only the e2e runner change applies; the upstream commits are already in v0.40.0. (cherry picked from commit 4f1535b) * fix(consensus): correct loop condition in checkDoubleSigningRisk for height=1 (backport cometbft#5668) (cometbft#6000) Fixes: cometbft#5435 When `double_sign_check_height` is set to `1`, the loop condition `i := int64(1); i < 1` is never satisfied, resulting in zero iterations and no double sign checks being performed. This makes the setting functionally equivalent to `0` (disabled), silently giving validators false confidence in their double-sign protection. Changed the loop condition from `i < doubleSignCheckHeight` to `i <= doubleSignCheckHeight` so that a value of `1` correctly checks `height - 1`, matching the documented intent of the configuration parameter. The existing guard `if doubleSignCheckHeight > height` already prevents out-of-bounds lookups on short chains, so no additional bounds protection is needed. - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5668 done by [Mergify](https://mergify.com). --------- Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> On v0.40.0 only the e2e runner change applies; the upstream commits are already in v0.40.0. (cherry picked from commit 222949a) * fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport cometbft#5959) (cometbft#6002) `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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#5950, which handles the second-peer race while the pool is still running. 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. --- - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <hr>This is an automatic backport of pull request cometbft#5959 done by [Mergify](https://mergify.com). --------- Co-authored-by: JayT106 <[email protected]> Co-authored-by: Dmitry S <[email protected]> On v0.40.0 only the e2e runner change applies; the upstream commits are already in v0.40.0. (cherry picked from commit 6ed1d96) * ci: run e2e-test on ubuntu-latest, not unavailable Depot runner Fork has no Depot runner registered, so depot-ubuntu-24.04-4 jobs queue indefinitely and get cancelled at the 24h timeout. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: songgaoye <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: jay.tseng <[email protected]> On v0.40.0 only the e2e runner change applies; the upstream commits are already in v0.40.0. (cherry picked from commit 14b7b93)
* fix(consensus): release cs.mtx before sending to statsMsgQueue (backport cometbft#5813) (cometbft#5999) ## Problem `handleMsg` sent to `cs.statsMsgQueue` while holding `cs.mtx`. If the buffer fills, the send blocks indefinitely — stalling the entire consensus state machine. ## Fix Hoist the `statsMsgQueue` send outside the `switch`, release `cs.mtx` before the send and re-acquire after. This also removes the duplicated `added` checks inside each `case` block, replacing them with a single check at the bottom. ## Testing - `TestHandleMsgReleasesLockBeforeStatsMsgQueueSend`: verifies `GetRoundState()` is not blocked while `handleMsg` is blocked on the send. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5813 done by [Mergify](https://mergify.com). Co-authored-by: songgaoye <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 4f1535b) * fix(consensus): correct loop condition in checkDoubleSigningRisk for height=1 (backport cometbft#5668) (cometbft#6000) Fixes: cometbft#5435 When `double_sign_check_height` is set to `1`, the loop condition `i := int64(1); i < 1` is never satisfied, resulting in zero iterations and no double sign checks being performed. This makes the setting functionally equivalent to `0` (disabled), silently giving validators false confidence in their double-sign protection. Changed the loop condition from `i < doubleSignCheckHeight` to `i <= doubleSignCheckHeight` so that a value of `1` correctly checks `height - 1`, matching the documented intent of the configuration parameter. The existing guard `if doubleSignCheckHeight > height` already prevents out-of-bounds lookups on short chains, so no additional bounds protection is needed. - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments<hr>This is an automatic backport of pull request cometbft#5668 done by [Mergify](https://mergify.com). --------- Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 222949a) * fix(blocksync): tolerate late BlockResponse from honest peers after switching to consensus (backport cometbft#5959) (cometbft#6002) `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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#5950, which handles the second-peer race while the pool is still running. 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. --- - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <hr>This is an automatic backport of pull request cometbft#5959 done by [Mergify](https://mergify.com). --------- Co-authored-by: JayT106 <[email protected]> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 6ed1d96) * ci: run e2e-test on ubuntu-latest, not unavailable Depot runner Fork has no Depot runner registered, so depot-ubuntu-24.04-4 jobs queue indefinitely and get cancelled at the 24h timeout. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: songgaoye <[email protected]> Co-authored-by: Dmitry S <[email protected]> Co-authored-by: Aditya Mishra <[email protected]> Co-authored-by: jay.tseng <[email protected]> Port note (v0.40.0): only the e2e runner change applies; the upstream commits are already in v0.40.0. Also pins buf to v1.72.0 (upstream cometbft#6057; buf@latest needs Go 1.26.7 and broke check-proto) and fixes the flaky TestPEXReactorSeedModeFlushStop. (cherry picked from commit 14b7b93)
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).