Repository navigation
consensus: proposer self-verifies its own vote extension before broadcast (#5204) [v2] - #5890
Conversation
|
PR author is not in the allowed authors list. |
aljo242
left a comment
There was a problem hiding this comment.
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.
|
Thanks, addressed both in 10e33fb.
Targeted test: |
|
missing changelog entry — nothing in one behavior question: |
406959f to
8279550
Compare
|
Thanks for the review. Changelog: added an entry under On the recover behavior: the panic isn't actually swallowed-and-skipped.
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 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 Also rebased onto |
aljo242
left a comment
There was a problem hiding this comment.
Both of @aljo242's CHANGES_REQUESTED items are addressed in this v2:
context.Background()is used at state.go:2474 (notTODO).TestSelfVerifyVoteExtensionAcceptscovers the happy path — non-empty extension accepted byVerifyVoteExtensionsigns 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.
…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>
Supersedes #5864.
Why a new PR
#5864 was opened with one unsigned base commit (
d184ae5) plus fiveMerge branch 'main'commits. Per @mattac21's request, this PR rebases the work onto currentmainas a single signed commit with no merge noise.What changed since #5864
Greptile flagged two valid issues on the previous PR; both addressed here:
Panic message no longer says "proposer's" (
consensus/state.go)signVoteruns 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 withvalidator %X failed self-verification of its own vote extension at height %dso the trace identifies the offending node regardless of role.Self-verify path now has dedicated test coverage (
consensus/state_test.go)New
TestSelfVerifyVoteExtensionRejectPanicsdrivessignVotedirectly from the test goroutine (bypassingreceiveRoutine'sdefer recover()), with a mock app whoseExtendVotereturns a non-empty extension thatVerifyVoteExtensionrejects. Asserts the panic fires with the expected message and that both ABCI methods were called.The
TestVoteExtensionEnableHeightVerifyVoteExtensionmock is restored toTimes(numValidators - 1)— that test'sExtendVotemock returns an empty extension, so the self-verify guard is never entered there and the exact count holds. The misleading// scheduling-dependent countcomment from consensus: proposer self-verifies its own vote extension before broadcast (#5204) #5864 is gone.Original bug (unchanged from #5864)
If the application's
ExtendVoteproduces data its ownVerifyVoteExtensionrejects, 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 insignVote: afterExtendVotereturns a non-empty extension,VerifyVoteExtensionis 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
SignAndCheckVotewith a recoverable error, preserving existing behavior.Validation
Closes #5204