refactor(fork-choice): simplify maybeUpdateBestChildAndDescendant Gloas edge case - #8951
Conversation
…as edge case Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary of ChangesHello @twoeths, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is an excellent refactoring that significantly simplifies the fork-choice logic in maybeUpdateBestChildAndDescendant. By removing the isEmptyVsFullEdgeCase helper and its associated guard, the code now relies on a more natural and easier-to-follow fall-through mechanism for tie-breaking. The addition of explicit isGloasBlock() assertions is a great improvement for robustness, making the code's invariants clear and ensuring it fails loudly if they are violated. The changes make the implementation cleaner and more aligned with the specification. Great work!
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0c3b62c19
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…tChildAndDescendant Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| * For older blocks: returns node.payloadStatus | ||
| * | ||
| * Note: pre-gloas logic won't reach here. Since it is impossible to have two nodes with same weight and root | ||
| * Note: pre-gloas logic won't reach here. Pre-Gloas blocks have different roots, so they are always resolved by the root tiebreaker before reaching here. |
There was a problem hiding this comment.
| * Note: pre-gloas logic won't reach here. Pre-Gloas blocks have different roots, so they are always resolved by the root tiebreaker before reaching here. | |
| * Note: pre-gloas logic won't reach here. Pre-Gloas blocks have different roots, so they are always resolved by the weight and root tiebreaker before reaching here. |
| // Per spec modified-get_weight (gloas/fork-choice.md#L442): a Gloas EMPTY/FULL block from the | ||
| // previous slot (n-1) has effective weight = 0 regardless of accumulated attestations. | ||
| // The isGloasBlock() guard prevents incorrectly zeroing pre-Gloas FULL blocks, which also have | ||
| // payloadStatus=FULL but must use their actual accumulated weight. |
There was a problem hiding this comment.
I think these comments are very lengthy. I think it should be more concise:
| // Per spec modified-get_weight (gloas/fork-choice.md#L442): a Gloas EMPTY/FULL block from the | |
| // previous slot (n-1) has effective weight = 0 regardless of accumulated attestations. | |
| // The isGloasBlock() guard prevents incorrectly zeroing pre-Gloas FULL blocks, which also have | |
| // payloadStatus=FULL but must use their actual accumulated weight. | |
| // Gloas: nodes from previous slot (n-1) with EMPTY/FULL variant post-gloas have weight hardcoded to 0. |
| const childTiebreaker = this.getPayloadStatusTiebreaker(childNode, currentSlot, proposerBoostRoot); | ||
| // Same effective weight and same root — must be Gloas EMPTY vs FULL from n-1 | ||
| if (!isGloasBlock(childNode)) { | ||
| throw new ProtoArrayError({ |
There was a problem hiding this comment.
I think throwing error here changes our Fulu behaviour.
The current behaviour on unstable is if we have two nodes with same weight and same root, we should do changeToChild:
lodestar/packages/fork-choice/src/protoArray/protoArray.ts
Lines 664 to 669 in 96f78af
I think theoretically two nodes with same weight and same root should not happen, but I am not educated to 100% sure throwing error here wouldn't cause issue.
There was a problem hiding this comment.
I removed it in the latest commit, don't think it will ever change the behaviour of pre-gloas through since 1 node cannot have 2 child nodes with the same root, that's enforced through VariantIndices typing
| }); | ||
| } | ||
|
|
||
| // Tie-breaker by payload status (EMPTY vs FULL) |
There was a problem hiding this comment.
The comment from L1256 should move to here. .
…escendant Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## nc/epbs-fc #8951 +/- ##
===========================================
Coverage 52.37% 52.37%
===========================================
Files 848 848
Lines 63047 63047
Branches 4670 4670
===========================================
Hits 33020 33020
Misses 29959 29959
Partials 68 68 🚀 New features to boost your workflow:
|
Motivation
isEmptyVsFullEdgeCase()is not in the spec — it was an implementation helper that bypassed the standard weight → blockRoot tiebreaking order before callinggetPayloadStatusTiebreaker(). Per spec, pre-Gloas nodes must always be tiebroken by weight first, then blockRoot. The guard was obscuring this and making the code harder to follow.Description
isEmptyVsFullEdgeCase()helper fromProtoArrayisEdgeCaseguard that was short-circuiting weight and blockRoot comparisonsgetPayloadStatusTiebreaker()already have equal weight and equal blockRoot by natural fall-through; that scenario can only arise for Gloas blocks (EMPTY vs FULL variants of the same block)isGloasBlock()assertions before the tiebreaker to make the invariant clear and fail loudly if violatedSpec reference: https://github.com/ethereum/consensus-specs/blob/69a2582d5d62c914b24894bdb65f4bd5d4e49ae4/specs/gloas/fork-choice.md?plain=1#L442
AI Assistance Disclosure
🤖 Generated with Claude Code
cc @nflaig @ensi321