Skip to content
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

feat(node-api): Allow querying beacon blocks by execution numbers #1824

Merged
merged 21 commits into from
Aug 1, 2024

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Jul 30, 2024

  • prune from the roots and executionNumbers maps in block store
  • use executionID instead of beacon API spec blockID for proof endpoints

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced methods GetTimestamp and GetSlotByTimestamp for improved timestamp and slot retrieval.
    • Added resolveExecutionID method for fetching slots based on execution IDs.
    • New mock function GetSlotByTimestamp in the BlockStore mock implementation.
  • Improvements

    • Increased the DefaultAvailabilityWindow for enhanced service performance.
    • Updated method signatures to enhance type safety, replacing uint64 with math.Slot.
    • Improved clarity in the BlockStore mock by using more specific types.
    • Removed Prune and Set methods from the BlockStore interface to streamline functionality.
  • Bug Fixes

    • Enhanced error logging in the listenAndStore method to include slot values for better debugging.
  • Documentation

    • Updated API request and response structures to reflect changes from BlockID to ExecutionID.

@calbera calbera requested a review from archbear July 30, 2024 22:45
Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

The changes significantly enhance the beacondb framework, focusing on improved handling of blocks, timestamps, and execution identifiers. Key updates include an increase in the DefaultAvailabilityWindow, refined method signatures for clarity and type safety, and the addition of new functions for managing execution numbers and timestamps. These enhancements collectively improve the API's performance, usability, and maintainability, making it more robust and efficient.

Changes

File Path Change Summary
mod/beacon/block_store/config.go Increased DefaultAvailabilityWindow from 1000 to 8192.
mod/beacon/block_store/service.go Simplified listenAndStore method; enhanced error logging with slot value.
mod/beacon/block_store/types.go Updated Set and Get methods to use math.Slot; added GetSlotByTimestamp method.
mod/consensus-types/pkg/types/block.go Added GetTimestamp and GetExecutionNumber methods to BeaconBlock struct.
mod/node-api/backend/*.go Introduced GetSlotByExecutionNumber and updated GetSlotByRoot to use common.Root.
mod/node-api/handlers/proof/*.go Replaced BlockID with ExecutionID in various methods to enhance handling of execution identifiers.
mod/node-api/handlers/types/request.go Replaced BlockIDRequest with ExecutionIDRequest.
mod/node-api/handlers/utils/*.go Added constants and functions for timestamp management; improved key handling.
mod/storage/pkg/block/*.go Enhanced KVStore with an executionNumbers map; updated method signatures and types.
mod/storage/pkg/encoding/*.go Restructured codec types and methods for improved functionality.
mod/node-api/backend/mocks/block_store.mock.go Updated mock implementations for type safety; added GetSlotByTimestamp; removed outdated methods.
mod/node-core/pkg/components/storage/types.go Updated BlockStore interface for type specificity; removed Prune and Set methods.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Backend
    participant BlockStore
    participant ExecutionStorage

    User->>Backend: Request data by ExecutionID
    Backend->>BlockStore: GetSlotByExecutionNumber(ExecutionID)
    BlockStore->>ExecutionStorage: Fetch slot for ExecutionID
    ExecutionStorage-->>BlockStore: Return Slot
    BlockStore-->>Backend: Return Slot
    Backend-->>User: Response with Slot data
Loading

🐰 In the fields where daisies play,
A rabbit hops both bright and gay,
With slots and timestamps now in sight,
Our system shines, oh what delight!
Hops of joy, let’s cheer and sing,
For brighter days that changes bring! 🌼


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 1.39860% with 141 lines in your changes missing coverage. Please review.

Project coverage is 23.81%. Comparing base (1e73a37) to head (0f9af65).

Files Patch % Lines
mod/storage/pkg/block/store.go 0.00% 64 Missing ⚠️
mod/node-api/handlers/proof/handler.go 0.00% 19 Missing ⚠️
mod/node-api/handlers/utils/id.go 0.00% 14 Missing ⚠️
mod/node-api/engines/echo/vaildator.go 0.00% 13 Missing ⚠️
mod/node-core/pkg/components/storage/provider.go 0.00% 6 Missing ⚠️
mod/beacon/block_store/service.go 0.00% 4 Missing ⚠️
mod/node-api/backend/backend.go 0.00% 3 Missing ⚠️
mod/node-api/handlers/proof/block_proposer.go 0.00% 3 Missing ⚠️
...node-api/handlers/proof/execution_fee_recipient.go 0.00% 3 Missing ⚠️
mod/node-api/handlers/proof/execution_number.go 0.00% 3 Missing ⚠️
... and 6 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1824      +/-   ##
==========================================
- Coverage   23.90%   23.81%   -0.10%     
==========================================
  Files         325      325              
  Lines       13988    14050      +62     
  Branches       18       18              
==========================================
+ Hits         3344     3346       +2     
- Misses      10529    10589      +60     
  Partials      115      115              
Files Coverage Δ
mod/beacon/block_store/config.go 0.00% <ø> (ø)
mod/consensus-types/pkg/types/block.go 90.90% <100.00%> (+0.16%) ⬆️
mod/storage/pkg/beacondb/kvstore.go 0.00% <ø> (ø)
mod/storage/pkg/encoding/ssz.go 0.00% <ø> (ø)
mod/node-core/pkg/components/block_store.go 0.00% <0.00%> (ø)
mod/node-core/pkg/components/deposit_store.go 0.00% <0.00%> (ø)
mod/storage/pkg/deposit/store.go 0.00% <0.00%> (ø)
mod/storage/pkg/pruner/pruner.go 78.26% <0.00%> (+9.03%) ⬆️
mod/node-core/pkg/components/store.go 0.00% <0.00%> (ø)
mod/node-api/backend/backend.go 0.00% <0.00%> (ø)
... and 10 more

... and 1 file with indirect coverage changes

@calbera calbera marked this pull request as ready for review July 31, 2024 22:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between f427600 and a866b88.

Files selected for processing (28)
  • mod/beacon/block_store/config.go (1 hunks)
  • mod/beacon/block_store/service.go (1 hunks)
  • mod/beacon/block_store/types.go (1 hunks)
  • mod/consensus-types/pkg/types/block.go (1 hunks)
  • mod/node-api/backend/backend.go (3 hunks)
  • mod/node-api/backend/types.go (1 hunks)
  • mod/node-api/handlers/beacon/backend.go (1 hunks)
  • mod/node-api/handlers/proof/backend.go (1 hunks)
  • mod/node-api/handlers/proof/block_proposer.go (1 hunks)
  • mod/node-api/handlers/proof/execution_fee_recipient.go (1 hunks)
  • mod/node-api/handlers/proof/execution_number.go (1 hunks)
  • mod/node-api/handlers/proof/handler.go (2 hunks)
  • mod/node-api/handlers/proof/routes.go (1 hunks)
  • mod/node-api/handlers/proof/types/request.go (1 hunks)
  • mod/node-api/handlers/proof/types/response.go (3 hunks)
  • mod/node-api/handlers/types/request.go (1 hunks)
  • mod/node-api/handlers/utils/constants.go (1 hunks)
  • mod/node-api/handlers/utils/id.go (2 hunks)
  • mod/node-core/pkg/components/storage/types.go (1 hunks)
  • mod/node-core/pkg/components/store.go (1 hunks)
  • mod/storage/pkg/beacondb/kvstore.go (1 hunks)
  • mod/storage/pkg/block/keys.go (1 hunks)
  • mod/storage/pkg/block/store.go (3 hunks)
  • mod/storage/pkg/block/types.go (1 hunks)
  • mod/storage/pkg/deposit/store.go (2 hunks)
  • mod/storage/pkg/encoding/ssz.go (2 hunks)
  • mod/storage/pkg/encoding/u64.go (1 hunks)
  • mod/storage/pkg/pruner/pruner.go (1 hunks)
Additional comments not posted (56)
mod/storage/pkg/block/keys.go (1)

1-33: LGTM!

The constants for key prefixes and map names are well-defined and follow Go naming conventions.

mod/node-api/handlers/types/request.go (1)

31-33: LGTM!

The new TimestampIDRequest type is well-defined and includes validation.

mod/storage/pkg/block/types.go (1)

34-34: LGTM!

The new GetTimestamp method enhances the BeaconBlock interface's functionality by allowing timestamp retrieval.

mod/node-api/handlers/utils/constants.go (4)

1-20: License Header: Approved

The license header is correctly formatted and provides the necessary legal information.


21-23: Package Declaration and Imports: Approved

The package declaration and imports are appropriate for the functionality provided in this file.


25-31: Constants Definition: Approved

The constants for state IDs and timestamp ID prefix are well-defined and appropriately named.


33-36: Slot Constants: Approved

The use of iota for defining slot constants is appropriate and efficient.

mod/storage/pkg/encoding/u64.go (3)

Line range hint 1-20:
License Header: Approved

The license header is correctly formatted and provides the necessary legal information.


21-25: Package Declaration and Imports: Approved

The package declaration and imports are appropriate for the functionality provided in this file.


28-39: Global Variables: Approved

The global variables U64Key and U64Value are well-defined and the comments provide clear explanations of their purpose and usage.

mod/node-api/handlers/proof/backend.go (3)

Line range hint 1-20:
License Header: Approved

The license header is correctly formatted and provides the necessary legal information.


21-25: Package Declaration and Imports: Approved

The package declaration and imports are appropriate for the functionality provided in this file.


28-31: Backend Interface: Approved

The change to include the GetSlotByTimestamp method enhances the flexibility of the API by allowing timestamp-based slot retrieval. The interface definitions are clear and well-structured.

mod/node-api/handlers/proof/types/request.go (3)

26-29: LGTM!

The BlockProposerRequest struct now correctly embeds types.TimestampIDRequest and aligns with the new endpoint path.


32-35: LGTM!

The ExecutionNumberRequest struct now correctly embeds types.TimestampIDRequest and aligns with the new endpoint path.


38-41: LGTM!

The ExecutionFeeRecipientRequest struct now correctly embeds types.TimestampIDRequest and aligns with the new endpoint path.

mod/beacon/block_store/config.go (1)

24-24: LGTM! But verify the impact on the system.

The DefaultAvailabilityWindow has been increased from 1000 to 8192. This change is likely aimed at enhancing the availability and performance of the block service.

However, ensure that this change does not negatively impact memory usage or other system resources.

mod/node-api/handlers/proof/routes.go (3)

37-39: LGTM!

The route for GetBlockProposer now correctly uses :timestamp_id instead of :block_id.


42-44: LGTM!

The route for GetExecutionNumber now correctly uses :timestamp_id instead of :block_id.


47-49: LGTM!

The route for GetExecutionFeeRecipient now correctly uses :timestamp_id instead of :block_id.

mod/node-core/pkg/components/store.go (2)

27-27: Verify the correctness of the new import path.

The import path for the encoding package has been changed. Ensure that the new path github.com/berachain/beacon-kit/mod/storage/pkg/encoding is correct and consistent with the rest of the codebase.

Verification successful

The new import path is correct.

The import path for the encoding package github.com/berachain/beacon-kit/mod/storage/pkg/encoding is correct and consistent with the package structure in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new import path for the encoding package.

# Test: Search for the package declaration. Expect: The package declaration should match the new import path.
rg --type go 'package encoding' mod/storage/pkg/encoding

Length of output: 156


Line range hint 31-36:
LGTM! But verify the function implementation.

The function ProvideKVStore looks good. Ensure that the function correctly uses the new import path and that there are no errors introduced by the change.

Verification successful

LGTM! But verify the function implementation.

The function ProvideKVStore looks good. The function correctly uses the new import paths for the encoding and beacondb packages, and there are no errors introduced by the change.

  • mod/node-core/pkg/components/store.go: Import statements and function implementation are correct.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function implementation for ProvideKVStore.

# Test: Search for the function implementation. Expect: The function implementation should match the new import path.
rg --type go 'func ProvideKVStore' mod/node-core/pkg/components/store.go

Length of output: 95


Script:

#!/bin/bash
# Description: Extract the full implementation of the ProvideKVStore function.

# Use ripgrep to search for the ProvideKVStore function and include 20 lines of context to capture the full implementation.
rg --type go 'func ProvideKVStore' -A 20 mod/node-core/pkg/components/store.go

Length of output: 378


Script:

#!/bin/bash
# Description: Verify the import statements for encoding and beacondb packages.

# Use ripgrep to search for the import statements in the store.go file.
rg --type go 'import' -A 10 mod/node-core/pkg/components/store.go

Length of output: 392

mod/beacon/block_store/types.go (1)

39-39: Verify the correctness of the new parameter type.

The Set method in the BlockStore interface has changed the parameter type for index from uint64 to math.Slot. Ensure that the new parameter type is correct and consistent with the rest of the codebase.

mod/node-api/handlers/proof/block_proposer.go (1)

40-42: Verify the correctness of the new method.

The Handler function has changed the method used to resolve block identifiers from resolveBlockID to resolveTimestampID. Ensure that the new method is correct and consistent with the rest of the codebase.

Verification successful

The new method resolveTimestampID is correctly implemented and consistent with the rest of the codebase.

  • The method resolveTimestampID is implemented in mod/node-api/handlers/proof/handler.go.
  • It is referenced in multiple files, including block_proposer.go, execution_fee_recipient.go, and execution_number.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new method used to resolve block identifiers.

# Test: Search for the method implementation. Expect: The method implementation should match the new method.
rg --type go 'func resolveTimestampID' mod/node-api/handlers/proof/block_proposer.go

Length of output: 86


Script:

#!/bin/bash
# Description: Verify the new method used to resolve block identifiers.

# Test 1: Search for the method implementation across the entire codebase.
rg --type go 'func resolveTimestampID'

# Test 2: Search for any references to the method across the entire codebase.
rg --type go 'resolveTimestampID'

Length of output: 492


Script:

#!/bin/bash
# Description: Verify the new method used to resolve block identifiers.

# Test: Search for the method implementation within the handler.go file.
rg --type go 'func resolveTimestampID' mod/node-api/handlers/proof/handler.go

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the new method used to resolve block identifiers.

# Test: Search for the method implementation within the context of a struct or interface.
rg --type go 'resolveTimestampID' -A 10

Length of output: 3593

mod/node-api/handlers/proof/execution_number.go (1)

41-43: Verify the correctness of the change from resolveBlockID to resolveTimestampID.

Ensure that the resolveTimestampID method correctly handles the timestamp-based resolution and that all relevant parts of the codebase are updated to use this new method.

mod/node-api/handlers/proof/execution_fee_recipient.go (1)

41-43: Verify the correctness of the change from resolveBlockID to resolveTimestampID.

Ensure that the resolveTimestampID method correctly handles the timestamp-based resolution and that all relevant parts of the codebase are updated to use this new method.

mod/storage/pkg/pruner/pruner.go (1)

91-91: Improved readability of error logging.

The consolidation of the error logging statement into a single line improves readability and maintainability without altering functionality.

mod/beacon/block_store/service.go (1)

94-97: Enhanced error logging and simplified slot handling.

The simplification of the slot handling and the enhancement of the error logging mechanism improve readability and provide more context in error messages, aiding in debugging.

mod/node-api/handlers/proof/handler.go (1)

76-102: Well-defined method with proper error handling.

The new method resolveTimestampID is well-defined, with proper error handling to retrieve the slot, beacon state, and block header associated with a given timestamp ID.

mod/storage/pkg/deposit/store.go (2)

30-30: LGTM!

The import path for the encoding package has been updated to reflect a more general path, enhancing modularity and clarity.


Line range hint 59-63:
LGTM!

The prefix used for the NewPrefix function has been updated to use the KeyDepositPrefix constant. This enhances readability and maintainability by avoiding hardcoded values.

mod/storage/pkg/encoding/ssz.go (2)

31-31: LGTM!

The Empty() method has been replaced with a new constraint constraints.Empty[T]. This change enhances type safety and potentially improves performance by leveraging compile-time checks.


73-73: LGTM!

An additional constraint constraints.Versionable has been introduced, and the Version() method has been removed. This ensures that any type used with SSZInterfaceCodec must support versioning, enhancing compatibility and correctness in serialization and deserialization processes.

mod/node-api/handlers/utils/id.go (2)

53-53: LGTM!

The type of the GetSlotByRoot method's parameter has been changed from a fixed-size byte array to a more abstract common.Root type. This enhances type safety and flexibility in handling different root types.


67-91: LGTM!

The new SlotFromTimestampID function allows querying of slots based on a timestamp ID. This expands the existing capabilities of the module by enabling users to retrieve slots using timestamp identifiers.

mod/node-api/handlers/proof/types/response.go (3)

31-31: LGTM! Documentation update for BlockProposerResponse.

The change correctly updates the endpoint identifier to use timestamp_id.


51-51: LGTM! Documentation update for ExecutionNumberResponse.

The change correctly updates the endpoint identifier to use timestamp_id.


69-69: LGTM! Documentation update for ExecutionFeeRecipientResponse.

The change correctly updates the endpoint identifier to use timestamp_id.

mod/storage/pkg/block/store.go (7)

47-49: LGTM! Addition of timestamps map in KVStore.

The new timestamps map enhances the functionality of the KVStore by allowing it to track block timestamps.


77-82: LGTM! Initialization of timestamps map in NewStore.

The change ensures that the timestamps map is properly set up when a new store is created.


89-92: LGTM! Update to Get function parameter type.

The change improves type safety by using the more specific math.Slot type for the slot parameter.


98-119: LGTM! Update to Set function to store block root and timestamp.

The change ensures that all relevant data is maintained cohesively by storing both the block root and the timestamp.


124-130: LGTM! Update to GetSlotByRoot function parameter type.

The change improves type safety and abstraction by using the more semantically meaningful common.Root type for the root parameter.


132-139: LGTM! Addition of GetSlotByTimestamp function.

The new function enhances the store's querying capabilities by allowing retrieval based on timestamps.


144-182: LGTM! Update to Prune function to handle removal of blocks, roots, and timestamps.

The change ensures that all related data is cleaned up efficiently by removing blocks, roots, and timestamps.

mod/node-api/backend/types.go (3)

84-84: LGTM! Update to Get method parameter type in BlockStore interface.

The change improves type safety by using the more specific math.Slot type for the slot parameter.


86-86: LGTM! Update to GetSlotByRoot method parameter type in BlockStore interface.

The change improves type safety and abstraction by using the more semantically meaningful common.Root type for the root parameter.


87-89: LGTM! Addition of GetSlotByTimestamp method in BlockStore interface.

The new method enhances the interface's querying capabilities by allowing retrieval based on timestamps.

mod/node-api/backend/backend.go (3)

124-127: LGTM!

The AttachNode method correctly sets the node on the backend for querying historical heights.


138-141: LGTM!

The parameter type change in GetSlotByRoot from [32]byte to common.Root enhances type safety and readability.


145-151: LGTM!

The GetSlotByTimestamp method is correctly implemented and complements the existing GetSlotByRoot method.

mod/consensus-types/pkg/types/block.go (1)

238-242: LGTM!

The GetTimestamp method is correctly implemented and follows the existing method structure.

mod/node-core/pkg/components/storage/types.go (2)

50-51: LGTM!

The parameter type change in Get from uint64 to math.Slot enhances type safety.


52-53: LGTM!

The parameter type change in GetSlotByRoot from [32]byte to common.Root enhances type safety and readability.

mod/storage/pkg/beacondb/kvstore.go (2)

31-31: Verify the usage of the encoding package within the file.

Ensure that the usage of the encoding package remains consistent with the previous implementation and that there are no errors introduced due to the import path change.

Verification successful

Verify the definitions of SSZInterfaceCodec and SSZValueCodec within the encoding package.

Ensure that these types are correctly defined and used in the encoding package to avoid any potential errors due to the import path change.


The import and usage of the encoding package are correct and consistent.

The SSZInterfaceCodec and SSZValueCodec types are correctly defined and used within the encoding package, and there are no errors introduced due to the import path change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `encoding` package within the file.

# Test: Search for the usage of the `encoding` package. Expect: The usage should be consistent with the previous implementation.
rg --type go 'encoding.' mod/storage/pkg/beacondb/kvstore.go

Length of output: 394


Script:

#!/bin/bash
# Description: Verify the definitions of `SSZInterfaceCodec` and `SSZValueCodec` within the `encoding` package.

# Test: Search for the definitions of `SSZInterfaceCodec` and `SSZValueCodec` in the `encoding` package.
rg 'SSZInterfaceCodec' mod/storage/pkg/encoding
rg 'SSZValueCodec' mod/storage/pkg/encoding

Length of output: 1599


31-31: Verify the correctness of the new import path.

The import path for the encoding package has been updated. Ensure that the new path github.com/berachain/beacon-kit/mod/storage/pkg/encoding is correct and aligns with the project's structure.

Verification successful

The new import path github.com/berachain/beacon-kit/mod/storage/pkg/encoding is correct.

The definitions for SSZInterfaceCodec and SSZValueCodec are found in mod/storage/pkg/encoding/ssz.go, confirming that the new import path is accurate.

  • mod/storage/pkg/encoding/ssz.go contains the necessary definitions for SSZInterfaceCodec and SSZValueCodec.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the new import path.

# Test: Check if the new import path exists. Expect: The path should exist.
if ! fd 'encoding.go' | grep -q 'mod/storage/pkg/encoding'; then
  echo "Error: The new import path 'mod/storage/pkg/encoding' does not exist."
  exit 1
fi

echo "The new import path 'mod/storage/pkg/encoding' exists."

Length of output: 215


Script:

#!/bin/bash
# Description: Search for the encoding.go file in the entire project to locate the correct path.

# Find the location of the encoding.go file.
fd 'encoding.go'

Length of output: 96


Script:

#!/bin/bash
# Description: Search for the usage of the encoding package within kvstore.go to determine the correct import path.

# Find the usage of the encoding package in kvstore.go
rg 'encoding\.' mod/storage/pkg/beacondb/kvstore.go -A 5

Length of output: 1352


Script:

#!/bin/bash
# Description: Search for the definitions of SSZInterfaceCodec and SSZValueCodec in the found encoding.go files.

# Search for SSZInterfaceCodec and SSZValueCodec in mod/primitives/pkg/constraints/encoding.go
rg 'SSZInterfaceCodec|SSZValueCodec' mod/primitives/pkg/constraints/encoding.go

# Search for SSZInterfaceCodec and SSZValueCodec in mod/runtime/pkg/encoding/encoding.go
rg 'SSZInterfaceCodec|SSZValueCodec' mod/runtime/pkg/encoding/encoding.go

Length of output: 157


Script:

#!/bin/bash
# Description: Search for the definitions of SSZInterfaceCodec and SSZValueCodec in the entire project.

# Search for SSZInterfaceCodec in the entire project
rg 'SSZInterfaceCodec'

# Search for SSZValueCodec in the entire project
rg 'SSZValueCodec'

Length of output: 2374

mod/node-api/handlers/beacon/backend.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a866b88 and d141618.

Files ignored due to path filters (1)
  • mod/node-api/engines/go.sum is excluded by !**/*.sum
