Skip to content

consensus: proposer self-verifies its own vote extension before broadcast (#5204) [v2] - #5890

Merged
aljo242 merged 4 commits into
cometbft:mainfrom
satyakwok:fix-proposer-self-verify-vote-extension-5204-v2
Jun 11, 2026
Merged

aljo242 merged 4 commits into
cometbft:mainfrom
satyakwok:fix-proposer-self-verify-vote-extension-5204-v2

Conversation

@satyakwok

Copy link
Copy Markdown
Contributor

Supersedes #5864.

Why a new PR

#5864 was opened with one unsigned base commit (d184ae5) plus five Merge branch 'main' commits. Per @mattac21's request, this PR rebases the work onto current main as a single signed commit with no merge noise.

What changed since #5864

Greptile flagged two valid issues on the previous PR; both addressed here:

  1. Panic message no longer says "proposer's" (consensus/state.go)
    signVote runs on every validator, not just the proposer, so the old wording would mislead operators when a non-proposer hit the panic. The message now leads with validator %X failed self-verification of its own vote extension at height %d so the trace identifies the offending node regardless of role.

  2. Self-verify path now has dedicated test coverage (consensus/state_test.go)
    New TestSelfVerifyVoteExtensionRejectPanics drives signVote directly from the test goroutine (bypassing receiveRoutine's defer recover()), with a mock app whose ExtendVote returns a non-empty extension that VerifyVoteExtension rejects. Asserts the panic fires with the expected message and that both ABCI methods were called.

    The TestVoteExtensionEnableHeight VerifyVoteExtension mock is restored to Times(numValidators - 1) — that test's ExtendVote mock returns an empty extension, so the self-verify guard is never entered there and the exact count holds. The misleading // scheduling-dependent count comment from consensus: proposer self-verifies its own vote extension before broadcast (#5204) #5864 is gone.

Original bug (unchanged from #5864)

If the application's ExtendVote produces data its own VerifyVoteExtension rejects, the chain deadlocks: the issuing validator advances locally while every peer loops rejecting the invalid extension and 2/3 precommits are never reached. This PR adds an immediate self-verification in signVote: after ExtendVote returns a non-empty extension, VerifyVoteExtension is called on it before broadcasting. On rejection, the node panics with a clear handler-inconsistency message.

Empty extensions are skipped — the absent-but-required case is caught downstream by SignAndCheckVote with a recoverable error, preserving existing behavior.

Validation

go test ./consensus -run 'TestSelfVerifyVoteExtensionRejectPanics|TestStateVoteExtension|TestVoteExtensionEnableHeight|TestVerifyVoteExtensionNotCalledOnAbsentPrecommit|TestExtendVoteCalledWhenEnabled' -count=1
ok  	github.com/cometbft/cometbft/consensus	1.042s

Closes #5204

@satyakwok
satyakwok requested a review from a team as a code owner May 23, 2026 08:41
@greptile-apps

greptile-apps Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

aljo242

This comment was marked as duplicate.

@aljo242 aljo242 left a comment

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.

state.go:2474: use context.Background() instead of context.TODO(). TODO signals a known placeholder to be replaced; if there's no intent to thread a real context through signVote, Background is correct.

test coverage gap: TestSelfVerifyVoteExtensionRejectPanics covers the reject/panic path. TestVoteExtensionEnableHeight uses an empty extension so it skips self-verify entirely. there's no test for the happy path: non-empty extension that VerifyVoteExtension accepts. a test confirming signVote succeeds and doesn't panic in that case would complete the coverage.

@satyakwok

Copy link
Copy Markdown
Contributor Author

Thanks, addressed both in 10e33fb.

  • Replaced the self-verify context.TODO() with context.Background().
  • Added TestSelfVerifyVoteExtensionAccepts to cover the happy path where a non-empty extension is accepted by VerifyVoteExtension and signVote completes without panic.

Targeted test:
go test ./consensus -run 'TestSelfVerifyVoteExtensionRejectPanics|TestSelfVerifyVoteExtensionAccepts|TestStateVoteExtension|TestVoteExtensionEnableHeight|TestVerifyVoteExtensionNotCalledOnAbsentPrecommit|TestExtendVoteCalledWhenEnabled' -count=1

@aljo242

aljo242 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

missing changelog entry — nothing in CHANGELOG.md for this fix.

one behavior question: signVote is called from receiveRoutine, which wraps its body in defer recover(). the panic will be caught there and logged rather than crashing the process. the pr description frames this as non-recoverable, but in practice the validator just silently skips casting its precommit for the round. is that acceptable, or should this be a fatal log + os.Exit to force the operator to fix their app?

@satyakwok
satyakwok force-pushed the fix-proposer-self-verify-vote-extension-5204-v2 branch from 406959f to 8279550 Compare June 9, 2026 12:02
@satyakwok

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Changelog: added an entry under UNRELEASED → ### BUG FIXES.

On the recover behavior: the panic isn't actually swallowed-and-skipped. signVote runs inside receiveRoutine, whose deferred recover doesn't continue the loop — it logs CONSENSUS FAILURE!!! with the stack and then calls onExit(cs), which stops the WAL and closes cs.done, halting the consensus routine. The comment there states the intent directly:

NOTE: We most probably shouldn't be running any further when there is some unexpected panic. [...] halting the chain upon unexpected consensus bugs sounds like the better option.

So the validator doesn't quietly skip its precommit and move on — consensus stops, loudly, which is the operator-visible "go fix your app" outcome you're describing.

It also keeps this consistent with how signVote already handles the same class of bug: it panics on a non-recoverable error when signing vote (just below the new code) and applyCommit/vote-extension absence-vs-presence mismatch panic the same way. A bespoke os.Exit here would diverge from that pattern and skip the clean WAL shutdown the recover path gives us.

So I've kept the panic. If you'd still prefer an explicit fatal exit for this specific case I'm happy to switch, but I'd lean toward staying consistent with the surrounding signVote panics and the existing recover → onExit halt.

Also rebased onto main and signed all commits to clear the failing check-signed-commits.

@satyakwok
satyakwok requested a review from aljo242 June 10, 2026 02:55

@aljo242 aljo242 left a comment

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.

Both of @aljo242's CHANGES_REQUESTED items are addressed in this v2:

  1. context.Background() is used at state.go:2474 (not TODO).
  2. TestSelfVerifyVoteExtensionAccepts covers the happy path — non-empty extension accepted by VerifyVoteExtension signs without panic.

The guard logic is correct: only fires when len(vote.Extension) > 0, panics on reject, preserves the empty-extension recoverable-error path downstream. Panic message leads with validator %X (not "proposer's"), which is correct since every validator signs precommits.

⚠️ This is a fork PR — the full CI suite (lint, unit tests, e2e) has not run. A maintainer needs to approve CI before merging.

@aljo242
aljo242 enabled auto-merge June 11, 2026 13:49
@aljo242
aljo242 added this pull request to the merge queue Jun 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@aljo242
aljo242 enabled auto-merge June 11, 2026 14:58
@aljo242
aljo242 added this pull request to the merge queue Jun 11, 2026
Merged via the queue into cometbft:main with commit 887dd1c Jun 11, 2026
37 checks passed
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
…cast (cometbft#5204) [v2] (cometbft#5890)

Supersedes cometbft#5864.

## Why a new PR

cometbft#5864 was opened with one unsigned base commit (`d184ae5`) plus five
`Merge branch 'main'` commits. Per @mattac21's request, this PR rebases
the work onto current `main` as **a single signed commit** with no merge
noise.

## What changed since cometbft#5864

Greptile flagged two valid issues on the previous PR; both addressed
here:

1. **Panic message no longer says "proposer's"** (`consensus/state.go`)
`signVote` runs on every validator, not just the proposer, so the old
wording would mislead operators when a non-proposer hit the panic. The
message now leads with `validator %X failed self-verification of its own
vote extension at height %d` so the trace identifies the offending node
regardless of role.

2. **Self-verify path now has dedicated test coverage**
(`consensus/state_test.go`)
New `TestSelfVerifyVoteExtensionRejectPanics` drives `signVote` directly
from the test goroutine (bypassing `receiveRoutine`'s `defer
recover()`), with a mock app whose `ExtendVote` returns a non-empty
extension that `VerifyVoteExtension` rejects. Asserts the panic fires
with the expected message and that both ABCI methods were called.

The `TestVoteExtensionEnableHeight` `VerifyVoteExtension` mock is
**restored** to `Times(numValidators - 1)` — that test's `ExtendVote`
mock returns an empty extension, so the self-verify guard is never
entered there and the exact count holds. The misleading `//
scheduling-dependent count` comment from cometbft#5864 is gone.

## Original bug (unchanged from cometbft#5864)

If the application's `ExtendVote` produces data its own
`VerifyVoteExtension` rejects, the chain deadlocks: the issuing
validator advances locally while every peer loops rejecting the invalid
extension and 2/3 precommits are never reached. This PR adds an
immediate self-verification in `signVote`: after `ExtendVote` returns a
non-empty extension, `VerifyVoteExtension` is called on it before
broadcasting. On rejection, the node panics with a clear
handler-inconsistency message.

Empty extensions are skipped — the absent-but-required case is caught
downstream by `SignAndCheckVote` with a recoverable error, preserving
existing behavior.

## Validation

```
go test ./consensus -run 'TestSelfVerifyVoteExtensionRejectPanics|TestStateVoteExtension|TestVoteExtensionEnableHeight|TestVerifyVoteExtensionNotCalledOnAbsentPrecommit|TestExtendVoteCalledWhenEnabled' -count=1
ok  	github.com/cometbft/cometbft/consensus	1.042s
```

Closes cometbft#5204

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

abci: Consensus Deadlock Caused by Proposer Vote Extension Verification Failure

2 participants