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(genesis): implement marshaler for executionPayloadHeader wrapper type #1512

Merged
merged 11 commits into from
Jun 18, 2024

Conversation

archbear
Copy link
Contributor

@archbear archbear commented Jun 17, 2024

Summary by CodeRabbit

  • Refactor

    • Standardized type declarations across various modules from ExecutionPayloadHeaderDeneb to ExecutionPayloadHeader for improved consistency and maintainability.
  • Bug Fixes

    • Fixed issues related to JSON unmarshalling by adding and updating methods to ensure proper handling of ExecutionPayloadHeader.
  • Tests

    • Updated test cases to reflect changes in method signatures and type declarations, ensuring continued accuracy and reliability.
  • Chores

    • Updated generated code comments to reflect new hash values for documentation consistency.

Copy link
Contributor

coderabbitai bot commented Jun 17, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The recent changes streamline the handling of ExecutionPayloadHeader types across multiple modules, replacing specific ExecutionPayloadHeaderDeneb instances. This refactor enhances code maintainability and consistency. Various files, including those related to blockchain processing, CLI commands, and consensus types, have been updated to reflect this new unified type, ensuring more standardized and simplified data handling.

Changes

File(s) / Module(s) Change Summary
.../beacon/blockchain/process.go Updated the type of ExecutionPayloadHeader for ProcessGenesisData function.
.../cli/pkg/commands/... Changed types.ExecutionPayloadHeaderDeneb to types.ExecutionPayloadHeader in multiple commands.
.../consensus-types/pkg/genesis/... Added UnmarshalJSON method, updated ExecutionPayloadHeaderT interface, and modified DefaultGenesisDeneb function.
.../consensus-types/pkg/types/payload_header.go Refactored UnmarshalJSON method into NewFromJSON method to handle JSON initialization.
...genesis_test.go, .../payload_header_test.go Updated test cases to use new getter methods and new JSON unmarshalling method.
.../pkg/types/payload_header.ssz.go Updated the hash value in the generated code comment.
.../node-core/pkg/components/module/module.go Modified ExportGenesis method to use ExecutionPayloadHeader.
.../runtime/pkg/middleware/finalize.go Changed types in the FinalizeBlockMiddleware method to use ExecutionPayloadHeader.
.../runtime/pkg/middleware/types.go Updated ProcessGenesisData method to accept ExecutionPayloadHeader.

Poem

In the code where changes flow,
Payload headers swapped for show.
Simplified with ease and grace,
Our blockchain hums at a steadier pace.
Lines refined, errors no more,
Whispering updates, we rabbits soar. 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 Configration 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 Jun 17, 2024

Codecov Report

Attention: Patch coverage is 9.24370% with 108 lines in your changes missing coverage. Please review.

Project coverage is 24.41%. Comparing base (5c6111f) to head (e7de272).

Current head e7de272 differs from pull request most recent head 66ad18f

Please upload reports for the commit 66ad18f to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1512      +/-   ##
==========================================
- Coverage   24.47%   24.41%   -0.06%     
==========================================
  Files         255      255              
  Lines       11318    11360      +42     
  Branches       18       18              
==========================================
+ Hits         2770     2774       +4     
- Misses       8382     8420      +38     
  Partials      166      166              
Files Coverage Δ
mod/consensus-types/pkg/types/payload_header.go 100.00% <100.00%> (ø)
mod/beacon/blockchain/process.go 0.00% <0.00%> (ø)
mod/cli/pkg/commands/genesis/collect.go 0.00% <0.00%> (ø)
mod/node-core/pkg/components/module/module.go 0.00% <0.00%> (ø)
mod/runtime/pkg/middleware/finalize.go 0.00% <0.00%> (ø)
mod/consensus-types/pkg/genesis/genesis.go 66.29% <16.66%> (-25.65%) ⬇️
mod/cli/pkg/commands/genesis/payload.go 0.00% <0.00%> (ø)

archbear and others added 4 commits June 17, 2024 19:02
A task emerged, a challenge to see,
To craft a marshaler, unique and grand,
But struggles arose, like shifting sand.

With structs so varied, and data wide,
The task was daunting, no place to hide.
Each field, a puzzle, each type, a quest,
To encode them rightly, and hope for the best.

Reflection’s mirror, a tool so bright,
Yet pitfalls lingered, in the dead of night.
To handle pointers, or nested arrays,
Complexities grew, in countless ways.

