Skip to content

consensus: proposer self-verifies its own vote extension before broadcast (#5204) - #5864

Closed
satyakwok wants to merge 6 commits into
cometbft:mainfrom
satyakwok:fix-proposer-self-verify-vote-extension-5204
Closed

satyakwok wants to merge 6 commits into
cometbft:mainfrom
satyakwok:fix-proposer-self-verify-vote-extension-5204

Conversation

@satyakwok

Copy link
Copy Markdown
Contributor

Closes #5204.

Bug

If the application's ExtendVote produces data that its own VerifyVoteExtension rejects, the chain deadlocks: the proposer happily advances to the next height while every other validator loops verifying the same invalid extension and never reaches 2/3 precommits. Issue reporter 's log trace shows exactly this — proposer at height 12, peers stuck at height 11 with repeated VerifyVoteExtensionHandler Price=0 errors.

Fix

Per the maintainer-blessed Option A (@liangping in the issue thread): immediately after ExtendVote returns on the proposer, call VerifyVoteExtension on the resulting extension. On self-rejection, panic with a clear error pointing at the inconsistency between the application's ExtendVote and VerifyVoteExtension handlers — better operator signal than a silent network-wide stall.

ext, err := cs.blockExec.ExtendVote(context.TODO(), vote, block, cs.state)
if err != nil {
    return nil, err
}
vote.Extension = ext

if len(vote.Extension) > 0 {
    if err := cs.blockExec.VerifyVoteExtension(context.TODO(), vote); err != nil {
        panic(fmt.Errorf(
            "proposer's own vote extension failed VerifyVoteExtension at height %d: %w; "+
                "application ExtendVote and VerifyVoteExtension handlers are inconsistent",
            vote.Height, err,
        ))
    }
}

The len(vote.Extension) > 0 guard preserves existing behavior for the "absent but required" case — that path is caught downstream by SignAndCheckVote and produces a recoverable error (the TestVoteExtensionEnableHeight/extension_absent_but_required subtest passes unchanged).

Tests

$ go test ./consensus/ -run "TestStateVoteExtension|TestVoteExtensionEnableHeight|TestVerifyVoteExtensionNotCalledOnAbsentPrecommit" -count=1
ok  	github.com/cometbft/cometbft/consensus	0.312s

All five TestVoteExtensionEnableHeight subtests pass:

  • extension_present_but_not_enabled
  • extension_absent_but_not_required
  • extension_present_and_required
  • extension_absent_but_required
  • extension_absent_but_required_in_future_height

One adjustment in the test file: TestVoteExtensionEnableHeight previously set m.On("VerifyVoteExtension", ...).Times(numValidators - 1) (assuming the proposer never self-verifies). With the new self-verify call, the exact count is timing-dependent (the proposer self-verifies once, then numValidators - 1 peers verify the proposer's precommit). Relaxed to an unbounded mock expectation — the test asserts round completion (expectSuccessfulRound), which is the property we care about.

Why panic and not log-and-continue

The proposer's ExtendVote and VerifyVoteExtension handlers disagreeing is a non-recoverable application logic bug, not a network condition. If we silently log and broadcast anyway, every peer will reject the precommit (existing behavior, deadlock). If we silently log and broadcast a nil extension, peers reject for "extension required but absent". Panicking with a clear message gives the operator a stack trace pointing at the application bug rather than chasing a network-level mystery. Mirrors the existing pattern at state/execution.go:413 where unrecoverable VerifyVoteExtension errors panic.

Race / claim history

Compatibility

  • Existing successful-path behavior unchanged (extension passes own verify → broadcast as before)
  • Empty extensions: handled by existing SignAndCheckVote recoverable-error path (no behavioral change)
  • New behavior only fires when the application's own handlers disagree — which today would silently deadlock the chain anyway

…cast (cometbft#5204)

If the application's ExtendVote produces data that its own
VerifyVoteExtension rejects, the chain deadlocks: the proposer happily
advances to the next height while every other validator loops verifying
the same invalid extension and never reaches 2/3 precommits.

Per the maintainer-blessed Option A in the issue thread, run
VerifyVoteExtension on the proposer's own extension immediately after
ExtendVote returns. On self-rejection panic with a clear error pointing
at the inconsistency between the application's ExtendVote and
VerifyVoteExtension handlers — better operator signal than a silent
network-wide stall.

Skip self-verify when the extension is empty: an absent-but-required
extension is caught downstream by SignAndCheckVote and produces a
recoverable error, which is the existing behavior we want to preserve
(TestVoteExtensionEnableHeight/'extension absent but required' still
passes unchanged).

Test mock for VerifyVoteExtension in TestVoteExtensionEnableHeight is
relaxed from Times(numValidators - 1) to unbounded — the new self-verify
call makes the exact count timing-dependent; what matters is that the
round completes correctly.

Closes cometbft#5204

@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.

Reviewed and validated locally:
go test ./consensus -run 'TestStateVoteExtension|TestVoteExtensionEnableHeight|TestVerifyVoteExtensionNotCalledOnAbsentPrecommit' -count=1

LGTM. Self-verifying proposer extensions closes the deadlock scenario and the test updates match the new behavior.

@mattac21

Copy link
Copy Markdown
Collaborator

@greptile review

@mattac21

Copy link
Copy Markdown
Collaborator

hey @satyakwok we require signed commits for contributors. could you reopen this pr with signed commits enabled?

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a chain-deadlock bug (#5204) where an application whose ExtendVote produces data that its own VerifyVoteExtension rejects would cause the issuing validator to advance while every peer looped rejecting the invalid extension and 2/3 precommits were never reached. The fix adds an immediate self-verification step inside signVote: after ExtendVote returns a non-empty extension, VerifyVoteExtension is called and, on rejection, panics with a clear message pointing at the application inconsistency.

  • consensus/state.go: Adds 13 lines of self-verify logic in signVote, guarded by len(vote.Extension) > 0 to preserve the existing "absent-but-required" recoverable-error path handled downstream by SignAndCheckVote. Panic on self-rejection mirrors the existing pattern in state/execution.go.
  • consensus/state_test.go: Relaxes VerifyVoteExtension mock from .Times(numValidators-1) to unbounded; the comment is slightly inaccurate (self-verify never fires in these tests because the mock returns an empty extension), and no new test covers the panic-on-rejection path introduced by this PR.

Confidence Score: 4/5

Safe to merge — the new code path only fires when an application's handlers are already broken, leaving all correct deployments unaffected.

The production logic change is small and well-reasoned: it intercepts an extension immediately after ExtendVote and re-validates it before signing, turning a silent network stall into an explicit panic with context. The main rough edges are a misleading 'proposer' label in the panic message (the code runs for any validator, not just the proposer) and a test suite that doesn't actually exercise the new self-verify call or the panic-on-rejection branch, since the mock returns an empty extension and the guard len(vote.Extension) > 0 is never satisfied.

consensus/state_test.go deserves a second look — the new behavior (self-verify fires on non-empty extension, panic fires on rejection) has no test coverage.

Important Files Changed

Filename Overview
consensus/state.go Adds self-verification of vote extensions in signVote: after ExtendVote returns a non-empty extension, calls VerifyVoteExtension and panics on rejection. Logic is sound but the panic message incorrectly labels any validator as "proposer", which will mislead operators when a non-proposer validator hits the panic.
consensus/state_test.go Relaxes VerifyVoteExtension mock from .Times(numValidators-1) to unbounded. The rationale in the comment is slightly inaccurate — the self-verify path is never entered in these tests because ExtendVote returns an empty extension — and no new test covers the actual new behavior (self-verify fires, or panic on rejection).

Sequence Diagram

sequenceDiagram
    participant CS as ConsensusState (signVote)
    participant BE as BlockExecutor
    participant App as Application (ABCI)

    CS->>BE: ExtendVote(ctx, vote, block, state)
    BE->>App: ExtendVote RPC
    App-->>BE: "ResponseExtendVote{VoteExtension}"
    BE-->>CS: ext ([]byte)
    CS->>CS: "vote.Extension = ext"

    alt "len(vote.Extension) > 0 (NEW)"
        CS->>BE: VerifyVoteExtension(ctx, vote)
        BE->>App: VerifyVoteExtension RPC
        App-->>BE: ResponseVerifyVoteExtension
        alt ACCEPT
            BE-->>CS: nil
        else REJECT
            BE-->>CS: ErrInvalidVoteExtension
            CS->>CS: panic(proposer's own vote extension failed...)
        end
    end

    CS->>CS: SignAndCheckVote(vote, privValidator, chainID, extRequired)
    CS-->>CS: signed vote (or recoverable error)
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix-proposer-se..." | Re-trigger Greptile

Comment thread consensus/state.go
Comment on lines +2477 to +2481
panic(fmt.Errorf(
"proposer's own vote extension failed VerifyVoteExtension at height %d: %w; "+
"application ExtendVote and VerifyVoteExtension handlers are inconsistent",
vote.Height, err,
))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Misleading "proposer" label in panic message

signVote is invoked by every validator for their own precommit, not exclusively by the block proposer. If a non-proposer validator's extension fails self-verification, the panic will say "proposer's own vote extension" — which will send an operator hunting for a proposer misconfiguration when the real culprit is a different node. Using the validator's address in the message would make the trace actionable regardless of which node hits the panic.

Comment thread consensus/state_test.go
Comment on lines 1873 to 1881
if testCase.expectVerifyCalled {
// Calls include numValidators-1 verifications of incoming
// precommits plus one self-verify on the proposer's own
// extension (#5204). The exact count depends on scheduling;
// we only care that the round completes.
m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(&abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
}, nil).Times(numValidators - 1)
}, nil)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 New self-verify path is never exercised by the existing tests

The ExtendVote mock is configured to return &abci.ResponseExtendVote{} (empty VoteExtension), so len(vote.Extension) == 0 is always true and the self-verify branch is never entered. The comment about "scheduling-dependent count" is therefore not the actual reason the .Times(numValidators - 1) constraint was dropped — the count remains exactly numValidators - 1 in practice. More importantly, there is no test that (a) returns a non-empty extension from ExtendVote and confirms VerifyVoteExtension is called once extra for the self-verify, and (b) returns a non-empty extension that VerifyVoteExtension rejects and confirms the panic fires. These two cases are the core of the new feature.

@satyakwok

Copy link
Copy Markdown
Contributor Author

Replaced by #5890 — rebased onto current main as a single signed commit, addressing the request for signed commits.

The replacement PR also folds in Greptile's two findings on this PR:

  1. Panic message updated to identify the offending validator by address instead of mislabeling any node as "proposer" (since signVote runs on every validator).
  2. Added TestSelfVerifyVoteExtensionRejectPanics to exercise the new code path directly, and restored TestVoteExtensionEnableHeight's VerifyVoteExtension mock to Times(numValidators - 1) (the misleading comment from this PR is gone — ExtendVote in that test returns empty, so the self-verify guard is not exercised there).

Closing this in favor of #5890. Thanks @aljo242 for the earlier review and @mattac21 for the signed-commits flag.

@satyakwok satyakwok closed this May 23, 2026
mergify Bot added a commit to Aboudjem/cometbft that referenced this pull request Jun 11, 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>
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

3 participants