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: make inflation params a collection and add commands to update them #1776

Merged
merged 15 commits into from
Feb 1, 2024

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Jan 24, 2024

Purpose / Abstract

  • Closes #AAA

Summary by CodeRabbit

  • New Features

    • Introduced gRPC service for managing inflation with methods to toggle inflation and edit parameters.
    • Added new message types for editing inflation parameters and toggling inflation state.
    • Implemented sudo functions for administrative control over inflation parameters.
  • Enhancements

    • Modified genesis initialization logic to utilize updated parameter setting methods.
    • Updated query server implementation and associated methods for improved parameter retrieval.
  • Bug Fixes

    • Adjusted test cases to reflect changes in inflation parameter setting logic.
  • Refactor

    • Refactored keeper structure to include new parameter field and initialization logic.
    • Revised module interfaces and service registration to align with updated server implementations.
  • Documentation

    • Updated documentation to reflect new message types and service definitions.
  • Tests

    • Added new test cases for sudo functionality and parameter editing within the inflation module.

@matthiasmatt matthiasmatt requested a review from a team as a code owner January 24, 2024 22:42
Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Warning

Rate Limit Exceeded

@matthiasmatt has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 26 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 61429ce and ba91a1e.

Walkthrough

The inflation module of a blockchain application has undergone a comprehensive update. The changes focus on enhancing the parameter management system, introducing new gRPC services for inflation control, and refining the keeper's functionality. The module now supports dynamic inflation toggling and parameter editing, with improved permission checks and test coverage to ensure robust operation.

Changes

File Path Change Summary
proto/nibiru/inflation/v1/tx.proto Added gRPC service Msg with methods for inflation control.
x/inflation/genesis.go, x/inflation/keeper/keeper.go Updated InitGenesis to use UpdateParams and added Params field.
x/inflation/keeper/grpc_query.go, x/inflation/keeper/params.go Restructured keeper, moved Params method, and updated parameter handling.
x/inflation/keeper/grpc_query_test.go, x/inflation/keeper/hooks_test.go, x/inflation/keeper/inflation_test.go Modified method calls from SetParams to UpdateParams.
x/inflation/keeper/msg_server.go, x/inflation/keeper/msg_server_test.go Introduced new MsgServer interface and related tests for inflation control.
x/inflation/keeper/sudo.go, x/inflation/keeper/sudo_test.go Introduced sudo functionality and added corresponding tests.
x/inflation/module.go Updated function signatures and logic for module interfaces and services.
x/inflation/types/codec.go, x/inflation/types/interfaces.go, x/inflation/types/msgs.go Updated codec registration, interface methods, and introduced new message types.
x/inflation/types/params.go, x/inflation/types/params_test.go Removed functions related to parameter key table and set pairs, and associated tests.
CHANGELOG.md Introduces a new feature related to inflation parameters, making them a collection and adding commands to update them.

Poem

As the moon does wax and wane,
So must inflation rise and restrain.
CodeRabbit hopped through the code with glee,
Crafting parameters as dynamic as can be. 🌕🔧🐇

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ecd125f and a7f0cc2.
Files ignored due to path filters (2)
  • x/inflation/types/tx.pb.go is excluded by: !**/*.pb.go
  • x/inflation/types/tx.pb.gw.go is excluded by: !**/*.pb.gw.go
Files selected for processing (17)
  • proto/nibiru/inflation/v1/tx.proto (1 hunks)
  • x/inflation/genesis.go (1 hunks)
  • x/inflation/keeper/grpc_query.go (2 hunks)
  • x/inflation/keeper/grpc_query_test.go (1 hunks)
  • x/inflation/keeper/hooks_test.go (2 hunks)
  • x/inflation/keeper/inflation_test.go (3 hunks)
  • x/inflation/keeper/keeper.go (3 hunks)
  • x/inflation/keeper/msg_server.go (1 hunks)
  • x/inflation/keeper/params.go (1 hunks)
  • x/inflation/keeper/sudo.go (1 hunks)
  • x/inflation/keeper/sudo_test.go (1 hunks)
  • x/inflation/module.go (2 hunks)
  • x/inflation/types/codec.go (1 hunks)
  • x/inflation/types/interfaces.go (1 hunks)
  • x/inflation/types/msgs.go (1 hunks)
  • x/inflation/types/params.go (2 hunks)
  • x/inflation/types/params_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • x/inflation/types/params_test.go
