forkchoice: simplify store's latest_justified and latest_finalized updates - #194
Merged
Merged
Conversation
tcoratger
approved these changes
Nov 26, 2025
tcoratger
left a comment
Collaborator
There was a problem hiding this comment.
Much better this way.
This was referenced Jun 13, 2026
GrapeBaBa
added a commit
to GrapeBaBa/leanSpec
that referenced
this pull request
Jun 13, 2026
…ependent max on_block advanced latest_finalized by an independent monotonic max over every imported block's post-state, decoupled from latest_justified and the head. A fork that finalizes a higher slot but then loses head selection left its finalized checkpoint latched in the store, so latest_finalized could sit on a dead branch that is not an ancestor of the head. Validators then derive attestation targets against that phantom finalized while the canonical state transition validates against its own lower finalized, so every advancing target is rejected and finalization freezes. Keep the store's finalized only when it lies on the head's chain (a genuinely finalized checkpoint such as a checkpoint-sync anchor), advancing it to the head state's finalized; otherwise replace it with the head chain's finalized. This restores the consistency the forkchoice store had before leanEthereum#194 and matches the 3sf-mini reference, where the finalized checkpoint travels with the chosen state. Add a regression test: a dead fork finalizes slot 4 then loses to a heavier fork that justifies slot 7 but finalizes only slot 1; the store's finalized must track the head (slot 1), not the dead fork (slot 4).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗒️ Description
The fork choice store was relying on looping through the entire historical states to update itself to the latest_justified and latest_finalized checkpoints. This is an overkill and also problematic as the genesis state's latest_justified and latest_finalized block roots are set to 0x00... (the latter might also be an issue, I'll bring up as a separate PR)
Zeam is doing it more elegantly by simply just comparing the latest state's latest_justified and latest_finalized with the fork choice store, and update the store if the state contains higher checkpoints. So I propose bringing this optimization over.
This should not change the behavior of the fork choice so tests are unchanged.
🔗 Related Issues or PRs
✅ Checklist
toxchecks to avoid unnecessary CI fails:uvx tox