Skip to content

feat: add bindings for more getters for BeaconStateView#189

Merged
wemeetagain merged 42 commits intoChainSafe:napifrom
guha-rahul:bindings/process_slot
Jan 29, 2026
Merged

feat: add bindings for more getters for BeaconStateView#189
wemeetagain merged 42 commits intoChainSafe:napifrom
guha-rahul:bindings/process_slot

Conversation

@guha-rahul
Copy link
Copy Markdown
Contributor

@guha-rahul guha-rahul commented Jan 22, 2026

  • 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

@guha-rahul guha-rahul requested a review from a team as a code owner January 22, 2026 21:20
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 processSlots functionality, enabling JavaScript/TypeScript applications to interact with the core state transition logic for advancing the beacon state. This enhancement provides a mechanism to process multiple slots efficiently, with an option to control cache transfer during the state cloning process, thereby expanding the capabilities of the bindings.

Highlights

  • New N-API Binding for processSlots: A new N-API function, BeaconStateView_processSlots, has been introduced in beacon_state_view.zig. This function allows processing slots from the current state to a target slot, returning a new BeaconStateView.
  • TypeScript Type Definitions: Corresponding TypeScript type definitions for the processSlots method and its optional parameters (ProcessSlotsOpts) have been added in index.ts, improving type safety and developer experience.
  • Demo/Test Usage: A demo call to processSlots has been added in demo.ts to showcase the usage of the new functionality and measure its execution duration.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 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.

Comment thread bindings/napi/beacon_state_view.zig Outdated
Comment on lines +242 to +244
if (try options_arg.typeof() == .object and try options_arg.hasNamedProperty("dontTransferCache")) {
dont_transfer_cache = try (try options_arg.getNamedProperty("dontTransferCache")).getValueBool();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. The style guide (lines 130-132) advises against compound conditions, recommending nested if/else branches to make it easier for the reader to verify that all cases are handled. (link)

@guha-rahul guha-rahul changed the title feat: add bindings for process_slot feat: add bindings for more getters for BeaconStateView Jan 24, 2026
Copy link
Copy Markdown
Collaborator

@spiral-ladder spiral-ladder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const processSlotsFn = state_transition.state_transition.processSlots;
const processSlots = state_transition.state_transition.processSlots;

do we need this rename?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/state_transition/cache/epoch_cache.zig
Comment thread src/state_transition/cache/state_cache.zig
Comment thread src/state_transition/cache/state_cache.zig Outdated
Comment thread src/state_transition/utils/validator_status.zig
Comment on lines +34 to +45
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;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I think this can be replaced with std.meta.stringToEnum

Comment thread ssz Outdated
@wemeetagain wemeetagain merged commit cfc06cb into ChainSafe:napi Jan 29, 2026
1 check passed
spiral-ladder pushed a commit that referenced this pull request Feb 24, 2026
- 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
```
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