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

[Mint] 🤑 New token model implementation #439

Merged
merged 24 commits into from
Dec 11, 2023
Merged

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Aug 23, 2023

⛏️ Mint

Update the mint module with the token model v2 specified by axone-protocol/docs#356, addressing issue #433.

I kept the yearly inflation calculation like is done in the cosmos-sdk mint implementation, it's allow kept the GRPC endpoints and make it compatible with most of explorer.

🧮 Calculation

Inflation calculation is made in the minter on NextInflation method.

r_inflation = (1 / ρ_bonded) * c_inflation

Where:

  • r_inflation is the inflation rate of KNOW, representing the rate at which new tokens are created and introduced into circulation.
  • ρ_bonded is the bonded ratio, i.e., the ratio between the number of tokens staked and the number of existing tokens.
  • c_inflation is the inflation coefficient, a constant factor that adjusts the influence of the bonded ratio on the inflation rate.

Once yearly inflation rate is known, we can calculate the yearly minted token divided by the number of block in a years to know how many token is minted for each block.

🚧 Todo

  • Configure new params on proto files
  • Generate new proto and documentation
  • Include new calculation function
  • Add migration params script
  • Update documentation
  • Update mint tests

Close #433

Summary by CodeRabbit

  • New Features

    • Introduced a new economic model with updated inflation calculation logic.
    • Added functionality to recalculate inflation rate and bonded ratio.
    • Implemented a new upgrade handler for transitioning to version 6.0.0.
  • Improvements

    • Enhanced the minting module with additional parameters for better configurability.
    • Improved clarity in the minting process with updated field names and descriptions.
    • Streamlined the proposal creation process with added title and summary.
  • Bug Fixes

    • Fixed issues with parameter validation in the minting module.
    • Corrected the voting period configuration for upgrade proposals.
  • Documentation

    • Updated documentation to reflect changes in the minting module's parameters and processes.
  • Refactor

    • Refactored minter creation and setting logic for better maintainability.
    • Removed outdated code and imports following the new economic model implementation.
  • Tests

    • Updated test cases to align with the new economic model and parameter changes.
    • Added new test cases for validating the updated minting parameters.
  • Chores

    • Cleaned up code by removing unnecessary comments and imports.

@bdeneux bdeneux marked this pull request as draft August 23, 2023 09:47
@bdeneux bdeneux force-pushed the feat/new-token-model branch 2 times, most recently from 61b966a to 6f10d0d Compare August 25, 2023 13:37
@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Merging #439 (33045db) into main (c5ddb85) will decrease coverage by 0.22%.
Report is 3 commits behind head on main.
The diff coverage is 40.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #439      +/-   ##
==========================================
- Coverage   64.94%   64.72%   -0.22%     
==========================================
  Files          62       61       -1     
  Lines        2707     2727      +20     
==========================================
+ Hits         1758     1765       +7     
- Misses        870      883      +13     
  Partials       79       79              
Files Changed Coverage Δ
x/mint/abci.go 0.00% <0.00%> (ø)
x/mint/keeper/migrations.go 0.00% <0.00%> (ø)
x/mint/module.go 0.00% <0.00%> (ø)
x/mint/types/params.go 9.52% <12.19%> (-1.80%) ⬇️
x/mint/simulation/genesis.go 95.12% <100.00%> (+1.78%) ⬆️
x/mint/simulation/proposals.go 100.00% <100.00%> (ø)
x/mint/types/minter.go 78.57% <100.00%> (-0.38%) ⬇️

@bdeneux bdeneux force-pushed the feat/new-token-model branch 2 times, most recently from 030fbe2 to b81906b Compare September 6, 2023 13:56
@bdeneux bdeneux marked this pull request as ready for review September 18, 2023 08:09
@bdeneux bdeneux self-assigned this Sep 18, 2023
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.

Thx!

I've made a first pass, I didn't check everything to make it step by step :)

proto/mint/v1beta1/mint.proto Outdated Show resolved Hide resolved
proto/mint/v1beta1/mint.proto Outdated Show resolved Hide resolved
x/mint/types/params.go Outdated Show resolved Hide resolved
Copy link

@ErikssonJoakim ErikssonJoakim left a comment

Choose a reason for hiding this comment

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

Looks good from my end 😃 Great work

@ccamel
Copy link
Member

ccamel commented Oct 24, 2023

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2023

Note

Reviews Paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The changes revolve around a significant update to the token model, particularly within the x/mint module. The alterations include renaming parameters to align with the new token model, removing deprecated fields, adding new error handling, and updating functions to reflect the revised inflation and minting logic. The Makefile and app.go files also see updates to testing configurations and module instantiation, respectively.

Changes

File(s) Summary
Makefile, app/..., docs/proto/mint.md, proto/mint/v1beta1/mint.proto Adjustments to testing configurations, module instantiation, and documentation to align with the new token model.
x/mint/*, app/upgrades/... Refactoring and updates across the x/mint module and upgrade handling to implement the new inflation mechanisms and parameters.
x/mint/types/*, x/mint/keeper/*, x/mint/migrations/* Changes to types, keeper logic, and migrations to support the new token model, including new error handling and parameter validation.

Assessment against linked issues

Objective Addressed Explanation
Implement the new Token model as described in the whitepaper (#433) The changes across multiple files in the x/mint module and related documentation align with the new Token model specifications.
Consider renaming the x/mint module to avoid conflicts with standard Cosmos SDK modules (#433) The changes are still within the x/mint module, and there's no indication of renaming it to x/inflation as suggested.

Poem

In the code where tokens flow,
A rabbit hopped, with changes in tow.
Fields renamed, logic refined,
A new token model, in the blockchain entwined. 🌟🐇💰

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5ddb85 and 33045db.
Files ignored due to filter (3)
  • proto/mint/docs.yaml
  • x/mint/migrations/v3/types/minter.pb.go
  • x/mint/types/mint.pb.go
Files selected for processing (23)
  • Makefile (2 hunks)
  • app/app.go (1 hunks)
  • app/upgrades.go (3 hunks)
  • app/upgrades/v6/upgrade.go (1 hunks)
  • docs/proto/mint.md (2 hunks)
  • proto/mint/v1beta1/mint.proto (1 hunks)
  • x/mint/abci.go (2 hunks)
  • x/mint/client/cli/query_test.go (1 hunks)
  • x/mint/keeper/genesis_test.go (2 hunks)
  • x/mint/keeper/keeper_test.go (1 hunks)
  • x/mint/keeper/migrations.go (1 hunks)
  • x/mint/keeper/msg_server_test.go (2 hunks)
  • x/mint/migrations/v3/migrations.go (1 hunks)
  • x/mint/migrations/v3/types/params.go (1 hunks)
  • x/mint/module.go (4 hunks)
  • x/mint/simulation/decoder_test.go (1 hunks)
  • x/mint/simulation/genesis.go (2 hunks)
  • x/mint/simulation/genesis_test.go (1 hunks)
  • x/mint/simulation/proposals.go (1 hunks)
  • x/mint/simulation/proposals_test.go (1 hunks)
  • x/mint/types/minter.go (2 hunks)
  • x/mint/types/minter_test.go (6 hunks)
  • x/mint/types/params.go (3 hunks)
Files skipped from review due to trivial changes (8)
  • Makefile
  • app/app.go
  • proto/mint/v1beta1/mint.proto
  • x/mint/client/cli/query_test.go
  • x/mint/keeper/genesis_test.go
  • x/mint/keeper/migrations.go
  • x/mint/module.go
  • x/mint/simulation/decoder_test.go
Additional comments: 39
app/upgrades/v6/upgrade.go (1)
  • 1-30: The upgrade handler CreateUpgradeHandler is correctly implemented to run the migrations for the modules. The StoreUpgrades variable correctly lists the new store "feeibc" that has been added in this upgrade. The logger is used appropriately to log the upgrade process. However, the comment on line 19 mentions that the mint module is migrated with new parameters, but there is no explicit code in this hunk that does this. Ensure that the mint module's migration is handled in the mm.RunMigrations method or elsewhere in the codebase.
app/upgrades.go (3)
  • 12-12: The import for the v6 upgrade package has been added. Ensure that the package exists and is accessible from this location.

  • 31-34: A new upgrade handler for v6 has been set. Ensure that the CreateUpgradeHandler function in the v6 package is implemented correctly and that it accepts the correct parameters.

  • 53-54: The storeUpgrades variable is being set to v6.StoreUpgrades when the upgrade name is v6.UpgradeName. Ensure that v6.StoreUpgrades is defined and correctly implemented in the v6 package.

docs/proto/mint.md (3)
  • 9-43: The new documentation provides a clear explanation of the new inflation calculation method, including the formula used and the meaning of each variable. It also explains how the yearly inflation rate is converted into a block-level token minting amount. This is a significant change from the previous static inflation calculation method, which should be noted for users of the system.

  • 81-94: The Minter section has been updated to reflect the new dynamic inflation calculation method. The target_supply field has been removed, which is consistent with the removal of the totalSupply parameter from the BlockProvision function.

  • 99-107: The Params section has been updated with new fields for the inflation coefficient, bonding adjustment, and target bonding ratio. The annual_reduction_factor field has been removed, which is consistent with the changes to the inflation calculation method.

x/mint/keeper/keeper_test.go (1)
  • 80-117: The test cases for setting invalid and valid parameters have been updated to include the new parameters BondingAdjustment, TargetBondingRatio, and InflationCoef. The test cases cover scenarios where these parameters are set to negative values, which are expected to cause errors, and scenarios where they are set to valid values. The test cases are comprehensive and cover all the new parameters. The changes are consistent with the updated Params message in the mint module.
x/mint/keeper/msg_server_test.go (4)
  • 23-35: The test case "set invalid params for bonding adjustment (negative value)" is correctly checking for an error when a negative value is set for the BondingAdjustment parameter. This is a good practice as it ensures that the system behaves as expected when invalid input is provided.

  • 37-49: The test case "set invalid params for target bonding ratio (negative value)" is correctly checking for an error when a negative value is set for the TargetBondingRatio parameter. This is a good practice as it ensures that the system behaves as expected when invalid input is provided.

  • 51-59: The test case "set invalid params for inflation coef (negative value)" is correctly checking for an error when a negative value is set for the InflationCoef parameter. This is a good practice as it ensures that the system behaves as expected when invalid input is provided.

  • 69-73: The test case for setting valid parameters is correctly checking that no error is returned when valid values are set for the BondingAdjustment, TargetBondingRatio, and InflationCoef parameters. This is a good practice as it ensures that the system behaves as expected when valid input is provided.

x/mint/types/minter.go (5)
  • 13-17: The NewMinter function no longer accepts targetSupply as a parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 21-26: The InitialMinter function no longer accepts targetSupply as a parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 30-32: The default inflation rate has been changed from 15% to 18%. Ensure that this change is intentional and that it does not negatively impact the system.

  • 45-48: The NextInflation function now calculates the inflation rate differently, taking into account the bonding ratio and the inflation coefficient. Ensure that this new calculation method is correct and that it provides the expected results.

  • 59-60: The BlockProvision function no longer accepts totalSupply as a parameter and no longer checks if the future supply exceeds the target supply. Ensure that all calls to this function throughout the codebase have been updated to match the new signature and that the removal of the future supply check does not introduce any issues.

x/mint/types/params.go (2)
  • 13-32: The NewParams and DefaultParams functions have been updated to include new parameters: inflationCoef, bondingAdjustment, and targetBondingRatio. Ensure that these new parameters are correctly used throughout the codebase and that their default values are appropriate.

  • 41-47: The Validate function has been updated to validate the new parameters. This is a good practice to ensure that the parameters are within the expected range and format.

x/mint/types/minter_test.go (6)
  • 18-32: The test cases for NextInflation have been updated to reflect the new inflation calculation method. The new test cases consider different bonded ratios and their expected inflation rates. Ensure that the expected inflation rates are calculated correctly according to the new inflation calculation method.

  • 45-54: The test cases for BlockProvision have been simplified. The totalSupply and targetSupply parameters are no longer considered in the test cases. Ensure that this change is consistent with the updated BlockProvision function.

  • 65-85: A new test function TestNextAnnualProvision has been added. This function tests the NextAnnualProvisions function with different inflation rates and total supplies. Ensure that the expected annual provisions are calculated correctly according to the new annual provision calculation method.

  • 101-128: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [95-105]

The benchmark function BenchmarkBlockProvision has been updated. The totalSupply parameter is no longer considered in the benchmark. Ensure that this change is consistent with the updated BlockProvision function.

  • 112-119: The benchmark function BenchmarkNextInflation has been updated to consider a bonded ratio. Ensure that this change is consistent with the updated NextInflation function.

  • 125-125: The benchmark function BenchmarkNextAnnualProvisions has been updated. The targetSupply parameter is no longer considered in the benchmark. Ensure that this change is consistent with the updated NextAnnualProvisions function.

x/mint/simulation/proposals_test.go (1)
  • 46-46: Ensure that the MintDenom parameter is correctly set to "xKGLwQvuyN" throughout the codebase.
x/mint/migrations/v3/types/params.go (6)
  • 20-28: The function NewParams is used to create a new Params object. It takes three parameters: mintDenom which is a string, annualReductionFactor which is of type sdk.Dec, and blocksPerYear which is of type uint64. The function returns a Params object with these values set. This function is straightforward and does not seem to have any issues.

  • 31-37: The function DefaultParams is used to create a Params object with default values. The MintDenom is set to sdk.DefaultBondDenom, the AnnualReductionFactor is set to 20% per year, and BlocksPerYear is set assuming 5-second block times. This function is straightforward and does not seem to have any issues.

  • 40-49: The Validate function is used to validate the Params object. It checks if the MintDenom, AnnualReductionFactor, and BlocksPerYear are valid. If any of these checks fail, it returns an error. This function is straightforward and does not seem to have any issues.

  • 58-68: The function validateMintDenom is used to validate the MintDenom parameter. It checks if the parameter is of type string and if it is not blank. If these checks pass, it validates the denom using sdk.ValidateDenom. If any of these checks fail, it returns an error. This function is straightforward and does not seem to have any issues.

  • 71-84: The function validateAnnualReductionFactor is used to validate the AnnualReductionFactor parameter. It checks if the parameter is of type sdk.Dec, if it is not negative, and if it is not greater than 1. If any of these checks fail, it returns an error. This function is straightforward and does not seem to have any issues.

  • 86-97: The function validateBlocksPerYear is used to validate the BlocksPerYear parameter. It checks if the parameter is of type uint64 and if it is not zero. If any of these checks fail, it returns an error. This function is straightforward and does not seem to have any issues.

x/mint/simulation/genesis.go (3)
  • 18-22: The simulation parameter constants have been updated to reflect the new parameters introduced in the mint module. The AnnualReductionFactor constant has been replaced with InflationCoef, BondingAdjustment, and TargetBondingRatio. Ensure that these new constants are used correctly throughout the codebase.

  • 57-72: The RandomizedGenState function has been updated to generate random values for the new parameters. The GetOrGenerate function is used to either get the existing value for a parameter or generate a new one. This is done for InflationCoef, TargetBondingRatio, and BondingAdjustment. The generated values are then used to create a new Params object.

  • 76-76: The NewParams function has been updated to include the new parameters. Ensure that the function signature has been updated everywhere it is used.

x/mint/simulation/genesis_test.go (2)
  • 52-54: The test now checks the new parameters InflationCoef, BondingAdjustment, and TargetBondingRatio in the mintGenesis.Params struct. Ensure these values are correctly set in the RandomizedGenState function.

  • 60-60: The NextInflation function now takes an additional argument, sdk.NewDecWithPrec(66, 2). Ensure that this change is reflected in all calls to NextInflation throughout the codebase.

x/mint/abci.go (2)
  • 21-26: The new inflation calculation now considers the total token supply, inflation coefficient, bonding ratio adjustment coefficient, current bonding ratio, and target bonding ratio. The BeginBlocker function has been refactored to recalculate the inflation rate and calculate the bonded ratio. The BlockProvision function now operates without the totalSupply parameter. This change simplifies the code and makes it easier to understand. However, ensure that the new inflation calculation logic is correct and that it doesn't introduce any potential issues or bugs.
-	if uint64(ctx.BlockHeight()) == 1 {
-		minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
-		minter.TargetSupply = totalSupply.Add(minter.AnnualProvisions.TruncateInt())
-		k.SetMinter(ctx, minter)
-	}
-
-	// If we have reached the end of the year by reaching the targeted supply for the year
-	// We need to re-calculate the next inflation for the next year.
-	if totalSupply.GTE(minter.TargetSupply) {
-		minter.Inflation = minter.NextInflation(params)
-		minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
-		minter.TargetSupply = totalSupply.Add(minter.AnnualProvisions.TruncateInt())
-		k.SetMinter(ctx, minter)
-	}
+	// recalculate inflation rate
+	totalSupply := k.TokenSupply(ctx, params.MintDenom)
+	bondedRatio := k.BondedRatio(ctx)
+	minter.Inflation = minter.NextInflation(params, bondedRatio)
+	minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
+	k.SetMinter(ctx, minter)
Committable suggestion (Beta)
	// recalculate inflation rate
	totalSupply := k.TokenSupply(ctx, params.MintDenom)
	bondedRatio := k.BondedRatio(ctx)
	minter.Inflation = minter.NextInflation(params, bondedRatio)
	minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
	k.SetMinter(ctx, minter)
  • 50-50: The addition of the AttributeKeyBondedRatio attribute to the event provides more information about the state of the system at the time of minting. This could be useful for debugging or for tracking the state of the system over time.
+	sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),
Committable suggestion (Beta)
	sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),

x/mint/types/params.go Outdated Show resolved Hide resolved
x/mint/simulation/proposals_test.go Outdated Show resolved Hide resolved
x/mint/migrations/v3/migrations.go Show resolved Hide resolved
x/mint/migrations/v3/migrations.go Show resolved Hide resolved
x/mint/simulation/proposals.go Outdated Show resolved Hide resolved
x/mint/simulation/genesis.go Outdated Show resolved Hide resolved
x/mint/simulation/genesis_test.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 33045db and bfdf5d1.
Files ignored due to filter (1)
  • x/mint/types/mint.pb.go
Files selected for processing (16)
  • proto/mint/v1beta1/mint.proto (1 hunks)
  • x/logic/predicate/uri.go (1 hunks)
  • x/mint/abci.go (2 hunks)
  • x/mint/client/cli/query_test.go (1 hunks)
  • x/mint/keeper/genesis_test.go (2 hunks)
  • x/mint/keeper/keeper_test.go (1 hunks)
  • x/mint/keeper/msg_server_test.go (2 hunks)
  • x/mint/simulation/genesis.go (2 hunks)
  • x/mint/simulation/genesis_test.go (1 hunks)
  • x/mint/simulation/proposals.go (1 hunks)
  • x/mint/simulation/proposals_test.go (1 hunks)
  • x/mint/types/errors.go (1 hunks)
  • x/mint/types/genesis.go (1 hunks)
  • x/mint/types/minter.go (1 hunks)
  • x/mint/types/minter_test.go (3 hunks)
  • x/mint/types/params.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • x/logic/predicate/uri.go
  • x/mint/client/cli/query_test.go
Additional comments: 28
proto/mint/v1beta1/mint.proto (4)
  • 17-29: The summary incorrectly states that the annual_provisions field was renamed to inflation. Both fields are present and distinct in the Minter message.

  • 32-45: The summary incorrectly states that the annual_reduction_factor field was renamed to inflation_coef. There is no annual_reduction_factor field present in the hunk, and inflation_coef appears to be a new addition.

  • 32-45: The summary incorrectly states that the blocks_per_year field was renamed to EstimatedBlocksPerYear. The field name remains blocks_per_year in the hunk.

  • 32-45: The summary incorrectly mentions mint_denom as a new field in the Params message, but it is not new and remains unchanged.

x/mint/abci.go (2)
  • 14-38: The refactoring of the BeginBlocker function to include the new inflation calculation logic and the removal of the block height condition for minter data update align with the PR objectives. The recalculated inflation rate and bonded ratio each block, as well as the refactored minter creation and setting logic, are consistent with the intended changes. The error handling with panic is appropriate given the context of a blockchain application where such errors are critical.

  • 50-56: The event emission in the BeginBlocker function has been updated to include new attributes related to the bonded ratio, inflation, and annual provisions, which aligns with the PR objectives. This change enhances the transparency and traceability of minting operations.

x/mint/keeper/genesis_test.go (2)
  • 6-11: > 💡 NOTE

Codebase verification is a beta feature.

The removal of the "cosmossdk.io/math" import from x/mint/keeper/genesis_test.go does not appear to cause issues within that file, as no other parts of the file were using it. However, the import is still in use in various other files within the codebase. Ensure that the removal does not affect the functionality of those files where the import remains.

  • 61-61: The change in the NewMinter function call in hunk 1 is consistent with the summary and the PR objectives, which indicate an update to the minting module's logic.
x/mint/keeper/keeper_test.go (2)
  • 77-94: The hunk shows updates to the InflationCoef field within the types.Params structure in the TestParams function. However, the summary mentions changes to the AnnualReductionFactor field, which is not present in the hunk. Please verify if the summary is accurate or if there are additional changes not reflected in the hunk.

  • 82-82: The BlocksPerYear field is used in the test cases, but according to the PR objectives, it should have been renamed to EstimatedBlocksPerYear. Please confirm if the field name change is correctly implemented across the codebase.

x/mint/keeper/msg_server_test.go (3)
  • 23-32: The test case "set invalid params for inflation coef (negative value)" correctly sets up a scenario to test the system's behavior with a negative inflation coefficient, which should be invalid according to the PR objectives. This is a good test to ensure that the new validation logic is working as expected.

  • 36-44: The test case "set full valid params" is designed to test the system's behavior with a set of valid parameters, including a positive InflationCoef. This test case is important to confirm that the system accepts valid configurations and the new parameter fields are functioning correctly.

  • 29-29: The PR summary mentions that the BlocksPerYear field has been renamed to EstimatedBlocksPerYear, but the code still uses BlocksPerYear. This inconsistency should be resolved to match the PR objectives and the updated codebase.

Also applies to: 41-41

x/mint/simulation/genesis.go (2)
  • 62-62: The BlocksPerYear field should be renamed to EstimatedBlocksPerYear to align with the PR objectives.

  • 62-62: The summary does not mention the renaming of BlocksPerYear to EstimatedBlocksPerYear, which is inconsistent with the PR objectives.

x/mint/simulation/genesis_test.go (1)
  • 44-58: The test assertions have been updated to reflect the new token model implementation, including the use of NewMinterWithInflationCoef to initialize the minter with inflationCoef and bondedRatio. The assertions check the BlocksPerYear, InflationCoef, MintDenom, BlockProvision, Inflation, and AnnualProvisions of both mintGenesis and minter objects, which align with the PR objectives and the new token model.
x/mint/simulation/proposals.go (2)
  • 37-42: The Params structure in the hunk still uses BlocksPerYear instead of EstimatedBlocksPerYear as mentioned in the summary. Please verify if the field should be renamed or if the summary contains outdated information.

  • 37-42: The changes to the Params structure and the SimulateMsgUpdateParams function align with the PR objectives and the provided summary, indicating a shift in the economic model or inflation calculation logic.

x/mint/simulation/proposals_test.go (2)
  • 42-42: The summary indicates that the BlocksPerYear field has been renamed to EstimatedBlocksPerYear, but the hunk still uses BlocksPerYear. Please verify if the field name in the code should be updated to match the summary or if the summary contains outdated information.

  • 41-44: The test assertions for MsgUpdateParams parameters appear to be correct and align with the PR objectives of updating the mint module with a new token model.

x/mint/types/genesis.go (1)
  • 26-26: The change from a standalone validation function to a method on the Minter type is consistent with the PR objectives and the provided summary. It simplifies the validation process and encapsulates the logic within the Minter type.
x/mint/types/minter.go (1)
  • 10-71: The changes in the x/mint/types/minter.go file align with the PR objectives and the summary of changes. The function signatures and logic have been updated to reflect the new token model, and the code is consistent with the described updates.
x/mint/types/minter_test.go (3)
  • 16-80: The refactoring of TestNextInflation to use the Convey function and the table-driven test cases align with best practices for readability and maintainability. The error handling within the test cases is consistent with the PR objectives.

  • 87-93: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [87-101]

The benchmark function BenchmarkBlockProvision has been updated to use NewMinterWithInitialInflation for creating the minter instance, which is consistent with the PR summary. The use of random values for AnnualProvisions is appropriate for benchmarking purposes.

  • 105-119: The benchmark function BenchmarkNextInflation has been updated to use NewMinterWithInflationCoef, which is consistent with the PR summary. The panic on error is acceptable in the context of a benchmark test, as it indicates a critical failure that should not be ignored.
x/mint/types/params.go (3)
  • 13-30: The changes to the NewParams and DefaultParams functions align with the PR objectives to update the parameter configuration with the new inflation model.

  • 33-41: The update to the Validate function to use validateInflationCoef instead of validateAnnualReductionFactor is in line with the PR objectives and the summary provided.

  • 64-79: The validateInflationCoef function correctly checks for negative values and values greater than one, which is appropriate for an inflation coefficient.

x/mint/types/errors.go Outdated Show resolved Hide resolved
x/mint/types/minter_test.go Show resolved Hide resolved
x/mint/types/params.go Show resolved Hide resolved
x/mint/simulation/genesis.go Show resolved Hide resolved
x/mint/simulation/genesis.go Outdated Show resolved Hide resolved
x/mint/simulation/genesis.go Outdated Show resolved Hide resolved
@ccamel ccamel force-pushed the feat/new-token-model branch from bfdf5d1 to 3c80c97 Compare December 4, 2023 16: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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0fe855c and 3c80c97.
Files ignored due to filter (4)
  • go.mod
  • proto/mint/docs.yaml
  • x/mint/migrations/v3/types/minter.pb.go
  • x/mint/types/mint.pb.go
Files selected for processing (25)
  • Makefile (2 hunks)
  • app/app.go (1 hunks)
  • app/upgrades.go (3 hunks)
  • app/upgrades/v6/upgrade.go (1 hunks)
  • docs/proto/mint.md (2 hunks)
  • proto/mint/v1beta1/mint.proto (1 hunks)
  • x/mint/abci.go (2 hunks)
  • x/mint/client/cli/query_test.go (1 hunks)
  • x/mint/keeper/genesis_test.go (2 hunks)
  • x/mint/keeper/keeper_test.go (1 hunks)
  • x/mint/keeper/migrations.go (1 hunks)
  • x/mint/keeper/msg_server_test.go (2 hunks)
  • x/mint/migrations/v3/migrations.go (1 hunks)
  • x/mint/migrations/v3/types/params.go (1 hunks)
  • x/mint/module.go (4 hunks)
  • x/mint/simulation/decoder_test.go (1 hunks)
  • x/mint/simulation/genesis.go (2 hunks)
  • x/mint/simulation/genesis_test.go (1 hunks)
  • x/mint/simulation/proposals.go (1 hunks)
  • x/mint/simulation/proposals_test.go (1 hunks)
  • x/mint/types/errors.go (1 hunks)
  • x/mint/types/genesis.go (1 hunks)
  • x/mint/types/minter.go (1 hunks)
  • x/mint/types/minter_test.go (3 hunks)
  • x/mint/types/params.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • proto/mint/v1beta1/mint.proto
  • x/mint/keeper/genesis_test.go
  • x/mint/types/params.go
Files skipped from review as they are similar to previous changes (11)
  • x/mint/abci.go
  • x/mint/client/cli/query_test.go
  • x/mint/keeper/keeper_test.go
  • x/mint/keeper/msg_server_test.go
  • x/mint/simulation/genesis.go
  • x/mint/simulation/genesis_test.go
  • x/mint/simulation/proposals.go
  • x/mint/simulation/proposals_test.go
  • x/mint/types/errors.go
  • x/mint/types/genesis.go
  • x/mint/types/minter.go
Additional comments: 25
Makefile (6)
  • 269-275: The summary indicates that additional fields title, summary, and metadata are added to a JSON object within an echo statement, but the hunk shows that these fields are added within a jq command, not an echo statement. This discrepancy should be corrected in the summary.

  • 289-289: The change from block to sync for the broadcast mode in the tx gov deposit command aligns with the PR objectives to change the block mode to sync mode for certain transactions.

  • 307-307: The change from block to sync for the broadcast mode in the tx gov vote command aligns with the PR objectives to change the block mode to sync mode for certain transactions.

  • 276-276: The update to the voting_period within the genesis configuration file is a significant change that should be included in the summary.

  • 291-291: The introduction of a delay before executing the tx gov deposit command with the sleep command is a significant change that should be included in the summary.

  • 300-300: The introduction of a delay before executing the tx gov vote command with the sleep command is a significant change that should be included in the summary.

app/app.go (1)
  • 683-686: The changes to the mint.NewAppModule function call in app/mm instantiation are consistent with the PR objectives and the summary provided. The removal of the app.GetSubspace(minttypes.ModuleName) parameter aligns with the new token model implementation that does not require a subspace for the mint module.
app/upgrades.go (3)
  • 9-12: The addition of the v6 import aligns with the PR objective of introducing a new token model and handling the migration of the x/mint module state.

  • 31-34: The addition of the upgrade handler for version 6 is consistent with the PR objectives, ensuring the new token model and inflation calculation are incorporated into the upgrade process.

  • 53-54: The inclusion of v6.StoreUpgrades is in line with the PR objectives, which require storage migration to support the new token model.

app/upgrades/v6/upgrade.go (2)
  • 12-16: The addition of the "feeibc" store is noted and appears to align with the PR objectives of introducing new functionality.

  • 18-30: The CreateUpgradeHandler function correctly sets up the migration from v5.0.0 to v6.0.0 and appears to be consistent with the PR objectives.

docs/proto/mint.md (2)
  • 6-44: The documentation updates in hunk 0 correctly describe the new token model's calculation mechanism and block-level token minting process, aligning with the PR objectives.

  • 78-107: The documentation updates in hunk 1 correctly reflect the changes to the Minter and Params structures, including the new fields and updated descriptions, which are in line with the PR objectives.

x/mint/keeper/migrations.go (1)
  • 3-21: The changes in the keeper package, including the updated Migrator struct and the new Migrate2to3 function, are consistent with the PR objectives and the provided summary. The removal of legacySubspace and the use of the v3 package align with the migration from version 2 to version 3 of the x/mint module.
x/mint/migrations/v3/migrations.go (2)
  • 26-31: The previous comment about adding a nil check before unmarshalling ParamsKey is still valid and the proposed fix should be applied.

  • 44-49: The previous comment about adding a nil check before unmarshalling MinterKey is still valid and the proposed fix should be applied.

x/mint/migrations/v3/types/params.go (1)
  • 1-97: The provided code does not reflect the changes mentioned in the PR objectives and the summary. The Params struct and related functions do not include the new fields such as inflation_coef, bonding_adjustment, target_bonding_ratio, and the new error variable ErrBondedRatioisZero. Additionally, the Minter struct and methods like BlockProvision and MigrateStore are not present. Please ensure that the code reflects all the changes described in the PR objectives and the summary.
x/mint/module.go (4)
  • 86-98: The NewAppModule function has been updated to remove the legacySubspace parameter, which aligns with the PR objectives of updating the mint module to reflect the new token model. The removal of legacySubspace from the AppModule struct is consistent with the changes in the function signature.

  • 111-123: The migration logic in RegisterServices has been updated to include a migration from version 2 to 3, which is in line with the PR objectives of updating the mint module for the new token model. This change is crucial for ensuring a smooth transition for existing data to the new model.

  • 146-150: The increment of the consensus version to 3 in the ConsensusVersion function is appropriate given the significant changes to the mint module, including the new token model and inflation calculation logic.

  • 151-152: The BeginBlock function calls BeginBlocker with the keeper as a parameter, which is standard for module operations. This change does not appear to be directly related to the new token model implementation but is part of the module's routine operations.

x/mint/simulation/decoder_test.go (1)
  • 23-23: The change in the initialization of the minter variable from three arguments to two is consistent with the PR objectives and the summary provided. This reflects the updated NewMinter function signature.
x/mint/types/minter_test.go (2)
  • 44-48: The previous comment about the hardcoded error message is still valid and does not need to be repeated.

  • 96-119: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [87-117]

The benchmark tests have been updated to reflect the new inflation calculation logic, which is consistent with the PR objectives.

app/upgrades/v6/upgrade.go Outdated Show resolved Hide resolved
x/mint/types/minter_test.go Show resolved Hide resolved
@ccamel ccamel marked this pull request as draft December 4, 2023 16:53
@ccamel ccamel force-pushed the feat/new-token-model branch 2 times, most recently from ea38e07 to 65ed2a8 Compare December 8, 2023 10:36
@ccamel
Copy link
Member

ccamel commented Dec 8, 2023

@coderabbitai pause

@ccamel ccamel force-pushed the feat/new-token-model branch from 65ed2a8 to d43a9a7 Compare December 8, 2023 10:38
@ccamel ccamel marked this pull request as ready for review December 8, 2023 13:46
@ccamel
Copy link
Member

ccamel commented Dec 8, 2023

@amimart I think we're good now. Can you review the PR again? Thanks 🙏

@ccamel ccamel requested a review from amimart December 8, 2023 13:48
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.

👍

@ccamel ccamel removed the request for review from tpelliet December 8, 2023 13:48
@ccamel ccamel assigned ccamel and unassigned bdeneux Dec 8, 2023
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.

Seems good to me, just noted a minor remark :)

x/mint/types/minter.go Outdated Show resolved Hide resolved
Co-authored-by: Arnaud Mimart <[email protected]>
@ccamel ccamel merged commit 6006ba1 into main Dec 11, 2023
20 checks passed
@ccamel ccamel deleted the feat/new-token-model branch December 11, 2023 10:00
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.

🤑 Implements Token model
4 participants