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

Handle the hash calculation DirectCall change to maintain backwards compatibility #339

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jul 9, 2024

Closes: #338

Description

Add a temporary config flag for setting the Cadence height at which we should be using the new hash calculation.
For previous transactions, we need to use the old hash calculation.
This will unblock deployments of new features on PreviewNet.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Introduced a configuration option to handle hash calculation changes based on block height.
  • Bug Fixes

    • Improved hash calculation logic to account for block height dynamically.
  • Tests

    • Added new test cases to verify hash calculation changes based on block height.
  • Chores

    • Updated configuration and test setups to support new hash calculation configuration.

@m-Peter m-Peter added this to the Flow-EVM-M2 milestone Jul 9, 2024
@m-Peter m-Peter self-assigned this Jul 9, 2024
Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The changes manage the alteration in the hash calculation method for DirectCall based on a specific block height (blockchain height). This includes the introduction of configuration settings to specify the height (HashCalculationHeightChange), the adjustment of hash calculation logic in the DirectCall struct, and updates to the transaction unmarshalling functions to handle block height-dependent behavior, ensuring backward compatibility.

Changes

File(s) Change Summary
bootstrap/bootstrap.go Temporary assignment for DirectCallHashCalculationBlockHeightChange with a comment for its future removal.
config/config.go Added HashCalculationHeightChange to Config struct and introduced hash-calc-height-change flag in the FromFlags function.
models/transaction.go Added blockHeight field to DirectCall struct, modified Hash method for conditional hashing, and updated UnmarshalTransaction with a blockHeight parameter.
models/transaction_test.go Updated test calls to UnmarshalTransaction to include blockHeight and added a new test case for hash calculation changes based on block height.
storage/pebble/transactions.go Added an import statement for encoding/binary, and Get method now fetches cadenceHeight value, passing it to models.UnmarshalTransaction.
tests/helpers.go Set HashCalculationHeightChange to 0 in the servicesSetup function's Config struct.

Sequence Diagrams

DirectCall Hash Calculation Change

sequenceDiagram
    participant User
    participant System

    User ->> System: Start loading transaction
    System ->> Config: Check HashCalculationHeightChange
    Config -->> System: Return Height
    System ->> Transaction: Fetch data with block height
    Transaction ->> DirectCall: Initialize with block height
    DirectCall ->> DirectCall: Conditional hash calculation
    DirectCall -->> Transaction: Return hash
    Transaction -->> System: Return processed transaction 
    System -->> User: Display processed transaction
Loading

Assessment against linked issues

