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(bank/v2): Add MsgSend handler #21736

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

feat(bank/v2): Add MsgSend handler #21736

wants to merge 24 commits into from

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Sep 15, 2024

Description

Closes: #21705

  • regist msg & query handler in runtime/v2
  • MsgSend handler, cmd
  • QueryBalance handler, cmd
  • InitGenesis with Balances and Supply
  • init bankv2 gen file in simapp/v2 testnet
  • systemtests

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, you can find examples of the prefixes below:
  • confirmed ! in 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
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced support for the new bank module version, enhancing the functionality for handling account balances and transactions.
    • Added CLI commands for querying account balances and sending funds between accounts.
    • Enhanced query capabilities with new message types for balance requests and responses.
    • Improved the process for initializing account balances and total supply validation.
  • Bug Fixes

    • Improved error handling and validation in the service registration process and transaction operations.
  • Documentation

    • Updated documentation to reflect new message types and CLI commands for better user guidance.

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Walkthrough

Walkthrough

The changes in this pull request primarily enhance the registration and handling of services within the Cosmos SDK's banking module. Key modifications include updates to service registration methods, the introduction of new message types for transactions, and enhancements to query capabilities. Additionally, the changes facilitate the transition to a new version of the bank module, ensuring compatibility with updated Genesis states and improving the overall functionality of the banking system.

Changes

File Path Change Summary
runtime/v2/manager.go Simplified RegisterServices method to accept appmodulev2.AppModule, enhancing service registration and error handling.
simapp/v2/simdv2/cmd/testnet.go Added support for transitioning from v1 to v2 Genesis state in the bank module, including a new helper function for converting balances.
tests/systemtests/bankv2_test.go Introduced a system test for the bank module's v2 functionality, validating transaction sending capabilities.
tests/systemtests/testnet_init.go Added isV2 function to check for simapp version 2, modifying command argument handling for minimum gas prices accordingly.
x/bank/proto/cosmos/bank/v2/genesis.proto Enhanced GenesisState with new fields for multiple balances and total supply management.
x/bank/proto/cosmos/bank/v2/query.proto Introduced QueryBalanceRequest and QueryBalanceResponse messages for querying account balances by address and denomination.
x/bank/proto/cosmos/bank/v2/tx.proto Added MsgSend, MsgSendResponse, MsgMint, and MsgMintResponse messages to facilitate coin transactions and minting.
x/bank/v2/client/cli/query.go Implemented CLI functionality for querying bank module data, including commands for retrieving account balances.
x/bank/v2/client/cli/tx.go Added CLI functionality for handling bank transactions, focusing on sending funds between accounts.
x/bank/v2/keeper/genesis.go Updated InitGenesis to validate total supply against account balances during state initialization.
x/bank/v2/keeper/handlers.go Enhanced message handling with methods for sending, minting coins, and querying balances.
x/bank/v2/module.go Added methods for registering message handlers and query decoders, improving transaction and query handling capabilities.
x/bank/v2/types/codec.go Registered new MsgSend message type within the interface registration process.
x/bank/v2/types/msgs.go Introduced MsgSend structure for handling coin transfers, including validation logic.
x/bank/v2/types/query.go Added NewQueryBalanceRequest function for creating balance query requests.

Possibly related issues

  • [Epic]: Bank/v2 #17579: The changes aim to create a new bank module that is extendable and efficient, aligning with the objectives of reducing the scope and improving performance as mentioned in this issue.

Possibly related PRs

Suggested labels

C:x/accounts, C:x/accounts/multisig, backport/v0.52.x

Suggested reviewers

  • julienrbrt
  • sontrinh16
  • akhilkumarpilli
  • facundomedica
  • kocubinski
  • tac0turtle

Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3aafcb0 and 0b5d9f3.

