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

Update to Cadence v1.0.0 #609

Merged
merged 2 commits into from
Oct 5, 2024
Merged

Conversation

jribbink
Copy link
Contributor

@jribbink jribbink commented Oct 3, 2024

Description

Automatically update to:

Summary by CodeRabbit

  • New Features

    • Updated dependencies to stable versions, improving overall stability and performance.
    • Enhanced block event handling for better error management and consistency.
    • Refined testing of the event ingestion engine for improved coverage and validation.
  • Bug Fixes

    • Minor updates to dependencies to address issues and enhance functionality.
    • Improved tests for block decoding and event ingestion, ensuring robustness against various scenarios.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The changes in this pull request involve updating the versions of several dependencies in the go.mod files for two modules: the main module and the github.com/onflow/flow-evm-gateway/integration module. Notable updates include transitioning from preview versions to stable releases for github.com/onflow/cadence and github.com/onflow/flow-go-sdk, as well as incrementing the versions of github.com/onflow/flow-emulator and github.com/onflow/flow/protobuf/go/flow. Additionally, modifications to the models/block.go, models/block_test.go, and services/ingestion/engine_test.go files enhance error handling and testing logic. The overall structure of both go.mod files remains unchanged.

Changes

File Change Summary
go.mod - Updated github.com/onflow/cadence from v1.0.0-preview.52 to v1.0.0
- Updated github.com/onflow/flow-go from v0.37.10 to v0.38.0-preview.0.0.20241002124048-21cfe5aea5a8
- Updated github.com/onflow/flow-go-sdk from v1.0.0-preview.56 to v1.0.0
- Updated github.com/onflow/flow/protobuf/go/flow from v0.4.6 to v0.4.7
- Updated github.com/onflow/flow-emulator from v1.0.0 to v1.0.1
tests/go.mod - Updated github.com/onflow/cadence from v1.0.0-preview.52 to v1.0.0
- Updated github.com/onflow/flow-emulator from v1.0.0 to v1.0.1
- Updated github.com/onflow/flow-go from v0.37.10 to v0.38.0-preview.0.0.20241002124048-21cfe5aea5a8
- Updated github.com/onflow/flow-go-sdk from v1.0.0-preview.56 to v1.0.0
- Updated github.com/onflow/flow/protobuf/go/flow from v0.4.6 to v0.4.7
models/block.go - Removed decodeLegacyBlockEvent function and blockEventPayloadV0 struct
- Improved error handling in decodeBlockEvent function
- Added check for zero hash in PrevRandao field
models/block_test.go - Replaced decodeLegacyBlockEvent with decodeBlockEvent in tests
- Added validation for b.FixedHash after decoding
services/ingestion/engine_test.go - Updated newBlock function to use types.NewBlock constructor
- Enhanced test cases for block ingestion scenarios

Possibly related PRs

Suggested labels

Improvement, EVM

Suggested reviewers

  • peterargue
  • zhangchiqing
  • ramtinms

🐇 In the meadow, we hop with glee,
Dependencies updated, oh what a spree!
Cadence and flow, now stable and bright,
With versions anew, we take flight!
A hop and a skip, through code we bound,
In the world of Go, joy is found! 🌼


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>, 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
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 and nitpick comments (1)
models/block.go (1)

88-89: Avoid taking the address of a local variable

Assigning fixedHash = &hash where hash is a local variable can be unnecessary. While Go's memory management ensures safety, it's clearer to allocate a new string for better readability.

Consider modifying the code as follows:

-		hash := payload.Hash.String()
-		fixedHash = &hash
+		fixedHash := new(string)
+		*fixedHash = payload.Hash.String()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 03d7783 and 7fbd1b5.

📒 Files selected for processing (3)
  • models/block.go (2 hunks)
  • models/block_test.go (2 hunks)
  • services/ingestion/engine_test.go (1 hunks)
🔇 Additional comments (3)
models/block_test.go (1)

Line range hint 153-164: LGTM! Consider adding explanatory comments and reviewing other tests.

The changes align well with the PR objectives of updating to Cadence v1.0.0. The switch from decodeLegacyBlockEvent to decodeBlockEvent reflects the updated event handling in the new version.

Suggestions:

  1. Add a comment explaining the reason for the new assertion require.NotNil(t, b.FixedHash). This will help future developers understand why this check is necessary.
  2. Review other test cases in this file and related files to ensure consistency in using decodeBlockEvent instead of decodeLegacyBlockEvent where applicable.

To ensure consistency across the codebase, let's check for any remaining usage of decodeLegacyBlockEvent:

✅ Verification successful

Verification Successful: No remaining usages of decodeLegacyBlockEvent found.

The transition to decodeBlockEvent has been consistently applied across the codebase with no lingering references to the legacy function.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of decodeLegacyBlockEvent
rg 'decodeLegacyBlockEvent' --type go

Length of output: 37

models/block.go (2)

76-81: Improved error handling is correct

The updated error handling provides a more descriptive error message and correctly wraps the original error using %w.


103-103: Setting FixedHash appropriately

Assigning FixedHash: fixedHash ensures that blocks with the legacy format have a consistent hash, maintaining integrity across different block versions.

@onflow onflow deleted a comment from coderabbitai bot Oct 4, 2024
@m-Peter m-Peter force-pushed the auto-update-onflow-cadence-v1.0.0 branch from 7fbd1b5 to f97fcd5 Compare October 4, 2024 12:04
@onflow onflow deleted a comment from coderabbitai bot Oct 4, 2024
Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM!

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 and nitpick comments (1)
models/block.go (1)

77-81: LGTM: Improved error handling and legacy block format handling

The changes in the decodeBlockEvent function are well-implemented:

  1. The error handling now provides more context, which is beneficial for debugging.
  2. The new logic for handling legacy block formats (checking PrevRandao against zeroGethHash) ensures backward compatibility.
  3. Setting the FixedHash field maintains consistency in hash calculations across different block formats.

These changes align well with the PR objectives of updating to Cadence v1.0.0 and handling legacy formats.

Consider wrapping the original error in the new error message using fmt.Errorf("... %w", err) instead of fmt.Errorf("... %s", err.Error()). This preserves the original error type and allows for better error handling upstream.

Also applies to: 84-90, 104-104

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7fbd1b5 and f97fcd5.

📒 Files selected for processing (3)
  • models/block.go (3 hunks)
  • models/block_test.go (2 hunks)
  • services/ingestion/engine_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • models/block_test.go
🔇 Additional comments (6)
models/block.go (4)

19-19: LGTM: Addition of zeroGethHash variable

The addition of the zeroGethHash variable is a good practice. It provides a clear, named constant for a zero hash, which enhances code readability and maintainability.


Line range hint 1-170: Summary of changes in models/block.go

The changes in this file align well with the PR objectives of updating to Cadence v1.0.0 and handling legacy formats. Key improvements include:

  1. Addition of zeroGethHash for better readability and maintainability.
  2. Enhanced error handling in decodeBlockEvent.
  3. Implementation of legacy block format handling.
  4. Removal of deprecated decodeLegacyBlockEvent function and blockEventPayloadV0 struct.

These changes should improve the codebase's maintainability and align it with the latest versions of dependencies. However, it's crucial to verify that the removals don't introduce any regressions or break existing functionality.

Please ensure comprehensive testing is performed, particularly focusing on:

  1. Decoding of both new and legacy block formats.
  2. Proper hash calculation and consistency across different block versions.
  3. Backward compatibility with any systems that might still be using the old formats.

Consider adding or updating unit tests to cover these scenarios if they're not already present.


Line range hint 1-170: Verify impact of removing blockEventPayloadV0 struct

The removal of the blockEventPayloadV0 struct aligns with the PR objectives of updating to newer versions and simplifying the codebase. This change can improve maintainability by removing legacy code.

Please ensure that this removal doesn't break any existing functionality or cause issues with data serialization/deserialization. Run the following script to check for any remaining references to this struct:

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

# Test: Search for any remaining references to blockEventPayloadV0
rg --type go 'blockEventPayloadV0'

If the script returns any results, those areas may need to be updated or removed as well. Additionally, verify that this change doesn't affect the ability to read or process any existing data that might have been serialized using this struct.


Line range hint 1-170: Verify impact of removing decodeLegacyBlockEvent

The removal of the decodeLegacyBlockEvent function aligns with the PR objectives of updating to newer versions and simplifying the codebase. This change can improve maintainability by removing legacy code.

Please ensure that this removal doesn't break any existing functionality. Run the following script to check for any remaining references to this function:

If the script returns any results, those areas may need to be updated or removed as well.

services/ingestion/engine_test.go (2)

553-559: Improved block creation logic

The update to use types.NewBlock is a positive change, aligning with the latest dependency versions and providing a more comprehensive block representation, including the TotalDifficulty parameter.


553-559: ⚠️ Potential issue

Address the unresolved type mismatch in types.NewBlock call

The previous review comment about the potential type mismatch in the last parameter of types.NewBlock is still valid and needs to be addressed.

Apply this diff to correct the parameter type:

gethBlock := types.NewBlock(
    gethCommon.HexToHash("0x1"),
    height,
    uint64(1337),
    big.NewInt(100),
-   gethCommon.HexToHash("0x15"),
+   []byte("0x15"),
)

Comment on lines +553 to +559
gethBlock := types.NewBlock(
gethCommon.HexToHash("0x1"),
height,
uint64(1337),
big.NewInt(100),
gethCommon.HexToHash("0x15"),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing assertions for TotalDifficulty in tests

The current tests in services/ingestion/engine_test.go do not include assertions for the TotalDifficulty property in the newBlock function. It's essential to add these assertions to ensure that the TotalDifficulty is correctly set and handled, thereby validating the updated block creation logic comprehensively.

  • File: services/ingestion/engine_test.go
  • Suggested Additions:
    • Assertions verifying the value of block.TotalDifficulty after block creation.
    • Test cases covering different scenarios involving TotalDifficulty.
🔗 Analysis chain

Review and update tests for new block creation logic

With the changes in the newBlock function, it's important to review the tests that use this function. Ensure that they still cover all necessary scenarios and remain valid with the updated block creation logic. Consider adding new test cases if needed to cover the new TotalDifficulty parameter and any other changes introduced by types.NewBlock.

To help with this verification, you can run the following script to identify tests that might need updating:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find test functions that use newBlock and might need updating

# Search for test functions that call newBlock
rg -t go --multiline '(?s)func Test.*\{.*newBlock\(' services/ingestion/engine_test.go

# Search for assertions related to block properties that might need updating
rg -t go 'assert.*block\.' services/ingestion/engine_test.go

Length of output: 15112


Script:

#!/bin/bash
# Description: Check if tests assert the TotalDifficulty property in newBlock usage

# Search for assertions on block.TotalDifficulty in engine_test.go
rg -t go 'assert.*block\.TotalDifficulty' services/ingestion/engine_test.go

Length of output: 77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants