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

chore: migrate bridge balances #760

Merged
merged 1 commit into from
Oct 21, 2024
Merged

chore: migrate bridge balances #760

merged 1 commit into from
Oct 21, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Oct 21, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced cross-chain module account permissions for minting and burning operations.
    • Enhanced upgrade handler with robust migration capabilities for cross-chain module accounts and bridge token balances.
    • Added new method to retrieve module accounts within the AccountKeeper interface.
  • Bug Fixes

    • Adjusted expected account sequences in tests to reflect updated transaction states.
  • Improvements

    • Streamlined initialization process for crosschain module accounts.
    • Expanded token processing conditions in migration methods for better handling of specific tokens.
  • Documentation

    • Added new constants and methods to improve clarity and functionality within the codebase.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces several key changes across multiple files, primarily focusing on the integration of the crosschaintypes package and enhancements to the upgrade process. Notable updates include new import statements, the addition of module account permissions for cross-chain operations, and the introduction of migration functions for handling bridge token balances. The InitGenesis function has been modified to retrieve existing module accounts, and new methods have been added to the AccountKeeper interface. Additionally, adjustments have been made to test cases reflecting changes in expected account states.

Changes

File Change Summary
app/modules.go - Added import for crosschaintypes.
- Updated maccPerms to include crosschaintypes.ModuleName with permissions for minting and burning.
app/upgrades/v8/upgrade.go - Added imports for new packages.
- Introduced migrateCrosschainModuleAccount, migrateBridgeBalance, and migrateAccountBalance functions for handling module account migrations and balance transfers.
- Modified updateMetadata for additional checks.
client/client_test.go - Updated expected account sequence numbers in TestClient_Tx.
- Changed expected length of accounts in TestClient_GetModuleAccounts.
x/crosschain/keeper/genesis.go - Modified InitGenesis to retrieve the existing crosschain module account instead of creating a new one.
x/crosschain/keeper/keeper.go - Changed initialization of callbackFrom in NewKeeper to use BridgeCallSender.
x/crosschain/mock/expected_keepers_mocks.go - Added GetModuleAccount method to MockAccountKeeper interface for retrieving module accounts.
x/crosschain/types/expected_keepers.go - Added GetModuleAccount method to AccountKeeper interface.
x/crosschain/types/key.go - Introduced new constant BridgeCallSender.
x/erc20/migrations/v8/migrate.go - Modified MigrateToken to include conditions for processing specific tokens.
x/erc20/migrations/v8/token.go - Added new IBC denomination trace for "pundix" in both testnet and mainnet maps.

Possibly related PRs

🐇 In the meadow, changes sprout,
New bridges built, no doubt!
With tokens dancing, side by side,
Cross-chain dreams, we now can ride.
Migrations flow, like streams so bright,
A leap for us, into the light! 🌟


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

@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: 4

🧹 Outside diff range and nitpick comments (8)
x/erc20/migrations/v8/migrate.go (1)

24-26: Approved: Improved token processing logic

The changes to the MigrateToken function enhance the token processing logic by:

  1. Moving the baseDenom calculation earlier for consistent application.
  2. Adding special handling for the "PUNDIX" token.
  3. Broadening the criteria for including the "pundix/purse" token.

These modifications appear to address specific token requirements effectively.

Consider adding a comment explaining the special handling for "PUNDIX" and the broadened criteria for "pundix/purse" to improve code clarity:

 baseDenom := strings.ToLower(md.Symbol)
+// Special handling for PUNDIX token and broadened criteria for pundix/purse
 // exclude FX and alias empty, except PUNDIX
 if md.Base == fxtypes.DefaultDenom || (len(md.DenomUnits) == 0 || len(md.DenomUnits[0].Aliases) == 0) && md.Symbol != "PUNDIX" {
     continue
 }
 // ...
 // only add pundix/purse token
 if md.Base == baseDenom || strings.Contains(md.Base, baseDenom) {
     continue
 }

Also applies to: 35-36

x/crosschain/types/expected_keepers.go (1)

85-85: LGTM! Consider adding a comment for clarity.

The addition of the GetModuleAccount method to the AccountKeeper interface is a good enhancement. It provides a way to retrieve module-specific accounts, which is useful for various operations in the Cosmos SDK ecosystem.

Consider adding a brief comment above the method to describe its purpose and any potential usage constraints. For example:

// GetModuleAccount retrieves the module account for the given module name.
// Returns nil if the module account doesn't exist.
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI
x/erc20/migrations/v8/token.go (2)

11-12: LGTM. Consider adding a comment for clarity.

The addition of the "pundix" entry to the testnetIBCDenomTrace map looks good. It follows the existing structure and appears to be correctly implemented.

Consider adding a brief comment explaining why "pundix" uses channel-0, as it differs from other entries in the map. This would improve code readability and maintainability.


26-27: LGTM. Consider adding a comment for consistency.

The addition of the "pundix" entry to the mainnetIBCDenomTrace map is correct and consistent with the testnet implementation.