Files selected for processing (4)
  • mod/node-api/backend/types.go (1 hunks)
  • mod/node-api/engines/echo/vaildator.go (4 hunks)
  • mod/node-api/engines/go.mod (1 hunks)
  • mod/node-api/handlers/utils/id.go (2 hunks)
Additional comments not posted (17)
mod/node-api/engines/go.mod (6)

16-16: Approved: Addition of github.com/berachain/beacon-kit/mod/chain-spec.

This dependency is likely related to blockchain specifications and seems necessary for the module's functionality.


17-17: Approved: Addition of github.com/berachain/beacon-kit/mod/primitives.

This dependency provides foundational data types or utilities, which are essential for the module's operations.


21-21: Approved: Addition of github.com/ethereum/go-ethereum.

This dependency is significant for providing Ethereum blockchain functionalities, indicating support for Ethereum-related operations.


28-28: Approved: Addition of github.com/holiman/uint256.

This dependency is particularly relevant in blockchain applications where large numerical values are common.


29-29: Approved: Addition of github.com/klauspost/cpuid/v2.

This dependency enhances performance optimizations based on the underlying hardware by detecting CPU features.


37-37: Approved: Addition of github.com/prysmaticlabs/gohashtree.

This dependency is useful for efficient data verification and integrity checks in blockchain implementations.

