feat(napi): add latestBlockHash and payloadBlockNumber accessors#297
feat(napi): add latestBlockHash and payloadBlockNumber accessors#297lodekeeper-z wants to merge 1 commit intoChainSafe:mainfrom
Conversation
Add two missing IBeaconStateView methods to NAPI bindings: - latestBlockHash: returns block_hash from latest execution payload header - payloadBlockNumber: returns block_number from latest execution payload header Both throw INVALID_FORK for pre-bellatrix states. Also adds latestExecutionPayloadHeaderBlockNumber to AnyBeaconState as the underlying accessor. 🤖 Generated with AI assistance
Summary of ChangesHello, 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 bridges gaps between the existing NAPI bindings and the upstream 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements getters for the latest execution payload header's block hash and block number across BeaconStateView and AnyBeaconState, including the necessary N-API bindings and TypeScript definitions. A review comment points out that the new function in any_beacon_state.zig violates the repository's style guide by failing to meet the required minimum assertion density for verifying invariants and preconditions.
| pub fn latestExecutionPayloadHeaderBlockNumber(self: *AnyBeaconState) !u64 { | ||
| return switch (self.*) { | ||
| .phase0, .altair => error.InvalidAtFork, | ||
| inline else => |state| { | ||
| var header = try state.get("latest_execution_payload_header"); | ||
| return try header.get("block_number"); | ||
| }, | ||
| }; | ||
| } |
There was a problem hiding this comment.
This function is missing assertions, which is a violation of the repository's style guide. The style guide requires an average of two assertions per function to ensure code safety and document invariants (lines 51-55).
Consider adding assertions for preconditions, such as checking that self is not null, and for critical invariants. For example, you could assert that the fork is indeed Bellatrix or newer before accessing fork-specific fields. The style guide encourages such "blatantly true assertions" as a form of documentation (line 62).
pub fn latestExecutionPayloadHeaderBlockNumber(self: *AnyBeaconState) !u64 {
std.debug.assert(self != null);
return switch (self.*) {
.phase0, .altair => error.InvalidAtFork,
inline else => |state| {
std.debug.assert(self.forkSeq().gte(.bellatrix));
var header = try state.get("latest_execution_payload_header");
return try header.get("block_number");
},
};
}
References
- Functions should contain assertions to check for pre/postconditions and invariants. The style guide mandates an average of at least two assertions per function to improve code safety and act as documentation. (link)
Summary
Close 2 of the remaining gaps between our NAPI bindings and the upstream
IBeaconStateViewinterface (lodestar PR #9067).New methods
latestBlockHashpayloadBlockNumberBoth throw
INVALID_FORKfor pre-bellatrix states, matching the upstream interface semantics.Changes
bindings/napi/BeaconStateView.zig: Two new NAPI getter functionssrc/fork_types/any_beacon_state.zig:latestExecutionPayloadHeaderBlockNumberaccessorbindings/src/index.d.ts: TypeScript type declarationsContext
With this PR + PR #276, only 3 non-Gloas methods remain unimplemented:
getValidatorsByStatus,toValue, andcomputeAttestationsRewards(naming mismatch).🤖 Generated with AI assistance