consensus/bor: guard nil sprint header in CommitStates#2181
consensus/bor: guard nil sprint header in CommitStates#2181LarryArnault45 wants to merge 1 commit into0xPolygon:developfrom
Conversation
|
manav2401
left a comment
There was a problem hiding this comment.
Have you encountered errors in pre-indore blocks due to this?
I don't think this case will ever happen due to following reasons.
- The first condition of
numberbeing less thansprintLengthwill never occur as first state-sync occurs at the start of first sprint. Hence, the condition is never less than 0. CommitStatesis called when your node is syncing and processing that block which has state-sync event. Fetching a slightly old block (16 blocks before current block) shouldn't fail due to ancient pruning - as ancient pruning is for blocks older than 90k from latest block. Hence, pruning a block which is just 16 blocks older is not possible.
|
Hi @manav2401 , thanks for the review. I agree this is unlikely in normal pre-Indore sync, and I haven’t reproduced a real mainnet crash with default pruning. My goal here is just defensive hardening: if If you want, I can remove the |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |



Description
In the pre-Indore path of
CommitStates, the state-sync upper timestamp was derived from the sprint-start header time. The previous code dereferencedGetHeaderByNumber(...).Timedirectly, without checking whether the header existed.Under ancient pruning conditions, that sprint-start header may be unavailable. In that case, the old flow could hit a nil dereference and panic on the consensus finalization path.
This update adds only the required safety checks:
sprintLengthonce;number < sprintLengthand return a clear error to avoid underflow;Time.Behavior is unchanged when data is present; only crash-prone branches now fail with explicit errors instead of panicking.
Changes
Breaking changes
N/A
Nodes audience
No node-segmented rollout is required.
Checklist
Cross repository changes
Testing
Manual tests
gofmt -w consensus/bor/bor.gogo test ./consensus/bor -run TestCommitStates -count=1go vet ./consensus/borgo test ./consensus/bor/... -count=1make lintAdditional comments