Methods to write, to JSON and back,
Ensuring no errors, no data lack.
Edge cases lingered, lurking unseen,
To trip the unwary, and break the machine.

Bytes to string, and string to bytes,
The dance of encoding, long sleepless nights.
Custom tags, and omitempty,
Each choice a crossroad, each turn a plea.

Testing and trials, the cycle spun,
Debugging the errors, till dawn’s first sun.
Panics and crashes, in the heat of the chase,
But persistence held, no retreat, no disgrace.

At last it worked, the marshalers fine,
Data in order, in perfect line.
A triumph hard-won, through toil and strife,
A coder’s journey, the coder’s life.

In Go’s vast realm, where challenges thrive,
The custom marshaler, now stands alive.
A testament bold, to effort and might,
In the world of Go, it shines so bright.
@archbear archbear marked this pull request as ready for review June 18, 2024 00:32
@archbear archbear requested a review from ocnc as a code owner June 18, 2024 00:32
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

Outside diff range comments (1)
mod/consensus-types/pkg/genesis/genesis.go (1)

Line range hint 92-108: The function DefaultGenesisDeneb uses a placeholder name 'deneb' which suggests that it might be tightly coupled to specific configurations. Consider renaming or refactoring to increase flexibility.

- func DefaultGenesisDeneb() *Genesis[
+ func DefaultGenesis() *Genesis[
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 1abdb40 and f1367da.

Files selected for processing (11)
  • mod/beacon/blockchain/process.go (1 hunks)
  • mod/cli/pkg/commands/genesis/collect.go (1 hunks)
  • mod/cli/pkg/commands/genesis/payload.go (2 hunks)
  • mod/consensus-types/pkg/genesis/genesis.go (4 hunks)
  • mod/consensus-types/pkg/genesis/genesis_test.go (1 hunks)
  • mod/consensus-types/pkg/types/payload_header.go (1 hunks)
  • mod/consensus-types/pkg/types/payload_header.ssz.go (1 hunks)
  • mod/consensus-types/pkg/types/payload_header_test.go (2 hunks)
  • mod/node-core/pkg/components/module/module.go (1 hunks)
  • mod/runtime/pkg/middleware/finalize.go (1 hunks)
  • mod/runtime/pkg/middleware/types.go (1 hunks)
Files not reviewed due to errors (1)
  • mod/cli/pkg/commands/genesis/payload.go (no review received)
Additional comments not posted (10)
mod/consensus-types/pkg/genesis/genesis_test.go (1)

55-63: The updated test cases effectively validate the properties of ExecutionPayloadHeader using getter methods. This is a good practice as it encapsulates the properties and allows for future modifications without affecting the test cases directly.

mod/runtime/pkg/middleware/types.go (1)

61-61: The update to use *types.ExecutionPayloadHeader in the ProcessGenesisData method aligns with the refactoring across the project to standardize the usage of ExecutionPayloadHeader. This maintains consistency and leverages the new type's capabilities.

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

108-108: The ExportGenesis method now correctly uses the updated ExecutionPayloadHeader type in the genesis structure. This ensures that the exported genesis state is consistent with the new data structure standards defined across the project.

mod/cli/pkg/commands/genesis/collect.go (1)

76-76: The CollectGenesisDepositsCmd function now initializes Genesis with the updated ExecutionPayloadHeader type. This change is crucial for ensuring that all parts of the system are using the updated type, which supports the overall goal of the refactor to improve data handling and consistency.
[APROVED]

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

76-79: Ensure that NewFromJSON is robust against different versions and handles errors gracefully, as it is critical for initializing ExecutionPayloadHeader from JSON.

Verification successful

The NewFromJSON method in mod/consensus-types/pkg/types/payload_header.go initializes an ExecutionPayloadHeader from JSON bytes and includes error handling for JSON unmarshalling. This indicates that the method is designed to handle errors gracefully.

  • The method signature is:
    func (e *ExecutionPayloadHeader) NewFromJSON(bz []byte, forkVersion uint32) (*ExecutionPayloadHeader, error) {
        e = e.Empty(forkVersion)
        if err := e.UnmarshalJSON(bz); err != nil {
            return nil, err
        }
        return e, nil
    }

The method does handle errors from JSON unmarshalling, returning an error if the unmarshalling fails. This suggests it is robust against malformed JSON inputs.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robustness of NewFromJSON method against various JSON inputs and versions.
# Test: Feed various JSON inputs and versions, expect no crashes or unhandled exceptions.
ast-grep --lang go --pattern $'func (e *ExecutionPayloadHeader) NewFromJSON($_, $_) {
  $$$
}'

Length of output: 95



Script:

#!/bin/bash
# Searching for the NewFromJSON method in the entire codebase
rg 'NewFromJSON' --type go

Length of output: 675



Script:

#!/bin/bash
# Extracting the implementation of NewFromJSON method
ast-grep --lang go --pattern $'func (e *ExecutionPayloadHeader) NewFromJSON($_, $_) {
  $$$
}' mod/consensus-types/pkg/types/payload_header.go

