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/protocolpool): Add Implementation for CreateContinuousFund and CancelContinuousFund features #18471

Merged
merged 112 commits into from
Jan 9, 2024

Conversation

likhita-809
Copy link
Contributor

@likhita-809 likhita-809 commented Nov 15, 2023

Description

Closes: #18374


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
  • added ! to 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
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • 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 ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced a new Continuous Fund feature, allowing for the creation of funds that distribute resources continuously until a cap or expiry is reached.
    • Added the ability to create and cancel continuous funds through new proposal types.
    • Implemented an EndBlocker function to process continuous fund distributions at the end of each block.
  • Enhancements

    • Updated the GenesisState to include continuous funds, enabling initialization and export of this state.
    • Improved validation for continuous funds and budget proposals during genesis initialization.
  • Bug Fixes

    • Fixed issues with continuous fund proposal handling, ensuring proper distribution and expiry behavior.
    • Corrected genesis export functionality to accurately reflect the current state of continuous funds and budget proposals.
  • Documentation

    • Updated the README to include information on the new continuous fund messages and their error conditions.
  • Testing

    • Added comprehensive tests for the EndBlocker function to ensure correct continuous fund behavior.
    • Expanded test coverage for genesis state initialization and export functions.
  • Refactor

    • Streamlined the creation and cancellation of continuous funds by refining message structures and server logic.
    • Enhanced the keeper logic for better management of continuous funds within the protocol pool module.

Copy link
Contributor

coderabbitai bot commented Nov 15, 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 introduce a system for creating and managing continuous funds within the Cosmos SDK, allowing for the allocation of funds via inflation/fees to specified recipients over time. This includes the ability to define funds at genesis, add new funds through governance, and handle fund distribution and cancellation. The system supports setting a cap, expiry, and distribution percentage for each fund.

Changes:

File Pattern Change Summary
proto/cosmos/protocolpool/v1/* Introduced new protobuf messages for continuous funds, including genesis state and transaction messages.
x/protocolpool/* Added functionality for creating, updating, and managing continuous funds, including CLI commands, keeper logic, and end-block processing.
simapp/*, testutil/* Integrated the new protocol pool module into the application configuration and testing utilities.
x/gov/client/cli/prompt.go Added a new proposal type for creating continuous funds.
api/cosmos/protocolpool/v1/genesis.pulsar.go Generated Go file for handling genesis state related to continuous funds.

Assessment against linked issues:

Objective Addressed Explanation
Define long-lived funds for developers or other groups that will be topped up over time (#18374)
Add a way to define funds at genesis and dynamically through governance (#18374)
Include a distribution split for funds, ensuring the total equates to 100% (#18374) The changes include percentage allocation for continuous funds, but it's unclear if there's a validation to ensure all funds total 100%.
Avoid moving funds to a multisig with less oversight (#18374)
Allow application developers to define funds (#18374)

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • 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.

@likhita-809
Copy link
Contributor Author

@coderabbitai review

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4ee4046 and dfc8631.
Files ignored due to filter (1)
  • x/protocolpool/types/types.pb.go
Files selected for processing (14)
  • api/cosmos/protocolpool/v1/types.pulsar.go (5 hunks)
  • proto/cosmos/protocolpool/v1/types.proto (1 hunks)
  • simapp/app.go (2 hunks)
  • x/gov/client/cli/prompt.go (1 hunks)
  • x/protocolpool/abci.go (1 hunks)
  • x/protocolpool/autocli.go (2 hunks)
  • x/protocolpool/keeper/keeper.go (4 hunks)
  • x/protocolpool/keeper/keeper_test.go (1 hunks)
  • x/protocolpool/keeper/msg_server.go (1 hunks)
  • x/protocolpool/module.go (6 hunks)
  • x/protocolpool/testutil/expected_keepers_mocks.go (2 hunks)
  • x/protocolpool/types/codec.go (1 hunks)
  • x/protocolpool/types/expected_keepers.go (2 hunks)
  • x/protocolpool/types/keys.go (1 hunks)
Files not summarized due to errors (1)
  • api/cosmos/protocolpool/v1/types.pulsar.go: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • x/protocolpool/types/codec.go
Additional comments: 29
x/gov/client/cli/prompt.go (1)
  • 49-58: The addition of the "create-continuous-fund" proposal type is consistent with the pull request's description of adding new features for creating continuous funds. This change allows users to create proposals of this new type via the CLI, which is a necessary update for the new functionality to be accessible.
x/protocolpool/keeper/keeper_test.go (1)
  • 48-60: The addition of the distrKeeper to the poolKeeper initialization is consistent with the changes described in the pull request summary. This update is necessary to support the new features related to continuous funds. Ensure that the distrKeeper mock is properly set up with expectations for any methods that will be called during the tests.
x/protocolpool/types/keys.go (1)
  • 18-24: The introduction of a new key ContinuousFundKey is consistent with the Cosmos SDK's pattern of using prefixed keys for different data types within a module's store. This change seems appropriate for the new feature being added and does not appear to conflict with existing keys.
x/protocolpool/testutil/expected_keepers_mocks.go (2)
  • 9-15: The addition of the math package import is necessary for the new GetCommunityTax method which returns a math.LegacyDec. This change is appropriate as long as the math.LegacyDec type is being used in the codebase.

  • 198-204: The new GetCommunityTax method has been added to the MockDistributionKeeper interface. This method should correctly simulate the behavior of the actual DistributionKeeper's GetCommunityTax method. Ensure that the mock implementation aligns with the expected behavior in tests, including error handling and return values.

simapp/app.go (2)
  • 325-330: The order of keeper initialization and the PoolKeeper dependency on DistrKeeper could lead to a potential initialization cycle or nil reference if not handled correctly. Ensure that the DistrKeeper is fully initialized before being passed to the PoolKeeper. This might require reordering the initialization sequence or ensuring that the necessary dependencies for DistrKeeper are set up beforehand.

  • 421-424: The addition of DistrKeeper to the protocolpool.NewAppModule call is consistent with the changes described in the pull request summary. This change integrates the distribution keeper into the protocol pool module, which is necessary for the new continuous funds feature to interact with the distribution module.

api/cosmos/protocolpool/v1/types.pulsar.go (4)
  • 931-981: The implementation of the _ContinuousFund_6_list type and its methods seems correct. It provides the necessary functionality to manipulate a list of v1beta1.Coin pointers as required by the protobuf reflection API. However, ensure that the v1beta1.Coin type is compatible with the expected operations, especially in the Set and Append methods where type assertions are used.

  • 1940-2030: The ContinuousFund struct is well-defined with appropriate protobuf field tags and JSON annotations. The getters for each field are also correctly implemented. Ensure that the Percentage field's format is validated elsewhere in the code, as it is a string that likely represents a numeric value.

  • 2131-2151: The initialization of file_cosmos_protocolpool_v1_types_proto_msgTypes and file_cosmos_protocolpool_v1_types_proto_goTypes is standard for protobuf-generated Go code. The dependency indexes are correctly mapped to the corresponding types. No issues here.

  • 2172-2191: This exporter function is part of the protobuf message registration process. It correctly exports the internal fields of the ContinuousFund message type for internal use by the protobuf library. This is boilerplate code generated by the protoc compiler and should work as intended.

x/protocolpool/types/expected_keepers.go (2)
  • 4-10: The import of the math package from cosmossdk.io is correctly placed and follows the standard Go convention of grouping standard library imports separately from third-party imports. Ensure that the math package is used elsewhere in the codebase to avoid importing it unnecessarily.

  • 27-29: The addition of the GetCommunityTax method to the DistributionKeeper interface is consistent with the summary provided. Ensure that all implementations of the DistributionKeeper interface are updated to include this new method to avoid compilation errors.

x/protocolpool/keeper/keeper.go (6)
  • 22-26: The addition of distrKeeper to the Keeper struct is consistent with the changes described in the summary. Ensure that all necessary checks and balances are in place when interacting with the DistributionKeeper to avoid potential security issues.

  • 31-34: The addition of ContinuousFund to the Keeper struct is a significant change. It's important to ensure that the map is properly initialized and that all CRUD operations are correctly implemented to prevent data inconsistencies.

  • 37-41: The update to the NewKeeper function signature to include a DistributionKeeper is in line with the changes described. Ensure that all instances where NewKeeper is called are updated accordingly.

  • 47-57: The initialization of ContinuousFund using collections.NewMap is correct. However, ensure that the schema is properly built and that no errors are encountered during the build process, as this could lead to a panic.

  • 234-278: The validateandUpdateContinuousFund function is a new addition and should be thoroughly tested to ensure that all validation checks are correct and that the function behaves as expected under various conditions.

  • 281-323: The ContinuousDistribution function is another critical addition. It is essential to ensure that the distribution logic is secure and that edge cases are handled, such as when the community tax is zero, the pool amount is insufficient, or the recipient address is invalid. Additionally, the function should handle the case where the distribution amount exceeds the cap correctly.

x/protocolpool/module.go (7)
  • 17-23: The import statement for sdk "github.com/cosmos/cosmos-sdk/types" has been added. This is a standard Cosmos SDK import and is necessary for the module's functionality.

  • 30-35: The AppModule struct now implements the appmodule.HasEndBlocker interface, which indicates that the module provides an EndBlock function. This is part of the new functionality to handle the distribution logic for continuous funds at the end of each block.

  • 64-68: The AppModule struct has been updated to include a DistrKeeper field of type types.DistributionKeeper. This is necessary for the module to interact with the distribution keeper, which is part of the new features being added.

  • 85-95: The NewAppModule function has been updated to accept a distrKeeper parameter and pass it to the AppModule struct. This change is necessary to provide the AppModule with access to the distribution keeper.

  • 100-104: The EndBlock function has been implemented to call EndBlocker with the current context and the module's keeper. This is where the logic for processing continuous funds at the end of each block will be executed.

  • 123-127: The ModuleInputs struct has been updated to include a DistrKeeper field. This is part of the dependency injection pattern used in the Cosmos SDK to provide the necessary dependencies to the module.

  • 140-147: The ProvideModule function has been updated to create a new keeper.Keeper with the DistrKeeper and to pass the DistrKeeper to the NewAppModule function. This is part of the setup for the module's dependency injection.

x/protocolpool/autocli.go (2)
  • 63-74: The create-continuous-fund command includes optional fields metadata and expiry. Ensure that the command-line interface handles these optional arguments correctly and that the backend logic is prepared to process requests without these fields if they are not provided.

  • 78-84: The cancel-continuous-fund command is correctly set up with the necessary positional argument recipient_address. Ensure that the corresponding backend logic correctly handles the cancellation based on the recipient address provided.

proto/cosmos/protocolpool/v1/types.proto (1)
  • 30-56: The ContinuousFund message definition looks well-structured and follows the conventions of Protocol Buffers and the Cosmos SDK. The use of custom type annotations for the percentage field ensures that the value is handled correctly as a cosmossdk.io/math.LegacyDec and is not nullable, which is important for financial calculations. The cap field is a repeated Coin type, which allows for specifying multiple denominations if needed. The optional expiry field with a timestamp is a good design choice for funds that should only be available for a limited time. Ensure that the corresponding Go types and handlers are properly implemented to handle these fields, especially the custom types and repeated fields.

x/protocolpool/abci.go Outdated Show resolved Hide resolved
x/protocolpool/autocli.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/msg_server.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/msg_server.go Outdated Show resolved Hide resolved
x/protocolpool/abci.go Outdated Show resolved Hide resolved
x/protocolpool/abci.go Outdated Show resolved Hide resolved
@alexanderbez alexanderbez self-assigned this Nov 17, 2023
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.

left a few comments but overall looks good. I think we need a test in which there are many funds with different percentages and one withdraws to make sure they are all getting the expected amount

x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/msg_server_test.go Show resolved Hide resolved
@likhita-809 likhita-809 requested a review from tac0turtle January 4, 2024 15:55
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.

LGTM

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK, minor nits.
imho we should still find a solution for this in a follow-up: #18471 (comment)

proto/cosmos/protocolpool/v1/tx.proto Outdated Show resolved Hide resolved
x/protocolpool/autocli.go Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
@tac0turtle
Copy link
Member

imho we should still find a solution for this in a follow-up: #18471 (comment)

in a follow up pr lets handle this. We can discuss it on the team call today

@tac0turtle tac0turtle added this pull request to the merge queue Jan 9, 2024
Merged via the queue into main with commit 6ffc209 Jan 9, 2024
63 of 65 checks passed
@tac0turtle tac0turtle deleted the likhita/18374-implementation branch January 9, 2024 16:19
relyt29 pushed a commit to relyt29/cosmos-sdk that referenced this pull request Jan 22, 2024
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.

[Feature]: protocol funds
6 participants