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): use timestamp ID instead of execution ID for proof namespace #2066

Merged
merged 11 commits into from
Oct 16, 2024

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Oct 11, 2024

Proofs are indexed by timestamp in EIP 4788, and not execution block numbers. Consequently this allows offchain clients to easily query for beacon block proofs by timestamps, which is directly applicable for use in EL.

Summary by CodeRabbit

  • New Features

    • Introduced a new GetTimestamp method in the BeaconBlock structure to retrieve the timestamp from the execution payload.
    • Added Timestamp field in the ExecutionPayload structure.
    • Updated methods across various components to focus on timestamps instead of execution numbers.
  • Bug Fixes

    • Corrected method references and assertions in tests to align with the new timestamp functionality.
  • Refactor

    • Renamed multiple methods and parameters to reflect the shift from execution IDs to timestamp IDs.
    • Updated the KVStore structure to replace execution numbers with timestamps.
    • Removed deprecated methods related to execution numbers and introduced new methods for handling timestamps.

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes in this pull request primarily involve renaming methods and fields related to execution numbers to their corresponding timestamp counterparts across various files. The GetExecutionNumber method has been renamed to GetTimestamp, and similar modifications have been made in multiple interfaces and structs, including the BlockStore interface. Additionally, the ExecutionPayload struct has been updated to include a Timestamp field. These changes reflect a shift in focus from execution numbers to timestamps in the related functionalities.

Changes

File Path Change Summary
mod/consensus-types/pkg/types/block.go Renamed GetExecutionNumber to GetTimestamp; updated implementation to return Timestamp from ExecutionPayload.
mod/consensus-types/pkg/types/block_test.go Added Timestamp field to ExecutionPayload; updated tests to reflect changes from GetExecutionNumber to GetTimestamp.
mod/node-api/backend/backend.go Renamed GetSlotByExecutionNumber to GetParentSlotByTimestamp; updated implementation accordingly.
mod/node-api/backend/types.go Removed GetSlotByExecutionNumber; added GetParentSlotByTimestamp.
mod/node-api/engines/echo/vaildator.go Renamed validation function from ValidateExecutionID to ValidateTimestampID.
mod/node-api/handlers/proof/backend.go Updated method signature from GetSlotByExecutionNumber to GetParentSlotByTimestamp.
mod/node-api/handlers/proof/block_proposer.go Renamed resolveExecutionID to resolveTimestampID.
mod/node-api/handlers/proof/execution_fee_recipient.go Renamed method call from resolveExecutionID to resolveTimestampID.
mod/node-api/handlers/proof/execution_number.go Renamed method call from resolveExecutionID to resolveTimestampID.
mod/node-api/handlers/proof/handler.go Renamed resolveExecutionID to resolveTimestampID with parameter change.
mod/node-api/handlers/proof/types/request.go Updated request types to replace execution_id with timestamp_id.
mod/node-api/handlers/types/request.go Removed ExecutionIDRequest; added TimestampIDRequest.
mod/node-api/handlers/utils/constants.go Renamed constant ExecutionIDPrefix to TimestampIDPrefix.
mod/node-api/handlers/utils/id.go Removed SlotFromExecutionID; added ParentSlotFromTimestampID. Updated IsExecutionNumberPrefix to IsTimestampIDPrefix.
mod/node-core/pkg/components/interfaces.go Renamed GetExecutionNumber to GetTimestamp in BeaconBlock and BlockStore interfaces.
mod/storage/pkg/block/store.go Removed executionNumbers field; added timestamps field; updated methods accordingly.
mod/storage/pkg/block/store_test.go Renamed GetExecutionNumber to GetTimestamp in MockBeaconBlock.

Suggested reviewers

  • itsdevbear
  • ocnc
  • archbear

🐇 In the code where numbers once reigned,
Timestamps now dance, unchained!
From execution to time, we leap,
In the world of blocks, our changes sweep.
Hooray for the new, let's hop with glee,
For every timestamp, a jubilee! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 9f5214e and 0e7d4e3.

📒 Files selected for processing (1)
  • mod/node-api/backend/mocks/block_store.mock.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
mod/node-api/backend/mocks/block_store.mock.go (3)

25-76: New method GetParentSlotByTimestamp implemented correctly

The GetParentSlotByTimestamp method and its associated mock call structures are correctly added, following the existing patterns in the codebase. The implementation aligns with the shift from execution numbers to timestamps as per the PR objectives.


81-132: New method GetSlotByBlockRoot implemented correctly

The GetSlotByBlockRoot method and its associated mock call structures are properly added and conform to the established code style. This addition enhances the functionality for retrieving slots by block root.


25-132: Ensure all references to GetSlotByExecutionNumber are updated

The method GetSlotByExecutionNumber has been removed in favor of GetParentSlotByTimestamp. Please verify that all references to GetSlotByExecutionNumber have been updated to prevent any potential build errors or runtime issues.

Run the following script to search for any remaining references to the old method:


🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 Oct 11, 2024

Codecov Report

Attention: Patch coverage is 30.55556% with 25 lines in your changes missing coverage. Please review.

