Skip to content

fix(consensus): do not apply a commit whose block we no longer hold - #1437

Merged
lklimek merged 6 commits into
v1.7-devfrom
fix/apply-commit-nil-proposal-block
Sep 7, 2026
Merged

lklimek merged 6 commits into
v1.7-devfrom
fix/apply-commit-nil-proposal-block

Conversation

@lklimek

@lklimek lklimek commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

The crash

AddCommitAction asks proposalUpdater.updateStateData to reconcile the round state with the commit being applied. When the node holds some block other than the committed one, that function clears ProposalBlock, points the part set at the committed block, and returns nil — it is reporting "we do not have this block, I have set up to fetch it, keep waiting".

AddCommitAction ignored the distinction and dispatched ApplyCommitEvent regardless. That reads the block it just cleared and hands the round state to mustEnsureProcess, which panics on any error. The nil block reaches ProcessProposal and the process dies on the first field access.

It is a crash, not a stall — the node exits rather than falling behind.

Reachability

The sequence is remotely reachable and does not need a coalition.

A node holding a parked commit — ordinary catch-up state — that advances a round and then assembles a different block will crash. A commit attests its own round only, so a proposal for a later round naming another block is not refused, which means the round's designated proposer can choose to cause this.

Two crash sites exist depending on which way the || in ensureProcess short-circuits: execution.go on block.Version.ToProto(), or block_executor.go on MatchesBlock(block.Header, …). Both were observed; the guard therefore has to sit above the condition rather than inside it.

The fix

Return without applying when the block is gone. The completing part of the committed block dispatches this event again, so the commit is applied when its own block arrives — which is what the parked commit was waiting for in the first place. No liveness is lost: the wait was already the intended behaviour, and the crash was the round state being handed on mid-reconciliation.

Also refuse a nil block in ensureProcess. This is defence in depth and explicitly not the fix. mustEnsureProcess panics on any error, so on its own this change converts a nil dereference into a panic one line later — verified by removing the AddCommitAction guard, which turns the crash into panic: proposal block is not set: height 1, round 0. It is included so a future caller reaching this path fails with a message naming the condition rather than dereferencing nil.

Verification

apply_commit_nil_block_test.go drives the real sequence through the controller — commit parked, round advanced, a different block assembled — and asserts the node does not crash and the commit is not applied against a block it does not hold.

RED-first: the test reproduces the panic on the unfixed tree, at the crash site named above. go test ./internal/consensus/... passes; golangci-lint at the version CI installs reports 0 issues against this base.

Scope

This targets v1.7-dev because the defect is present there and the fix applies cleanly to that lineage. It is independent of the consensus work on v1.8-dev and shares no code with it.

🤖 Generated with Claude Code

https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj

AddCommitAction asks proposalUpdater.updateStateData to reconcile the
round state with the commit being applied. When the node is holding some
block other than the committed one, that function clears ProposalBlock,
points the part set at the committed block and returns nil -- it is
reporting "we do not have this block, I have set up to fetch it, keep
waiting". AddCommitAction ignored the distinction and dispatched
ApplyCommitEvent regardless, which reads the block it just cleared and
hands the round state to mustEnsureProcess. The nil block reaches
ProcessProposal and the process dies on the first field access.

The sequence is remotely reachable. A node holding a parked commit --
ordinary catch-up state -- that advances a round and then assembles a
different block will crash. A commit attests its own round only, so a
proposal for a later round naming another block is not refused, and the
round's designated proposer can therefore choose to cause this. It is a
crash, not a stall: the node exits rather than falling behind.

Return without applying when the block is gone. The completing part of
the committed block dispatches this event again, so the commit is
applied when its own block arrives, which is what the parked commit was
waiting for in the first place.

Also refuse a nil block in ensureProcess rather than passing it on. This
is defence in depth and not the fix: mustEnsureProcess panics on any
error, so on its own it converts a nil dereference into a panic one line
later -- verified by removing the AddCommitAction guard, which turns the
crash into "panic: proposal block is not set: height 1, round 0". The
guard goes above the condition rather than inside it because both
operands can reach the block: the || short-circuits when the round state
did not come from ProcessProposal, so the nil reaches ProcessProposal,
and when it did not short-circuit MatchesBlock dereferences the block one
frame earlier. Guarding either site alone leaves the other live.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 89017fb2-8f37-4436-a4fd-5963112b409a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 7, 2026 •

Copy link
Copy Markdown

🕓 Ready for review — 23 ahead in queue (commit 4377f3f)
Queue position: 24/25 · 2 reviews active
ETA: start ~01:14 UTC · complete ~02:12 UTC (median 57m across 30 recent reviews; 2 slots)
Queued 12m ago · Last checked: 2026-09-07 14:10 UTC

Preserve the nil proposal block guard and adopt upstream proposal validation
that discards mismatched metadata while retaining downloaded blocks.

Validation: formatting and diff checks pass. Targeted race tests and lint
are blocked by the missing native dashbls/bls.hpp header.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek
lklimek enabled auto-merge (squash) September 7, 2026 13:57
@lklimek
lklimek merged commit f6325b8 into v1.7-dev Sep 7, 2026
17 checks passed
@lklimek
lklimek deleted the fix/apply-commit-nil-proposal-block branch September 7, 2026 14:14
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.

2 participants