For consistency with the suggested improvement in the testnet map, consider adding a brief comment explaining the use of channel-0 for "pundix" in the mainnet context as well.

x/crosschain/keeper/genesis.go (1)

20-20: LGTM: Update to use BridgeCallSender

The change to use types.BridgeCallSender for the crosschainBridgeCallFrom address is correct and aligns with changes in other parts of the codebase.

Consider adding a comment to explain the significance of using BridgeCallSender:

// Use BridgeCallSender as the module address for cross-chain bridge calls
crosschainBridgeCallFrom := autytypes.NewModuleAddress(types.BridgeCallSender)
x/crosschain/types/key.go (1)

16-16: Add a descriptive comment for the new constant.

The new constant BridgeCallSender has been added correctly. However, to improve code documentation and maintainability, consider adding a brief comment explaining its purpose and usage.

For example:

// BridgeCallSender is the module name used for bridge call operations
BridgeCallSender = "bridgecall"
app/upgrades/v8/upgrade.go (2)

151-151: Address the pending migration of bridge and IBC token balances

A TODO comment notes that the migration of bridge token and IBC token balances to the crosschain module is pending. This migration is crucial for ensuring all balances are correctly handled during the upgrade.

Do you want assistance in implementing this migration step or opening a GitHub issue to track this task?


167-167: Enhance logging for better traceability

When logging the migration of coins, include additional context such as the transaction hash or a unique identifier. This will aid in troubleshooting if issues arise during the migration process.

Apply this diff to enhance logging:

 ctx.Logger().Info("migrate coin", "address", address.String(), "src-denom", srcBase, "dst-denom", dstBase, "amount", coin.Amount.String())
+// Optionally include more context
+ctx.Logger().Info("migrate coin", "address", address.String(), "src-denom", srcBase, "dst-denom", dstBase, "amount", coin.Amount.String(), "tx-hash", ctx.TxBytes())
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 70924ed and dc64402.

📒 Files selected for processing (10)
  • app/modules.go (2 hunks)
  • app/upgrades/v8/upgrade.go (4 hunks)
  • client/client_test.go (3 hunks)
  • x/crosschain/keeper/genesis.go (1 hunks)
  • x/crosschain/keeper/keeper.go (1 hunks)
  • x/crosschain/mock/expected_keepers_mocks.go (1 hunks)
  • x/crosschain/types/expected_keepers.go (1 hunks)
  • x/crosschain/types/key.go (1 hunks)
  • x/erc20/migrations/v8/migrate.go (1 hunks)
  • x/erc20/migrations/v8/token.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (14)
x/erc20/migrations/v8/migrate.go (1)

24-26: Verify the impact on the overall migration process

The changes to the token processing logic in MigrateToken function seem to align with the PR objectives of migrating bridge balances. However, it's important to ensure that these modifications don't have unintended consequences on the overall migration process.

Please run the following script to check for any potential issues:

This script will help identify any potential areas that might be affected by the changes in the token migration logic.

Also applies to: 35-36

x/erc20/migrations/v8/token.go (1)

Line range hint 1-94: Summary: "pundix" token integration looks good.

The additions of "pundix" entries to both testnetIBCDenomTrace and mainnetIBCDenomTrace maps are correctly implemented and consistent with the existing structure. These changes appear to be part of a larger update involving the "pundix" token, as mentioned in other modified files.

The existing functions getIBCDenomTrace and getExcludeBridgeToken remain unchanged, which is appropriate as they don't require modification to support the new entries.

To ensure the correct integration of the "pundix" token across the codebase, consider running the following verification script:

This script will help identify any inconsistencies or potential issues related to the integration of the "pundix" token across the codebase.

x/crosschain/keeper/genesis.go (2)

Line range hint 1-156: Ensure comprehensive testing for module account changes

The changes in this file, particularly around module account handling, are part of a larger refactoring effort. While the changes themselves are minimal, they could have significant implications for the module's behavior.

Please ensure that comprehensive integration tests are in place to verify:

  1. The correct initialization of module accounts
  2. Proper handling of the BridgeCallSender address
  3. No regression in existing functionality

Consider running the following commands to check for relevant test coverage:

#!/bin/bash
# Description: Check for relevant test coverage

# Test 1: Look for tests related to InitGenesis in crosschain module
rg -A 10 'func.*Test.*InitGenesis' --glob '**/crosschain/**/*_test.go'

# Test 2: Check for tests involving BridgeCallSender
rg -A 5 'BridgeCallSender' --glob '**/crosschain/**/*_test.go'

# Test 3: Look for integration tests that might cover this functionality
rg -A 10 'func.*Test.*Integration' --glob '**/crosschain/**/*_test.go'

18-18: Clarify the intention of GetModuleAccount call

The GetModuleAccount method is called, but its result is not used or checked. Is this intended to ensure the module account exists? If so, consider adding an error check or using a method that explicitly creates the account if it doesn't exist.

✅ Verification successful

