Skip to content

fix(blocksync): tolerate redundant near-tip BlockResponse from a second peer - #5950

Closed
thomas-nguy wants to merge 8 commits into
cometbft:mainfrom
thomas-nguy:fix/blocksync-second-peer-window-tolerance-upstream
Closed

thomas-nguy wants to merge 8 commits into
cometbft:mainfrom
thomas-nguy:fix/blocksync-second-peer-window-tolerance-upstream

Conversation

@thomas-nguy

@thomas-nguy thomas-nguy commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Commit 4590e7ac introduced a pre-unmarshal MsgBytesFilter on the blocksync reactor. Before unmarshalling a BlockResponse, the filter calls BlockPool.HasPendingRequestFrom(src) to confirm we actually have an outstanding request to the sending peer, rejecting (and disconnecting) any peer that sends an unsolicited response.

Problem

The pool requests each height from two peers (peerID + secondPeerID) for redundancy, but PopRequest deletes the requester the instant that height commits. So when the faster peer's block commits first and the second peer's (solicited, expected) response arrives just after, no live requester remains, the filter can't distinguish "already committed" from "never requested" and rejects the response. On the comet p2p transport that rejection panics the peer's receive routine (p2p/peer.go), which _recover catches and tears down the connection (libp2p instead calls StopPeerForError)

The fix

HasPendingRequestFrom now also accepts any response whose height falls within the current sync window [startHeight, height], in addition to peers with an explicit outstanding request. The pre-unmarshal filter extracts the block height from the wire stub and passes it in.

Evidence
https://github.com/cometbft/cometbft/blob/main/blocksync/pool.go#L383

PR checklist

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

@thomas-nguy
thomas-nguy requested a review from a team as a code owner July 2, 2026 07:49
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@thomas-nguy
thomas-nguy force-pushed the fix/blocksync-second-peer-window-tolerance-upstream branch 4 times, most recently from 56681ad to 2c19330 Compare July 2, 2026 10:06
@thomas-nguy
thomas-nguy force-pushed the fix/blocksync-second-peer-window-tolerance-upstream branch from 2c19330 to 0baf713 Compare July 2, 2026 10:15
Comment thread blocksync/pool.go
func (pool *BlockPool) HasPendingRequestFrom(peerID p2p.ID, height int64) bool {
pool.mtx.Lock()
defer pool.mtx.Unlock()
if height >= pool.startHeight && height <= pool.height {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces the assumption that if height is within the boundary, then the node definitely expects a block from peerID. How can we ensure that this invariant holds? At first glance, I'm not 100% confident.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @swift1337 here, this change was introduced to stop blocksync from blindly accepting responses from peers that looked somewhat real (like these that fall within the expected height range), but are spam or malicious. I do agree this is a bug that we should be fixing however but we should take a different approach.

Maybe instead of removing both the primary and secondary peers assigned to a request once we receive the primaries response, we keep the entry around for some duration, giving the secondary time to respond, then only after that duration do we remove from the requesters set?

Comment thread blocksync/pool.go
func (pool *BlockPool) HasPendingRequestFrom(peerID p2p.ID, height int64) bool {
pool.mtx.Lock()
defer pool.mtx.Unlock()
if height >= pool.startHeight && height <= pool.height {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @swift1337 here, this change was introduced to stop blocksync from blindly accepting responses from peers that looked somewhat real (like these that fall within the expected height range), but are spam or malicious. I do agree this is a bug that we should be fixing however but we should take a different approach.

Maybe instead of removing both the primary and secondary peers assigned to a request once we receive the primaries response, we keep the entry around for some duration, giving the secondary time to respond, then only after that duration do we remove from the requesters set?

pull Bot pushed a commit to mtrackeros/cometbft that referenced this pull request Jul 21, 2026
…witching to consensus (cometbft#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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#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]>
swift1337 added a commit that referenced this pull request Jul 27, 2026
…witching to consensus (backport #5959) (#6003)

### 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
<hr>This is an automatic backport of pull request #5959 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: JayT106 <[email protected]>
Co-authored-by: Dmitry S <[email protected]>
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Jul 28, 2026
…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)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Jul 29, 2026
* 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]>
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
…witching to consensus (cometbft#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 cometbft#5860 (`FilterMsgBytes`). Not covered by cometbft#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]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs.

@github-actions github-actions Bot closed this Sep 23, 2026
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 30, 2026
* 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)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Nov 2, 2026
* 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)
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.

3 participants