Objective Addressed Explanation
Handle the hash calculation DirectCall change to maintain backwards compatibility (#338)

Poem

In the code, a change is rife,
Hashes bloom at a certain height.
Config set the stage just right,
Transactions flow smooth, day and night.
A tweak so small, a fix so bright,
Compatibility honed with insight. 🚀


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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50a7728 and 807151c.

Files selected for processing (6)
  • bootstrap/bootstrap.go (1 hunks)
  • config/config.go (2 hunks)
  • models/transaction.go (2 hunks)
  • models/transaction_test.go (3 hunks)
  • storage/pebble/transactions.go (2 hunks)
  • tests/helpers.go (1 hunks)
Additional comments not posted (14)
storage/pebble/transactions.go (3)

4-4: Import statement added.

The encoding/binary package is imported to handle byte order conversions, which is necessary for the new functionality.


50-56: Ensure error handling for height retrieval.

The Get method now retrieves cadenceHeight. Ensure that the fallback to 0 is appropriate and does not mask potential issues.


57-57: Pass cadenceHeight to UnmarshalTransaction.

The cadenceHeight is correctly passed to models.UnmarshalTransaction to handle the new hash calculation logic.

models/transaction.go (4)

56-57: Add blockHeight field to DirectCall.

The blockHeight field is added to handle the conditional hash calculation. Ensure this temporary field is removed after the PreviewNet reset.


60-61: Temporary configuration parameter added.

The DirectCallHashCalculationBlockHeightChange parameter is introduced to handle the hash calculation change. Ensure this is removed after the PreviewNet reset.


64-76: Conditional hash calculation in Hash method.

The Hash method now conditionally calculates the hash based on blockHeight. This change ensures backward compatibility.


215-223: Update UnmarshalTransaction to accept blockHeight.

The UnmarshalTransaction method now accepts blockHeight and initializes DirectCall with it. This change supports the new hash calculation logic.

bootstrap/bootstrap.go (1)

97-99: Temporary assignment of configuration parameter.

The DirectCallHashCalculationBlockHeightChange is assigned from cfg.HashCalculationHeightChange. Ensure this is removed after the PreviewNet reset.

tests/helpers.go (1)

157-157: Add HashCalculationHeightChange to test configuration.

The HashCalculationHeightChange field is added to the Config struct in the servicesSetup function to support testing the new hash calculation logic.

config/config.go (2)

94-95: LGTM! New configuration parameter added.

The HashCalculationHeightChange field has been correctly added to the Config struct.


155-157: LGTM! New flag added.

The hash-calc-height-change flag has been correctly added to the FromFlags function to set the HashCalculationHeightChange value.

models/transaction_test.go (3)

Line range hint 190-194:
LGTM! Test case updated.

The test case with TransactionCall value has been correctly updated to include the DirectCallHashCalculationBlockHeightChange parameter in the UnmarshalTransaction function call.


Line range hint 244-248:
LGTM! Test case updated.

The test case with DirectCall value has been correctly updated to include the DirectCallHashCalculationBlockHeightChange parameter in the UnmarshalTransaction function call.


283-341: LGTM! New test case added.

The new test case with DirectCall hash calculation change correctly tests the hash calculation changes based on block height. It verifies both the new and old hash calculations.

@m-Peter m-Peter force-pushed the handle-direct-call-hash-calc-change branch from 807151c to 0271686 Compare July 9, 2024 10:15
return models.UnmarshalTransaction(val)
heightVal, err := t.store.get(latestCadenceHeightKey)
if err != nil {
heightVal = []byte{0, 0, 0, 0, 0, 0, 0, 0}
Copy link
Collaborator Author

@m-Peter m-Peter Jul 9, 2024

Choose a reason for hiding this comment

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

In case of err, I am just adding a default value of 0. Not sure how to handle that. I am open to ideas.

@m-Peter m-Peter force-pushed the handle-direct-call-hash-calc-change branch from 0271686 to 0b75260 Compare July 9, 2024 10: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: 0

Outside diff range and nitpick comments (1)
bootstrap/bootstrap.go (1)

97-99: Add a TODO comment for tracking temporary code.

The comment indicates that this assignment is temporary and should be removed after PreviewNet is reset. To ensure this is tracked, consider adding a TODO comment.

// TEMP: Remove `DirectCallHashCalculationBlockHeightChange` after PreviewNet is reset
+ // TODO: Remove this temporary assignment after PreviewNet reset
models.DirectCallHashCalculationBlockHeightChange = cfg.HashCalculationHeightChange
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 807151c and 0b75260.

Files selected for processing (6)
  • bootstrap/bootstrap.go (1 hunks)
  • config/config.go (2 hunks)
  • models/transaction.go (2 hunks)
  • models/transaction_test.go (3 hunks)
  • storage/pebble/transactions.go (2 hunks)
  • tests/helpers.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • config/config.go
  • models/transaction.go
  • models/transaction_test.go
  • storage/pebble/transactions.go
  • tests/helpers.go

@m-Peter m-Peter merged commit 11f6124 into main Jul 9, 2024
2 checks passed
@m-Peter m-Peter deleted the handle-direct-call-hash-calc-change branch July 9, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Handle the hash calculation DirectCall change to maintain backwards compatibility
2 participants