Additional comments: 26
x/inflation/genesis.go (1)
  • 24-24: The InitGenesis function now uses k.UpdateParams instead of k.SetParams. This change is consistent with the PR's objective to refactor parameter handling.
x/inflation/keeper/params.go (2)
  • 9-10: The UpdateParams method has been added to the Keeper struct to handle parameter updates. Ensure that the Params field is properly initialized and that the UpdateParams method is correctly implemented.
  • 13-15: The GetParams method has been modified to retrieve parameters using the Params field. Ensure that the Params field is correctly populated during initialization and that the GetParams method is retrieving the correct data.
x/inflation/keeper/msg_server.go (2)
  • 21-34: The EditInflationParams method has been added to handle editing inflation parameters. Ensure that the method correctly updates the parameters and that appropriate permission checks are in place.
  • 36-46: The ToggleInflation method has been added to enable or disable inflation. Ensure that the method correctly updates the inflation status and that appropriate permission checks are in place.
x/inflation/types/codec.go (2)
  • 11-16: The RegisterLegacyAminoCodec function has been updated to register new message types. Ensure that the message types are correctly registered and that the codec is properly initialized.
  • 18-25: The RegisterInterfaces function has been updated to register new interface implementations. Ensure that the interface types are correctly registered and that the interface registry is properly initialized.
x/inflation/types/interfaces.go (1)
  • 45-45: A new method CheckPermissions has been added to the SudoKeeper interface. Ensure that this method is implemented correctly and that it is used appropriately to check permissions.
x/inflation/types/msgs.go (2)
  • 19-38: The MsgEditInflationParams message type has been added with methods to satisfy the sdk.Msg interface. Ensure that the methods are correctly implemented and that the message type is properly used.
  • 49-75: The MsgToggleInflation message type has been added with methods to satisfy the sdk.Msg interface. Ensure that the methods are correctly implemented and that the message type is properly used.
proto/nibiru/inflation/v1/tx.proto (1)
  • 11-21: New RPC methods ToggleInflation and EditInflationParams have been defined in the tx.proto file. Ensure that these methods are correctly implemented in the corresponding server and that the RPC endpoints are properly exposed.
x/inflation/keeper/keeper.go (1)
  • 30-30: The Keeper struct now includes a new field Params for inflation parameters. Ensure that this field is properly initialized in the NewKeeper function and that it is used correctly throughout the module.
x/inflation/keeper/grpc_query_test.go (1)
  • 98-98: The test for the Params method has been updated to use the new Params field. Ensure that the test correctly retrieves the parameters and that the expected behavior is validated.
x/inflation/keeper/sudo.go (2)
  • 27-46: The EditInflationParams method in the sudoExtension struct has been added to handle administrative updates to inflation parameters. Ensure that the method correctly merges and validates the new parameters.
  • 48-63: The ToggleInflation method in the sudoExtension struct has been added to enable or disable inflation. Ensure that the method correctly updates the inflation status and that the change is persisted.
x/inflation/keeper/grpc_query.go (1)
  • 12-35: The querier type has been introduced, and the Params function has been moved from the Keeper type to the new querier type. Ensure that the querier type is correctly implemented and that the Params function is correctly moved.
x/inflation/types/params.go (1)
  • 5-10: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-90]

Functions related to parameter key tables and parameter set pairs have been removed from params.go. Ensure that the removal of these functions does not affect the module's ability to manage parameters correctly.

