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

fix: remove deprecated tokens from testnet #856

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Jan 2, 2025

Summary by CodeRabbit

  • New Features

    • Added new constants for token symbols: PUNDIX and PURSE
    • Introduced functions to remove deprecated testnet denominations and coins
  • Improvements

    • Enhanced upgrade process error handling
    • Refined balance and metadata migration logic
    • Updated type consistency for account handling
  • Bug Fixes

    • Improved validation for account balances during upgrade process

Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces modifications to the upgrade process, focusing on testnet-specific operations and balance validation. Changes are made across three files: app/upgrade_test.go, app/upgrades/v8/constants.go, and app/upgrades/v8/upgrade.go. The updates include adding new constants for token symbols, implementing functions to remove deprecated testnet denominations and coins, and adjusting balance validation logic in test scenarios. The modifications aim to enhance the upgrade process's flexibility and error handling.

Changes

File Change Summary
app/upgrade_test.go - Modified checkMigrateBalance to use greater-than-or-equal check for account balances
- Simplified chain ID condition for token checks
- Updated checkAccountBalance to allow zero balance validation
app/upgrades/v8/constants.go - Added pundixSymbol constant set to "PUNDIX"
- Added purseSymbol constant set to "PURSE"
app/upgrades/v8/upgrade.go - Added new functions: removeTestnetDeprecatedDenom, removeTestnetDeprecatedCoins, removeTestnetERC20DeprecatedCoins
- Updated CreateUpgradeHandler to include new deprecation removal functions
- Modified updateMetadata to return errors
- Updated BaseAccount type reference

Possibly related PRs

Poem

🐰 Upgrade hopping, constants bright,
Testnet coins take flight!
Deprecated tokens fade away,
Balance checks dance and sway
Code evolves with rabbit might! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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

🧹 Nitpick comments (3)
app/upgrades/v8/upgrade.go (3)

161-161: Clarify operator precedence.
The condition combines || and &&. To avoid confusion, consider adding parentheses for readability:

-if md.Base == fxtypes.DefaultDenom || (len(md.DenomUnits) == 0 || len(md.DenomUnits[0].Aliases) == 0) && md.Symbol != pundixSymbol {
+if md.Base == fxtypes.DefaultDenom || ((len(md.DenomUnits) == 0 || len(md.DenomUnits[0].Aliases) == 0) && md.Symbol != pundixSymbol) {

Line range hint 233-270: updateMetadata function considerations.

  1. The type-assertion to bankkeeper.BaseKeeper tightly couples the code to a specific implementation. If possible, use an interface-based approach for better extensibility.
  2. Removing metadata only if it still exists is prudent. Error handling is correct.
  3. Consider additional logs or comments explaining why removing old metadata is safe and desired.

403-432: removeTestnetDeprecatedCoins approach.

  • The usage of slices.Contains for each balance is convenient. However, for large sets of deprecated denominations, a set/dictionary lookup might be more performant.
  • The flow to burn coins by first sending to the erc20types.ModuleName is consistent with the removal logic in other modules.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c75311 and 9f8e844.

📒 Files selected for processing (3)
  • app/upgrade_test.go (2 hunks)
  • app/upgrades/v8/constants.go (1 hunks)
  • app/upgrades/v8/upgrade.go (8 hunks)
🔇 Additional comments (12)
app/upgrades/v8/upgrade.go (8)

6-7: Imports look consistent.
No issues found with these newly introduced imports (fmt, slices, etc.). They align with usage in the code (e.g., slices.Contains) and follow standard Go practices.

Also applies to: 10-10, 18-18, 20-21


54-58: Use additional logs if necessary.
The code properly retrieves the list of removed denominations and returns on error. If you need more visibility (e.g., to handle edge cases where removeDenoms might be empty), consider adding a debug log statement. Otherwise, this looks fine.


65-68: Error handling is correct here.
The call to remove deprecated coins properly returns an error if anything fails. No concerns.


87-89: Metadata update call is straightforward.
Error handling is consistent. Good job integrating the metadata update into the upgrade flow.


97-100: Consistent error handling for ERC20 coin removal.
The removal of testnet ERC20-deprecated coins is structurally similar to other removal functions. No issues found.


149-153: BaseAccount type casting.
Creating a module account from a BaseAccount is correct unless you expect non-BaseAccount subtypes (e.g., vesting accounts). Confirm that crosschain accounts can never be vesting accounts. Otherwise, you might need a more flexible approach.


364-401: removeTestnetDeprecatedDenom logic.

  1. Properly returns nil if not on testnet.
  2. Halts and returns an error when token pair is not found (line 394). Verify whether this is expected or if some deprecated tokens may not have a token pair at all.
  3. Thorough logging is good.

434-450: removeTestnetERC20DeprecatedCoins function clarity.

  1. Checks if metadata display indicates an IBC token. This is a neat logic trick but might benefit from an explanatory code comment for future maintainers.
  2. Burning coins is consistent with the overall approach to deprecate testnet tokens.
app/upgrades/v8/constants.go (1)

63-66: New constants are clearly named.
Defining pundixSymbol and purseSymbol centrally promotes consistent usage throughout the code. Great addition.

app/upgrade_test.go (3)

193-193: Lenient check of account balances.
Replacing an equality check with GreaterOrEqual broadens the acceptable range if some accounts lose all tokens (e.g., deprecated tokens were removed). Confirm this is intentional.


199-199: Removed chain ID restriction.
Now this logic always runs for the ERC20 module, potentially changing test coverage for non-Mainnet chains. Make sure this aligns with your desired coverage scope.


231-231: Zero or exact match check.
Allowing zero balances can mask unintended balance wipes if you expect specific amounts. Confirm that zero is an acceptable outcome before skipping the rest of the checks.

@zakir-code zakir-code merged commit 3556b71 into main Jan 2, 2025
13 checks passed
@zakir-code zakir-code deleted the nulnut/remove-testnet-token branch January 2, 2025 02:32
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