mod/node-api/handlers/utils/id.go (4)

48-66: Approved: Changes to SlotFromBlockID.

The changes enhance type safety and flexibility by using the common.Root type instead of a fixed-size byte array.


67-91: Approved: Addition of SlotFromTimestampID.

This new function allows querying slots using a timestamp ID, expanding the module's capabilities to include timestamp-based queries.


93-97: Approved: Addition of IsTimestampPrefix.

This function correctly checks if the given timestampID is prefixed with the timestamp prefix.


99-104: Approved: Repositioning of U64FromString.

The function has been correctly repositioned within the file without any change to its functionality.

mod/node-api/engines/echo/vaildator.go (4)

Line range hint 60-69: Approved: Enhancements to ConstructValidator.

The function has been enhanced with new validators, including ValidateTimestampID, improving the validator's capabilities.


98-111: Approved: Addition of ValidateTimestampID.

This new function correctly checks if the provided timestamp ID is valid by comparing it against a set of allowed values.


Line range hint 83-96: Approved: Changes to ValidateBlockID.

The function has been modified to integrate with new validators, improving its capabilities.


Line range hint 155-172: Approved: Changes to validateStateBlockIDs.

The function has been streamlined to handle empty fields directly within the validation logic for state block IDs, simplifying the validation process.

