-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
Note Reviews PausedUse the following commands to manage reviews:
Walkthrough: Changes:
Assessment against linked issues:
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai review |
There was a problem hiding this 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
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 thepoolKeeper
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 thedistrKeeper
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 newGetCommunityTax
method which returns amath.LegacyDec
. This change is appropriate as long as themath.LegacyDec
type is being used in the codebase.198-204: The new
GetCommunityTax
method has been added to theMockDistributionKeeper
interface. This method should correctly simulate the behavior of the actualDistributionKeeper
'sGetCommunityTax
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 onDistrKeeper
could lead to a potential initialization cycle or nil reference if not handled correctly. Ensure that theDistrKeeper
is fully initialized before being passed to thePoolKeeper
. This might require reordering the initialization sequence or ensuring that the necessary dependencies forDistrKeeper
are set up beforehand.421-424: The addition of
DistrKeeper
to theprotocolpool.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 ofv1beta1.Coin
pointers as required by the protobuf reflection API. However, ensure that thev1beta1.Coin
type is compatible with the expected operations, especially in theSet
andAppend
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 thePercentage
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
andfile_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 theprotoc
compiler and should work as intended.x/protocolpool/types/expected_keepers.go (2)
4-10: The import of the
math
package fromcosmossdk.io
is correctly placed and follows the standard Go convention of grouping standard library imports separately from third-party imports. Ensure that themath
package is used elsewhere in the codebase to avoid importing it unnecessarily.27-29: The addition of the
GetCommunityTax
method to theDistributionKeeper
interface is consistent with the summary provided. Ensure that all implementations of theDistributionKeeper
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 theKeeper
struct is consistent with the changes described in the summary. Ensure that all necessary checks and balances are in place when interacting with theDistributionKeeper
to avoid potential security issues.31-34: The addition of
ContinuousFund
to theKeeper
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 aDistributionKeeper
is in line with the changes described. Ensure that all instances whereNewKeeper
is called are updated accordingly.47-57: The initialization of
ContinuousFund
usingcollections.NewMap
is correct. However, ensure that theschema
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 theappmodule.HasEndBlocker
interface, which indicates that the module provides anEndBlock
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 aDistrKeeper
field of typetypes.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 adistrKeeper
parameter and pass it to theAppModule
struct. This change is necessary to provide theAppModule
with access to the distribution keeper.100-104: The
EndBlock
function has been implemented to callEndBlocker
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 aDistrKeeper
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 newkeeper.Keeper
with theDistrKeeper
and to pass theDistrKeeper
to theNewAppModule
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 fieldsmetadata
andexpiry
. 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 argumentrecipient_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 thepercentage
field ensures that the value is handled correctly as acosmossdk.io/math.LegacyDec
and is not nullable, which is important for financial calculations. Thecap
field is a repeatedCoin
type, which allows for specifying multiple denominations if needed. The optionalexpiry
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.
…ita/18374-implementation
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ita/18374-implementation
There was a problem hiding this 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)
in a follow up pr lets handle this. We can discuss it on the team call today |
…mos/cosmos-sdk into likhita/18374-implementation
…ita/18374-implementation
… CancelContinuousFund features (cosmos#18471)
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
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...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit
New Features
Continuous Fund
feature, allowing for the creation of funds that distribute resources continuously until a cap or expiry is reached.EndBlocker
function to process continuous fund distributions at the end of each block.Enhancements
GenesisState
to include continuous funds, enabling initialization and export of this state.Bug Fixes
Documentation
Testing
EndBlocker
function to ensure correct continuous fund behavior.Refactor