Skip to content

⬆️ Update mint module to align on latest cosmos-sdk v0.50.6 #645

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

Merged
merged 6 commits into from
May 22, 2024

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented May 21, 2024

This PR includes the necessary updates to the Mint module to align it with the Cosmos-SDK v0.50.6. ⚙️

Key changes include:

  • Updated the Keeper struct and its methods to match the new Cosmos-SDK version. 🔧
  • Kept our custom mint implementation intact while ensuring compatibility with the new SDK version. 🛡️
  • Updated the necessary dependencies in go.mod. 📦

Summary by CodeRabbit

  • Refactor

    • Improved code consistency and readability by renaming variables and refining method signatures across the mint module.
    • Updated import paths and reorganized code structure for better maintainability.
  • New Features

    • Introduced NewAppModule function with updated parameters and logic.
    • Added methods to implement depinject.OnePerModuleType and appmodule.AppModule interfaces.
  • Bug Fixes

    • Enhanced validation logic in ValidateGenesis and ValidateMinter functions to ensure more accurate genesis state validation.
  • Tests

    • Updated test functions to align with new method signatures and parameter changes for consistent testing practices.

Copy link
Contributor

coderabbitai bot commented May 21, 2024

Warning

Rate Limit Exceeded

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

Walkthrough

The recent updates to the mint module in the Cosmos SDK project involve renaming variables for consistency, updating import paths, refining method signatures, and reorganizing imports. These changes enhance code readability and maintainability. Additionally, the validation logic has been refactored, and new methods and constants have been introduced for improved functionality and modularization.

Changes

File Change Summary
.../keeper/genesis.go Renamed receiver variable from keeper to k in InitGenesis and ExportGenesis methods.
.../keeper/genesis_test.go Updated parameters in TestImportExportGenesis function for genesisState.Minter.
.../keeper/keeper.go Updated import paths, adjusted struct fields, refined method signatures, and renamed method receivers.
.../keeper/keeper_test.go Modified SetupTest function to initialize and pass a storeService to keeper.NewKeeper.
.../keeper/msg_server.go Renamed function parameter to k, updated function signature, and modified UpdateParams function.
.../module.go Reorganized imports, added constants, modified function signatures, and updated module initialization logic.
.../module_test.go Reordered import statements for testutil and types from different packages.
.../testutil/app_config.go Updated AppConfig to include configurations for various modules.
.../types/genesis.go Refactored ValidateGenesis to call ValidateMinter instead of data.Minter.Validate().
.../types/keys.go Updated MinterKey and ParamsKey to use collections.NewPrefix, removed unused constants.
.../types/minter.go Refactored Validate method in Minter struct into standalone ValidateMinter function.

🐇✨ In the code where logic flows,
Changes bloom like springtime shows.
Variables renamed with care,
Imports shuffled here and there.
Methods polished, functions bright,
Genesis state now set just right.
Amidst the lines, improvements grow,
A rabbit's joy in code does show. 🌸


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@bdeneux bdeneux linked an issue May 21, 2024 that may be closed by this pull request
@bdeneux bdeneux added the security audit Categorizes an issue or PR as relevant to Security Audit label May 21, 2024
@bdeneux bdeneux changed the title Refactor/update mint ⬆️ mint: align module to latest cosmos-idk v0.50.6 May 21, 2024
@bdeneux bdeneux changed the title ⬆️ mint: align module to latest cosmos-idk v0.50.6 ⬆️ mint: align module to latest cosmos-sdk v0.50.6 May 21, 2024
@bdeneux bdeneux changed the title ⬆️ mint: align module to latest cosmos-sdk v0.50.6 ⬆️ Update mint module to align on latest cosmos-sdk v0.50.6 May 21, 2024
@bdeneux bdeneux marked this pull request as ready for review May 22, 2024 07:42
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks 🙏

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

Great! Thanks 😌

@bdeneux bdeneux force-pushed the refactor/update-mint branch from f4b0841 to afab832 Compare May 22, 2024 13:38
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: 2

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 44f1152 and afab832.
Files ignored due to path filters (5)
  • docs/command/axoned_query.md is excluded by !docs/command/**/*.md
  • docs/command/axoned_query_mint.md is excluded by !docs/command/**/*.md
  • docs/command/axoned_query_mint_annual-provisions.md is excluded by !docs/command/**/*.md
  • docs/command/axoned_query_mint_inflation.md is excluded by !docs/command/**/*.md
  • docs/command/axoned_query_mint_params.md is excluded by !docs/command/**/*.md
Files selected for processing (11)
  • x/mint/keeper/genesis.go (1 hunks)
  • x/mint/keeper/genesis_test.go (1 hunks)
  • x/mint/keeper/keeper.go (5 hunks)
  • x/mint/keeper/keeper_test.go (2 hunks)
  • x/mint/keeper/msg_server.go (1 hunks)
  • x/mint/module.go (6 hunks)
  • x/mint/module_test.go (1 hunks)
  • x/mint/testutil/app_config.go (1 hunks)
  • x/mint/types/genesis.go (1 hunks)
  • x/mint/types/keys.go (2 hunks)
  • x/mint/types/minter.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • x/mint/keeper/genesis.go
  • x/mint/testutil/app_config.go
  • x/mint/types/keys.go
Additional comments not posted (16)
x/mint/module_test.go (1)

11-13: Updated import paths to reflect new module structure.

x/mint/keeper/msg_server.go (1)

15-24: Updated msgServer struct and NewMsgServerImpl function to use new receiver variable name for consistency.

x/mint/keeper/genesis_test.go (1)

73-73: Updated parameters for NewMinter in test to reflect changes in initialization logic.

Verification successful

The NewMinter function is defined in x/mint/types/minter.go with the following signature:

func NewMinter(inflation, annualProvisions math.LegacyDec) Minter {

This matches the updated call in the test file x/mint/keeper/genesis_test.go:

genesisState.Minter = types.NewMinter(math.LegacyNewDecWithPrec(20, 2), math.LegacyNewDec(1))

The parameters math.LegacyNewDecWithPrec(20, 2) and math.LegacyNewDec(1) correspond to the inflation and annualProvisions parameters of the NewMinter function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `NewMinter` function definition matches the updated call in tests.

# Test: Search for the `NewMinter` function definition.
ast-grep --lang go --pattern $'func NewMinter($_, $_) { $$$ }'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify the `NewMinter` function definition matches the updated call in tests.

# Test: Search for the `NewMinter` function definition with a more flexible pattern.
ast-grep --lang go --pattern 'func NewMinter($$$) { $$$ }'

Length of output: 60



Script:

#!/bin/bash
# Description: Locate the `NewMinter` function definition by searching for the function name directly.

# Test: Search for the `NewMinter` function name in the codebase.
rg 'NewMinter' --type go

Length of output: 1732

x/mint/keeper/keeper_test.go (1)

56-56: Updated NewKeeper function call to reflect the removal of the authority parameter, simplifying the function signature.

x/mint/keeper/keeper.go (6)

8-8: Update import path to align with new SDK version.


20-21: The authority field has been removed from the Keeper struct, aligning with the PR description and summary.

Also applies to: 26-29


47-47: Good use of panic to handle the critical error scenario where the module account is not set.


57-57: The authority field is correctly initialized in the Keeper struct.


71-72: Method signatures have been updated to use the new receiver variable name k. This change improves consistency across the module.

Also applies to: 76-76, 83-84, 89-90, 95-96, 101-107, 112-113


38-38: Ensure that the storeService parameter type change is reflected wherever NewKeeper is called.

Verification successful

Ensure that the storeService parameter type change is reflected wherever NewKeeper is called.

The extracted lines around each NewKeeper call show that the storeService parameter type change has been correctly handled in all instances.

  • x/mint/module.go
  • x/mint/keeper/keeper_test.go
  • x/mint/keeper/genesis_test.go
  • x/mint/keeper/grpc_query_test.go
  • x/logic/keeper/msg_server_test.go
  • x/logic/keeper/grpc_query_params_test.go
  • x/logic/keeper/grpc_query_ask_test.go
  • x/logic/keeper/features_test.go
  • app/app.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `storeService` parameter type change in `NewKeeper` is correctly handled in all calls.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go $'NewKeeper'

Length of output: 1985



Script:

#!/bin/bash
# Description: Extract lines around each `NewKeeper` call to verify the parameter types.

# Extract 5 lines before and after each `NewKeeper` call to check the parameters.
rg --type go -A 5 -B 5 $'NewKeeper('

Length of output: 108



Script:

#!/bin/bash
# Description: Extract lines around each `NewKeeper` call to verify the parameter types.

# Extract 5 lines before and after each `NewKeeper` call to check the parameters.
rg --type go -A 5 -B 5 'NewKeeper('

Length of output: 108



Script:

#!/bin/bash
# Description: Extract lines around each `NewKeeper` call to verify the parameter types.

# Extract 5 lines before and after each `NewKeeper` call to check the parameters.
rg --type go -A 5 -B 5 'NewKeeper\('

Length of output: 16443

x/mint/module.go (6)

8-8: Updated import paths to align with new SDK version and added new dependencies.

Also applies to: 10-13, 21-22


30-30: Introduction of a new constant ConsensusVersion to specify the module's consensus version.


58-59: Updated method signatures to reflect changes in parameter names and types.

Also applies to: 79-79


137-137: The new method ConsensusVersion correctly returns the newly defined constant.


170-221: The new dependency injection setup using ModuleInputs and ModuleOutputs is well-structured and aligns with modern Go practices.


93-99: Ensure that the new AppModule constructor is used correctly throughout the codebase.

Verification successful

The rg command output shows multiple occurrences of NewAppModule in various files. To ensure the new AppModule constructor is used correctly, we need to verify the relevant occurrences in the x/mint/module.go and app/app.go files.


The new AppModule constructor is correctly used in the x/mint/module.go file and the app/app.go file. The constructor is invoked with the appropriate arguments, ensuring that the new implementation is correctly integrated.

  • In x/mint/module.go, the NewAppModule function is defined and used correctly.
  • In app/app.go, the NewAppModule is used with the correct parameters.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new `AppModule` constructor is correctly used in all relevant parts of the codebase.

# Test: Search for the function usage. Expect: Only occurrences of the new constructor.
rg --type go $'NewAppModule'

Length of output: 3092



Script:

#!/bin/bash
# Description: Verify the correct usage of the new `AppModule` constructor in the relevant files.

# Extract the relevant lines from x/mint/module.go
rg --type go --context 5 'NewAppModule' x/mint/module.go

# Extract the relevant lines from app/app.go
rg --type go --context 5 'NewAppModule' app/app.go

Length of output: 4315

@bdeneux bdeneux merged commit 8f3cdb8 into main May 22, 2024
19 checks passed
@bdeneux bdeneux deleted the refactor/update-mint branch May 22, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security audit Categorizes an issue or PR as relevant to Security Audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🛡️ Barberry issue unresolved due to faulty upstream
3 participants