-
-
Notifications
You must be signed in to change notification settings - Fork 433
feat: model BeaconStateView #8773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Conversation
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 introduces a significant architectural improvement by implementing a 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the BeaconStateView interface and its implementation, providing a read-only facade over the CachedBeaconStateAllForks. This is a positive step towards encapsulating state access logic and improving maintainability. The changes also include refactoring RootCache and proposerShufflingDecisionRoot to utilize this new view, ensuring consistency. New types and utility functions for light client proofs and validator status mapping have also been added. Overall, the changes are well-structured and align with the goal of abstracting state access. There are a few areas identified for potential improvement regarding robustness and efficiency.
| const n2 = n1.left; | ||
| const n5 = n2.right; | ||
| const n10 = n5.left; | ||
| const n21 = n10.right; | ||
| const n43 = n21.right; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The direct access to n1.left, n2.right, etc., in getSyncCommitteesWitness relies heavily on the internal structure of the Tree and node properties. This makes the code brittle to future changes in the SSZ tree structure. If the SSZ structure is modified, these direct accesses could break silently or produce incorrect proofs, which is a critical correctness issue for light client proofs. It would be more robust to use explicit GINDEXes or a more abstract way to navigate the tree if available, or at least add comments explaining the gindex for each node access to make it easier to maintain.
| getValidatorsByStatus(statuses: Set<string>, currentEpoch: Epoch): phase0.Validator[] { | ||
| const validators: phase0.Validator[] = []; | ||
| const validatorsArr = this.cachedState.validators.getAllReadonlyValues(); | ||
|
|
||
| for (const validator of validatorsArr) { | ||
| const validatorStatus = getValidatorStatus(validator, currentEpoch); | ||
| if (statuses.has(validatorStatus) || statuses.has(mapToGeneralStatus(validatorStatus))) { | ||
| validators.push(validator); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getValidatorsByStatus method creates a new array validatorsArr by calling this.cachedState.validators.getAllReadonlyValues() on every invocation. If this method is called frequently and the validator list is large, this could lead to unnecessary memory allocations and performance overhead. Consider iterating directly over the cachedState.validators view or caching the getAllReadonlyValues() result if appropriate to improve efficiency.
| // TODO: consider also populate index2pubkey? | ||
| export function createBeaconStateView(config: BeaconConfig, stateBytes: Uint8Array): IBeaconStateView { | ||
| const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes); | ||
| const pubkey2index = new PubkeyIndexMap(); | ||
| // TODO: dedup? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO comments on lines 536 and 540 indicate areas that might need further attention or are incomplete. While not a bug, they suggest potential future work or unresolved design decisions that could impact maintainability or correctness. It would be beneficial to address these or provide more context on their future resolution.
Motivation
Description
IBeaconStateViewinterfacetsBeaconStateViewblocked by #8728 to build successfully