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

bump up mods.irisnet.org/modules/mt to cosmos-sdk v0.50.10 #447

Merged
merged 11 commits into from
Nov 7, 2024

Conversation

wangjiulian
Copy link
Collaborator

@wangjiulian wangjiulian commented Nov 7, 2024

Copy link

coderabbitai bot commented Nov 7, 2024

Warning

Rate limit exceeded

@wangjiulian has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 37 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

Reviewing files that changed from the base of the PR and between cd2de03 and d28a2c1.

Walkthrough

The changes in this pull request involve significant updates to the Go modules and dependencies across various files. The Go version is upgraded from 1.19 to 1.21, and a new toolchain version 1.23.1 is introduced. Multiple dependencies are updated to their latest versions, including core libraries and indirect dependencies. Additionally, there are modifications to import paths, particularly shifting from github.com/cosmos/cosmos-sdk to cosmossdk.io, and some methods are streamlined by removing unnecessary parameters. Overall, the updates enhance compatibility and maintain the existing functionality of the codebase.

Changes

File Change Summary
e2e/go.mod Updated Go version to 1.21, added toolchain 1.23.1, and upgraded multiple dependencies.
modules/mt/depinject.go Changed import for store package from github.com/cosmos/cosmos-sdk/store/types to cosmossdk.io/store/types.
modules/mt/go.mod Updated Go version to 1.21, added toolchain 1.23.1, and upgraded multiple dependencies.
modules/mt/handler.go Changed return type of NewHandler from sdk.Handler to func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error).
modules/mt/keeper/balance.go Updated import for storetypes from github.com/cosmos/cosmos-sdk/store/types to cosmossdk.io/store/types and modified getBalances method.
modules/mt/keeper/denom.go Updated import for storetypes from github.com/cosmos/cosmos-sdk/store/types to cosmossdk.io/store/types.
modules/mt/keeper/grpc_query.go Changed import path for prefix from github.com/cosmos/cosmos-sdk/store/prefix to cosmossdk.io/store/prefix.
modules/mt/keeper/keeper.go Updated imports for logging and store types from github.com/cometbft/cometbft/libs/log and github.com/cosmos/cosmos-sdk/store/types to cosmossdk.io/log and cosmossdk.io/store/types.
modules/mt/keeper/mt.go Updated import for storetypes from github.com/cosmos/cosmos-sdk/store/types to cosmossdk.io/store/types and modified GetMTs method.
modules/mt/module.go Removed BeginBlock and EndBlock methods, updated RegisterStoreDecoder parameter type from sdk.StoreDecoderRegistry to simtypes.StoreDecoderRegistry.
modules/mt/simulation/genesis.go Removed simState.Cdc parameter from GetOrGenerate method calls in RandomizedGenState.
modules/mt/simulation/operations.go Removed cdc parameter from WeightedOperations and simulation function signatures, streamlined return statements.

Poem

🐇 In the meadow where code does bloom,
The rabbits hop, dispelling gloom.
With versions fresh and paths anew,
Dependencies dance in a vibrant hue.
A leap of joy, a code so bright,
In every change, we find delight! 🌼


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.

@wangjiulian wangjiulian changed the title Update MT Module bump up mods.irisnet.org/modules/mt to cosmos-sdk v0.50.10 Nov 7, 2024
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: 3

🧹 Outside diff range and nitpick comments (4)
modules/mt/simulation/genesis.go (1)

Line range hint 1-132: Consider Go 1.21 improvements and optimizations.

Since this PR includes an upgrade to Go 1.21, consider these potential improvements:

  1. The genMTs, genCollections, and genOwners functions could benefit from using slices package introduced in Go 1.21 for cleaner slice operations
  2. Consider using rand.Float64 with math.Round for more uniform distribution in balance calculations