mod/node-api/backend/types.go (3)

84-84: Improved Type Safety and Abstraction.

The change from [32]byte to common.Root enhances type safety and abstraction.


85-87: New Functionality: Query by Timestamp.

The addition of GetSlotByTimestamp enhances the BlockStore interface by allowing queries based on timestamps.


88-88: Enhanced Type Safety with math.Slot.

The change from uint64 to math.Slot improves type safety and consistency within the interface.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between d141618 and d992c34.

Files selected for processing (1)
  • mod/node-api/backend/mocks/block_store.mock.go (5 hunks)
Additional comments not posted (5)
mod/node-api/backend/mocks/block_store.mock.go (5)

6-8: Imports look good.

The new imports for bytes and math are appropriate for the updated function signatures and new functionalities.


Line range hint 26-48: Function signature update improves type safety.

The update to use bytes.B32 instead of [32]byte enhances type safety and clarity. The function implementation correctly handles the return values.


Line range hint 59-76: Helper methods updated for consistency.

The helper methods for GetSlotByRoot have been updated to reflect the new parameter type bytes.B32, ensuring consistency.


81-106: New function GetSlotByTimestamp added.

The new function GetSlotByTimestamp follows the pattern of existing mock functions and correctly handles the return values.


109-132: Helper methods for GetSlotByTimestamp added.

The helper methods for GetSlotByTimestamp are consistent with the new function and follow the existing patterns for defining mock expectations and return values.

@calbera calbera marked this pull request as draft July 31, 2024 23:20
@calbera calbera changed the title feat(node-api): Allow querying blocks by timestamp feat(node-api): Allow querying beacon blocks by execution numbers Jul 31, 2024
@calbera calbera marked this pull request as ready for review August 1, 2024 14:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between d992c34 and d170fde.

Files selected for processing (29)
  • contracts/src/eip4788/BeaconVerifier.sol (2 hunks)
  • contracts/src/eip4788/SSZ.sol (1 hunks)
  • contracts/src/eip4788/interfaces/IBeaconVerifier.sol (1 hunks)
  • contracts/test/eip4788/SSZ.t.sol (1 hunks)
  • mod/consensus-types/pkg/types/block.go (1 hunks)
  • mod/consensus-types/pkg/types/block_test.go (2 hunks)
  • mod/node-api/backend/backend.go (3 hunks)
  • mod/node-api/backend/mocks/block_store.mock.go (5 hunks)
  • mod/node-api/backend/types.go (1 hunks)
  • mod/node-api/engines/echo/vaildator.go (4 hunks)
  • mod/node-api/handlers/proof/backend.go (1 hunks)
  • mod/node-api/handlers/proof/block_proposer.go (1 hunks)
  • mod/node-api/handlers/proof/execution_fee_recipient.go (1 hunks)
  • mod/node-api/handlers/proof/execution_number.go (1 hunks)
  • mod/node-api/handlers/proof/handler.go (2 hunks)
  • mod/node-api/handlers/proof/routes.go (1 hunks)
  • mod/node-api/handlers/proof/types/request.go (1 hunks)
  • mod/node-api/handlers/proof/types/response.go (3 hunks)
  • mod/node-api/handlers/types/request.go (1 hunks)
  • mod/node-api/handlers/utils/constants.go (1 hunks)
  • mod/node-api/handlers/utils/id.go (2 hunks)
  • mod/node-core/pkg/components/block_store.go (2 hunks)
  • mod/node-core/pkg/components/deposit_store.go (2 hunks)
  • mod/node-core/pkg/components/storage/provider.go (1 hunks)
  • mod/node-core/pkg/components/store.go (2 hunks)
  • mod/storage/pkg/block/keys.go (1 hunks)
  • mod/storage/pkg/block/store.go (2 hunks)
  • mod/storage/pkg/block/types.go (1 hunks)
  • mod/storage/pkg/deposit/store.go (2 hunks)
Additional comments not posted (66)
mod/node-api/handlers/types/request.go (2)

Line range hint 14-16:
LGTM! The BlockIDRequest structure is well-defined.

The BlockID field is appropriately annotated with parameter and validation tags.


31-33: LGTM! The ExecutionIDRequest structure is well-defined.

The ExecutionID field is appropriately annotated with parameter and validation tags.

mod/storage/pkg/block/keys.go (2)

23-27: LGTM! The block key prefixes are well-defined.

The constants for BlockKeyPrefix, RootsKeyPrefix, and ExecutionNumbersKeyPrefix are appropriately defined.


29-33: LGTM! The map names are well-defined.

The constants for BlocksMapName, RootsMapName, and ExecutionNumbersMapName are appropriately defined.

mod/storage/pkg/block/types.go (1)

34-34: LGTM! The GetExecutionNumber method is well-defined.

The method is appropriately added to the BeaconBlock interface.

mod/node-api/handlers/utils/constants.go (4)

1-20: LGTM!

The license information is standard and appears correct.


21-21: LGTM!

The package declaration is correct.


23-23: LGTM!

The import statement is necessary and correct.


25-36: LGTM!

The constants are well-defined and follow a consistent naming convention.

mod/node-api/handlers/proof/backend.go (3)

Line range hint 1-20:
LGTM!

The license information is standard and appears correct.


22-22: LGTM!

The package declaration is correct.


23-25: LGTM!

The import statement reformatting improves readability and aligns with Go's conventions.

mod/node-api/handlers/proof/types/request.go (3)

Line range hint 1-20:
LGTM!

The license information is standard and appears correct.


Line range hint 22-22:
LGTM!

The package declaration is correct.


24-24: LGTM!

The import statement is necessary and correct.

mod/node-core/pkg/components/storage/provider.go (3)

30-32: LGTM! Struct definition is clear and concise.

The KVStoreProvider struct correctly embeds store.KVStoreWithBatch to extend its functionality.


34-39: LGTM! Constructor function is well-defined.

The NewKVStoreProvider function correctly initializes and returns a KVStoreProvider.


41-44: LGTM! Function is simple and effective.

The OpenKVStore function correctly returns the embedded KVStoreWithBatch.

mod/node-api/handlers/proof/routes.go (3)

37-37: LGTM! Route path updated to use execution_id.

The route for GetBlockProposer has been correctly updated to use execution_id.


42-42: LGTM! Route path updated to use execution_id.

The route for GetExecutionNumber has been correctly updated to use execution_id.


47-47: LGTM! Route path updated to use execution_id.

The route for GetExecutionFeeRecipient has been correctly updated to use execution_id.

mod/node-core/pkg/components/store.go (2)

27-27: LGTM! Import path simplified.

The import path for encoding has been correctly simplified, improving modularity.


37-37: LGTM! Function signature streamlined.

The function signature for ProvideKVStore has been correctly streamlined, improving readability.

contracts/test/eip4788/SSZ.t.sol (1)

16-25: LGTM! Ensure comprehensive test coverage.

The changes correctly update the function to handle uint256 and use SSZ.toLittleEndian. Ensure that the new behavior is adequately covered by tests.

mod/node-api/handlers/proof/block_proposer.go (1)

40-42: LGTM! Ensure comprehensive test coverage.

The changes correctly update the function to use resolveExecutionID instead of resolveBlockID. Ensure that the new method is adequately tested.

mod/node-api/handlers/proof/execution_number.go (1)

41-43: LGTM! Ensure comprehensive test coverage.

The changes correctly update the function to use resolveExecutionID instead of resolveBlockID. Ensure that the new method is adequately tested.

mod/node-api/handlers/proof/execution_fee_recipient.go (1)

41-43: LGTM! But verify the implementation of resolveExecutionID.

The code changes are approved.

However, ensure that the resolveExecutionID method is correctly implemented and handles errors appropriately.

Verification successful

The implementation of resolveExecutionID is correct and handles errors appropriately.

The method resolveExecutionID in mod/node-api/handlers/proof/handler.go correctly implements error handling for each potential error source.

  • SlotFromExecutionID call (line 86)
  • StateFromSlotForProof call (line 91)
  • BlockHeaderAtSlot call (line 96)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `resolveExecutionID`.

# Test: Search for the method implementation. Expect: Correct implementation with proper error handling.
ast-grep --lang go --pattern $'func (h *Handler[$_, $_, $_, $_, $_, $_]) resolveExecutionID($_) ($_ , $_, $_, error) {
  $$$
}'

Length of output: 1926

mod/node-core/pkg/components/block_store.go (1)

29-29: LGTM! But verify the implementation of storage.NewKVStoreProvider.

The code changes are approved.

However, ensure that the storage.NewKVStoreProvider method is correctly implemented and integrated.

Verification successful

Let's correct the shell script to search for the NewKVStoreProvider function implementation in the specified directory.


To ensure thorough verification, let's check the definition of KVStoreProvider and its usage in the codebase.


The implementation of storage.NewKVStoreProvider is correctly integrated.

The KVStoreProvider struct and its initialization via NewKVStoreProvider are properly defined and used in the codebase.

  • KVStoreProvider struct is defined in mod/node-core/pkg/components/storage/provider.go.
  • NewKVStoreProvider function initializes KVStoreProvider correctly.
  • Usage of KVStoreProvider is consistent in mod/node-core/pkg/components/deposit_store.go and mod/node-core/pkg/components/block_store.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `storage.NewKVStoreProvider`.

# Test: Search for the method implementation. Expect: Correct implementation with proper integration.
ast-grep --lang go --pattern $'func NewKVStoreProvider($_) $_ {
  $$$
}' --path mod/node-core/pkg/components/storage

Length of output: 305


Script:

#!/bin/bash
# Description: Verify the implementation of `storage.NewKVStoreProvider`.

# Test: Search for the method implementation. Expect: Correct implementation with proper integration.
ast-grep --lang go --pattern $'func NewKVStoreProvider($_) $_ {
  $$$
}' mod/node-core/pkg/components/storage

Length of output: 499


Script:

#!/bin/bash
# Description: Verify the definition and usage of `KVStoreProvider`.

# Search for the definition of the `KVStoreProvider` struct.
ast-grep --lang go --pattern $'type KVStoreProvider struct {
  $$$
}' mod/node-core/pkg/components/storage

# Search for the usage of `KVStoreProvider` in the codebase.
rg 'KVStoreProvider' -A 5

Length of output: 2468

mod/node-core/pkg/components/deposit_store.go (1)

28-28: LGTM! But verify the implementation of storage.NewKVStoreProvider.

The code changes are approved.

However, ensure that the storage.NewKVStoreProvider method is correctly implemented and integrated.

Verification successful

Let's correct the shell script and re-run it to verify the implementation of storage.NewKVStoreProvider.


The implementation of storage.NewKVStoreProvider is correctly integrated.

The NewKVStoreProvider function is properly implemented in mod/node-core/pkg/components/storage/provider.go at line 35, returning a new instance of KVStoreProvider initialized with KVStoreWithBatch.

  • mod/node-core/pkg/components/storage/provider.go:35
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `storage.NewKVStoreProvider`.

# Test: Search for the method implementation. Expect: Correct implementation with proper integration.
ast-grep --lang go --pattern $'func NewKVStoreProvider($_) $_ {
  $$$
}' --path mod/node-core/pkg/components/storage