Project coverage is 22.23%. Comparing base (6697ddb) to head (0e7d4e3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
mod/node-api/handlers/utils/id.go 0.00% 10 Missing ⚠️
mod/node-api/engines/echo/vaildator.go 0.00% 3 Missing ⚠️
mod/storage/pkg/block/store.go 75.00% 2 Missing and 1 partial ⚠️
mod/node-api/backend/backend.go 0.00% 2 Missing ⚠️
mod/node-api/handlers/proof/block_proposer.go 0.00% 2 Missing ⚠️
...node-api/handlers/proof/execution_fee_recipient.go 0.00% 2 Missing ⚠️
mod/node-api/handlers/proof/execution_number.go 0.00% 2 Missing ⚠️
mod/node-api/handlers/proof/handler.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2066      +/-   ##
==========================================
- Coverage   22.25%   22.23%   -0.03%     
==========================================
  Files         356      356              
  Lines       16020    16022       +2     
  Branches       12       12              
==========================================
- Hits         3566     3563       -3     
- Misses      12302    12306       +4     
- Partials      152      153       +1     
Files with missing lines Coverage Δ
mod/consensus-types/pkg/types/block.go 92.72% <100.00%> (ø)
mod/node-api/handlers/proof/handler.go 0.00% <0.00%> (ø)
mod/node-api/backend/backend.go 0.00% <0.00%> (ø)
mod/node-api/handlers/proof/block_proposer.go 0.00% <0.00%> (ø)
...node-api/handlers/proof/execution_fee_recipient.go 0.00% <0.00%> (ø)
mod/node-api/handlers/proof/execution_number.go 0.00% <0.00%> (ø)
mod/node-api/engines/echo/vaildator.go 0.00% <0.00%> (ø)
mod/storage/pkg/block/store.go 72.09% <75.00%> (-6.98%) ⬇️
mod/node-api/handlers/utils/id.go 0.00% <0.00%> (ø)

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: 21

🧹 Outside diff range comments (6)
mod/node-api/handlers/types/request.go (1)

Line range hint 1-33: Summary: Successful implementation of timestamp-based identification

The changes in this file successfully implement the transition from execution ID to timestamp ID for proof namespace, as outlined in the PR objectives. This modification aligns with EIP 4788 and will facilitate offchain clients in querying beacon block proofs based on timestamps.

Key points:

  1. The ExecutionIDRequest has been removed and replaced with TimestampIDRequest.
  2. The new TimestampIDRequest follows the same structure and validation pattern as other request types in the file.
  3. This change is likely to affect API consumers, so thorough testing and clear communication of the API changes will be crucial.

To ensure a smooth transition:

  1. Update all related API documentation to reflect this change.
  2. Implement proper error handling for cases where clients might still try to use the old ExecutionID-based endpoints.
  3. Consider providing a migration guide for API consumers to update their implementations.
  4. Ensure that all parts of the system that previously used ExecutionID are updated to use TimestampID consistently.
mod/node-api/handlers/proof/types/request.go (1)

Line range hint 1-41: Summary of changes and their impact

The modifications in this file consistently replace execution_id with timestamp_id across all struct definitions and comments. This change aligns well with the PR objectives of using timestamp IDs instead of execution IDs for indexing proofs.

These changes will affect how clients interact with the proof endpoints, now requiring them to provide timestamp IDs instead of execution IDs. This could potentially improve the ability of offchain clients to query beacon block proofs based on timestamps, as mentioned in the PR objectives.

To ensure a smooth transition:

  1. Update any client code that interacts with these endpoints to use timestamp IDs.
  2. Update any documentation or API references to reflect these changes.
  3. Consider adding a deprecation notice or backwards compatibility for any existing code that might still use execution IDs.
mod/node-api/handlers/proof/execution_number.go (1)

Line range hint 28-40: Update method name and return type for consistency

The method name GetExecutionNumber and the return type ExecutionNumberResponse are now inconsistent with the internal logic, which uses a timestamp ID instead of an execution ID. Consider updating these to reflect the new functionality.

Suggested changes:

  1. Rename the method to GetExecutionNumberByTimestamp or similar.
  2. Update the return type and its fields to use "Timestamp" terminology where appropriate.

Also, update the function comment to reflect these changes and the use of timestamp ID.

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

Line range hint 27-30: Consider updating the function documentation.

While the function logic remains consistent after the change to use timestamp IDs, it would be beneficial to update the function's documentation to reflect this change. This will help maintain clarity for future developers working with this code.

Consider updating the comment to something like:

// GetExecutionFeeRecipient returns the fee recipient from the latest execution
// payload header for the given timestamp ID, along with the proof that can be
// verified against the beacon block root. The timestamp ID is used to identify
// the relevant block in accordance with EIP 4788.

This change would more accurately reflect the function's current behavior and its alignment with the PR objectives.

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

Action Required: Update Remaining References to execution_id

Several instances of execution_id remain in comments and route paths:

  • Files:
    • mod/node-api/handlers/proof/types/response.go
      • Endpoints: /proof/block_proposer/{execution_id}, /proof/execution_number/{execution_id}, /proof/execution_fee_recipient/{execution_id}
    • mod/node-api/handlers/proof/routes.go
      • Paths: "bkit/v1/proof/block_proposer/:execution_id", "bkit/v1/proof/execution_number/:execution_id", "bkit/v1/proof/execution_fee_recipient/:execution_id"
    • mod/node-api/engines/echo/validator.go
      • Validation: "execution_id": ValidateTimestampID

Additionally, there's an outstanding TODO:

  • examples/berad/pkg/state-transition/state_processor_payload.go:
    // TODO: Verify timestamp data once Clock is done.

Ensure all execution_id references are updated to timestamp_id and address the pending TODO to complete the timestamp data verification.

🔗 Analysis chain

Line range hint 74-102: LGTM! The changes align well with the PR objectives.

The renaming from resolveExecutionID to resolveTimestampID and the corresponding updates in the function signature, comment, and internal logic are consistent with the goal of using timestamp ID instead of execution ID. This change aligns with the EIP 4788 requirement mentioned in the PR objectives.

Consider updating the comment to be more specific:

// resolveTimestampID gets the slot, beacon state, and beacon block header for the given timestamp ID.

Let's verify the impact of these changes on the rest of the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to ExecutionID or execution_id
# that might need to be updated.

# Test 1: Search for ExecutionID
echo "Searching for ExecutionID:"
rg --type go 'ExecutionID'

# Test 2: Search for execution_id
echo "Searching for execution_id:"
rg --type go 'execution_id'

# Test 3: Search for resolveExecutionID
echo "Searching for resolveExecutionID:"
rg --type go 'resolveExecutionID'

# Test 4: Check for any TODO comments related to this change
echo "Checking for related TODO comments:"
rg --type go 'TODO.*timestamp'

Length of output: 1204

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

Line range hint 1-214: Consider adding more test coverage for the Timestamp field.

While the changes made are correct and focused, it might be beneficial to add more test coverage for the new Timestamp field. This could include:

  1. Testing edge cases for the Timestamp value.
  2. Verifying the behavior when Timestamp and Number fields have different values.
  3. Adding assertions in other relevant test functions to ensure the Timestamp is correctly handled throughout the BeaconBlock functionality.

Would you like assistance in generating additional test cases for the Timestamp field?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 05ce9dc and 0eec400.

📒 Files selected for processing (18)
  • 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 (1 hunks)
  • mod/node-api/backend/types.go (1 hunks)
  • mod/node-api/engines/echo/vaildator.go (3 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 (1 hunks)
  • mod/node-api/handlers/proof/types/request.go (1 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 (1 hunks)
  • mod/node-core/pkg/components/interfaces.go (4 hunks)
  • mod/storage/pkg/block/store.go (4 hunks)
  • mod/storage/pkg/block/store_test.go (3 hunks)
  • mod/storage/pkg/block/types.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (16)
mod/node-api/handlers/utils/constants.go (1)

30-30: LGTM! Constant renamed as per PR objectives.

The change from ExecutionIDPrefix to TimestampIDPrefix aligns with the PR's goal of using timestamp ID instead of execution ID for proof namespace. The new prefix "t" is concise and clear.

To ensure consistency across the codebase, let's verify that there are no remaining references to the old constant name:

✅ Verification successful

Verified: No remaining references to ExecutionIDPrefix found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to ExecutionIDPrefix

# Test: Search for ExecutionIDPrefix. Expect: No results.
rg --type go "ExecutionIDPrefix"

# Test: Search for TimestampIDPrefix to confirm its usage. Expect: At least one result (this file).
rg --type go "TimestampIDPrefix"

Length of output: 571

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

33-33: Verify the impact of replacing GetExecutionNumber with GetTimestamp.

The change from GetExecutionNumber() to GetTimestamp() is significant and may have far-reaching effects in the codebase. To ensure a smooth transition:

  1. Update all implementations of the BeaconBlock interface.
  2. Modify any code that calls GetExecutionNumber() to use GetTimestamp().
  3. Review the logic in dependent code to account for the semantic difference between execution number and timestamp.

Run the following script to identify potential areas that need updating:

Please review the output of this script and update the identified areas accordingly.

✅ Verification successful

Verified that replacing GetExecutionNumber with GetTimestamp has been consistently applied across the codebase and no usages of GetExecutionNumber remain. Ensure that dependent logic accounts for the semantic change from execution number to timestamp.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Identify usages of GetExecutionNumber and BeaconBlock interface implementations

# Search for GetExecutionNumber usages
echo "Searching for GetExecutionNumber usages:"
rg --type go "GetExecutionNumber\(\)"

# Search for BeaconBlock interface implementations
echo "Searching for BeaconBlock interface implementations:"
rg --type go "type \w+ struct" -A 10 | rg "BeaconBlock"

# Search for timestamp-related functions that might need updating
echo "Searching for timestamp-related functions that might need updating:"
rg --type go "func.*Timestamp"

Length of output: 4195

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

38-40: LGTM!

The change from execution_id to timestamp_id is consistent with the PR objectives and correctly implemented.

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

40-41: LGTM! Verify consistency across the codebase.

The change from resolveExecutionID to resolveTimestampID and the corresponding parameter update align with the PR objectives. This modification correctly implements the shift from execution ID to timestamp ID for proof namespace.

To ensure consistency across the codebase, please run the following script:

This script will help identify any inconsistencies or missed updates related to this change.

✅ Verification successful

Consistency Verified Across Codebase.

All instances of ExecutionID and resolveExecutionID have been successfully updated to TimestampID and resolveTimestampID respectively. No remaining references to the old identifiers were found, ensuring consistency throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all occurrences of ExecutionID have been updated to TimestampID

# Test 1: Search for any remaining instances of ExecutionID
echo "Searching for remaining instances of ExecutionID:"
rg --type go 'ExecutionID'

# Test 2: Verify that TimestampID is now used consistently
echo "Verifying usage of TimestampID:"
rg --type go 'TimestampID'

# Test 3: Check for any remaining instances of resolveExecutionID
echo "Checking for any remaining instances of resolveExecutionID:"
rg --type go 'resolveExecutionID'

Length of output: 2402

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

74-76: LGTM! Change is consistent with the new timestamp-based approach.

The update from GetSlotByExecutionNumber to GetSlotByTimestamp is consistent with the PR objective and the changes made to the MockBeaconBlock struct.


Line range hint 1-87: Overall, the changes successfully implement the timestamp-based approach.

The modifications in this file consistently replace execution number references with timestamp references, aligning well with the PR objectives. The test structure and coverage remain intact, ensuring that the new timestamp-based functionality is properly tested.

Key points:

  1. GetExecutionNumber method renamed to GetTimestamp.
  2. GetSlotByExecutionNumber calls updated to GetSlotByTimestamp.
  3. Error checking adjusted to reflect the new timestamp-based approach.

These changes contribute to the goal of indexing proofs by timestamp in accordance with EIP 4788, facilitating offchain clients in querying beacon block proofs based on timestamps.

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

51-53: LGTM: Proper initialization of timestamps cache

The initialization of the timestamps cache in the NewStore function is consistent with the struct changes. The error handling and use of the availabilityWindow parameter for cache size are appropriate.

Also applies to: 60-63


Line range hint 1-108: Summary: Successful implementation of timestamp-based indexing

The changes in this file successfully implement the transition from execution number-based to timestamp-based indexing for beacon block proofs. This aligns well with the PR objectives and EIP 4788 requirements. The modifications are consistent across the KVStore struct, its initialization, and associated methods.

Key points:

  1. executionNumbers field replaced with timestamps in KVStore.
  2. NewStore function updated to initialize the timestamps cache.
  3. Set method now stores timestamps instead of execution numbers.
  4. New GetSlotByTimestamp method added to replace GetSlotByExecutionNumber.

The implementation is clean and maintains the existing error handling patterns. Minor suggestions for improvement have been made in the individual comments.


Line range hint 1-108: Verify complete removal of GetSlotByExecutionNumber

The GetSlotByExecutionNumber method has been correctly removed as part of the transition from execution numbers to timestamps. To ensure a clean transition, we should verify that all references to this method have been updated or removed throughout the codebase.

Let's run a check to ensure no references to GetSlotByExecutionNumber remain:

#!/bin/bash
# Check for any remaining references to GetSlotByExecutionNumber
rg --type go "GetSlotByExecutionNumber" ./

If this search returns any results, those locations will need to be updated to use GetSlotByTimestamp instead.

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

Line range hint 1-213: Summary: Changes align well with PR objectives

The modifications in this file successfully implement the transition from execution IDs to timestamp IDs for the proof namespace. The changes are focused, maintain backwards compatibility, and align well with the PR objectives. The implementation is solid, with only a minor suggestion for improvement in error handling.

Key points:

  1. The ConstructValidator function has been updated to use ValidateTimestampID.
  2. The ValidateTimestampID function has been implemented to handle both timestamp IDs and existing state IDs.
  3. The changes maintain backwards compatibility while introducing the new functionality.

Overall, the implementation looks good and achieves the intended goals of the PR.


65-65: LGTM: Validator function updated to use timestamp ID

The change from ValidateExecutionID to ValidateTimestampID is consistent with the PR objective of using timestamp IDs instead of execution IDs for proof namespace.

To ensure consistency across the codebase, let's verify that all references to ValidateExecutionID have been updated:


Line range hint 99-113: LGTM: ValidateTimestampID function implemented correctly

The ValidateTimestampID function has been successfully updated to handle timestamp IDs while maintaining backwards compatibility with state IDs. The implementation aligns well with the PR objectives.

A minor suggestion for improvement:

Consider adding explicit error handling for the case where IsTimestampIDPrefix returns true, but ValidateUint64Dec fails. This could help in providing more specific error messages.

 func ValidateTimestampID(fl validator.FieldLevel) bool {
     // ... (existing code)
     
     if utils.IsTimestampIDPrefix(value) {
-        return ValidateUint64Dec(value[1:])
+        if !ValidateUint64Dec(value[1:]) {
+            // Log an error or set a more specific error message
+            return false
+        }
+        return true
     }
     
     // ... (existing code)
 }

To ensure the utils.IsTimestampIDPrefix function is properly implemented, let's check its definition:

✅ Verification successful

LGTM: ValidateTimestampID function implemented correctly

The ValidateTimestampID function is correctly implemented, effectively handling timestamp IDs while maintaining backwards compatibility with state IDs. The implementation aligns with the PR objectives.

A minor suggestion for improvement:

Consider adding explicit error handling for cases where IsTimestampIDPrefix returns true but ValidateUint64Dec fails. This can provide more specific error messages or logging.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find the implementation of IsTimestampIDPrefix
# Expect: The function definition in a utils file

rg --type go "func IsTimestampIDPrefix"

Length of output: 127


Script:

#!/bin/bash
# Description: Extract the implementation of IsTimestampIDPrefix function from id.go
# Expect: The full function definition including its logic

ast-grep --lang go --pattern 'func IsTimestampIDPrefix($_) bool { $$$ }' mod/node-api/handlers/utils/id.go

Length of output: 334

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

105-105: LGTM! Assertion updated correctly.

The change from GetExecutionNumber() to GetTimestamp() is consistent with the PR objective and the addition of the Timestamp field. The expected value of 10 matches the Timestamp set in the generateValidBeaconBlock function.

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

116-118: LGTM: Method renamed from GetExecutionNumber to GetTimestamp

This change aligns with the PR objective of using timestamp ID instead of execution ID for proof namespace. The return type (math.U64) remains appropriate for the timestamp.


Line range hint 1-1173: Overall assessment: Changes align with PR objectives

The modifications in this file consistently rename methods related to execution numbers to use timestamps instead. This aligns well with the PR objective of indexing proofs by timestamp in accordance with EIP 4788. The changes are applied consistently across multiple interfaces (BeaconBlock, BlockStore, NodeAPIBackend, and NodeAPIProofBackend).

A minor suggestion has been made to update the parameter names in the renamed methods for better clarity and consistency.

These changes should facilitate offchain clients in querying beacon block proofs based on timestamps, as intended.

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

98-101: Ensure TimestampIDPrefix is defined and consistent.

The function IsTimestampIDPrefix relies on TimestampIDPrefix to check the prefix of timestampID. Please verify that TimestampIDPrefix is defined appropriately (e.g., as const TimestampIDPrefix = "t") and that this prefix is used consistently throughout the codebase.

Run the following script to check the definition and usage of TimestampIDPrefix:

✅ Verification successful

TimestampIDPrefix is correctly defined and consistently used across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'TimestampIDPrefix' is defined and used consistently.

# Search for the definition of 'TimestampIDPrefix'. Expect: A single definition.
rg --type go --word-regex --pcre2 'const\s+TimestampIDPrefix\s*=\s*.*'

# Search for all usages of 'TimestampIDPrefix'. Expect: Consistent usage across files.
rg --type go 'TimestampIDPrefix'

Length of output: 1055


Script:

#!/bin/bash
# Description: Verify that 'TimestampIDPrefix' is defined and used consistently.

# Search for the definition of 'TimestampIDPrefix'. Expect: A single definition.
rg --type go --word-regexp --pcre2 'const\s+TimestampIDPrefix\s*=\s*.*'

# Search for all usages of 'TimestampIDPrefix'. Expect: Consistent usage across files.
rg --type go 'TimestampIDPrefix'

Length of output: 612

mod/node-api/handlers/types/request.go Show resolved Hide resolved
mod/storage/pkg/block/types.go Show resolved Hide resolved
mod/node-api/handlers/proof/backend.go Outdated Show resolved Hide resolved
mod/node-api/handlers/proof/types/request.go Show resolved Hide resolved
mod/node-api/handlers/proof/types/request.go Show resolved Hide resolved
mod/consensus-types/pkg/types/block.go Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Outdated Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Outdated Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Outdated Show resolved Hide resolved
mod/node-api/handlers/utils/id.go Outdated 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: 6

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between be58e45 and 3c6b004.

📒 Files selected for processing (8)
  • mod/node-api/backend/backend.go (1 hunks)
  • mod/node-api/backend/types.go (1 hunks)
  • mod/node-api/handlers/proof/backend.go (1 hunks)
  • mod/node-api/handlers/proof/handler.go (1 hunks)
  • mod/node-api/handlers/utils/id.go (1 hunks)
  • mod/node-core/pkg/components/interfaces.go (4 hunks)
  • mod/storage/pkg/block/store.go (4 hunks)
  • mod/storage/pkg/block/store_test.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (14)
mod/storage/pkg/block/store_test.go (4)

45-47: LGTM! Consider adding a clarifying comment.

The renaming from GetExecutionNumber to GetTimestamp aligns well with the PR objective of using timestamp IDs instead of execution IDs. However, the implementation assumes that the slot number is equivalent to the timestamp, which may not be immediately clear to readers.

As suggested in a previous review, consider adding a comment to clarify this assumption:

 func (m MockBeaconBlock) GetTimestamp() math.U64 {
+	// For testing purposes, we assume the slot number is equivalent to the timestamp
 	return m.slot
 }

74-76: LGTM! The change is consistent with the PR objective.

The update from GetSlotByExecutionNumber to GetParentSlotByTimestamp aligns well with the PR's goal of using timestamp IDs instead of execution IDs. The test logic remains intact, which maintains the existing test coverage.


86-87: LGTM! Consider updating the error message for clarity.

The update to check GetParentSlotByTimestamp instead of GetSlotByExecutionNumber is consistent with the previous changes and aligns with the PR objective.

As suggested in a previous review, consider updating the error message to explicitly mention "timestamp" for improved clarity and consistency:

 _, err = blockStore.GetParentSlotByTimestamp(2)
-require.ErrorContains(t, err, "not found")
+require.ErrorContains(t, err, "timestamp not found")

Line range hint 1-89: Overall, the changes successfully implement the PR objective.

The modifications in this file consistently reflect the shift from execution numbers to timestamps, aligning well with the PR's goal. The test coverage appears to be maintained, which is crucial for ensuring the reliability of the changes.

A few minor suggestions for improved clarity have been made:

  1. Adding a comment to clarify the assumption in the GetTimestamp method.
  2. Updating an error message to be more specific about timestamps.

These small improvements will enhance the readability and maintainability of the test code.

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

86-86: Verify the implications of using ParentSlotFromTimestampID

The change from utils.SlotFromExecutionID to utils.ParentSlotFromTimestampID might have implications on the slot calculation logic. Please ensure that:

  1. The ParentSlotFromTimestampID function correctly calculates the slot based on the timestamp.
  2. Using the parent slot instead of the direct slot is intentional and doesn't affect the proof generation process.
  3. The rest of the codebase is updated to handle this change in slot calculation.

To verify the usage and implementation of ParentSlotFromTimestampID, please run the following script:

This script will help us understand the implementation of ParentSlotFromTimestampID and verify that it's being used consistently across the codebase.

✅ Verification successful

Verification Successful: ParentSlotFromTimestampID Usage Confirmed

The ParentSlotFromTimestampID function is correctly implemented and consistently used in handler.go. There are no remaining references to SlotFromExecutionID, ensuring that the slot calculation logic has been updated as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of ParentSlotFromTimestampID

# Check the implementation of ParentSlotFromTimestampID
echo "Checking ParentSlotFromTimestampID implementation:"
ast-grep --lang go --pattern $'func ParentSlotFromTimestampID($_, $_) ($_) {
  $$$
}'

# Check for other usages of ParentSlotFromTimestampID in the codebase
echo "\nChecking other usages of ParentSlotFromTimestampID:"
rg --type go "ParentSlotFromTimestampID"

# Check for any remaining usages of SlotFromExecutionID
echo "\nChecking for any remaining usages of SlotFromExecutionID:"
rg --type go "SlotFromExecutionID"

Length of output: 830

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

Line range hint 1-215: Reminder: Update mock references

As mentioned in a previous review, please ensure that any mock implementations in mod/node-api/backend/mocks/block_store.mock.go are updated to use GetParentSlotByTimestamp instead of GetSlotByExecutionNumber. This will maintain consistency across the codebase and ensure accurate test behavior.


153-158: LGTM! Verify usage across the codebase.

The introduction of GetParentSlotByTimestamp aligns well with the PR objectives of using timestamp ID instead of execution ID. The implementation correctly delegates to the block store, maintaining a good separation of concerns.

To ensure consistency across the codebase, please run the following script to check for any remaining references to GetSlotByExecutionNumber that might need updating:

If any results are found, they may need to be updated to use GetParentSlotByTimestamp and timestamp respectively.

Additionally, please verify that this change doesn't introduce any unexpected behavior in the system, especially in areas where the execution number was previously used for other purposes beyond retrieving the parent slot.

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

31-31: Ensure all references to the renamed method are updated

The method GetSlotByExecutionNumber has been renamed to GetParentSlotByTimestamp. Please verify that all implementations of the Backend interface and any code calling this method have been updated to reflect this change to prevent potential inconsistencies or runtime errors.

Run the following script to identify any remaining references to the old method name:

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

73-96: Well-documented implementation of ParentSlotFromTimestampID.

The new function ParentSlotFromTimestampID effectively replaces SlotFromExecutionID, aligning with the shift from execution numbers to timestamps as per the PR objectives. The documentation is clear, providing detailed explanations and examples for the usage of timestampID. The function logic is correct and maintains consistency with the existing codebase.


99-102: Correct implementation of IsTimestampIDPrefix.

The IsTimestampIDPrefix function appropriately checks for the 't' prefix in timestampID, which is essential for the new timestamp-based querying mechanism. The implementation is straightforward and efficient.

mod/node-core/pkg/components/interfaces.go (4)

116-118: Method GetTimestamp correctly updated

The GetTimestamp() method has been correctly introduced to replace GetExecutionNumber(), aligning with the shift from execution numbers to timestamps as per the PR objectives.


298-300: Parameter name inconsistency remains

The parameter name executionNumber should be updated to timestamp for consistency with the method GetParentSlotByTimestamp.

This issue has been previously noted.


1094-1094: Parameter name inconsistency remains

The parameter name executionNumber should be updated to timestamp to maintain consistency with the method GetParentSlotByTimestamp.

This issue has been previously noted.


1126-1126: Parameter name inconsistency remains

The parameter name executionNumber should be updated to timestamp for consistency with the updated method name GetParentSlotByTimestamp.

This issue has been previously noted.

mod/node-api/handlers/proof/handler.go Show resolved Hide resolved
mod/storage/pkg/block/store.go Outdated Show resolved Hide resolved
mod/storage/pkg/block/store.go Show resolved Hide resolved
mod/storage/pkg/block/store.go Outdated Show resolved Hide resolved
mod/storage/pkg/block/store.go Outdated Show resolved Hide resolved
mod/node-api/backend/types.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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 1404bf9 and c7a690d.

📒 Files selected for processing (6)
  • mod/node-api/handlers/proof/block_proposer.go (2 hunks)
  • mod/node-api/handlers/proof/execution_fee_recipient.go (2 hunks)
  • mod/node-api/handlers/proof/execution_number.go (2 hunks)
  • mod/node-api/handlers/utils/id.go (1 hunks)
  • mod/storage/pkg/block/store.go (4 hunks)
  • mod/storage/pkg/block/store_test.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (10)
mod/node-api/handlers/proof/block_proposer.go (2)

29-31: LGTM: Documentation updated to reflect the use of timestamp ID

The method documentation has been correctly updated to mention "timestamp id" instead of "execution id". This change aligns with the PR objective of using timestamp ID for indexing proofs.


41-42: LGTM: Implementation updated to use timestamp ID

The method implementation has been correctly updated to use resolveTimestampID instead of resolveExecutionID, and the parameter has been changed to params.TimestampID. These changes are consistent with the PR objective and the updated documentation.

To ensure the changes are applied consistently throughout the codebase, please run the following verification script:

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

30-30: LGTM: Comment updated to reflect timestamp usage

The comment has been correctly updated to mention "timestamp id" instead of "execution id", which aligns with the PR objectives of using timestamp ID for proof namespace.


41-42: LGTM: Method and parameter updated to use timestamp

The changes from resolveExecutionID to resolveTimestampID and params.ExecutionID to params.TimestampID align well with the PR objectives of using timestamp ID for proof namespace.


Line range hint 34-34: Consider updating the function name for consistency

While the internal logic has been updated to use timestamp ID, the function name GetExecutionNumber still refers to "Execution". Consider renaming this function to better reflect its new purpose, such as GetTimestampNumber or GetBlockNumberByTimestamp.

Here's a suggested change:

-func (h *Handler[
-	BeaconBlockHeaderT, _, _, ContextT, _, _,
-]) GetExecutionNumber(c ContextT) (any, error) {
+func (h *Handler[
+	BeaconBlockHeaderT, _, _, ContextT, _, _,
+]) GetBlockNumberByTimestamp(c ContextT) (any, error) {

Don't forget to update any references to this function in other parts of the codebase.

✅ Verification successful

Function name updated for consistency

The function GetExecutionNumber has been successfully renamed to GetBlockNumberByTimestamp. All references to this function in the codebase have been updated to reflect the new name.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for references to GetExecutionNumber in the codebase

echo "Checking for references to GetExecutionNumber:"
rg --type go 'GetExecutionNumber'

Length of output: 426

mod/storage/pkg/block/store_test.go (4)

45-47: LGTM! Consider adding a comment for clarity.

The implementation of GetTimestamp aligns with the PR objective of using timestamps instead of execution numbers. However, it assumes that the slot number is equivalent to the timestamp, which might not be immediately clear to all readers.

As suggested in a previous review, consider adding a clarifying comment:

 func (m MockBeaconBlock) GetTimestamp() math.U64 {
+	// For testing purposes, we assume the slot number is equivalent to the timestamp
 	return m.slot
 }

68-76: LGTM! Changes align with PR objectives.

The modifications in this test loop accurately reflect the shift from execution numbers to timestamps:

  1. The use of GetParentSlotByTimestamp instead of GetSlotByExecutionNumber is consistent with the PR's goal.
  2. The adjustment of the expected value from i to i-1 is correct, as we're now retrieving the parent slot.

These changes ensure that the test cases properly validate the updated functionality of the block store.


86-87: Consider updating the error message for clarity.

The update to check GetParentSlotByTimestamp instead of GetSlotByExecutionNumber is consistent with the previous changes. However, the error message could be more specific.

As suggested in a previous review, consider updating the error message to explicitly mention "timestamp" for improved clarity and consistency:

 _, err = blockStore.GetParentSlotByTimestamp(2)
-require.ErrorContains(t, err, "not found")
+require.ErrorContains(t, err, "timestamp not found")

Line range hint 1-87: Overall implementation aligns well with PR objectives.

The changes in this file successfully transition from using execution numbers to timestamps, which is consistent with the PR's goal of facilitating offchain clients in querying beacon block proofs based on timestamps. The test cases have been appropriately updated to reflect this change.

A few minor suggestions for improved clarity have been made:

  1. Adding a comment to clarify the assumption in the GetTimestamp method.
  2. Updating the error message in the test case for better specificity.

These small improvements will enhance the readability and maintainability of the test code.

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

73-97: Implementation of ParentSlotFromTimestampID aligns with the timestamp ID usage.

The function correctly handles both prefixed and non-prefixed timestampID values, parsing the timestamp and retrieving the parent slot as intended. The documentation is comprehensive and clarifies the semantics.

mod/storage/pkg/block/store.go Outdated Show resolved Hide resolved
mod/node-api/handlers/utils/id.go Outdated Show resolved Hide resolved
mod/node-api/handlers/utils/id.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

logic seems fine to me.
Found a few nits to cleanup, major of which is the slot == 0 case handling.
Ready to approve as soon as nits are cleared

@calbera calbera requested a review from abi87 October 15, 2024 19:18
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

🧹 Outside diff range comments (1)
mod/node-api/engines/echo/vaildator.go (1)

Line range hint 1-1: Typo in filename 'vaildator.go'

The filename vaildator.go appears to be misspelled. It should likely be validator.go.

Apply the following change:

-Rename file: vaildator.go
+Rename file: validator.go
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c7a690d and 1767d2c.

📒 Files selected for processing (4)
  • mod/node-api/engines/echo/vaildator.go (3 hunks)
  • mod/node-api/handlers/utils/id.go (2 hunks)
  • mod/node-core/pkg/components/interfaces.go (4 hunks)
  • mod/storage/pkg/block/store.go (5 hunks)
🧰 Additional context used
🔇 Additional comments (9)
mod/node-api/handlers/utils/id.go (3)

27-27: Import statement added for enhanced error handling

Including github.com/berachain/beacon-kit/mod/errors allows for consistent and detailed error wrapping throughout the package, improving error tracing and debugging.


86-98: Ensure handling of empty timestampID after prefix

The function ParentSlotFromTimestampID does not handle the case where timestampID is only the prefix 't' without any timestamp value. This can lead to an error when slicing or parsing an empty string.

This issue was previously raised and is still applicable. Consider adding a check to handle this edge case explicitly.


86-98: Consider refactoring to reduce code duplication

The functions SlotFromStateID, SlotFromBlockID, and ParentSlotFromTimestampID share similar patterns in parsing IDs and retrieving slots. Extracting common logic into shared helper functions can improve code maintainability and reduce redundancy.

As noted in previous reviews, this suggestion remains valid and can enhance the codebase's readability and maintainability.

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

65-65: Registering 'timestamp_id' validator

The addition of "timestamp_id": ValidateTimestampID correctly registers the new validation function for timestamp IDs.


Line range hint 99-112: Ensure safe slicing of 'value' in ValidateTimestampID

When slicing value[1:] after checking utils.IsTimestampIDPrefix(value), ensure that value has sufficient length to prevent potential index out of range errors.

Run the following script to confirm that utils.IsTimestampIDPrefix(value) guarantees value is at least two characters long:

mod/node-core/pkg/components/interfaces.go (4)

116-118: Addition of GetTimestamp() method is appropriate

The inclusion of GetTimestamp() in the BeaconBlock interface aligns with the PR objective of shifting from execution numbers to timestamps. This provides necessary access to the block's timestamp derived from the execution payload.


298-300: Introduction of GetParentSlotByTimestamp() in BlockStore

Adding GetParentSlotByTimestamp(timestamp math.U64) to the BlockStore interface enables retrieval of the parent slot based on a given timestamp. This supports timestamp-based queries as per the PR objectives.


1094-1094: Implementation of GetParentSlotByTimestamp() in NodeAPIBackend

The addition of GetParentSlotByTimestamp(timestamp math.U64) in the NodeAPIBackend interface is appropriate and consistent with the transition to timestamp-based methods, facilitating improved access patterns.


1126-1126: Addition of GetParentSlotByTimestamp() in NodeAPIProofBackend

Including GetParentSlotByTimestamp(timestamp math.U64) in the NodeAPIProofBackend interface aligns with the goal of enabling timestamp-based access within the proof backend, supporting the changes outlined in the PR.

mod/storage/pkg/block/store.go Show resolved Hide resolved
mod/node-api/handlers/utils/id.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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 1767d2c and 9f5214e.

📒 Files selected for processing (1)
  • mod/consensus-types/pkg/types/block_test.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
mod/consensus-types/pkg/types/block_test.go (1)

104-104: LGTM! Test case updated correctly.

The change from GetExecutionNumber() to GetTimestamp() in the assertion is consistent with the modifications made to the ExecutionPayload struct. The test case now correctly validates the Timestamp field while maintaining the same expected value.

mod/consensus-types/pkg/types/block_test.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: 8

🧹 Outside diff range comments (2)
mod/node-api/engines/echo/vaildator.go (2)

Line range hint 99-111: Handle potential index out of range error in ValidateTimestampID

There's a potential edge case in the ValidateTimestampID function. If value is an empty string and utils.IsTimestampIDPrefix(value) returns true, slicing value[1:] could result in an index out of range error.

Apply this diff to handle the edge case:

 func ValidateTimestampID(fl validator.FieldLevel) bool {
     allowedValues := map[string]bool{
         utils.StateIDHead:      true,
         utils.StateIDGenesis:   true,
         utils.StateIDFinalized: true,
         utils.StateIDJustified: true,
     }

     value := fl.Field().String()
+    if len(value) < 1 {
+        return false
+    }
     if utils.IsTimestampIDPrefix(value) {
         return ValidateUint64Dec(value[1:])
     }

     return validateStateBlockIDs(value, allowedValues)
 }

Line range hint 1-1: Correct the filename from 'vaildator.go' to 'validator.go'

The filename vaildator.go appears to be misspelled. It should be validator.go to reflect the correct spelling of "validator" and maintain consistency.

Apply this change to rename the file:

-// File: vaildator.go
+// File: validator.go
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c7a690d and 9f5214e.

📒 Files selected for processing (5)
  • mod/consensus-types/pkg/types/block_test.go (2 hunks)
  • mod/node-api/engines/echo/vaildator.go (3 hunks)
  • mod/node-api/handlers/utils/id.go (2 hunks)
  • mod/node-core/pkg/components/interfaces.go (4 hunks)
  • mod/storage/pkg/block/store.go (5 hunks)
🧰 Additional context used
🔇 Additional comments (7)
mod/consensus-types/pkg/types/block_test.go (1)

104-104: LGTM: Test assertion updated correctly.

The modification of the test assertion from GetExecutionNumber() to GetTimestamp() is consistent with the PR objective of using timestamp ID instead of execution ID. The test now correctly validates the new Timestamp field, and the expected value of 10 matches the Timestamp value set in the generateValidBeaconBlock function.

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

39-42: Well-Documented timestamps Field

Great job adding detailed comments for the timestamps cache. The explanation clarifies that the timestamp-to-slot mapping is injective for finalized blocks due to CometBFT consensus, ensuring that each slot corresponds to a unique timestamp. This enhances the code's readability and maintainability.


107-109: Appropriate Handling of Genesis Slot Edge Case

The explicit check for slot == 0 correctly handles the edge case where the genesis slot has no parent. Returning a specific error message improves the robustness of the method.

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

86-101: Function ParentSlotFromTimestampID implementation looks good.

The ParentSlotFromTimestampID function correctly parses the timestamp ID and retrieves the corresponding parent slot. The error handling and use of generics are appropriate.


86-101: ⚠️ Potential issue

Undefined constant TimestampIDPrefix in IsTimestampIDPrefix.

The function IsTimestampIDPrefix uses TimestampIDPrefix, but this constant is not defined within the provided code. This will lead to a compilation error. Ensure that TimestampIDPrefix is defined appropriately.

Apply this diff to define TimestampIDPrefix:

+const TimestampIDPrefix = "t"

Place this definition at the top of the file, after the package declaration and before any functions, to ensure it is accessible throughout the module.

Likely invalid or redundant comment.

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

65-65: Approve addition of timestamp_id validator

The registration of ValidateTimestampID under the "timestamp_id" tag is appropriate and follows the existing pattern.

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

116-118: Approved: Addition of 'GetTimestamp' Method

The addition of the GetTimestamp method to the BeaconBlock interface is appropriate and aligns with the shift to using timestamps. The implementation is correct.

mod/consensus-types/pkg/types/block_test.go Show resolved Hide resolved
mod/storage/pkg/block/store.go Show resolved Hide resolved
mod/storage/pkg/block/store.go Show resolved Hide resolved
mod/node-api/handlers/utils/id.go Show resolved Hide resolved
mod/node-api/handlers/utils/id.go Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Show resolved Hide resolved
mod/node-core/pkg/components/interfaces.go Show resolved Hide resolved
@itsdevbear itsdevbear merged commit a2cce37 into main Oct 16, 2024
16 checks passed
@itsdevbear itsdevbear deleted the node-api-timestamps branch October 16, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants