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

feat(x/mint)!: Replace InflationCalculationFn with MintFn + simple epoch minting #20363

Merged
merged 51 commits into from
Jun 11, 2024

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented May 13, 2024

Description

MintFn is a breaking replacement for InflationCalculationFn (only for non-depinject users, depinject will continue to work with no changes).

Until now, developers could only modify minting by passing an inflation calculation function that could take in some x/mint parameters and the bonded ratio from x/staking. The rest of the minting process was being handled by the module, so minting to custom accounts was not possible without having to create a separate module for this.

type InflationCalculationFn func(ctx context.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec

Now MintFn...

type MintFn func(ctx context.Context, env appmodule.Environment, minter *Minter, epochId string, epochNumber int64) error

Minter now contains arbitrary data

Minter now has a data field which can contain []byte. This can be used by developers to store data related to the minting process. For example, the last time tokens were minted, or any other information. The SDK does not make any assumptions on it and does not run any checks on it, so it's the developers' responsibility to ensure deterministic behavior when using this field.

Changes in NewAppModule (breaking if passing in a custom InflationCalculationFn)

NewAppModule now receives a MintFn instead of a InflationCalculationFn. If no custom function was being passed in, no breaks occur as it can continue to be nil. If an InflationCalculationFn was being passed, developers can use mintKeeper.DefaultMintFn(theCustomInflationFn) to keep the current minting behavior

For depinject users this is abstracted away, but for legacy users they'll have to change this in their app.go.

Before & after

Before only the "Calculate Inflation" step was user/dev defined.

flowchart
    subgraph x/mint
        B[BeginBlock] --> C[Get data from x/staking]
        C --> D[Calculate Inflation<br/><i>user defined</i>]
        D --> E[Mint tokens]
    end

    style D fill:#9f6,stroke:#333,stroke-width:2px
Loading

Now the entire MintFn is user defined, so the user can make it work like it used to work:

flowchart LR
    A[BeforeEpochStart] --> B[MintFn]

    subgraph B["MintFn (user defined)"]
        direction LR
        C[Get x/staking info] --> D[Calculate Inflation]
        D --> E[Mint Tokens]
    end
Loading

Or it can get creative and do other stuff:

flowchart LR
    A[BeforeEpochStart] --> B[MintFn]

    subgraph B["MintFn (user defined)"]
        direction LR
        C[Mint tokens to team] --> D[Mint tokens to Community Pool]
        D --> E[Mint Tokens to Distribute]
    end
Loading

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced flexible minting logic with MintFn, allowing users to define custom minting functions.
    • Added support for both epoch-based and block-based minting.
    • Introduced a max supply genesis parameter for enhanced control over token supply.
  • Bug Fixes

    • Improved error handling and assertion methods in the minting module's test suite.
  • Tests

    • Added comprehensive tests for new minting functionalities, including TestDefaultMintFn, TestBeginBlocker, and TestMigrator.
    • Updated integration tests to reflect changes in minting logic and configurations.
  • Refactor

    • Deprecated InflationCalculationFn in favor of MintFn for better flexibility.
    • Simplified parameter validation functions for enhanced type safety and clarity.

Copy link
Contributor

coderabbitai bot commented May 13, 2024

Walkthrough

Walkthrough

The changes introduce a new flexible minting logic in the Cosmos SDK's x/mint module, allowing users to define custom minting functions (MintFn). This update also includes deprecating the old InflationCalculationFn, adding a new max supply parameter, and enhancing test coverage. Additionally, it updates various validation functions to improve type safety and simplifies error handling in tests.

Changes

File Path Change Summary
x/mint/CHANGELOG.md, x/mint/README.md Introduced MintFn for custom minting logic, added max supply parameter, deprecated InflationCalculationFn.
x/mint/keeper/keeper.go Added DefaultMintFn and imported telemetry package.
x/mint/keeper/keeper_test.go Renamed IntegrationTestSuite to KeeperTestSuite, updated error handling, added new test functions.
simapp/app.go Changed EpochsKeeper type from epochskeeper.Keeper to *epochskeeper.Keeper.
tests/e2e/bank/grpc.go Updated test data values in QuerySupplyOfResponse structs.
tests/e2e/distribution/grpc_query_suite.go Updated values for rewards and commission in test functions.
x/group/go.mod Added new indirect dependency on cosmossdk.io/x/epochs.
x/mint/types/minter_test.go Added TestValidateMinter to validate Minter struct with different values.
x/mint/types/params.go Refactored validation functions for better type safety and clarity.
x/mint/module_test.go Added integration tests for the mint module.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AppModule
    participant Keeper
    participant MintFn

    User->>AppModule: Define custom MintFn
    AppModule->>Keeper: Initialize with MintFn
    Keeper->>MintFn: Invoke MintFn at epoch start
    MintFn->>Keeper: Mint tokens based on custom logic
    Keeper->>AppModule: Update state with minted tokens
    AppModule->>User: Minting process complete
Loading
sequenceDiagram
    participant User
    participant AppModule
    participant Keeper
    participant DefaultMintFn

    User->>AppModule: Use default MintFn
    AppModule->>Keeper: Initialize with DefaultMintFn
    Keeper->>DefaultMintFn: Invoke DefaultMintFn at epoch start
    DefaultMintFn->>Keeper: Mint tokens based on default logic
    Keeper->>AppModule: Update state with minted tokens
    AppModule->>User: Minting process complete
Loading

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.

x/mint/keeper/abci.go Dismissed Show dismissed Hide dismissed
x/mint/module.go Dismissed Show dismissed Hide dismissed
api/cosmos/mint/v1beta1/mint.pulsar.go Fixed Show fixed Hide fixed
api/cosmos/mint/v1beta1/mint.pulsar.go Fixed Show fixed Hide fixed
api/cosmos/mint/v1beta1/mint.pulsar.go Fixed Show fixed Hide fixed
x/mint/types/mint.pb.go Fixed Show fixed Hide fixed
x/mint/types/mint.pb.go Fixed Show fixed Hide fixed
@facundomedica facundomedica changed the title feat(x/mint)!: Replace InflationCalculationFn with MintFn feat(x/mint)!: Replace InflationCalculationFn with MintFn + simple epoch minting May 23, 2024
@facundomedica facundomedica marked this pull request as ready for review May 23, 2024 16:58
@facundomedica facundomedica requested a review from a team as a code owner May 23, 2024 16:58

This comment has been minimized.

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

Outside diff range and nitpick comments (1)
x/epochs/keeper/keeper_test.go (1)

Line range hint 52-70: Update to Setup function to return a pointer and initialize the genesis state is well-implemented. Consider adding a test to verify the correct initialization of the genesis state.

Would you like me to help by adding a test case for genesis state initialization?

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between a1ae4c3 and faa40de.
Files ignored due to path filters (7)
  • simapp/go.mod is excluded by !**/*.mod
  • tests/go.mod is excluded by !**/*.mod
  • x/group/go.mod is excluded by !**/*.mod
  • x/group/go.sum is excluded by !**/*.sum
  • x/mint/go.mod is excluded by !**/*.mod
  • x/mint/go.sum is excluded by !**/*.sum
  • x/mint/types/mint.pb.go is excluded by !**/*.pb.go
Files selected for processing (22)
  • api/cosmos/mint/v1beta1/mint.pulsar.go (17 hunks)
  • simapp/app.go (1 hunks)
  • simapp/app_di.go (3 hunks)
  • simapp/mint_fn.go (1 hunks)
  • tests/e2e/bank/grpc.go (4 hunks)
  • tests/e2e/distribution/grpc_query_suite.go (3 hunks)
  • x/epochs/depinject.go (2 hunks)
  • x/epochs/keeper/epoch_test.go (1 hunks)
  • x/epochs/keeper/genesis_test.go (1 hunks)
  • x/epochs/keeper/grpc_query.go (1 hunks)
  • x/epochs/keeper/grpc_query_test.go (1 hunks)
  • x/epochs/keeper/keeper.go (2 hunks)
  • x/epochs/keeper/keeper_test.go (3 hunks)
  • x/epochs/module.go (1 hunks)
  • x/epochs/types/genesis.go (1 hunks)
  • x/mint/depinject.go (4 hunks)
  • x/mint/epoch_hooks.go (1 hunks)
  • x/mint/keeper/abci.go (2 hunks)
  • x/mint/keeper/keeper.go (2 hunks)
  • x/mint/module.go (2 hunks)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto (1 hunks)
  • x/mint/types/genesis.go (1 hunks)
Files not summarized due to errors (1)
  • api/cosmos/mint/v1beta1/mint.pulsar.go: Error: Message exceeds token limit
Additional Context Used
GitHub Check Runs (1)
CodeQL success (7)

api/cosmos/mint/v1beta1/mint.pulsar.go: [warning] 36-42: Iteration over map
Iteration over map may be a possible source of non-determinism


api/cosmos/mint/v1beta1/mint.pulsar.go: [warning] 441-443: Iteration over map
Iteration over map may be a possible source of non-determinism


api/cosmos/mint/v1beta1/mint.pulsar.go: [warning] 509-515: Iteration over map
Iteration over map may be a possible source of non-determinism


x/mint/keeper/abci.go: [warning] 28-28: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call


x/mint/module.go: [warning] 161-161: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call

Path-based Instructions (21)
x/epochs/keeper/grpc_query_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"

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

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

x/mint/epoch_hooks.go (1)

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

x/epochs/keeper/keeper.go (1)

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

x/mint/types/genesis.go (1)

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

x/epochs/keeper/grpc_query.go (1)

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

x/epochs/depinject.go (1)

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

x/epochs/types/genesis.go (1)

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

x/mint/depinject.go (1)

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

x/epochs/keeper/keeper_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"

x/epochs/keeper/genesis_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"

x/epochs/keeper/epoch_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"

x/epochs/module.go (1)

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

simapp/mint_fn.go (1)

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

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

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

x/mint/module.go (1)

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

tests/e2e/bank/grpc.go (2)

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


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

tests/e2e/distribution/grpc_query_suite.go (2)

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


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

simapp/app_di.go (1)

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

simapp/app.go (1)

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

api/cosmos/mint/v1beta1/mint.pulsar.go (1)

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

Learnings (1)
x/epochs/keeper/genesis_test.go (1)
User: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
Additional comments not posted (24)
x/mint/keeper/abci.go (1)

28-28: Ensure that the Set method in Minter handles all possible error scenarios to prevent panics.

x/mint/epoch_hooks.go (1)

16-29: Ensure that the mintFn used in BeforeEpochStart is robust against all potential errors, especially since it interacts with external state.

x/epochs/keeper/keeper.go (1)

Line range hint 22-35: Ensure that the panic in NewKeeper is handled or logged appropriately to aid in debugging.

x/mint/types/genesis.go (1)

10-10: The new MintFn type provides the necessary flexibility for custom minting operations as described in the PR. Ensure it is well-documented.

x/epochs/keeper/grpc_query.go (1)

18-18: The changes to the Querier struct and the NewQuerier function are correct and improve the handling of the keeper instance.

Also applies to: 22-22

x/epochs/depinject.go (1)

42-42: Change from value to pointer type for EpochKeeper looks good. Ensure all usages correctly handle the pointer semantics.

Verification successful

The usages of EpochKeeper correctly handle pointer semantics.

  • ProvideModule assigns EpochKeeper the result of keeper.NewKeeper, which returns a pointer.
  • InvokeSetHooks accepts EpochKeeper as a pointer argument.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all usages of `EpochKeeper` handle pointer semantics.

# Test: Search for usages of `EpochKeeper`. Expect: Proper handling of pointers.
rg --type go 'EpochKeeper' --context 5

Length of output: 851

x/epochs/types/genesis.go (1)

20-20: Addition of the "minute" epoch aligns with the PR's objectives. Ensure it is integrated correctly in the system.

Verification successful

The "minute" epoch is correctly integrated into the system, as evidenced by its usage in multiple relevant files.

  • x/tx/signing/textual/duration.go: Formatting of durations includes "minute".
  • x/epochs/types/genesis.go: Added to the genesis configuration.
  • x/epochs/keeper/epoch_test.go: Included in the epoch tests.
  • simapp/mint_fn.go: Used in the minting function.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of the "minute" epoch.

# Test: Search for usages of the "minute" epoch. Expect: Correct integration.
rg --type go '"minute"' --context 5

Length of output: 3333

x/mint/depinject.go (2)

9-9: Addition of epochstypes import is necessary for the new integration with the epochs module.


46-46: Integration of EpochHooks and handling of MintFn in ProvideModule are well-implemented. Verify the integration and fallback mechanisms.

Also applies to: 76-76, 79-79

Verification successful

The integration of EpochHooks and MintFn is well-implemented across the codebase. The fallback mechanism for MintFn is correctly handled.

  • MintFn is used in x/mint/module.go, x/mint/depinject.go, x/mint/keeper/keeper.go, and simapp/mint_fn.go.
  • EpochHooks is used in x/mint/epoch_hooks.go, x/mint/depinject.go, x/epochs/types/hooks.go, and x/epochs/keeper/keeper.go.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `EpochHooks` and `MintFn`.

# Test: Search for usages of `EpochHooks` and `MintFn`. Expect: Correct integration and fallback.
rg --type go 'EpochHooks|MintFn' --context 5

Length of output: 16300

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

30-30: Transition to pointer type for EpochsKeeper in tests is consistent with main code changes. Ensure all test cases correctly handle the pointer type.

Verification successful

The previous script failed because the specified directory or file does not exist. Let's locate the correct directory or file containing the test cases for EpochsKeeper and verify the handling of EpochsKeeper pointers.


The script successfully located the test files and found occurrences of EpochsKeeper in several test files, including x/epochs/keeper/keeper_test.go. Let's review the context around these occurrences to ensure proper handling of the pointer type.


The script successfully located the test files and found occurrences of EpochsKeeper in several test files, including x/epochs/keeper/keeper_test.go. The context around these occurrences shows that the EpochsKeeper pointer type is being handled correctly in the test cases.

Transition to pointer type for EpochsKeeper in tests is consistent with main code changes. Ensure all test cases correctly handle the pointer type.

  • x/epochs/keeper/keeper_test.go
  • x/epochs/keeper/epoch_test.go
  • x/epochs/keeper/abci_test.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all test cases handle the `EpochsKeeper` pointer type correctly.

# Test: Search for test cases using `EpochsKeeper`. Expect: Correct handling of pointers.
rg --type go 'EpochsKeeper' 'x/epochs/keeper/*_test.go' --context 5

Length of output: 133



Script:

#!/bin/bash
# Description: Locate the correct directory or file containing the test cases for `EpochsKeeper` and verify the handling of `EpochsKeeper` pointers.

# Step 1: Find all Go test files in the repository.
test_files=$(fd --type f --extension go --glob '*_test.go')

# Step 2: Search for occurrences of `EpochsKeeper` in the test files.
for file in $test_files; do
  echo "Checking file: $file"
  rg --type go 'EpochsKeeper' "$file" --context 5
done

Length of output: 178958



Script:

#!/bin/bash
# Description: Review the context around the occurrences of `EpochsKeeper` in the test files to ensure proper handling of the pointer type.

# Step 1: Find all Go test files in the repository.
test_files=$(fd --type f --extension go --glob '*_test.go')

# Step 2: Search for occurrences of `EpochsKeeper` in the test files and display the context.
for file in $test_files; do
  echo "Checking file: $file"
  rg --type go 'EpochsKeeper' "$file" --context 10
done

Length of output: 180975

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

21-21: Update to expect four epochs in the genesis test is correct. Verify that the genesis state is correctly initialized elsewhere in the system.

x/epochs/keeper/epoch_test.go (1)

96-101: Updated assertions correctly reflect the addition of the "minute" epoch and its order among other epochs.

x/epochs/module.go (1)

39-43: Transitioning keeper from a value to a pointer in the AppModule struct and its constructor enhances performance and maintainability.

simapp/mint_fn.go (1)

19-123: The ProvideExampleMintFn function is well-implemented, with comprehensive error handling and condition checks for minting based on the epoch ID.

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

107-180: The DefaultMintFn function encapsulates the minting logic effectively, with appropriate checks for conditions like epoch ID and max supply, and includes comprehensive error handling.

x/mint/module.go (1)

47-69: Adding a mintFn field to the AppModule struct and handling it in the NewAppModule constructor enhances the flexibility of the mint module by allowing for custom minting logic.

tests/e2e/bank/grpc.go (1)

Line range hint 38-75: Updated expected amounts in GRPC handler test cases correctly reflect the new staking tokens configuration.

tests/e2e/distribution/grpc_query_suite.go (3)

286-286: Updated delegator rewards value to "60.27stake" appears correct given the PR context.


173-173: Updated commission value to "60.27stake" appears correct given the PR context.

Verification successful

The search results show that the value "60.27stake" appears in two places within the same file: once for commission and once for rewards. To ensure the correctness of the updated commission value, we need to verify if this value is consistent with the actual commission calculation logic in the codebase.


To verify the correctness of the updated commission value, we need to inspect the implementation of the SetInitialCommission and buildCommissionRates functions, as they seem directly related to commission settings.


To fully understand the commission calculation, we need the complete implementation of both the SetInitialCommission and buildCommissionRates functions.


To fully verify the commission calculation, we still need the complete implementation of the SetInitialCommission function.


The command to extract the remaining part of the SetInitialCommission function did not produce any output. To ensure we capture the full implementation of this function, we need to use a broader search pattern.


The updated commission value in the test is consistent with the commission calculation logic in the codebase.

  • The SetInitialCommission function validates and sets the commission for the validator.
  • The buildCommissionRates function converts string inputs to decimal values for commission rates.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the updated commission value in the distribution logic.

# Test: Search for the commission calculation logic. Expect: Consistency with the new test value.
rg --type go $'60.27stake'

Length of output: 212



Script:

#!/bin/bash
# Description: Search for the commission calculation logic in the codebase to verify consistency with the test value.

# Search for functions or methods related to commission calculation.
rg --type go 'commission' | grep -i 'func\|method'

Length of output: 1247



Script:

#!/bin/bash
# Description: Extract and review the implementation of the SetInitialCommission and buildCommissionRates functions to verify commission calculation logic.

# Extract the implementation of the SetInitialCommission function.
rg --type go --context 10 'func (v Validator) SetInitialCommission' x/staking/types/validator.go

# Extract the implementation of the buildCommissionRates function.
rg --type go --context 10 'func buildCommissionRates' x/staking/client/cli/utils.go

Length of output: 857



Script:

#!/bin/bash
# Description: Extract the full implementation of the SetInitialCommission and buildCommissionRates functions to verify commission calculation logic.

# Extract the full implementation of the SetInitialCommission function.
rg --type go --context 20 'func (v Validator) SetInitialCommission' x/staking/types/validator.go

# Extract the remaining part of the buildCommissionRates function.
rg --type go --context 20 'func buildCommissionRates' x/staking/client/cli/utils.go

Length of output: 1436



Script:

#!/bin/bash
# Description: Extract the remaining part of the SetInitialCommission function to verify commission calculation logic.

# Extract the remaining part of the SetInitialCommission function.
rg --type go --context 30 'func (v Validator) SetInitialCommission' x/staking/types/validator.go

Length of output: 98



Script:

#!/bin/bash
# Description: Use a broader search pattern to locate the full implementation of the SetInitialCommission function.

# Search for the full implementation of the SetInitialCommission function.
rg --type go --context 50 'SetInitialCommission' x/staking/types/validator.go

Length of output: 3735


119-119: Updated reward value to "120.54stake" appears correct given the PR context.

simapp/app_di.go (2)

96-96: Transition of EpochsKeeper to pointer type aligns with the PR's objectives to enhance performance and manageability.


115-115: Addition of ProvideExampleMintFn to the dependency injection setup is consistent with the PR's objectives to introduce new minting logic.

simapp/app.go (1)

174-174: Ensure that EpochsKeeper is properly instantiated before use to avoid nil pointer dereferences.

api/cosmos/mint/v1beta1/mint.pulsar.go (1)

441-443: Verify deterministic behavior in map iteration during size calculation.

The iteration over x.ArbitraryParams in the Size method of fastReflection_Minter might lead to non-deterministic size calculations. If the order of map entries affects the size calculation, consider implementing a sorting mechanism before iteration.

Verification successful

The Size function in fastReflection_Minter already includes a mechanism to ensure deterministic behavior when iterating over x.ArbitraryParams. When options.Deterministic is true, the keys are sorted before iteration, ensuring consistent size calculations.

  • Lines 427-443 in api/cosmos/mint/v1beta1/mint.pulsar.go handle this correctly.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the map order affects the size calculation logic.
grep -rn 'Size' api/cosmos/mint/v1beta1/mint.pulsar.go

Length of output: 944



Script:

#!/bin/bash
# Extract the relevant portion of the Size function to analyze the iteration over x.ArbitraryParams
sed -n '400,460p' api/cosmos/mint/v1beta1/mint.pulsar.go

Length of output: 1835

x/epochs/depinject.go Show resolved Hide resolved
api/cosmos/mint/v1beta1/mint.pulsar.go Outdated Show resolved Hide resolved
x/epochs/keeper/grpc_query_test.go Show resolved Hide resolved
api/cosmos/mint/v1beta1/mint.pulsar.go Outdated Show resolved Hide resolved
x/mint/depinject.go Outdated Show resolved Hide resolved
@@ -21,6 +21,8 @@ message Minter {
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

map<string, string> arbitrary_params = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Addition of arbitrary_params to the Minter message enhances customization. Consider documenting its intended use cases.

+ // arbitrary_params can be used to pass custom parameters for minting operations.

Committable suggestion was skipped due low confidence.

x/epochs/keeper/keeper.go Show resolved Hide resolved
@@ -35,7 +35,7 @@ func (s *E2ETestSuite) TestTotalSupplyGRPCHandler() {
&types.QueryTotalSupplyResponse{
Supply: sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Add(math.NewInt(10))),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Add(math.NewInt(123))),
Copy link
Member

Choose a reason for hiding this comment

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

why the increase ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because now it mints the equivalent of a minute in the first block (the beginning of the epoch)

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: 3

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 32fe4d9 and 2c80fed.

Files ignored due to path filters (1)
  • x/mint/go.mod is excluded by !**/*.mod
Files selected for processing (3)
  • x/mint/CHANGELOG.md (1 hunks)
  • x/mint/README.md (3 hunks)
  • x/mint/keeper/keeper.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/mint/keeper/keeper.go
Additional context used
Path-based instructions (2)
x/mint/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/mint/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/mint/CHANGELOG.md

[style] ~37-~37: Consider a shorter alternative to avoid wordiness.
Context: ...per.DefaultMintFnwrapper must be used in order to continue using it inNewAppModule`. Th...

x/mint/README.md

[uncategorized] ~10-~10: Possible missing preposition found.
Context: ...ontents * Concepts * [The Minting Mechanism](#the-minting-mechani...


[uncategorized] ~120-~120: Possible missing preposition found.
Context: ...e desired ratio (67%). The maximum rate change possible is defined to be 13% per year,...


[typographical] ~121-~121: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...e possible is defined to be 13% per year, however, the annual inflation is capped as betwe...

Markdownlint
x/mint/CHANGELOG.md

30-30: Expected: 0 or 2; Actual: 1
Trailing spaces

x/mint/README.md

10-10: Expected: 2; Actual: 4
Unordered list indentation


12-12: Expected: 2; Actual: 4
Unordered list indentation


13-13: Expected: 2; Actual: 4
Unordered list indentation


15-15: Expected: 2; Actual: 4
Unordered list indentation


17-17: Expected: 2; Actual: 4
Unordered list indentation


18-18: Expected: 2; Actual: 4
Unordered list indentation


19-19: Expected: 2; Actual: 4
Unordered list indentation


20-20: Expected: 2; Actual: 4
Unordered list indentation


23-23: Expected: 2; Actual: 4
Unordered list indentation


25-25: Expected: 2; Actual: 4
Unordered list indentation


26-26: Expected: 2; Actual: 4
Unordered list indentation


27-27: Expected: 2; Actual: 4
Unordered list indentation


72-72: Expected: 0 or 2; Actual: 1
Trailing spaces


102-102: Expected: 0 or 2; Actual: 1
Trailing spaces


126-126: Column: 1
Hard tabs


127-127: Column: 1
Hard tabs


129-129: Column: 1
Hard tabs


130-130: Column: 1
Hard tabs


131-131: Column: 1
Hard tabs


132-132: Column: 1
Hard tabs


133-133: Column: 1
Hard tabs


134-134: Column: 1
Hard tabs


135-135: Column: 1
Hard tabs


136-136: Column: 1
Hard tabs


138-138: Column: 1
Hard tabs


149-149: Column: 1
Hard tabs


158-158: Column: 1
Hard tabs


159-159: Column: 1
Hard tabs


54-54: Expected: 1; Actual: 2
Multiple consecutive blank lines


95-95: Expected: 1; Actual: 2
Multiple consecutive blank lines


162-162: Expected: 1; Actual: 2
Multiple consecutive blank lines


178-178: Expected: 1; Actual: 2
Multiple consecutive blank lines


192-192: Expected: 1; Actual: 2
Multiple consecutive blank lines

Additional comments not posted (5)
x/mint/CHANGELOG.md (1)

30-30: Correct the trailing space issue.

Tools
Markdownlint

30-30: Expected: 0 or 2; Actual: 1
Trailing spaces

x/mint/README.md (4)

59-60: Ensure the new data field in the Minter struct is clearly explained.


83-83: Clarify the transition from InflationCalculationFn to MintFn.


87-91: Ensure the MintFn function signature is correct and matches the implementation.


98-98: Clarify the conditions under which block-based minting occurs.


### Improvements

### API Breaking Changes

* [#20363](https://github.com/cosmos/cosmos-sdk/pull/20363) Deprecated InflationCalculationFn in favor of MintFn, `keeper.DefaultMintFn` wrapper must be used in order to continue using it in `NewAppModule`. This is not breaking for depinject users, as both `MintFn` and `InflationCalculationFn` are accepted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a more concise expression.

- `keeper.DefaultMintFn` wrapper must be used in order to continue using it in `NewAppModule`.
+ `keeper.DefaultMintFn` wrapper is required in `NewAppModule`.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [#20363](https://github.com/cosmos/cosmos-sdk/pull/20363) Deprecated InflationCalculationFn in favor of MintFn, `keeper.DefaultMintFn` wrapper must be used in order to continue using it in `NewAppModule`. This is not breaking for depinject users, as both `MintFn` and `InflationCalculationFn` are accepted.
* [#20363](https://github.com/cosmos/cosmos-sdk/pull/20363) Deprecated InflationCalculationFn in favor of MintFn, `keeper.DefaultMintFn` wrapper is required in `NewAppModule`. This is not breaking for depinject users, as both `MintFn` and `InflationCalculationFn` are accepted.
Tools
LanguageTool

[style] ~37-~37: Consider a shorter alternative to avoid wordiness.
Context: ...per.DefaultMintFnwrapper must be used in order to continue using it inNewAppModule`. Th...

x/mint/README.md Outdated Show resolved Hide resolved
Co-authored-by: Marko <marko@baricevic.me>
params, err := k.Params.Get(ctx)
// we pass -1 as epoch number to indicate that this is not an epoch minting,
// but a regular block minting. Same with epoch id "block".
err = mintFn(ctx, k.Environment, &minter, "block", -1)
Copy link
Member

Choose a reason for hiding this comment

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

how would you disable this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The mintFn always check for the epoch ID and returns early if it doesn't match. It's not the cleanest, but works :D

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

how does inflation work on epochs, is it the user needs to estimate how many epochs in a year? also is it the same as the old way with 67% bond ratio?

@facundomedica
Copy link
Member Author

how does inflation work on epochs, is it the user needs to estimate how many epochs in a year? also is it the same as the old way with 67% bond ratio?

For the default function in x/mint, it works exactly the same way as before, it mints on every block.

For ProvideExampleMintFn, the one in simapp, it's the same in terms of inflation, but with some slight changes. So we mint every minute, by taking the annual provisions, dividing it by the amount of seconds in a year and multiplying it by the seconds elapsed since the last mint. Some chains might want to make this accurate down to milliseconds.

The other difference, which is a bit of a workaround to avoid breaking all the current code, we mint tokens for 60s prior to the chain genesis. It's just to get tokens on the very first block, as many tests depend on this.

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: 5

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c80fed and 29970a6.

Files ignored due to path filters (6)
  • simapp/go.mod is excluded by !**/*.mod
  • tests/go.mod is excluded by !**/*.mod
  • x/group/go.mod is excluded by !**/*.mod
  • x/group/go.sum is excluded by !**/*.sum
  • x/mint/go.mod is excluded by !**/*.mod
  • x/mint/go.sum is excluded by !**/*.sum
Files selected for processing (4)
  • x/mint/README.md (3 hunks)
  • x/mint/keeper/keeper_test.go (3 hunks)
  • x/mint/keeper/msg_server_test.go (1 hunks)
  • x/mint/module_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/mint/module_test.go
Additional context used
Path-based instructions (3)
x/mint/keeper/msg_server_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"

x/mint/keeper/keeper_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"

x/mint/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/mint/README.md

[uncategorized] ~10-~10: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...ontents * Concepts * [The Minting Mechanism](#the-minting-mechani...


[typographical] ~132-~132: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence. (HOWEVER_SENTENCE)
Context: ...e possible is defined to be 13% per year, however, the annual inflation is capped as betwe...

Markdownlint
x/mint/README.md

10-10: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


12-12: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


13-13: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


15-15: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


17-17: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


18-18: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


19-19: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


20-20: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


23-23: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


25-25: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


26-26: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


27-27: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


72-72: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


113-113: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs


138-138: Column: 1 (MD010, no-hard-tabs)
Hard tabs


140-140: Column: 1 (MD010, no-hard-tabs)
Hard tabs


141-141: Column: 1 (MD010, no-hard-tabs)
Hard tabs


142-142: Column: 1 (MD010, no-hard-tabs)
Hard tabs


143-143: Column: 1 (MD010, no-hard-tabs)
Hard tabs


144-144: Column: 1 (MD010, no-hard-tabs)
Hard tabs


145-145: Column: 1 (MD010, no-hard-tabs)
Hard tabs


146-146: Column: 1 (MD010, no-hard-tabs)
Hard tabs


147-147: Column: 1 (MD010, no-hard-tabs)
Hard tabs


149-149: Column: 1 (MD010, no-hard-tabs)
Hard tabs


160-160: Column: 1 (MD010, no-hard-tabs)
Hard tabs


169-169: Column: 1 (MD010, no-hard-tabs)
Hard tabs


170-170: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


106-106: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


173-173: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


189-189: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


203-203: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (1)
x/mint/README.md (1)

113-113: Remove trailing spaces.

- If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`. 
+ If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`.

Likely invalid or redundant comment.

Tools
Markdownlint

113-113: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

@@ -7,7 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (s *IntegrationTestSuite) TestUpdateParams() {
func (s *KeeperTestSuite) TestUpdateParams() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure comprehensive test coverage for TestUpdateParams.

Would you like me to help expand the test cases to cover more scenarios or edge cases?

s.Nil(s.mintKeeper.AddCollectedFees(s.ctx, fees))
}

func (s *KeeperTestSuite) TestDefaultMintFn() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance test coverage for TestDefaultMintFn.

Would you like assistance in adding more test cases to cover scenarios where MintCoins and SendCoinsFromModuleToModule might fail?

s.NotEqual(minter, newMinter)
}

func (s *KeeperTestSuite) TestMigrator() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve clarity and coverage of migration tests.

Consider clarifying the intent behind setting the max supply to one and then zero in the migration tests. Additionally, testing other critical migration paths could ensure comprehensive coverage.

@@ -24,7 +24,7 @@ import (

const govModuleNameStr = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"

type IntegrationTestSuite struct {
type KeeperTestSuite struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor KeeperTestSuite to improve clarity and maintainability.

Consider breaking down the SetupTest method into smaller, more focused methods to improve readability and maintainability.

@@ -6,10 +6,15 @@ sidebar_position: 1

## Contents

* [Concepts](#concepts)
* [The Minting Mechanism](#the-minting-mechanism)
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 7, 2024

Choose a reason for hiding this comment

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

Correct the indentation for the unordered list.

-    * [The Minting Mechanism](#the-minting-mechanism)
+  * [The Minting Mechanism](#the-minting-mechanism)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [The Minting Mechanism](#the-minting-mechanism)
* [The Minting Mechanism](#the-minting-mechanism)
Tools
LanguageTool

[uncategorized] ~10-~10: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...ontents * Concepts * [The Minting Mechanism](#the-minting-mechani...

Markdownlint

10-10: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

Copy link
Member Author

Choose a reason for hiding this comment

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

pause

Copy link
Contributor

Choose a reason for hiding this comment

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

@facundomedica, understood! I'll hold off on any further actions or comments until you indicate otherwise. If there's anything specific you need when you're ready to resume, just let me know!

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: 3

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29970a6 and a66e1e8.

Files selected for processing (8)
  • simapp/app.go (1 hunks)
  • tests/e2e/bank/grpc.go (4 hunks)
  • tests/e2e/distribution/grpc_query_suite.go (3 hunks)
  • x/group/go.mod (1 hunks)
  • x/mint/README.md (3 hunks)
  • x/mint/keeper/keeper_test.go (3 hunks)
  • x/mint/types/minter_test.go (2 hunks)
  • x/mint/types/params.go (6 hunks)
Files skipped from review as they are similar to previous changes (6)
  • simapp/app.go
  • tests/e2e/bank/grpc.go
  • tests/e2e/distribution/grpc_query_suite.go
  • x/mint/keeper/keeper_test.go
  • x/mint/types/minter_test.go
  • x/mint/types/params.go
Additional context used
Path-based instructions (1)
x/mint/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/mint/README.md

[uncategorized] ~10-~10: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...ontents * Concepts * [The Minting Mechanism](#the-minting-mechani...


[uncategorized] ~72-~72: This verb may not be in the correct form. Consider using a different form for this context. (AI_EN_LECTOR_REPLACEMENT_VERB_FORM)
Context: ...ion of the MaxSupply parameter allows controlling the maximum supply of tokens minted by ...


[uncategorized] ~120-~120: A determiner appears to be missing. Consider inserting it. (AI_EN_LECTOR_MISSING_DETERMINER)
Context: ...Fn)`. ### Inflation rate calculation Inflation rate is calculated using an "inflation ...


[uncategorized] ~135-~135: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...e desired ratio (67%). The maximum rate change possible is defined to be 5% per year, ...


[typographical] ~136-~136: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence. (HOWEVER_SENTENCE)
Context: ...ge possible is defined to be 5% per year, however, the annual inflation is capped between ...

Markdownlint
x/mint/README.md

10-10: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


12-12: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


13-13: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


15-15: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


17-17: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


18-18: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


19-19: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


20-20: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


23-23: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


25-25: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


26-26: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


27-27: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


72-72: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


117-117: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


140-140: Column: 1 (MD010, no-hard-tabs)
Hard tabs


141-141: Column: 1 (MD010, no-hard-tabs)
Hard tabs


143-143: Column: 1 (MD010, no-hard-tabs)
Hard tabs


144-144: Column: 1 (MD010, no-hard-tabs)
Hard tabs


145-145: Column: 1 (MD010, no-hard-tabs)
Hard tabs


146-146: Column: 1 (MD010, no-hard-tabs)
Hard tabs


147-147: Column: 1 (MD010, no-hard-tabs)
Hard tabs


148-148: Column: 1 (MD010, no-hard-tabs)
Hard tabs


149-149: Column: 1 (MD010, no-hard-tabs)
Hard tabs


150-150: Column: 1 (MD010, no-hard-tabs)
Hard tabs


152-152: Column: 1 (MD010, no-hard-tabs)
Hard tabs


163-163: Column: 1 (MD010, no-hard-tabs)
Hard tabs


172-172: Column: 1 (MD010, no-hard-tabs)
Hard tabs


173-173: Column: 1 (MD010, no-hard-tabs)
Hard tabs


54-54: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


110-110: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


176-176: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


192-192: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


206-206: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (2)
x/group/go.mod (1)

47-47: The addition of cosmossdk.io/x/epochs as an indirect dependency aligns with the changes in the minting logic. Ensure that this dependency is maintained up-to-date and review its impact periodically.

x/mint/README.md (1)

59-60: The addition of the data field in the Minter struct is correctly documented. Ensure that examples or guidelines on how to use this field are provided to avoid misuse.

Comment on lines +9 to +17
* [Concepts](#concepts)
* [The Minting Mechanism](#the-minting-mechanism)
* [State](#state)
* [Minter](#minter)
* [Params](#params)
* [Begin-Block](#begin-block)
* [Epoch minting](#epoch-minting)
* [MintFn](#mintfn)
* [Block based minting](#block-based-minting)
* [Default configuration](#default-configuration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent indentation for list items to improve readability.

-    * [The Minting Mechanism](#the-minting-mechanism)
+  * [The Minting Mechanism](#the-minting-mechanism)
-    * [Default configuration](#default-configuration)
+  * [Default configuration](#default-configuration)
-    * [NextInflationRate](#nextinflationrate)
+  * [NextInflationRate](#nextinflationrate)
-    * [NextAnnualProvisions](#nextannualprovisions)
+  * [NextAnnualProvisions](#nextannualprovisions)
-    * [BlockProvision](#blockprovision)
+  * [BlockProvision](#blockprovision)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* [Concepts](#concepts)
* [The Minting Mechanism](#the-minting-mechanism)
* [State](#state)
* [Minter](#minter)
* [Params](#params)
* [Begin-Block](#begin-block)
* [Epoch minting](#epoch-minting)
* [MintFn](#mintfn)
* [Block based minting](#block-based-minting)
* [Default configuration](#default-configuration)
* [Concepts](#concepts)
* [The Minting Mechanism](#the-minting-mechanism)
* [State](#state)
* [Minter](#minter)
* [Params](#params)
* [Epoch minting](#epoch-minting)
* [MintFn](#mintfn)
* [Block based minting](#block-based-minting)
* [Default configuration](#default-configuration)
Tools
LanguageTool

[uncategorized] ~10-~10: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...ontents * Concepts * [The Minting Mechanism](#the-minting-mechani...

Markdownlint

10-10: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


12-12: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


13-13: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


15-15: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


17-17: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

Comment on lines +83 to +104
In the latest release of x/mint, the minting logic has been refactored to allow for more flexibility in the minting process. The `InflationCalculationFn` has been deprecated in favor of `MintFn`. The `MintFn` function is passed to the `NewAppModule` function and is used to mint tokens on the configured epoch beginning. This change allows users to define their own minting logic and removes any assumptions on how tokens are minted.

The minting logic in the `BeginBlocker` function provides an optional feature for controlling token minting based on the maximum allowable supply (MaxSupply). This feature allows users to adjust the minting process according to their specific requirements and use cases. However, it's important to note that the MaxSupply parameter is independent of the minting process and assumes that any adjustments to the total supply, including burning tokens, are handled by external modules.
```mermaid
flowchart LR
A[BeforeEpochStart] --> B[MintFn]

subgraph B["MintFn (user defined)"]
direction LR
C[Get x/staking info] --> D[Calculate Inflation]
D --> E[Mint Tokens]
end
```

### MintFn

The `MintFn` function is called at the beginning of each epoch and is responsible for minting tokens. The function signature is as follows:

```go
type MintFn func(ctx context.Context, env appmodule.Environment, minter *Minter, epochId string, epochNumber int64) error
```

How this function mints tokens is defined by the app developers, meaning they can query state and perform any calculations they deem necessary. [This implementation](https://github.com/cosmos/cosmos-sdk/blob/ace7bca105a8d5363782cfd19c6f169b286cd3b2/simapp/mint_fn.go#L25) in SimApp contains examples of how to use `QueryRouterService` and the Minter's `data`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation for the new MintFn is clear and informative. Consider adding a warning about ensuring the idempotency of MintFn to prevent unintended minting due to repeated calls or reverts.

Would you like me to draft a section on ensuring the idempotency of MintFn?


### Default configuration

If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove trailing spaces to maintain clean and professional documentation.

- If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`. 
+ If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`.
If no `MintFn` is passed to the `NewAppModule` function, the minting logic defaults to block-based minting, corresponding to `mintKeeper.DefaultMintFn(types.DefaultInflationCalculationFn)`.
Tools
Markdownlint

117-117: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

@facundomedica facundomedica added this pull request to the merge queue Jun 11, 2024
Merged via the queue into main with commit 150ca96 Jun 11, 2024
65 of 68 checks passed
@facundomedica facundomedica deleted the facu/exp-mintfn2 branch June 11, 2024 12:31
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 a66e1e8 and 226091c.

Files selected for processing (1)
  • x/mint/module_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/mint/module_test.go

alpe added a commit that referenced this pull request Jun 12, 2024
* main:
  refactor(x/auth): Fix system test (#20531)
  feat(crypto): add blst (#20296)
  docs: Update high level overview and introduction (#20535)
  refactor(x/core): remove test (#20624)
  feat(x/mint)!: Replace InflationCalculationFn with MintFn + simple epoch minting (#20363)
  docs: remove duplicate words (#20622)
  feat: prep for errors v2 (#20539)
  chore: reduce default inflation (#20606)
  refactor(store): add miss defer (#20602)
  chore: use comet api pkg instead of comet alias (#20614)
  chore: write gentx info to cmd.ErrOrStderr (#20616)
  docs: ADR 073: update to accepted and add to README.md (#20619)
  chore(proto): change future extracted modules version from v1.0.0 to v0.2.0 (#20600)
  fix: remove some duplicate words (#20605)
  feat(stf): port simappv2 changes (#20587)
  chore: bring patch changelogs to main (#20599)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants