feat: add bindings for more getters for BeaconStateView#189
feat: add bindings for more getters for BeaconStateView#189wemeetagain merged 42 commits intoChainSafe:napifrom
Conversation
Summary of ChangesHello @guha-rahul, 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 N-API bindings for 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. 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 pull request introduces N-API bindings for the processSlots function, allowing it to be called from JavaScript. The changes are well-structured, including the core Zig implementation, TypeScript type definitions, and a new test case. The code is clean and follows the existing patterns. I have one suggestion to improve adherence to the repository's style guide for code clarity.
| if (try options_arg.typeof() == .object and try options_arg.hasNamedProperty("dontTransferCache")) { | ||
| dont_transfer_cache = try (try options_arg.getNamedProperty("dontTransferCache")).getValueBool(); | ||
| } |
There was a problem hiding this comment.
To improve readability and align with the repository's style guide, it's better to split this compound if condition into nested if statements. This makes the control flow clearer and easier to reason about.
if (try options_arg.typeof() == .object) {
if (try options_arg.hasNamedProperty("dontTransferCache")) {
dont_transfer_cache = try (try options_arg.getNamedProperty("dontTransferCache")).getValueBool();
}
}
References
- The style guide (lines 130-132) advises against compound conditions, recommending nested
if/elsebranches to make it easier for the reader to verify that all cases are handled. (link)
spiral-ladder
left a comment
There was a problem hiding this comment.
Nice! Some comments
| @@ -9,6 +9,17 @@ const SignedBlock = state_transition.SignedBlock; | |||
| const isExecutionEnabledFunc = state_transition.isExecutionEnabled; | |||
| const computeUnrealizedCheckpoints = state_transition.computeUnrealizedCheckpoints; | |||
| const getEffectiveBalanceIncrementsZeroInactiveFn = state_transition.getEffectiveBalanceIncrementsZeroInactive; | |||
| const processSlotsFn = state_transition.state_transition.processSlots; | |||
There was a problem hiding this comment.
| const processSlotsFn = state_transition.state_transition.processSlots; | |
| const processSlots = state_transition.state_transition.processSlots; |
do we need this rename?
There was a problem hiding this comment.
every other function uses fn and i noticed isExecutionEnabledFunc is different so i should change it right?
| const cached_state = try env.unwrap(CachedBeaconState, cb.this()); | ||
| const slot: u64 = @intCast(try cb.arg(0).getValueInt64()); | ||
|
|
||
| var dont_transfer_cache = false; |
There was a problem hiding this comment.
I know this is because of do_not_transfer_cache in our native layer, but I think it's bad to have double negatives as bool, and we should just have transfer_cache in a future refactor PR. transfer_cache = true is clearer than do_not_transfer_cache = false.
Just noting this down first, no changes needed for this PR - we can change it together with the native part
| pub fn fromString(s: []const u8) ?ValidatorStatus { | ||
| if (std.mem.eql(u8, s, "pending_initialized")) return .pending_initialized; | ||
| if (std.mem.eql(u8, s, "pending_queued")) return .pending_queued; | ||
| if (std.mem.eql(u8, s, "active_ongoing")) return .active_ongoing; | ||
| if (std.mem.eql(u8, s, "active_exiting")) return .active_exiting; | ||
| if (std.mem.eql(u8, s, "active_slashed")) return .active_slashed; | ||
| if (std.mem.eql(u8, s, "exited_unslashed")) return .exited_unslashed; | ||
| if (std.mem.eql(u8, s, "exited_slashed")) return .exited_slashed; | ||
| if (std.mem.eql(u8, s, "withdrawal_possible")) return .withdrawal_possible; | ||
| if (std.mem.eql(u8, s, "withdrawal_done")) return .withdrawal_done; | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Similarly, I think this can be replaced with std.meta.stringToEnum
- implemented bindings for ``` getValidator getValidatorStatus getValidatorCount getActiveValidatorCount getBeaconProposer getBeaconProposers getBeaconProposersPrevEpoch getBeaconProposersNextEpoch getIndexedSyncCommitteeAtEpoch getBlockRootAtSlot getBlockRoot isMergeTransitionComplete getRandaoMix getHistoricalSummaries getPendingDeposits getPendingPartialWithdrawals getPendingConsolidations getProposerLookahead getSingleProof isValidVoluntaryExit getVoluntaryExitValidity proposerRewards processSlots previousDecisionRoot currentDecisionRoot nextDecisionRoot getShufflingDecisionRoot ```
Uh oh!
There was an error while loading. Please reload this page.