Files selected for processing (5)
  • x/bank/v2/client/cli/query.go (1 hunks)
  • x/bank/v2/keeper/genesis.go (2 hunks)
  • x/bank/v2/keeper/handlers.go (3 hunks)
  • x/bank/v2/module.go (3 hunks)
  • x/bank/v2/types/msgs.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • x/bank/v2/client/cli/query.go
  • x/bank/v2/keeper/genesis.go
  • x/bank/v2/keeper/handlers.go
  • x/bank/v2/module.go
  • x/bank/v2/types/msgs.go

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>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Preliminary review, looks already good but I have a few comments

x/bank/v2/types/msgs.go Outdated Show resolved Hide resolved
@@ -102,6 +104,12 @@ func (am AppModule) RegisterMsgHandlers(router appmodulev2.MsgRouter) {
errs = errors.Join(errs, err)
}

if err := appmodulev2.RegisterHandler(
Copy link
Member

Choose a reason for hiding this comment

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

@testinginprod, imho we should improve the API to register multiple messages and handlers in that method. Otherwise it is imho way too verbose.

like

appmodulev2.RegisterHandlers(router, "cosmos.bank.v2.MsgSend": handlers.SendHandler, "cosmos.bank.v2.MsgUpdateParams": handlers.ParamsHandler)

It will need to be a bit less type safe I think, but still a better UX.


var FlagSplit = "split"

// NewTxCmd returns a root CLI command handler for all x/bank transaction commands.
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a TODO to remove and link the gRPC / AutoCLI issue ?

message MsgSend {
option (cosmos.msg.v1.signer) = "from_address";
option (amino.name) = "cosmos-sdk/MsgSend";
Copy link
Member

Choose a reason for hiding this comment

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

To delete

@@ -480,6 +480,14 @@ func (m *MM[T]) RegisterServices(app *App[T]) error {
if module, ok := module.(appmodulev2.HasPostMsgHandlers); ok {
module.RegisterPostMsgHandlers(app.msgRouterBuilder)
}

if module, ok := module.(appmodulev2.HasMsgHandlers); ok {
Copy link
Member

Choose a reason for hiding this comment

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

We should add a check in registerService to avoid the double registration.

}

if c.err != nil {
app.logger.Warn("error registering services", "error", c.err)
}

// TODO: query regist by RegisterQueryHandlers not in grpcQueryDecoders
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do some hacky here cause RegisterQueryHandlers not add query decoder to grpcQueryDecoders so I have to add again.
Must be some way better but idk yet.

if errs != nil {
panic(errs)
}
}

// GetQueryDecoders registers the query handlers for the bank module.
func (am AppModule) GetQueryDecoders() map[string]func() gogoproto.Message {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dito ref

Comment on lines +621 to +623
decoderMap := module.GetQueryDecoders()
for path, decoder := range decoderMap {
app.GRPCMethodsToMessageMap[path] = decoder

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
@@ -5,11 +5,14 @@
"encoding/json"
"errors"
"fmt"
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
@hieuvubk hieuvubk marked this pull request as ready for review September 19, 2024 07:23
Copy link
Contributor

@hieuvubk your pull request is missing a changelog!

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.

Actionable comments posted: 2

Outside diff range and nitpick comments (3)
x/bank/v2/keeper/handlers.go (1)

79-80: Reminder: Address the TODO comment.

The TODO comment indicates that the denom enable check is not yet implemented. Please ensure that this check is added to prevent potential issues.

Do you want me to generate the code for the denom enable check or open a GitHub issue to track this task?

x/bank/v2/module.go (2)

108-119: Consider improving the API to register multiple messages and handlers.

The changes to register handlers for MsgSend and MsgMint messages are crucial for the bank module's functionality. However, as suggested in the past review comments, the registration process could be improved to be less verbose.

Consider updating the API to allow registering multiple messages and handlers in a single call, like:

appmodulev2.RegisterHandlers(router,
  "cosmos.bank.v2.MsgSend": handlers.SendHandler,
  "cosmos.bank.v2.MsgUpdateParams": handlers.ParamsHandler,
  "cosmos.bank.v2.MsgMint": handlers.MintHandler,
)

This would improve the developer experience while maintaining type safety.


136-141: Consider applying the same improvement as RegisterMsgHandlers.

The changes to register a handler for QueryBalanceRequest are important for the bank module's query functionality. However, similar to RegisterMsgHandlers, the registration process could be improved to be less verbose.

Consider updating the API to allow registering multiple queries and handlers in a single call, like:

appmodulev2.RegisterHandlers(router,
  "cosmos.bank.v2.QueryParamsRequest": handlers.QueryParamsHandler,
  "cosmos.bank.v2.QueryBalanceRequest": handlers.QueryBalanceHandler,
)

This would maintain consistency with the suggested improvement for RegisterMsgHandlers.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29077c8 and 3aafcb0.

Files ignored due to path filters (3)
  • x/bank/v2/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/bank/v2/types/query.pb.go is excluded by !**/*.pb.go
  • x/bank/v2/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (15)
  • runtime/v2/manager.go (4 hunks)
  • simapp/v2/simdv2/cmd/testnet.go (3 hunks)
  • tests/systemtests/bankv2_test.go (1 hunks)
  • tests/systemtests/testnet_init.go (3 hunks)
  • x/bank/proto/cosmos/bank/v2/genesis.proto (1 hunks)
  • x/bank/proto/cosmos/bank/v2/query.proto (2 hunks)
  • x/bank/proto/cosmos/bank/v2/tx.proto (2 hunks)
  • x/bank/v2/client/cli/query.go (1 hunks)
  • x/bank/v2/client/cli/tx.go (1 hunks)
  • x/bank/v2/keeper/genesis.go (2 hunks)
  • x/bank/v2/keeper/handlers.go (3 hunks)
  • x/bank/v2/module.go (3 hunks)
  • x/bank/v2/types/codec.go (1 hunks)
  • x/bank/v2/types/msgs.go (1 hunks)
  • x/bank/v2/types/query.go (1 hunks)
Additional context used
Path-based instructions (12)
runtime/v2/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/simdv2/cmd/testnet.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/systemtests/bankv2_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/systemtests/testnet_init.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

x/bank/v2/client/cli/query.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/client/cli/tx.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/keeper/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/keeper/handlers.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/module.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/types/codec.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/types/msgs.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/v2/types/query.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (40)
x/bank/v2/types/query.go (1)

4-6: LGTM!

The NewQueryBalanceRequest function is a well-implemented constructor for the QueryBalanceRequest struct. It follows the Golang naming convention, has appropriately named parameters with specified types, and initializes the struct fields correctly. The function body is concise and readable.

x/bank/v2/types/codec.go (1)

11-11: LGTM!

The addition of &MsgSend{} to the RegisterInterfaces function is a straightforward change that enhances the functionality of the transaction.Msg interface by allowing it to handle a new message type. This change conforms to the Uber Golang style guide and does not alter existing logic or control flow.

x/bank/v2/types/msgs.go (2)

16-18: LGTM!

The NewMsgSend constructor function is implemented correctly. It initializes a new MsgSend instance with the provided fromAddr, toAddr, and amount parameters.


21-39: LGTM!

The ValidateBasic method performs important validations on the MsgSend fields:

  1. It checks if FromAddress and ToAddress are valid Bech32 addresses using sdk.AccAddressFromBech32. If invalid, it wraps the error with appropriate messages using sdkerrors.ErrInvalidAddress.

  2. It checks if the Amount is valid using the IsValid method. If invalid, it wraps the error with an appropriate message using sdkerrors.ErrInvalidCoins.

  3. It checks if the Amount is positive using the IsAllPositive method. If not positive, it wraps the error with an appropriate message using sdkerrors.ErrInvalidCoins.

The error handling and wrapping is done correctly using the errorsmod and sdkerrors packages. The method is implemented correctly and follows the expected validation logic.

x/bank/proto/cosmos/bank/v2/query.proto (4)

7-7: LGTM!

The import statement is necessary and correctly added.


19-20: LGTM!

The closing brace and empty line are correctly added, improving the structure and readability of the code.


21-31: LGTM!

The QueryBalanceRequest message is well-defined and includes the necessary fields to query balances for a specific address and denomination. The address field annotation provides clarity on the expected format.


33-36: LGTM!

The QueryBalanceResponse message is well-defined and includes the balance field of type cosmos.base.v1beta1.Coin, which accurately represents the balance of the coin for the queried address and denomination. The usage of the Coin type from the Cosmos SDK ensures consistency.

tests/systemtests/bankv2_test.go (1)

13-47: Excellent system test for the bank module's send transaction functionality!

This test is well-structured, covering all the essential aspects of sending a transaction using the bank module in version 2 of the application. It follows a clear setup, execution, and assertion pattern, making it easy to understand and maintain.

Some key strengths of this test:

  • It sets up the necessary accounts and balances before executing the transaction.
  • It constructs the send command correctly and waits for the transaction to be committed.
  • It uses appropriate assertions to validate the transaction's success.
  • It is well-documented with comments explaining each step.
  • It skips execution if the application is not running in version 2, ensuring that it only runs in the appropriate context.

Overall, this test provides a comprehensive check of the transaction sending capabilities in the bank module, enhancing the testing suite and helping ensure the correctness and reliability of the module's functionality.

x/bank/v2/keeper/genesis.go (5)

18-19: LGTM!

The totalSupplyMap is initialized correctly using sdk.NewMapCoins with an empty sdk.Coins slice.


20-35: LGTM!

The code correctly iterates over the state.Balances slice, sets the balances in the balances collection using a joined key of the address bytes and coin denomination, and updates the totalSupplyMap by adding the balance coins. Error handling is in place for the address conversion and balance setting operations.


36-37: LGTM!

The totalSupplyMap is correctly converted to a sdk.Coins slice using the ToCoins method, and the totalSupply variable is assigned the value of the converted coins.


38-40: LGTM!

The code correctly checks if the state.Supply is not empty and not equal to the totalSupply. If the condition is true, it returns an error indicating that the genesis supply is incorrect, providing the expected and actual values. The error is returned using the fmt.Errorf function.


42-44: LGTM!

The code correctly iterates over the totalSupply coins and calls the setSupply method of the keeper with the context and supply coin for each supply coin.

x/bank/proto/cosmos/bank/v2/genesis.proto (5)

16-18: LGTM!

The addition of the repeated Balance balances field to the GenesisState message enhances the flexibility of the genesis state by allowing the inclusion of multiple account balances during initialization. The (gogoproto.nullable) = false and (amino.dont_omitempty) = true options ensure that the field is always present and not omitted when empty, providing a consistent structure for the genesis state.


20-27: LGTM!

The addition of the repeated cosmos.base.v1beta1.Coin supply field to the GenesisState message provides flexibility in defining the total supply of coins in the genesis state. It allows for explicit definition of the total supply or automatic calculation based on the provided account balances. The (gogoproto.nullable) = false and (amino.dont_omitempty) = true options ensure that the field is always present and not omitted when empty, maintaining a consistent structure for the genesis state.


32-37: LGTM!

The introduction of the Balance message provides a structured way to represent account balances in the genesis state. The address field holds the address of the balance holder as a string, and the (cosmos_proto.scalar) = "cosmos.AddressString" option ensures that it is properly validated and serialized as a Cosmos address string. This improves the organization and readability of account balances in the genesis state.


39-45: LGTM!

The addition of the repeated cosmos.base.v1beta1.Coin coins field to the Balance message enables the representation of multiple coin balances for each account in the genesis state. The (gogoproto.nullable) = false and (amino.dont_omitempty) = true options ensure that the field is always present and not omitted when empty, maintaining a consistent structure for the account balances.


7-7: LGTM!

The inclusion of the cosmos/base/v1beta1/coin.proto import ensures that the necessary Coin message type is available for use in the GenesisState and Balance messages. It maintains the dependency on the cosmos.base.v1beta1 package for the Coin type, which is used in the supply and coins fields.

x/bank/v2/client/cli/tx.go (3)

14-15: Address the TODO comment.

The TODO comment indicates that AutoCLI commands should be used in the future. Please ensure that this is tracked and addressed in the linked issue (#21682).


16-30: LGTM!

The implementation of the root command for the bank module is well-structured and follows the expected pattern. The usage, description, and validation properties are set appropriately, and the NewSendTxCmd subcommand is added correctly.


33-63: LGTM!

The implementation of the NewSendTxCmd function is well-structured and follows the expected pattern for creating a CLI command. The usage, description, and argument validation are set appropriately. The RunE function handles the command execution correctly by parsing the arguments, creating a MsgSend message, and generating or broadcasting the transaction using the GenerateOrBroadcastTxCLI utility. The standard transaction flags are also added to the command.

x/bank/v2/client/cli/query.go (2)

22-36: LGTM!

The GetQueryCmd function is implemented correctly and follows the Uber Golang style guide. It sets up the parent command for bank queries with appropriate metadata and adds the GetBalanceCmd subcommand.


38-78: LGTM!

The GetBalanceCmd function is implemented correctly and follows the Uber Golang style guide. It sets up the CLI command to query account balances with the following key points:

  • Validates input arguments for address and denom.
  • Converts the address from Bech32 to sdk.AccAddress.
  • Constructs a new QueryBalanceRequest with the provided arguments.
  • Invokes the query through the client context.
  • Prints the response in proto format.

The function also sets up appropriate flags for the denom and pagination.

x/bank/proto/cosmos/bank/v2/tx.proto (4)

9-9: LGTM!

The import statement is necessary and correctly added.


27-28: LGTM!

The MsgUpdateParamsResponse message is correctly defined as an empty message, following the common practice for gRPC services.


29-42: LGTM!

The MsgSend message is well-defined and includes all necessary fields for sending coins between accounts. The use of cosmos_proto.scalar, amino, and gogoproto.castrepeated options ensures compatibility with the Cosmos SDK's messaging framework and type safety.


47-62: LGTM!

The MsgMint message is well-defined and includes all necessary fields for minting new coins. The use of cosmos_proto.scalar, amino, and gogoproto.castrepeated options ensures compatibility with the Cosmos SDK's messaging framework and type safety.

x/bank/v2/keeper/handlers.go (3)

55-99: LGTM!

The MsgSend function correctly implements the following:

  • Validation of sender and receiver addresses.
  • Checking the validity and positivity of coin amounts.
  • Processing the coin transfer using the SendCoins method.
  • Recording telemetry metrics for the transferred amounts.

101-136: LGTM!

The MsgMint function correctly implements the following:

  • Verification of the authority of the minting request.
  • Checking the validity and positivity of coin amounts.
  • Performing the minting operation using the MintCoins method.

152-170: LGTM!

The QueryBalance function correctly implements the following:

  • Validation of the request and checking for nil.
  • Validation of the denom using the sdk.ValidateDenom function.
  • Validation of the address using the addressCodec.StringToBytes method.
  • Retrieval of the balance using the GetBalance method.
x/bank/v2/module.go (3)

148-172: LGTM!

The GetQueryDecoders function is a good addition to the bank module. It provides a flexible way to register query decoders by creating a map of message names to decoder functions.

The use of reflection to create instances of the query request types is a clever solution, but it's worth noting that it could have some performance implications. However, given the benefits of flexibility and maintainability, it seems like a reasonable trade-off.

Overall, the function is well-structured and follows good practices.


175-177: LGTM!

The GetTxCmd function is a simple yet useful addition to the bank module. By leveraging the cli.NewTxCmd() function, it promotes code reuse and provides a convenient way to access the root transaction command.

The function is concise and follows good practices.


179-181: LGTM!

The GetQueryCmd function is another simple yet useful addition to the bank module. Similar to GetTxCmd, it leverages the cli package, specifically the cli.GetQueryCmd() function, to promote code reuse and provide a convenient way to access the root query command.

The function is concise and follows good practices.

tests/systemtests/testnet_init.go (2)

17-20: LGTM!

The isV2 function is well-named, has a clear purpose, and follows the Golang naming convention. The logic is straightforward and easy to understand.


66-70: Approve the conditional argument appending based on isV2().

The changes introduce a conditional check to append the appropriate minimum gas price argument based on the simapp version. This ensures compatibility with both simapp v1 and v2. The logic is clear and the changes are well-integrated into the existing code.

simapp/v2/simdv2/cmd/testnet.go (1)

514-522: LGTM!

The getBankV2GenesisFromV1 function correctly converts the bank v1 genesis state to v2 genesis state by iterating over the balances, converting each balance to the v2 format, and aggregating the total supply. The implementation follows the expected logic and ensures a smooth transition from v1 to v2 genesis state.

runtime/v2/manager.go (3)

462-463: LGTM!

The changes to registerServices simplify the service registration process and make it more adaptable to different module types. The function is now more resilient and flexible in handling various module implementations.


604-608: Fallback mechanism for registering message and query handlers.

The changes provide a fallback mechanism to register message and query handlers if the module does not implement RegisterServices. This ensures that the necessary handlers are registered even if the module does not fully implement the hasServicesV1 interface.


616-624: Verify the query registration process.

The TODO comment indicates that there might be an issue with query registration not being added to grpcQueryDecoders. Please verify the query registration process and ensure that the registered queries are correctly added to grpcQueryDecoders.

Run the following script to verify the query registration:

Comment on lines +129 to +130
// TODO: should mint to mint module then transfer?
err = h.MintCoins(ctx, to, msg.Amount)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider the approach mentioned in the TODO comment.

The TODO comment suggests minting to the mint module and then transferring to the recipient, instead of minting directly to the recipient. This approach might be a better practice for maintaining a clear separation of concerns and improving auditability.

Please consider implementing the suggested approach or provide a rationale for the current implementation.

Comment on lines +124 to +127
if isV2() {
args = append(args, "--server.minimum-gas-prices="+s.minGasPrice)
} else {
args = append(args, "--minimum-gas-prices="+s.minGasPrice)
Copy link
Contributor

Choose a reason for hiding this comment

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

Approve the conditional argument appending based on isV2(), but consider refactoring to remove duplication.

The changes introduce a conditional check to append the appropriate minimum gas price argument based on the simapp version, ensuring compatibility with both simapp v1 and v2. The logic is clear and the changes are well-integrated into the existing code.

However, the same conditional logic is present in both SingleHostTestnetCmdInitializer and ModifyConfigYamlInitializer. Consider extracting this logic into a separate function to avoid duplication and improve maintainability.

@@ -657,6 +675,7 @@ func (c *configurator) registerQueryHandlers(sd *grpc.ServiceDesc, ss interface{
for _, md := range sd.Methods {
// TODO(tip): what if a query is not deterministic?
requestFullName, err := registerMethod(c.stfQueryRouter, sd, md, ss)
fmt.Println("requestFullName", requestFullName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Println("requestFullName", requestFullName)

@@ -402,6 +403,11 @@ func initGenFiles[T transaction.Tx](
}
appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState)

var bankV2GenState bankv2types.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[bankv2types.ModuleName], &bankV2GenState)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need this step as you are assigning bankV2GenState a new value in next step?

rsp := cli.Run(append(bankSendCmdArgs, "--fees=1stake")...)
txResult, found := cli.AwaitTxCommitted(rsp)
require.True(t, found)
RequireTxSuccess(t, txResult)
Copy link
Contributor

Choose a reason for hiding this comment

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

check balances after tx to confirm transfer done successfully

}
}

// GetQueryDecoders registers the query handlers for the bank module.
Copy link
Contributor

Choose a reason for hiding this comment

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

please update godoc

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.

Create handlers and commands for send and mint
3 participants