Length of output: 143



Script:

#!/bin/bash
# Extracting the implementation of NewFromJSON method with a more flexible pattern
rg 'func (e \*ExecutionPayloadHeader) NewFromJSON' -A 20 mod/consensus-types/pkg/types/payload_header.go

Length of output: 106



Script:

#!/bin/bash
# Searching for all method signatures in the file to capture the exact signature of NewFromJSON
rg 'func ' mod/consensus-types/pkg/types/payload_header.go

Length of output: 1550



Script:

#!/bin/bash
# Extracting the implementation of NewFromJSON method using the exact method signature
rg 'func (e \*ExecutionPayloadHeader) NewFromJSON' -A 50 mod/consensus-types/pkg/types/payload_header.go

Length of output: 106



Script:

#!/bin/bash
# Searching for the NewFromJSON method in the entire file to ensure we capture it correctly
rg 'NewFromJSON' mod/consensus-types/pkg/types/payload_header.go -A 50

Length of output: 3111

mod/beacon/blockchain/process.go (1)

49-55: This function correctly updates the type used in ProcessGenesisData to *types.ExecutionPayloadHeader. Ensure that all related data handling and processing logic is updated accordingly for the new type.

mod/runtime/pkg/middleware/finalize.go (1)

95-100: The InitGenesis function correctly initializes Genesis with the new ExecutionPayloadHeader. Ensure that the unmarshalling and subsequent processing are correctly handling the new structure.

mod/consensus-types/pkg/types/payload_header.ssz.go (1)

2-2: The hash value in the comment has been updated. Verify that this new hash corresponds to the current state of the code and all dependencies are aligned.

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

74-82: The new method NewFromJSON properly initializes an ExecutionPayloadHeader from JSON for a specific fork version. This method correctly uses the Empty method for initialization, which is consistent with the modular design of handling different fork versions.

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

Line range hint 483-527: The new test case TestExecutionPayloadHeader_NewFromJSON appropriately checks the functionality of the NewFromJSON method. It handles both valid and invalid JSON inputs, which is crucial for robustness. Ensure the error messages and conditions are correctly aligned with the expected outcomes.

mod/consensus-types/pkg/genesis/genesis.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: 1

Outside diff range comments (1)
mod/consensus-types/pkg/genesis/genesis.go (1)

Line range hint 92-108: The DefaultGenesis method correctly constructs a default genesis object. Consider changing the error handling strategy from panic to returning an error to allow calling code more flexibility in handling initialization failures.

- panic(err)
+ return nil, fmt.Errorf("failed to create default genesis: %w", err)
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between f1367da and afceb92.

Files selected for processing (1)
  • mod/consensus-types/pkg/genesis/genesis.go (4 hunks)
Additional comments not posted (3)
mod/consensus-types/pkg/genesis/genesis.go (3)

43-43: The method NewFromJSON is well-defined, providing a clear interface for JSON deserialization that includes version handling.


55-56: The Genesis struct is well-defined with appropriate JSON tags for serialization.


42-43: The interface name ExecutionPayloadHeaderT is misspelled. It should be ExecutionPayloadHeaderT.

- ExecutionPayloadHeaderT interface {
+ ExecutionPayloadHeaderT interface {

Likely invalid or redundant comment.

mod/consensus-types/pkg/genesis/genesis.go Show resolved Hide resolved
@itsdevbear itsdevbear merged commit eb477fe into main Jun 18, 2024
15 checks passed
@itsdevbear itsdevbear deleted the marshal-matters branch June 18, 2024 01:39
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.

2 participants