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

imp: add migration handler for DenomTrace to Denom #6453

Merged
merged 10 commits into from
Jun 3, 2024

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Jun 3, 2024

Description

closes: #6221
closes: #6414


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Improved handling and migration of coin denomination formats for better accuracy and consistency.
  • Bug Fixes

    • Enhanced validation and extraction of denomination information to prevent errors and ensure data integrity.
  • Tests

    • Updated test cases to cover new denomination handling logic and ensure robustness against corrupted and invalid data.
  • Refactor

    • Streamlined functions and methods related to denomination traces to improve code maintainability and performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copied test from trace.go

Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Warning

Rate limit exceeded

@colin-axner has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 51 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 101c834 and 2da407c.

Walkthrough

The changes involve migrating the internal storage and handling of IBC token denomination traces from a single string format to an array format. This includes replacing the ParseDenomTrace function with ExtractDenomFromFullPath, updating associated methods and tests, and removing deprecated functions and migration steps. The goal is to simplify maintenance and improve performance by aligning with ICS20-v2 standards.

Changes

File Path Change Summary
e2e/testsuite/testsuite.go Updated GetIBCToken to return Denom type and use ExtractDenomFromFullPath.
modules/apps/transfer/client/cli/tx.go Replaced ParseDenomTrace with ExtractDenomFromFullPath for coin denomination handling.
modules/apps/transfer/keeper/grpc_query.go Switched from ParseDenomTrace to ExtractDenomFromFullPath in DenomHash function.
modules/apps/transfer/keeper/migrations.go Removed MigrateTraces and added MigrateDenomTraceToDenom for migrating storage from DenomTrace to Denom.
modules/apps/transfer/keeper/migrations_test.go Renamed and updated test functions to work with Denom instead of DenomTrace. Added new tests for multiple and corrupted denoms.
modules/apps/transfer/module.go Removed old migration step and added new migration for DenomTrace to Denom. Updated ConsensusVersion.
modules/apps/transfer/types/denom_trace.go Introduced functions for handling denom hashes, prefixes, and formats for ICS20 tokens.
modules/apps/transfer/types/trace.go Removed functions related to DenomTrace parsing, hashing, and validation.
modules/apps/transfer/types/trace_test.go Removed old test functions and added TestExtractDenomFromFullPath for new denom extraction logic.
modules/apps/transfer/types/denom_trace_test.go No alterations to exported entities; focused on testing IBCDenom method of DenomTrace.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant CLI
    participant Keeper
    participant Migrator
    participant Denom

    User->>CLI: Send IBC Token
    CLI->>Keeper: Extract Denom From Full Path
    Keeper->>Denom: Validate and Hash Denom
    Denom-->>Keeper: Return Validated and Hashed Denom
    Keeper->>Migrator: Migrate DenomTrace to Denom
    Migrator-->>Keeper: Migration Complete
    Keeper-->>CLI: Return Processed Token
    CLI-->>User: Transaction Complete
Loading

Assessment against linked issues

Objective Addressed Explanation
Migrate internal storage of trace string to array of trace info (#6221)
Remove MigrateTraces from transfer (#6414)

Possibly related issues


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 Author

Choose a reason for hiding this comment

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

copied from trace.go

// - "portidone/channel-0/gamm/pool/1" => DenomTrace{Path: "portidone/channel-0", BaseDenom: "gamm/pool/1"}
// - "gamm/pool/1" => DenomTrace{Path: "", BaseDenom: "gamm/pool/1"}
// - "uatom" => DenomTrace{Path: "", BaseDenom: "uatom"}
func ParseDenomTrace(rawDenom string) DenomTrace {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -140,40 +84,6 @@ func ExtractDenomFromFullPath(fullPath string) Denom {
}
}

// validateTraceIdentifiers validates the correctness of the trace associated with a particular base denom.
func validateTraceIdentifiers(identifiers []string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

}

// Validate performs a basic validation of the DenomTrace fields.
func (dt DenomTrace) Validate() error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@colin-axner colin-axner added the priority PRs that need prompt reviews label Jun 3, 2024
@colin-axner colin-axner marked this pull request as ready for review June 3, 2024 14:43
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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33de45f and 4088f9f.

Files selected for processing (10)
  • e2e/testsuite/testsuite.go (1 hunks)
  • modules/apps/transfer/client/cli/tx.go (1 hunks)
  • modules/apps/transfer/keeper/grpc_query.go (1 hunks)
  • modules/apps/transfer/keeper/migrations.go (3 hunks)
  • modules/apps/transfer/keeper/migrations_test.go (3 hunks)
  • modules/apps/transfer/module.go (3 hunks)
  • modules/apps/transfer/types/denom_trace.go (1 hunks)
  • modules/apps/transfer/types/denom_trace_test.go (1 hunks)
  • modules/apps/transfer/types/trace.go (3 hunks)
  • modules/apps/transfer/types/trace_test.go (3 hunks)
Additional context used
Path-based instructions (10)
modules/apps/transfer/types/denom_trace_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

modules/apps/transfer/types/denom_trace.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/types/trace_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

modules/apps/transfer/types/trace.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/keeper/grpc_query.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/client/cli/tx.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/keeper/migrations.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/module.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/keeper/migrations_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

e2e/testsuite/testsuite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern e2e/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

golangci-lint
modules/apps/transfer/keeper/migrations.go

18-18: undefined: Keeper


22-22: undefined: Keeper


116-116: undefined: Keeper


124-124: undefined: Keeper


131-131: undefined: Keeper


147-147: undefined: Keeper

Additional comments not posted (16)
modules/apps/transfer/types/denom_trace_test.go (1)

10-26: The test case TestDenomTrace_IBCDenom effectively checks the IBCDenom method for both base and trace scenarios. It's good to see that the expected outcomes are clearly defined and tested against the actual results.

modules/apps/transfer/types/denom_trace.go (4)

10-16: The Hash method correctly computes the SHA256 hash of the full denomination path. This is a crucial function for ensuring the uniqueness and integrity of the denomination trace.


18-21: The GetPrefix method is straightforward and correctly constructs the prefix from the trace path. This method is essential for maintaining consistency in how denominations are represented and processed.


23-30: The IBCDenom method is well-implemented, providing a clear and correct format for the IBC denomination based on the trace information. This method is vital for the correct functioning of token transfers in the IBC protocol.


32-40: The GetFullDenomPath method accurately constructs the full denomination path from the trace and base denomination. This method is essential for the correct parsing and handling of IBC tokens.

modules/apps/transfer/types/trace_test.go (1)

Line range hint 47-65: The test cases in TestExtractDenomFromFullPath cover a wide range of scenarios, from simple base denominations to complex IBC paths with multiple hops. This thorough testing ensures that the ExtractDenomFromFullPath function behaves as expected across various inputs.

modules/apps/transfer/types/trace.go (1)

1-1: The file trace.go contains essential functions for handling IBC token traces, including validation and parsing. It's important to ensure that these functions are robust and error-free given their critical role in the IBC token transfer process.

modules/apps/transfer/keeper/grpc_query.go (1)

99-105: The DenomHash method in grpc_query.go correctly extracts and validates the denomination from the provided trace, and then checks for its existence in the store. This method is crucial for the integrity and correctness of denomination queries in the IBC module.

modules/apps/transfer/client/cli/tx.go (1)

63-64: The changes in NewTransferTxCmd to use ExtractDenomFromFullPath and IBCDenom for handling coin denominations are correctly implemented. These changes are crucial for ensuring that the CLI handles IBC token transfers correctly with the updated denomination handling logic.

modules/apps/transfer/keeper/migrations.go (2)

74-109: ### Review of MigrateDenomTraceToDenom function
The function MigrateDenomTraceToDenom is designed to migrate storage from using DenomTrace to Denom. The function iterates over all DenomTrace entries, converts each to a Denom, validates it, and then updates the storage to use Denom while deleting the old DenomTrace. The use of panic for error handling is aggressive but appropriate for a blockchain setting where data integrity is critical.

However, there are a few points to consider:

  1. Error Handling: The use of panic ensures that any error during migration leads to a halt in the process, which is suitable for critical migrations in a blockchain context. However, it might be beneficial to log the error for better traceability before panicking.
  2. Migration Logic: The logic correctly ensures that the IBC denom does not change during the migration, which is crucial for maintaining consistency across the network.
  3. Performance: The function handles potentially large data sets by iterating over traces and applying changes one by one. This approach is necessary given the constraints of blockchain state management but should be monitored for performance in a production environment.

Overall, the function appears well-constructed for its purpose, with thorough error handling and appropriate safety checks.


123-127: ### Review of deleteDenomTrace function
The deleteDenomTrace function is straightforward and correctly implements the deletion of a DenomTrace from the store. It uses the DenomTrace hash as the key, which is a standard approach for ensuring that deletions are correctly targeted.

Suggestion: It might be beneficial to check if the deletion was successful or if the key did not exist in the first place. This could help in debugging issues during migration where expected keys are not found.

Tools
golangci-lint

124-124: undefined: Keeper

modules/apps/transfer/module.go (2)

136-138: ### Review of Migration Registration in RegisterServices
The registration of the MigrateDenomTraceToDenom migration function is correctly implemented. It specifies that this migration should occur when upgrading from version 5 to 6 of the module. The use of panic in error handling is appropriate here to prevent the module from running in an incorrect state.

Consideration: Ensure that all dependent modules and functionalities are compatible with this version change to prevent issues in multi-module setups.


157-157: ### Consensus Version Update
The update of the consensus version to 6 is a critical change that signifies backward-incompatible changes in the module. This change is well-documented in the code and correctly implemented.

Action: It is crucial to ensure that all network participants are aware of this change and that it is coordinated with network upgrades to prevent consensus errors.

modules/apps/transfer/keeper/migrations_test.go (2)

51-127: ### Review of TestMigratorMigrateDenomTraceToDenom
This test function covers various scenarios for the migration from DenomTrace to Denom, including cases with no traces, single trace, multiple traces, and complex trace paths. The test is well-structured and covers a broad range of possible real-world scenarios.

Improvement: Consider adding assertions for the state of the store before and after the migration to ensure that no unintended changes occur during the process.


195-227: ### Review of TestMigratorMigrateDenomTraceToDenomCorruptionDetection
This test function checks the robustness of the migration process against corrupted or invalid DenomTrace entries. It is crucial for ensuring that the migration process can handle unexpected data gracefully.

Suggestion: Expand the test cases to cover more types of corruption, such as invalid characters in the denom or excessively long paths, to further ensure the migration's resilience.

e2e/testsuite/testsuite.go (1)

521-522: The update to use transfertypes.ExtractDenomFromFullPath aligns with the PR's objectives to simplify and optimize the handling of token denominations. This change appears correctly implemented.

panic(err)
}

if dt.IBCDenom() != denom.IBCDenom() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should in theory be unreachable or am I missing something? It should all hinge on how much we trust our conversion funcs

Copy link
Contributor

Choose a reason for hiding this comment

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

also, on this, do we want to exercise these panic paths, open issue etc.

Copy link
Contributor Author

@colin-axner colin-axner Jun 3, 2024

Choose a reason for hiding this comment

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

in theory unreachable, but provides a nice defense mechanism in case we miss a step. We absolutely do not want to be generating different sdk coin denoms after this migration, so this is just for peace of mind

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm, wouldn't mind a comment signaling defense in depth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Love the 🔴 diffs! Super clean, good stuff 🚀

I just left one suggestion about the looping for set/delete.

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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4088f9f and 101c834.

Files selected for processing (3)
  • modules/apps/transfer/keeper/migrations.go (3 hunks)
  • modules/apps/transfer/keeper/migrations_test.go (3 hunks)
  • modules/apps/transfer/types/denom_trace_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/apps/transfer/types/denom_trace_test.go
Additional context used
Path-based instructions (2)
modules/apps/transfer/keeper/migrations.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/apps/transfer/keeper/migrations_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (3)
modules/apps/transfer/keeper/migrations.go (1)

119-123: The deleteDenomTrace function correctly handles the deletion of denom traces using their hash as the key. This is a crucial part of the migration process to ensure that old traces are properly cleaned up.

modules/apps/transfer/keeper/migrations_test.go (2)

Line range hint 51-189: The test function TestMigratorMigrateDenomTraceToDenom is well-structured and covers a comprehensive range of scenarios from simple to complex trace paths. This thorough testing ensures that the migration logic is robust across different cases.


194-226: The function TestMigratorMigrateDenomTraceToDenomCorruptionDetection effectively tests the migration logic's response to corrupted and invalid denom traces, ensuring that such cases lead to a panic as expected. This is crucial for maintaining the integrity of the migration process.
[APROVED]

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

lovely to see this final step of the refactor. great job with all of it! 🎉

Copy link

sonarqubecloud bot commented Jun 3, 2024

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
12 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@colin-axner colin-axner merged commit 56ba440 into main Jun 3, 2024
78 checks passed
@colin-axner colin-axner deleted the colin/6221-migrate-denomtrace-to-denom branch June 3, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove MigrateTraces from transfer Migrate internal storage of trace string to array of trace info
3 participants