Repository navigation
fix(consensus): do not apply a commit whose block we no longer hold - #1437
Conversation
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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
🕓 Ready for review — 23 ahead in queue (commit 4377f3f) |
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>
The crash
AddCommitActionasksproposalUpdater.updateStateDatato reconcile the round state with the commit being applied. When the node holds some block other than the committed one, that function clearsProposalBlock, points the part set at the committed block, and returnsnil— it is reporting "we do not have this block, I have set up to fetch it, keep waiting".AddCommitActionignored the distinction and dispatchedApplyCommitEventregardless. That reads the block it just cleared and hands the round state tomustEnsureProcess, which panics on any error. The nil block reachesProcessProposaland 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
||inensureProcessshort-circuits:execution.goonblock.Version.ToProto(), orblock_executor.goonMatchesBlock(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.mustEnsureProcesspanics on any error, so on its own this change converts a nil dereference into a panic one line later — verified by removing theAddCommitActionguard, which turns the crash intopanic: 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.godrives 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-lintat the version CI installs reports 0 issues against this base.Scope
This targets
v1.7-devbecause the defect is present there and the fix applies cleanly to that lineage. It is independent of the consensus work onv1.8-devand shares no code with it.🤖 Generated with Claude Code
https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj