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: add inflation events detailed distribution #1695

Merged
merged 8 commits into from
Dec 7, 2023

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Dec 6, 2023

Description

Purpose

Why is this PR important?

Summary by CodeRabbit

  • New Features

    • Introduced events for inflation distribution, enhancing transparency in reward allocation.
    • Implemented new error handling strategies with formatted messages for improved clarity.
  • Enhancements

    • Added logic to set up genesis states for epochs and sudo modules, ensuring a smoother initialization process.
    • Improved test setups and error message clarity in various modules.
  • Refactor

    • Renamed methods for consistency and clarity, such as changing GetRoot to GetRootAddr.
    • Restructured variable declarations for better readability.
  • Documentation

    • Updated comments to reflect changes in default genesis states and error handling.
  • Bug Fixes

    • Fixed test case configurations and updated test assertions for accuracy.
  • Style

    • Adjusted code formatting for better maintainability.

@matthiasmatt matthiasmatt requested a review from a team as a code owner December 6, 2023 15:35
Copy link
Contributor

coderabbitai bot commented Dec 6, 2023

Walkthrough:
The changes revolve around enhancing the inflation event details within a blockchain protocol. A new protocol buffer message InflationDistributionEvent has been introduced to encapsulate details about staking rewards, strategic reserves, and community pool distributions. Additionally, the AllocatePolynomialInflation function in the inflation keeper now emits an event before returning values, and various other files have been updated to reflect changes in error handling, testing, and interface method renaming.

Changes:

File Path Change Summary
proto/nibiru/inflation/v1/event.proto Introduced InflationDistributionEvent message.
x/inflation/keeper/inflation.go Added event emission in AllocatePolynomialInflation.
CHANGELOG.md Documented new feature for inflation event details.
x/common/testutil/testapp/testapp.go Added logic for setting genesis for epochs and sudo modules.
x/inflation/keeper/inflation_test.go Updated error handling and balance comparison in tests.
x/inflation/types/interfaces.go Renamed GetRoot to GetRootAddr in SudoKeeper interface.
x/sudo/... Various updates including error handling, function renaming, and genesis state validation.
x/tokenfactory/... Test case updates and restructuring of variable declarations.
x/oracle/integration/app_test.go Added SetupSuite method and testutil package import.

Assessment against linked issues:

Objective Addressed Explanation
Add more details to the inflation event for tracking and stats generation (#1692) The InflationDistributionEvent message and the event emission in AllocatePolynomialInflation address this objective.

Poem:

In the code where logic weaves, 🐇💻
A rabbit hops through lines with ease,
With each commit, the details grow,
Inflation tracked, the blockchain flows. 🌟🌊


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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cf8bea5 and 4fdff12.
Files ignored due to filter (1)
  • x/inflation/types/event.pb.go
Files selected for processing (2)
  • proto/nibiru/inflation/v1/event.proto (1 hunks)
  • x/inflation/keeper/inflation.go (1 hunks)
Additional comments: 2
proto/nibiru/inflation/v1/event.proto (1)
  • 1-26: The InflationDistributionEvent protobuf message has been correctly defined with the required fields and serialization metadata.
x/inflation/keeper/inflation.go (1)
  • 92-98: The addition of the InflationDistributionEvent emission is consistent with the PR objectives and the summary provided. It correctly includes the staking, strategic, and community fields as per the new protocol buffer message definition.

x/inflation/keeper/inflation.go Outdated Show resolved Hide resolved
x/inflation/keeper/inflation.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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4fdff12 and a95cee7.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)

Copy link
Member

@Unique-Divine Unique-Divine left a comment

Choose a reason for hiding this comment

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

--- FAIL: TestMintAndAllocateInflation (0.10s)
--- FAIL: TestMintAndAllocateInflation/Case_pass_-no_root_account (0.04s)
inflation_test.go:75: setting root account to
inflation_test.go:82:
Error Trace: /home/runner/work/nibiru/nibiru/x/inflation/keeper/inflation_test.go:82
Error: Received unexpected error:
empty address string is not allowed
Test: TestMintAndAllocateInflation/Case_pass
-_no_root_account

@Unique-Divine Unique-Divine enabled auto-merge (squash) December 7, 2023 07:19
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 8adab45 and 1ecad2d.
Files ignored due to filter (2)
  • x/inflation/types/event.pb.go
  • x/sudo/types/state.pb.go
Files selected for processing (12)
  • CHANGELOG.md (1 hunks)
  • proto/nibiru/inflation/v1/event.proto (1 hunks)
  • x/common/testutil/testapp/testapp.go (1 hunks)
  • x/inflation/keeper/inflation.go (2 hunks)
  • x/inflation/keeper/inflation_test.go (2 hunks)
  • x/inflation/types/interfaces.go (1 hunks)
  • x/sudo/genesis.go (1 hunks)
  • x/sudo/keeper/keeper.go (1 hunks)
  • x/sudo/keeper/msg_server_test.go (3 hunks)
  • x/sudo/types/errors.go (1 hunks)
  • x/sudo/types/genesis.go (1 hunks)
  • x/sudo/types/state.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • proto/nibiru/inflation/v1/event.proto
Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • x/inflation/keeper/inflation.go
Additional comments: 11
x/common/testutil/testapp/testapp.go (1)
  • 32-49: The changes made to x/common/testutil/testapp/testapp.go correctly implement the logic to set a happy genesis state for the epochs and sudo modules, as described in the PR objectives and the AI-generated summaries. This will facilitate testing by providing a default, valid genesis state for these modules.
x/inflation/keeper/inflation_test.go (3)
  • 81-87: The error handling logic has been updated to check for the presence of tc.rootAccount. If tc.rootAccount is not empty, it requires that no error occurs, otherwise, it requires that an error does occur. This is a logical way to handle the test cases based on whether a root account is provided or not.

  • 88-90: The balance assertions have been updated to compare the expected amounts directly without converting them to strings. This is a more accurate way to compare balances as it avoids potential issues with string formatting and comparison.

  • 115-124: The balance comparison assertions have been updated to compare string representations of the balances. This change is consistent with the summary provided and is a valid way to compare balances, ensuring that the comparison is not affected by any internal representation differences of the sdk.Coin and sdk.DecCoins types.

x/inflation/types/interfaces.go (1)
  • 43-44: The change from GetRoot to GetRootAddr in the SudoKeeper interface is consistent with the PR objectives and the provided summaries.
x/sudo/genesis.go (1)
  • 31-35: The comment added to the DefaultGenesis function provides clarity on the invalidity of the default genesis state due to the absence of "Sudoers.Root". This is a good practice as it helps developers understand the expected structure of a valid genesis state.
x/sudo/keeper/keeper.go (1)
  • 29-33: The function GetRoot has been successfully renamed to GetRootAddr. Ensure that all calls to this function throughout the codebase have been updated to match the new function name.

The function GetRoot has been successfully renamed to GetRootAddr, and references to the new function name have been confirmed in the codebase.

Commands executed:

  • rg 'GetRoot\('
  • rg 'GetRootAddr\('

Inference:

  • The first command did not find any occurrences of the old function name, indicating all references have likely been updated.
  • The second command found multiple references to the new function name, confirming the updates.
x/sudo/keeper/msg_server_test.go (2)
  • 26-28: The refactoring of the setup function to use testapp.NewNibiruTestAppAndContextAtTime simplifies the test setup process and ensures consistency across tests. Ensure that the new method provides the necessary context setup for all tests that rely on it.

  • 37-41: The test case has been updated to use panic: true instead of an empty field. Verify that this change accurately reflects the intended behavior of the test case and that the test is still valid and meaningful.

x/sudo/types/genesis.go (1)
  • 9-15: The changes to the Validate function correctly implement the use of the custom error type ErrGenesis for more specific error handling. This aligns with the PR objectives to enhance error handling.
x/sudo/types/state.go (1)
  • 9-18: The changes to the Validate method correctly introduce additional validation for the root address and contract addresses, ensuring they are valid Bech32 addresses. This enhances the robustness of the validation logic.

x/sudo/types/errors.go Outdated Show resolved Hide resolved
x/sudo/genesis.go Show resolved Hide resolved
@Unique-Divine Unique-Divine force-pushed the mat/event-inflation-detail branch from 92b20dd to e80ea3f Compare December 7, 2023 07:46
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 1ecad2d and e80ea3f.
Files selected for processing (6)
  • x/common/testutil/testapp/testapp.go (3 hunks)
  • x/oracle/integration/app_test.go (2 hunks)
  • x/sudo/types/errors.go (1 hunks)
  • x/tokenfactory/keeper/msg_server_test.go (1 hunks)
  • x/tokenfactory/types/state_test.go (3 hunks)
  • x/tokenfactory/types/tx_msgs.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • x/tokenfactory/keeper/msg_server_test.go
  • x/tokenfactory/types/state_test.go
Files skipped from review as they are similar to previous changes (3)
  • x/common/testutil/testapp/testapp.go
  • x/sudo/types/errors.go
  • x/tokenfactory/types/tx_msgs.go
Additional comments: 3
x/oracle/integration/app_test.go (3)
  • 11-17: The addition of the testutil package import and related packages is consistent with the PR objectives and the AI-generated summaries.

  • 27-29: The addition of the SetupSuite method to the IntegrationTestSuite type is consistent with the PR objectives and the AI-generated summaries.

  • 31-33: The changes in the SetupTest method are not mentioned in the AI-generated summaries, but since they are not related to the declarations of exported entities, this is acceptable.

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 e80ea3f and a82a0d8.
Files selected for processing (2)
  • app/ibc_test.go (1 hunks)
  • x/common/testutil/testapp/testapp.go (4 hunks)
Additional comments: 4
app/ibc_test.go (1)
  • 34-39: The addition of testapp.SetDefaultSudoGenesis(genesisState) in SetupNibiruTestingApp aligns with the PR's objective to enhance the inflation event details and improve the testing setup. Ensure that this new default genesis setting is correctly integrated with the rest of the test suite and does not introduce any inconsistencies.
x/common/testutil/testapp/testapp.go (3)
  • 25-27: The addition of the init function to set the Bech32 prefix is a good practice to ensure consistency across tests.

  • 36-52: The logic added to set happy genesis for epochs and sudo modules is correctly implemented and will help in initializing the test app with a consistent state.

  • 83-93: The summary does not mention the addition of the SetDefaultSudoGenesis function, which sets the sudo module genesis state to a valid default. This function is important for initializing the genesis state and should be included in the summary.

x/common/testutil/testapp/testapp.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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a82a0d8 and d449ffa.
Files selected for processing (8)
  • wasmbinding/test/cli_test.go (2 hunks)
  • x/common/testutil/genesis/genesis.go (2 hunks)
  • x/common/testutil/testapp/testapp.go (4 hunks)
  • x/oracle/integration/app_test.go (2 hunks)
  • x/perp/v2/client/cli/cli_test.go (2 hunks)
  • x/spot/client/testutil/cli_test.go (2 hunks)
  • x/sudo/cli/cli_test.go (2 hunks)
  • x/tokenfactory/cli/cli_test.go (1 hunks)
Additional comments: 20
wasmbinding/test/cli_test.go (2)
  • 21-27: The addition of the testapp import and related packages is consistent with the changes described in the summary.

  • 43-48: The replacement of app.SetPrefixes(app.AccountAddressPrefix) with testapp.EnsureNibiruPrefix() is consistent with the summary and seems to be a refactoring to use a more specific function from the testapp package.

x/common/testutil/genesis/genesis.go (3)
  • 9-13: The import statement for github.com/NibiruChain/nibiru/x/common/testutil/testapp is correctly added to support the new function call.

  • 29-34: The call to testapp.SetDefaultSudoGenesis(genState) is correctly placed to set up the default genesis state for the sudo module in the test environment. Ensure that the SetDefaultSudoGenesis function is properly defined and exported in the testapp package.


The call to testapp.SetDefaultSudoGenesis(genState) is correctly placed to set up the default genesis state for the sudo module in the test environment. The SetDefaultSudoGenesis function is confirmed to be properly defined and exported in the testapp package.

  • 29-30: The modification to the governance module's genesis state to set a minimum deposit is a logical change for test setup, ensuring that tests can be run with a consistent and expected environment.
x/common/testutil/testapp/testapp.go (4)
  • 25-27: The addition of the init() function to ensure a specific prefix is a good practice to avoid runtime errors related to address prefixes.

  • 36-48: The logic added to set up the genesis state for the epochs and sudo modules is correct and aligns with the summary.

  • 83-93: The addition of the SetDefaultSudoGenesis function to set the sudo module genesis state to a valid default is a good practice for maintainability and ensuring a consistent test environment.

  • 108-115: The NewNibiruTestApp function now includes a call to SetDefaultSudoGenesis to ensure the sudo module has a valid genesis state upon app initialization. This change was not mentioned in the summary and is important for ensuring a consistent test environment.

x/oracle/integration/app_test.go (1)
  • 25-26: The summary does not mention the addition of the network field to the IntegrationTestSuite type. This field is crucial for the setup and execution of integration tests, as it represents the test network being used.
x/perp/v2/client/cli/cli_test.go (3)
  • 18-21: The addition of the testapp import is consistent with the PR objectives and the summary provided.

  • 38-38: The change from app.SetPrefixes(app.AccountAddressPrefix) to testapp.EnsureNibiruPrefix() aligns with the PR objectives and the summary provided.

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

No further issues or inconsistencies found in the provided hunks.

x/spot/client/testutil/cli_test.go (3)
  • 10-13: The addition of the testapp import is consistent with the PR objectives and the summary provided.

  • 28-28: Refactoring to use testapp.EnsureNibiruPrefix() improves maintainability by centralizing the prefix setup logic.

  • 31-31: The call to WhitelistGenesisAssets modifies the genesis state, which is a significant change not mentioned in the summary. This should be documented as it affects the test setup.

x/sudo/cli/cli_test.go (3)
  • 25-30: The addition of the testapp import is consistent with the summary provided.

  • 104-106: The replacement of app.SetPrefixes(app.AccountAddressPrefix) with testapp.EnsureNibiruPrefix() in the SetupSuite method aligns with the summary provided.

  • 104-106: Please verify that the change from app.SetPrefixes to testapp.EnsureNibiruPrefix() does not affect other tests or parts of the codebase that may rely on the address prefixes being set in a specific way.


The change from app.SetPrefixes to testapp.EnsureNibiruPrefix() is localized to the SetupSuite method in x/sudo/cli/cli_test.go. Other occurrences of app.SetPrefixes are found in different files, indicating that the change does not globally affect the setting of address prefixes in the codebase. However, it's important to ensure that the new method testapp.EnsureNibiruPrefix() sets the prefixes in a compatible manner with app.SetPrefixes.

x/tokenfactory/cli/cli_test.go (1)
  • 42-42: The summary indicates that the line testutil.BeforeIntegrationSuite(s.T()) was removed, but it is still present in the provided code. Please verify if the summary is outdated or if the code change was not applied as intended.

@Unique-Divine Unique-Divine merged commit b04e0ad into main Dec 7, 2023
15 checks passed
@Unique-Divine Unique-Divine deleted the mat/event-inflation-detail branch December 7, 2023 09:33
k-yang pushed a commit that referenced this pull request Dec 8, 2023
* feat: add inflation events detailed distribution

* chore: changelog

* fix: improve error handling

* fix: broken unit test + make x/sudo safer by making blank genesis invalid

* refactor: run gofumpt formatter

---------

Co-authored-by: Unique-Divine <realuniquedivine@gmail.com>
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.

feat: add more details to the inflation event
3 participants