Clarify the usage of GetModuleAccount

The GetModuleAccount method is called to retrieve the module account, and subsequent lines handle account creation if it does not exist. This pattern ensures that the module account is properly initialized without requiring an immediate error check on the GetModuleAccount call.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's a create-if-not-exists method for module accounts

# Test: Search for methods in the auth keeper that might create module accounts
rg -A 5 'func.*Module(Account|Address)' --glob '**/*.go'

Length of output: 208


Script:

#!/bin/bash
# Description: Search for all usages of GetModuleAccount and examine error handling
rg 'GetModuleAccount' --glob '**/*.go' -A 5

# Description: Search for functions related to creating or initializing module accounts
rg -e 'CreateModuleAccount' -e 'InitModuleAccount' --glob '**/*.go'

Length of output: 6392

app/modules.go (2)

56-56: LGTM: New import for crosschain types added.

The new import for crosschaintypes is correctly formatted and aligns with the subsequent changes in the file.


95-95: LGTM: Crosschain module permissions added. Verify implications.

The addition of minting and burning permissions for the crosschain module is consistent with other bridge-like modules. However, as this change could significantly impact token economics, please ensure that:

  1. The crosschain module's logic properly safeguards these powerful permissions.
  2. There are appropriate checks and balances in place to prevent misuse.
  3. The change has been thoroughly tested in a staging environment.

To verify the usage and safeguards of these new permissions, please run the following script:

client/client_test.go (2)

192-192: Verify the reason for increased account sequence numbers.

The expected account sequence numbers have been incremented:

  1. For the first validator's account: from 14+i to 15+i
  2. For the Ethereum address: from 17 to 18

These changes suggest an additional transaction or operation is now expected to occur before these checks. Please ensure this aligns with any recent modifications to the transaction processing logic or account initialization process.

To confirm these changes are correct, let's examine the transaction history and account initialization process:

Also applies to: 227-227

✅ Verification successful

Sequence numbers update aligns with new module account addition.
The increase in expected account sequence numbers corresponds to the introduction of the crosschain module account in the recent code changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify transaction history and account initialization

# Check for any changes in transaction processing or account initialization
rg -p "account.*initialization|transaction.*process" --type go

# Look for any recent changes in files related to account or transaction handling
git log -p --since="2 weeks ago" -- "**/account*" "**/transaction*" "**/tx*"

# Check for any new module accounts that might affect the sequence numbers
rg -p "NewModuleAccount|RegisterModuleAccount" --type go

Length of output: 362


443-443: Verify the addition of a new module account.

The expected number of module accounts has increased from 17 to 18. This change is likely related to the integration of the crosschaintypes package and the addition of module account permissions for cross-chain operations, as mentioned in the PR summary.

Please ensure that:

  1. The new module account is properly documented.
  2. The initialization process for this new account is correctly implemented.
  3. Any necessary permissions or configurations for the new module account are set up correctly.

Let's confirm the addition of the new module account:

x/crosschain/mock/expected_keepers_mocks.go (3)

687-693: LGTM: New GetModuleAccount method added correctly

The new GetModuleAccount method has been properly implemented in the MockAccountKeeper struct. It correctly takes a context and module name as parameters and returns a types.ModuleAccountI. The implementation uses the mock controller as expected.


695-699: LGTM: GetModuleAccount recorder method added correctly

The GetModuleAccount method has been properly implemented in the MockAccountKeeperMockRecorder struct. It correctly takes a context and module name as parameters and returns a *gomock.Call. The implementation uses the mock controller to record the method call as expected.


687-699: Summary: Successful addition of GetModuleAccount functionality

The changes to this file successfully implement the GetModuleAccount method in both the MockAccountKeeper and its corresponding recorder. This addition aligns with the updates mentioned in the AI-generated summary and enhances the mock implementation to support module account retrieval.

These changes likely reflect new functionality in the actual AccountKeeper interface, allowing for better testing and mocking of module account-related operations in the crosschain module.

app/upgrades/v8/upgrade.go (3)

36-38: Verify migration of the crosschain module account

The migrateCrosschainModuleAccount function is now called during the upgrade process. Please ensure that this migration is thoroughly tested to confirm that the crosschain module account is correctly converted with the appropriate permissions.


56-58: Ensure accurate migration of bridge balances

The addition of migrateBridgeBalance handles the migration of bridge token balances. Verify that all relevant balances are correctly migrated and that edge cases, such as unusual denominations or aliases, are appropriately handled.


187-197: Ensure consistent metadata updates for denomination display

In the updateMetadata function, when updating the base denomination and display values, ensure that these changes do not conflict with existing IBC prefixes or module names. This prevents potential issues with denomination recognition elsewhere in the system.

x/crosschain/keeper/keeper.go Show resolved Hide resolved
app/upgrades/v8/upgrade.go Show resolved Hide resolved
app/upgrades/v8/upgrade.go Show resolved Hide resolved
app/upgrades/v8/upgrade.go Show resolved Hide resolved
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