Skip to content

fix: ensure bestDescendant when bestChild set in applyDeltas#549

Merged
ch4r10t33r merged 5 commits intomainfrom
panic-fix
Feb 6, 2026
Merged

fix: ensure bestDescendant when bestChild set in applyDeltas#549
ch4r10t33r merged 5 commits intomainfrom
panic-fix

Conversation

@ch4r10t33r
Copy link
Copy Markdown
Contributor

Fixes panic invalid forkchoice with null best descendant for a non null best child during rebase (issue #545).

  • Cause: In applyDeltas, when a parent's best child had weight below cutoff_weight and no descendant above cutoff, bestDescendant was set to null while bestChild was set, violating the invariant expected by rebase().
  • Fix: When updating a parent's best child, set bestDescendant = nodeBestDescendant orelse node_idx so the invariant (bestChild non-null ⇒ bestDescendant non-null) always holds.
  • Test: Added regression test rebase: bestChild/bestDescendant invariant maintained with cutoff_weight that applies deltas with cutoff_weight > 0 and then rebases (previously panicked).

…n applyDeltas

Fixes panic 'invalid forkchoice with null best descendant for a non null best child'
during rebase (issue #545). Add regression test with cutoff_weight.
@ch4r10t33r ch4r10t33r changed the title fix(forkchoice): ensure bestDescendant when bestChild set in applyDeltas (fixes #545) fix: ensure bestDescendant when bestChild set in applyDeltas Feb 5, 2026
@ch4r10t33r ch4r10t33r marked this pull request as ready for review February 5, 2026 22:50
anshalshukla
anshalshukla previously approved these changes Feb 6, 2026
If bestDescendant is null (e.g., when cutoff_weight filters out descendants),
keep it null after rebase rather than remapping to bestChild.

Addresses review comment from @g11tech.
@ch4r10t33r ch4r10t33r merged commit a471b66 into main Feb 6, 2026
12 checks passed
@ch4r10t33r ch4r10t33r deleted the panic-fix branch February 6, 2026 18:16
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.

3 participants