Length of output: 305


Script:

#!/bin/bash
# Description: Verify the implementation of `storage.NewKVStoreProvider`.

# Test: Search for the method implementation. Expect: Correct implementation with proper integration.
ast-grep --lang go --pattern $'func NewKVStoreProvider($_) $_ {
  $$$
}' mod/node-core/pkg/components/storage

Length of output: 499

mod/storage/pkg/deposit/store.go (2)

30-30: Import path updated for better modularity.

The import path for the encoding package has been modified, likely to improve the package structure.


50-50: Prefix updated for better readability and consistency.

The prefix for the NewPrefix function has been updated from a hardcoded byte array to the constant KeyDepositPrefix, enhancing readability and consistency.

mod/node-api/handlers/proof/handler.go (1)

74-102: New method resolveExecutionID added to enhance functionality.

The new method resolveExecutionID retrieves the slot associated with a given execution ID, along with the corresponding beacon state and block header. It is well-structured, ensuring clear error reporting and early exit on failures.

contracts/src/eip4788/interfaces/IBeaconVerifier.sol (1)

63-68: Parameter type updated to uint256 for better handling of larger values.

The type of the blockNumber parameter has been changed from uint64 to uint256, enhancing the function's ability to handle larger values and aligning with broader Ethereum standards.

mod/node-api/handlers/proof/types/response.go (3)

31-31: Documentation Update Approved.

The update to replace block_id with execution_id in the comment improves clarity and aligns with the new API usage.


51-51: Documentation Update Approved.

The update to replace block_id with execution_id in the comment improves clarity and aligns with the new API usage.


69-69: Documentation Update Approved.

The update to replace block_id with execution_id in the comment improves clarity and aligns with the new API usage.

mod/node-api/handlers/utils/id.go (3)

48-66: Improved Type Safety and Flexibility Approved.

The change of the parameter type from a fixed-size byte array to common.Root enhances type safety and flexibility.


67-91: New Function Addition Approved.

The SlotFromExecutionID function correctly parses the execution number and handles errors appropriately, enhancing the module's capabilities.


99-104: Function Repositioning Approved.

The U64FromString function's repositioning within the file does not affect its functionality.

contracts/src/eip4788/SSZ.sol (1)

Line range hint 1-104:
Function Removal Approved. Verify Impact on Codebase.

The removal of the uint64HashTreeRoot function simplifies the library, but ensure it does not negatively impact the codebase.

Verification successful

Function Removal Verified. No Impact on Codebase.

The removal of the uint64HashTreeRoot function has been verified, and there are no occurrences of this function in the codebase. Therefore, its removal does not impact the functionality of the library.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the `uint64HashTreeRoot` function.

# Test: Search for usage of `uint64HashTreeRoot`. Expect: No occurrences.
rg --type solidity -A 5 $'uint64HashTreeRoot'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the impact of removing the `uint64HashTreeRoot` function.

# Test: Search for usage of `uint64HashTreeRoot`. Expect: No occurrences.
rg --type-add 'solidity:*.sol' -A 5 $'uint64HashTreeRoot'

Length of output: 56

mod/node-api/backend/mocks/block_store.mock.go (4)

25-52: Review the new GetSlotByExecutionNumber method.

The method correctly mocks the functionality of retrieving a slot by execution number. Ensure that all return paths are handled correctly.


53-76: Review the new BlockStore_GetSlotByExecutionNumber_Call type.

The type correctly supports the chaining of mock call methods for GetSlotByExecutionNumber.


Line range hint 82-123:
Review changes to GetSlotByRoot method.

The method correctly handles the new bytes.B32 type and maintains existing functionality.


6-8: Ensure correct usage of new imports.

The new imports for bytes and math from the beacon-kit package should be used correctly in the file.

Verification successful

Imports are correctly used.

The new imports for bytes and math from the beacon-kit package are used correctly in the file:

  • math.U64 is used in multiple function signatures and implementations.
  • bytes.B32 is used in function signatures and implementations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new imports.

# Test: Search for the usage of `bytes` and `math` in the file.
rg 'bytes|math' mod/node-api/backend/mocks/block_store.mock.go

Length of output: 1858

mod/storage/pkg/block/store.go (6)

37-43: Review the addition of executionNumbers field.

The executionNumbers field is correctly integrated into the KVStore struct.


54-74: Review changes to NewStore function.

The function correctly initializes all fields, including the new executionNumbers field.


79-84: Review changes to Get method.

The method correctly handles the new math.Slot type and maintains existing functionality.


88-112: Review changes to Set method.

The method correctly handles the new fields and maintains existing functionality.


125-133: Review the new GetSlotByExecutionNumber method.

The method correctly retrieves slots based on execution numbers.


30-32: Ensure correct usage of new imports.

The new imports for common and math from the beacon-kit package should be used correctly in the file.

Verification successful

Verified: New imports are used correctly.

The new imports for common and math from the beacon-kit package are used appropriately in the file.

  • math.Slot is used in multiple places.
  • math.U64 is used in function signatures.
  • common.Root is used in function parameters.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new imports.

# Test: Search for the usage of `common` and `math` in the file.
rg 'common|math' mod/storage/pkg/block/store.go

Length of output: 659

mod/node-api/engines/echo/vaildator.go (4)

Line range hint 61-75:
Review changes to ConstructValidator function.

The function correctly registers the new ValidateExecutionID validator.


98-111: Review the new ValidateExecutionID function.

The function correctly validates execution IDs based on the allowed values.


Line range hint 91-96:
Review changes to ValidateBlockID function.

The function correctly integrates with the new validators and maintains existing functionality.


30-32: Ensure correct usage of new import.

The new import for the utils package should be used correctly in the file.

Verification successful

Verify definitions in the utils package.

The constants StateIDHead, StateIDGenesis, StateIDFinalized, StateIDJustified, and the function IsExecutionNumberPrefix should be correctly defined in the utils package.


Verification successful.

The utils package is correctly imported and used in the file. The constants StateIDHead, StateIDGenesis, StateIDFinalized, StateIDJustified, and the function IsExecutionNumberPrefix are properly defined and utilized.

  • StateIDHead defined in mod/node-api/handlers/utils/constants.go
  • StateIDGenesis defined in mod/node-api/handlers/utils/constants.go
  • StateIDFinalized defined in mod/node-api/handlers/utils/constants.go
  • StateIDJustified defined in mod/node-api/handlers/utils/constants.go
  • IsExecutionNumberPrefix defined in mod/node-api/handlers/utils/id.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new import.

# Test: Search for the usage of `utils` in the file.
rg 'utils' mod/node-api/engines/echo/vaildator.go

Length of output: 297


Script:

#!/bin/bash
# Description: Verify definitions in the utils package.

# Test: Search for the definitions of the constants and function in the utils package.
rg 'StateIDHead|StateIDGenesis|StateIDFinalized|StateIDJustified|IsExecutionNumberPrefix' mod/node-api/handlers/utils

Length of output: 826

mod/node-api/backend/types.go (3)

84-84: Improved type safety and clarity.

The update to use common.Root instead of [32]byte enhances type safety and clarity.


85-87: New method added for execution number-based queries.

The addition of GetSlotByExecutionNumber broadens the interface's capabilities and aligns with the PR objectives.


84-84: Improved semantic representation and type safety.

The update to use math.Slot instead of uint64 enhances the semantic representation of slots and improves type safety.

mod/consensus-types/pkg/types/block_test.go (2)

45-45: Execution number added to ExecutionPayload.

The addition of the Number field enhances the functionality of the ExecutionPayload by allowing it to carry an execution number.


104-104: New assertion added to validate execution number.

The new assertion ensures that the block correctly reflects the execution number, enhancing the robustness of the test suite.

mod/node-api/backend/backend.go (3)

124-127: New method added for attaching node.

The addition of the AttachNode method sets the node on the backend for querying historical heights, providing clearer context for developers.


138-141: Improved type safety and clarity.

The update to use common.Root instead of [32]byte enhances type safety and clarity.


145-151: New method added for execution number-based queries.

The addition of GetSlotByExecutionNumber expands the backend's querying capabilities and aligns with the PR objectives.

mod/consensus-types/pkg/types/block.go (2)

237-237: LGTM!

The GetHeader function is well-implemented and does not have any issues.


238-242: LGTM! But verify the initialization of ExecutionPayload.

The code changes are approved.

However, ensure that the ExecutionPayload is always initialized to avoid potential nil pointer dereference.

contracts/src/eip4788/BeaconVerifier.sol (2)

124-124: LGTM! But verify the consistency of blockNumber type change.

The code changes are approved.

However, ensure that the change in blockNumber type from uint64 to uint256 is consistent across the codebase.

Verification successful

Let's generate a new shell script to verify the consistency of the blockNumber type change across the codebase.


The change in blockNumber type from uint64 to uint256 is consistent across the codebase.

  • contracts/src/eip4788/BeaconVerifier.sol
  • contracts/src/eip4788/interfaces/IBeaconVerifier.sol
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of `blockNumber` type change in `BeaconVerifier`.

# Test: Search for the usage of `blockNumber` in `BeaconVerifier`. Expect: All instances of `blockNumber` are of type `uint256`.
rg --type solidity -A 5 'blockNumber' | grep -i 'uint256'

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the consistency of `blockNumber` type change in `BeaconVerifier`.

# Test: Search for the usage of `blockNumber` in Solidity files. Expect: All instances of `blockNumber` are of type `uint256`.
rg 'blockNumber' -g '*.sol' -A 5 | grep -i 'uint256'

Length of output: 513


190-199: LGTM! But verify the consistency of blockNumber type change and hashing mechanism.

The code changes are approved.

However, ensure that the change in blockNumber type from uint64 to uint256 and the update in hashing mechanism are consistent across the codebase.

Verification successful

The change in blockNumber type to uint256 and the update in the hashing mechanism to SSZ.toLittleEndian are consistent across the codebase.

  • All instances of blockNumber are of type uint256.
  • The executionNumberRoot uses SSZ.toLittleEndian.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of `blockNumber` type change and hashing mechanism in `BeaconVerifier`.

# Test: Search for the usage of `blockNumber` and `executionNumberRoot` in `BeaconVerifier`. Expect: All instances of `blockNumber` are of type `uint256` and `executionNumberRoot` uses `SSZ.toLittleEndian`.
rg --type solidity -A 5 'blockNumber' | grep -i 'uint256'
rg --type solidity -A 5 'executionNumberRoot' | grep -i 'SSZ.toLittleEndian'

Length of output: 196


Script:

#!/bin/bash
# Description: Verify the consistency of `blockNumber` type change and hashing mechanism in `BeaconVerifier`.

# Test: Search for the usage of `blockNumber` and `executionNumberRoot` in Solidity files. Expect: All instances of `blockNumber` are of type `uint256` and `executionNumberRoot` uses `SSZ.toLittleEndian`.
rg 'blockNumber' -A 5 --glob '*.sol' | grep -i 'uint256'
rg 'executionNumberRoot' -A 5 --glob '*.sol' | grep -i 'SSZ.toLittleEndian'

Length of output: 703

mod/node-api/handlers/proof/backend.go Show resolved Hide resolved
mod/node-api/handlers/proof/types/request.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between d170fde and 3b52a04.

Files selected for processing (1)
  • mod/node-core/pkg/components/storage/types.go (1 hunks)
Additional comments not posted (2)
mod/node-core/pkg/components/storage/types.go (2)

50-50: Improved type safety in Get method.

The update from uint64 to math.Slot enhances type safety by ensuring that only appropriate slot values are processed.


52-52: Enhanced code clarity in GetSlotByRoot method.

The update from [32]byte to common.Root improves code clarity and maintainability by using a more descriptive and flexible representation of root values.

@calbera calbera requested a review from itsdevbear August 1, 2024 18:29
Copy link
Contributor

@archbear archbear left a comment

Choose a reason for hiding this comment

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

utack makes sense

Copy link
Member

@itsdevbear itsdevbear left a comment

Choose a reason for hiding this comment

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

lgtm

@itsdevbear itsdevbear merged commit 7dce5a0 into main Aug 1, 2024
18 checks passed
@itsdevbear itsdevbear deleted the api-block-store branch August 1, 2024 18:46
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