Example optimization for balance distribution:

 func genDenomBalances(r *rand.Rand, denomId string, mts []mt.MT, accounts []simtypes.Account) []mt.DenomBalance {
     denomBalances := make([]mt.DenomBalance, len(accounts))
     for i := 0; i < len(accounts); i++ {
         balances := make([]mt.Balance, len(mts))
 
         // amount evenly distributed and sum-up not exceeding the total supply
         for j := 0; j < len(mts); j++ {
-            balances[j] = mt.Balance{
-                MtId:   mts[j].Id,
-                Amount: mts[j].Supply / uint64(len(accounts)),
-            }
+            // More random distribution while maintaining total supply
+            ratio := math.Round(r.Float64() * 100) / 100
+            amount := uint64(float64(mts[j].Supply) * ratio / float64(len(accounts)))
+            balances[j] = mt.Balance{
+                MtId:   mts[j].Id,
+                Amount: amount,
+            }
         }
e2e/go.mod (1)

Line range hint 214-241: Consider tracking the TODO comments for replace directives.

The replace directives contain important security fixes, but there are TODO comments that should be tracked:

  • cosmos-sdk#13134: Remove deprecated jwt-go
  • cosmos-sdk#10409: Remove gin-gonic/gin fix after upstream fix

Would you like me to create GitHub issues to track these TODOs?

modules/mt/simulation/operations.go (1)

Line range hint 513-513: Fix unsafe integer conversion in SimulateMsgBurnMT

The comment indicates an unsafe conversion from int to uint64. This could lead to potential issues if the random value is negative.

Apply this fix:

-amt = uint64(simtypes.RandIntBetween(r, 1, int(amt))) // unsafe conversion
+amt = uint64(simtypes.RandIntBetween(r, 1, int(math.MaxInt64)))
+if amt > k.GetBalance(ctx, denomID, mtr.Id, sender.Address) {
+    amt = k.GetBalance(ctx, denomID, mtr.Id, sender.Address)
+}
modules/mt/go.mod (1)

Line range hint 162-164: Address the Deprecated jwt-go Dependency

The package github.com/dgrijalva/jwt-go is deprecated and has been replaced with github.com/golang-jwt/jwt/v4 v4.4.2. There's a TODO to remove the deprecated dependency: cosmos-sdk issue #13134. Consider addressing this to enhance security and reduce reliance on deprecated libraries.

Would you like assistance in updating the codebase to fully migrate away from the deprecated dependency?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ef0885f and cd2de03.

⛔ Files ignored due to path filters (2)
  • e2e/go.sum is excluded by !**/*.sum
  • modules/mt/go.sum is excluded by !**/*.sum
📒 Files selected for processing (12)
  • e2e/go.mod (6 hunks)
  • modules/mt/depinject.go (1 hunks)
  • modules/mt/go.mod (1 hunks)
  • modules/mt/handler.go (1 hunks)
  • modules/mt/keeper/balance.go (2 hunks)
  • modules/mt/keeper/denom.go (2 hunks)
  • modules/mt/keeper/grpc_query.go (1 hunks)
  • modules/mt/keeper/keeper.go (1 hunks)
  • modules/mt/keeper/mt.go (2 hunks)
  • modules/mt/module.go (1 hunks)
  • modules/mt/simulation/genesis.go (1 hunks)
  • modules/mt/simulation/operations.go (7 hunks)
✅ Files skipped from review due to trivial changes (3)
  • modules/mt/depinject.go
  • modules/mt/keeper/grpc_query.go
  • modules/mt/keeper/keeper.go
🔇 Additional comments (16)
modules/mt/handler.go (1)

Line range hint 13-45: LGTM! Improved type safety in handler signature.

The updated NewHandler function now returns a more explicit function signature instead of the generic sdk.Handler. This change:

  • Improves type safety and code clarity
  • Maintains proper error handling and result wrapping
  • Follows current Cosmos SDK best practices for message handling
modules/mt/keeper/denom.go (2)

8-8: LGTM: Import update aligns with SDK namespace migration

The change from cosmos-sdk to cosmossdk.io namespace is consistent with the module's modernization efforts.


55-55: LGTM: Iterator implementation properly updated

The switch to storetypes.KVStorePrefixIterator maintains the same functionality while aligning with the new import structure. The iterator is properly managed with defer Close().

modules/mt/keeper/mt.go (1)

8-8: LGTM: Import path update aligns with Cosmos SDK migration

The change from github.com/cosmos/cosmos-sdk to cosmossdk.io for store types follows the recommended migration path for Cosmos SDK modules.

modules/mt/keeper/balance.go (3)

8-8: LGTM: Import update aligns with SDK modularization

The update to use storetypes from cosmossdk.io/store/types follows the new SDK convention and is part of the broader dependency updates.


66-66: LGTM: Store iterator update maintains functionality

The update to storetypes.KVStorePrefixIterator is a direct consequence of the SDK modularization and maintains the same functionality. The iterator is properly managed with defer it.Close().


66-66: Verify consistent store types usage across the module

Let's ensure that all store iterator usages in the MT module have been updated to use the new storetypes package.

✅ Verification successful

Let me verify the actual implementation details in those files to ensure complete consistency.


Store iterator usage is consistent across the module

All instances of KVStorePrefixIterator in the MT module are using the new storetypes package consistently. The verification shows uniform implementation across mt.go, denom.go, and balance.go, with no remaining usage of the old sdk.KVStorePrefixIterator pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of the old store iterator pattern
# across the MT module to ensure consistent updates.

echo "Checking for old store iterator usage patterns..."
rg -l "sdk\.KVStorePrefixIterator" "modules/mt/"

echo "Verifying new store types usage..."
rg -l "storetypes\.KVStorePrefixIterator" "modules/mt/"

Length of output: 372


Script:

#!/bin/bash
# Check the actual implementation of KVStorePrefixIterator in these files
echo "Checking mt.go implementation:"
rg "KVStorePrefixIterator" "modules/mt/keeper/mt.go" -B 2 -A 2

echo -e "\nChecking denom.go implementation:"
rg "KVStorePrefixIterator" "modules/mt/keeper/denom.go" -B 2 -A 2

echo -e "\nChecking balance.go implementation:"
rg "KVStorePrefixIterator" "modules/mt/keeper/balance.go" -B 2 -A 2

Length of output: 934

modules/mt/module.go (1)

161-163: LGTM: Parameter type update for RegisterStoreDecoder

The change from sdk.StoreDecoderRegistry to simtypes.StoreDecoderRegistry is correct and aligns with the module simulation framework's type system. This change maintains the same functionality while using a more specific and appropriate type.

e2e/go.mod (2)

Line range hint 32-212: LGTM! Security and stability improvements in indirect dependencies.

The updates to indirect dependencies include important security and stability improvements, particularly in:

  • Cloud platform dependencies
  • Monitoring tools (Prometheus)
  • Cryptographic libraries

8-16: Verify compatibility between major version upgrades.

The updates include significant version jumps in core dependencies:

  • cosmossdk.io/api → v0.7.5
  • cosmossdk.io/core → v0.11.1
  • github.com/cometbft/cometbft → v0.38.12
  • github.com/cosmos/cosmos-sdk → v0.50.10

Let's verify compatibility between these versions:

modules/mt/simulation/operations.go (2)

39-39: LGTM: Parameter removal is consistent with module updates

The removal of the cdc parameter from GetOrGenerate calls maintains the core functionality while aligning with the broader changes in the module.

Also applies to: 46-46, 53-53, 60-60, 67-67, 73-73


173-173: LGTM: Return statement simplification

The removal of redundant nil arguments from NewOperationMsg calls improves code clarity while maintaining functionality.

Also applies to: 268-268, 356-356, 461-461, 545-545, 635-635

modules/mt/go.mod (4)

3-5: Ensure Build and CI Environments Support Updated Go Versions

The Go version has been updated to 1.21, and the toolchain is now set to go1.23.1. Please verify that all development, build, and CI/CD environments are configured to use these versions to prevent any compatibility issues.


8-24: Verify Compatibility with Updated Dependencies

Several dependencies have been updated to newer versions. Ensure that these updates do not introduce any breaking changes or deprecated APIs that could affect the module's functionality.


Line range hint 165-167: Review Replacement of gin-gonic/gin Dependency

The replacement of github.com/gin-gonic/gin with version v1.9.0 aims to fix the GHSA-h395-qcrw-5vmq vulnerability. Verify if the latest version of gin-gonic/gin has resolved this issue, and consider updating to it directly to benefit from the latest features and security patches.


Line range hint 167-169: Re-evaluate Downgrade of goleveldb Dependency

The github.com/syndtr/goleveldb dependency has been downgraded to avoid bugs causing simulations to fail. Check if these issues have been resolved in newer versions so you can upgrade and take advantage of improvements and fixes.

modules/mt/keeper/mt.go Show resolved Hide resolved
modules/mt/simulation/genesis.go Show resolved Hide resolved
e2e/go.mod Outdated 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.

3 participants