Skip to content

Use flow-go conversion for execution results. - #75

Merged
jordanschalm merged 4 commits into
mainfrom
jord/er-hash
Mar 26, 2025
Merged

Use flow-go conversion for execution results. #75
jordanschalm merged 4 commits into
mainfrom
jord/er-hash

Conversation

@jordanschalm

@jordanschalm jordanschalm commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores

    • Updated several third-party components to their latest stable versions for improved performance and support.
  • Refactor

    • Enhanced conversion routines with improved error handling and logging to ensure safer processing during operations.
  • Tests

    • Added a new test case to validate consistency of execution results across different protocol states.

@coderabbitai

coderabbitai Bot commented Mar 25, 2025

Copy link
Copy Markdown

Walkthrough

The changes include updates to dependency versions in the go.mod file and a refactoring of the convertExecutionResult function in state/convert.go. The convertExecutionResult function now includes an additional parameter, sporkVersion, and utilizes a new helper function, convertChunk, for chunk conversion. This refactor enhances error handling and modularity in the code.

Changes

File Change Summary
go.mod Updated dependency versions:
- github.com/onflow/cadence: v1.3.1 → v1.3.3
- github.com/onflow/flow-go: v0.38.1 → v0.39.0
- github.com/onflow/flow/protobuf/go/flow: v0.4.7 → v0.4.9
- github.com/onflow/flow-core-contracts/lib/go/{contracts,templates}: v1.4.0 → v1.6.0
- github.com/onflow/flow-go-sdk: v1.3.1 → v1.3.3
- github.com/onflow/flow-nft/lib/go/contracts: v1.2.2 → v1.2.3
state/convert.go Refactored the convertExecutionResult function:
- Updated signature to include sporkVersion
- Introduced new helper function convertChunk
- Enhanced error handling during chunk conversion
state/convert_test.go Added new test function: TestExecutionResultConsistency_ChunkServiceEventCountField to validate consistency of execution results across protocol states v1 and v2. Updated import statements to include necessary packages for the new test.
state/process.go Modified import statements and updated the call to convertExecutionResult to include spork.Version as the first argument.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as convertExecutionResult
    participant Converter as convertChunk
    participant Logger as ErrorLogger

    Caller->>Converter: Convert each chunk
    Converter-->>Caller: Return converted chunk or error
    alt Conversion Successful
        Caller->>Caller: Process converted chunk
    else Conversion Fails
        Caller->>Logger: Log the error
        Caller->>Caller: Return empty result & failure flag
    end
Loading

Poem

I'm a rabbit hopping through the code,
Dependencies spruced up on every node.
Chunks now convert with a magic spell,
Errors caught, logged—oh, all is well.
I nibble on updates with a joyful cheer,
Celebrating smooth changes far and near!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ff10de and 6d52f06.

📒 Files selected for processing (3)
  • state/convert.go (4 hunks)
  • state/convert_test.go (3 hunks)
  • state/process.go (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
state/convert.go (1)
log/log.go (1)
  • Errorf (72-74)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (10)
state/process.go (2)

15-17: LGTM: Added necessary imports for gRPC error handling.

The addition of gRPC code and status imports is appropriate for the error handling mechanisms used in this file.


330-330: Function call updated to match new signature.

The call to convertExecutionResult has been updated to include spork.Version as the first parameter, which matches the new function signature in state/convert.go.

state/convert.go (5)

15-15: LGTM: Added import for flow-go conversion.

The addition of the "github.com/onflow/flow-go/engine/common/rpc/convert" import is necessary for using the convert.MessageToChunk function.


26-26: Function signature updated to handle spork versioning.

The convertExecutionResult function now takes a sporkVersion parameter, which is used to determine how to handle chunk conversion based on the protocol version.


34-40: Enhanced error handling for chunk conversion.

The code now uses a helper function convertChunk for chunk conversion and properly handles errors. If conversion fails, it logs the error and returns an empty result along with a failure status.


56-73: Well-implemented version-specific chunk conversion.

The new convertChunk function correctly handles different spork versions:

  • For versions < 7: Sets ServiceEventCount to nil after conversion
  • For versions >= 7: Uses standard conversion

The function includes appropriate comments explaining the rationale for handling Protocol State v1 differently.


448-448: Function call updated to match new signature.

The call to convertExecutionResult in the verifyBlockHash function has been updated to include spork.Version as the first parameter.

state/convert_test.go (3)

8-17: LGTM: Imports updated for new test.

Imports have been updated to include necessary dependencies for the new test function.


66-66: Function call updated to match new signature.

The call to convertExecutionResult has been updated to include spork.Version as the first parameter.


143-176: Excellent test coverage for protocol version compatibility.

This comprehensive test ensures that Rosetta computes consistent entity IDs for execution results across both Protocol State v1 and v2 formats. It specifically tests the handling of the ServiceEventCount field:

  1. For Protocol State v1: Tests with ServiceEventCount set to nil
  2. For Protocol State v2: Tests with ServiceEventCount set to a pointer to 0

The test includes helpful comments explaining the reasoning and context behind the test.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80d60fc and 991dae8.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod (2 hunks)
  • state/convert.go (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
state/convert.go (1)
log/log.go (1)
  • Errorf (72-74)
🔇 Additional comments (2)
state/convert.go (2)

15-15: Good import of the conversion module

Adding the import for the convert package from flow-go is consistent with the PR objective to use flow-go conversion for execution results.


34-39:

Details

❓ Verification inconclusive

Excellent refactoring using dedicated conversion function with proper error handling

The change replaces direct chunk construction with the convert.MessageToChunk function from flow-go, which is more maintainable and consistent with the codebase standards. The added error handling improves robustness by logging failures and returning early when conversion fails.

Run the following script to verify that all callers of convertExecutionResult handle the boolean return value correctly:


🏁 Script executed:

#!/bin/bash
# Find all usages of convertExecutionResult to ensure they check the boolean return value
rg "exec,\s*ok\s*:=\s*convertExecutionResult" --type go
rg "convertExecutionResult" -A 2 -B 2 --type go | grep "if !ok" -C 3

Length of output: 293


Action Required: Verify Boolean Handling in convertExecutionResult Callers

The refactoring in state/convert.go to use the convert.MessageToChunk function improves consistency and robustness by centralizing conversion logic and adding error logging. However, the automated script intended to ensure that all callers of convertExecutionResult correctly handle the returned boolean value did not produce clear output. In particular, while we located the call sites in state/convert.go and state/convert_test.go, the expected checks (such as if !ok { … }) were not clearly identified.

Please take an extra moment to manually verify that every usage of convertExecutionResult properly checks the boolean return value to handle conversion failures. For additional context, you may run the following script with increased context to inspect the code:

#!/bin/bash
# Display context of convertExecutionResult calls to verify proper error handling
rg -C 10 "exec,\\s*ok\\s*:=\\s*convertExecutionResult" --type go

Once you've confirmed that all callers handle the boolean flag correctly, please update the review status.

Comment thread go.mod
@jordanschalm
jordanschalm merged commit 9f18a99 into main Mar 26, 2025
@jordanschalm
jordanschalm deleted the jord/er-hash branch March 26, 2025 01:13
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