x/inflation/keeper/hooks_test.go (1)
  • 18-24: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [21-157]

The hooks_test.go file has been updated to use the UpdateParams method instead of SetParams. Ensure that the tests are updated accordingly and that they correctly test the new behavior.

x/inflation/keeper/sudo_test.go (3)
  • 22-69: The MergeInflationParams function is tested to ensure it correctly merges new parameters into the existing ones. Verify that the test covers all scenarios and that the merged parameters are validated.
  • 71-116: The EditInflationParams method is tested to ensure it correctly updates the inflation parameters. Verify that the test checks for all parameter changes and that the updated parameters are validated.
  • 118-133: The ToggleInflation method is tested to ensure it correctly enables and disables inflation. Verify that the test checks the updated inflation status and that the changes are persisted.
x/inflation/module.go (2)
  • 51-53: The RegisterInterfaces method has been updated to register the module's interface types. Ensure that the interface types are correctly registered and that the interface registry is properly initialized.
  • 119-123: The RegisterServices method has been updated to register module services and utilize new server implementations. Ensure that the services are correctly registered and that the new server implementations are properly utilized.
x/inflation/keeper/inflation_test.go (3)
  • 140-140: The UpdateParams method is used correctly in place of SetParams. Ensure that the new method's behavior aligns with the test expectations.
  • 155-155: The UpdateParams method is used correctly in place of SetParams. Verify that the behavior of UpdateParams is consistent with the intended logic of the test case.
  • 165-165: The UpdateParams method is used correctly in place of SetParams. Confirm that the UpdateParams method performs as expected within the test's context.

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Attention: 44 lines in your changes are missing coverage. Please review.

Comparison is base (19fb4e5) 73.13% compared to head (61429ce) 73.08%.

❗ Current head 61429ce differs from pull request most recent head ba91a1e. Consider uploading reports for the commit ba91a1e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1776      +/-   ##
==========================================
- Coverage   73.13%   73.08%   -0.05%     
==========================================
  Files         192      196       +4     
  Lines       15472    15566      +94     
==========================================
+ Hits        11315    11376      +61     
- Misses       3496     3526      +30     
- Partials      661      664       +3     
Files Coverage Δ
x/inflation/keeper/grpc_query.go 100.00% <100.00%> (ø)
x/inflation/keeper/keeper.go 90.00% <100.00%> (-0.91%) ⬇️
x/inflation/keeper/msg_server.go 100.00% <100.00%> (ø)
x/inflation/keeper/params.go 100.00% <100.00%> (ø)
x/inflation/types/params.go 70.96% <ø> (+7.50%) ⬆️
x/inflation/types/codec.go 50.00% <50.00%> (ø)
x/inflation/keeper/sudo.go 79.06% <79.06%> (ø)
x/inflation/types/msgs.go 0.00% <0.00%> (ø)

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 a7f0cc2 and f1a2ef7.
Files selected for processing (1)
  • x/inflation/keeper/msg_server_test.go (1 hunks)

x/inflation/keeper/msg_server_test.go Outdated Show resolved Hide resolved
x/inflation/keeper/msg_server_test.go Outdated Show resolved Hide resolved
matthiasmatt and others added 3 commits January 30, 2024 00:37
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f1a2ef7 and 990dfd7.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

x/inflation/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/inflation/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/inflation/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/inflation/keeper/grpc_query_test.go Show resolved Hide resolved
x/inflation/keeper/sudo.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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 990dfd7 and a5133b6.
Files selected for processing (1)
  • x/inflation/keeper/grpc_query.go (2 hunks)
Additional comments: 3
x/inflation/keeper/grpc_query.go (3)
  • 12-15: The introduction of the querier struct, which embeds the Keeper struct, is a good design choice for separating query handling logic from the main keeper logic. This change enhances modularity and clarity in the codebase.
  • 17-21: The NewQuerier function correctly instantiates a querier with the provided Keeper. This approach ensures that the query handling logic has access to all necessary keeper functionalities.
  • 9-39: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [37-57]

The Period, EpochMintProvision, SkippedEpochs, InflationRate, and CirculatingSupply functions remain within the Keeper type, which is appropriate as they pertain to core business logic rather than query handling. Ensure that their implementations are consistent with the new design and that they interact correctly with the updated querier type where necessary.

x/inflation/keeper/grpc_query.go Outdated Show resolved Hide resolved
@matthiasmatt matthiasmatt enabled auto-merge (squash) January 30, 2024 13:01
@Unique-Divine Unique-Divine enabled auto-merge (squash) January 31, 2024 01:06
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a5133b6 and 61429ce.
Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • x/inflation/keeper/grpc_query.go (2 hunks)
  • x/inflation/keeper/grpc_query_test.go (2 hunks)
  • x/inflation/keeper/msg_server_test.go (1 hunks)
  • x/inflation/keeper/sudo.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • CHANGELOG.md
  • x/inflation/keeper/grpc_query_test.go
  • x/inflation/keeper/msg_server_test.go
  • x/inflation/keeper/sudo.go
Additional comments: 4
x/inflation/keeper/grpc_query.go (4)
  • 12-15: The introduction of the querier struct, which embeds the Keeper struct, is a good design choice for separating query handling logic from the main Keeper logic. This change enhances modularity and clarity in the codebase.
  • 17-21: The NewQuerier function correctly instantiates a querier with the provided Keeper. This approach ensures that the querier has access to all methods of Keeper, facilitating a clean separation of concerns between querying and state management.
  • 26-31: Moving the Params function to the querier type aligns with the objective of separating query handling from the main Keeper logic. This change is consistent with the overall design goal of enhancing modularity and clarity. Ensure that all references to the Params function throughout the codebase are updated to use the querier type.
  • 9-34: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [33-65]

The retention of functions such as Period, EpochMintProvision, SkippedEpochs, InflationRate, and CirculatingSupply within the Keeper type is appropriate, as these functions pertain to the core responsibilities of the Keeper. However, ensure that the logic within these functions does not inadvertently depend on the now-removed Params function from the Keeper type, which could lead to issues.

Verification successful

The executed script aimed to verify if the retained functions Period, EpochMintProvision, SkippedEpochs, and InflationRate in the Keeper type depend on a potentially removed Params function. The script did not produce any output, indicating that these functions do not call a Params method within their bodies. This suggests that the concern raised in the review comment about these functions inadvertently depending on a removed Params function is unfounded based on the script's findings.

Given this information, it can be concluded that the functions mentioned in the review comment do not depend on the Params function, aligning with the initial approval of retaining these functions within the Keeper type without issues related to the removal of the Params function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the retained functions do not depend on the removed Params function.
ast-grep --lang go --pattern $'func (k Keeper) $_($_, $_) {
  $$$
  k.Params($_)
  $$$
}'

Length of output: 90

@Unique-Divine Unique-Divine merged commit d17c887 into main Feb 1, 2024
13 checks passed
@Unique-Divine Unique-Divine deleted the mat/change-inflation-params branch February 1, 2024 15:15
k-yang pushed a commit that referenced this pull request Feb 9, 2024
…hem (#1776)

* feat: make inflation params a collection and add commands to update them

* fix: more tests

* chore: changelog

* Update x/inflation/keeper/grpc_query.go

Co-authored-by: Unique Divine <[email protected]>

* Update x/inflation/keeper/grpc_query.go

Co-authored-by: Unique Divine <[email protected]>

* Update x/inflation/keeper/sudo.go

Co-authored-by: Unique Divine <[email protected]>

* fix: fix tests and improve function

* fix: add test for queryserver

---------

Co-authored-by: Unique Divine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants