-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
WalkthroughWalkthroughThe changes in this pull request enhance the service registration process within the Cosmos SDK's banking module. Key modifications include the simplification of the Changes
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Preliminary review, looks already good but I have a few comments
@@ -102,6 +104,12 @@ func (am AppModule) RegisterMsgHandlers(router appmodulev2.MsgRouter) { | |||
errs = errors.Join(errs, err) | |||
} | |||
|
|||
if err := appmodulev2.RegisterHandler( |
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.
@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.
x/bank/v2/client/cli/tx.go
Outdated
|
||
var FlagSplit = "split" | ||
|
||
// NewTxCmd returns a root CLI command handler for all x/bank transaction commands. |
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.
Can we add a TODO to remove and link the gRPC / AutoCLI issue ?
x/bank/proto/cosmos/bank/v2/tx.proto
Outdated
message MsgSend { | ||
option (cosmos.msg.v1.signer) = "from_address"; | ||
option (amino.name) = "cosmos-sdk/MsgSend"; |
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.
To delete
runtime/v2/manager.go
Outdated
@@ -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 { |
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.
We should add a check in registerService to avoid the double registration.
…os-sdk into hieu/bankv2/handlers
runtime/v2/manager.go
Outdated
} | ||
|
||
if c.err != nil { | ||
app.logger.Warn("error registering services", "error", c.err) | ||
} | ||
|
||
// TODO: query regist by RegisterQueryHandlers not in grpcQueryDecoders |
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.
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 { |
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.
dito ref
decoderMap := module.GetQueryDecoders() | ||
for path, decoder := range decoderMap { | ||
app.GRPCMethodsToMessageMap[path] = decoder |
Check warning
Code scanning / CodeQL
Iteration over map Warning
@@ -5,11 +5,14 @@ | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"reflect" |
Check notice
Code scanning / CodeQL
Sensitive package import Note
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!, mostly docs missing
@@ -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) |
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.
I like the fallback tbh for now, maybe we should check if len(bankV2GenState.Balances) > 0
and if not, we use bank v1 genesis?
@@ -504,3 +510,13 @@ func writeFile(name, dir string, contents []byte) error { | |||
|
|||
return os.WriteFile(file, contents, 0o600) | |||
} | |||
|
|||
func getBankV2GenesisFromV1(v1GenesisState banktypes.GenesisState) bankv2types.GenesisState { |
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.
let's add a comment on the rationale of doing this (basically, to be deleted after genesis migration command addition)
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.
Actionable comments posted: 4
Outside diff range and nitpick comments (1)
x/bank/v2/module.go (1)
174-178
: LGTM! Address the TODO comment in a follow-up task.The
GetTxCmd
method is a good addition that provides access to the transaction commands for the bank/v2 module.The TODO comment suggests that this method might be replaced by autocli in the future. To ensure this doesn't get overlooked:
- Consider creating a follow-up task or issue to track the migration to autocli.
- Add a more descriptive comment explaining why autocli will be used and any potential blockers for the migration.
Would you like me to create a GitHub issue to track this TODO?
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- simapp/v2/simdv2/cmd/testnet.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 (2)
- simapp/v2/simdv2/cmd/testnet.go
- x/bank/v2/types/msgs.go
Additional context used
Path-based instructions (1)
x/bank/v2/module.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (1)
x/bank/v2/module.go (1)
8-8
: Address the security alert regarding the use of the "reflect" package.The addition of new import statements is necessary for the added functionality. However, there's a security alert from GitHub Advanced Security about the import of the "reflect" package.
The use of the "reflect" package might introduce non-determinism, which could be a concern in blockchain applications. Consider the following:
- Evaluate if the use of reflection is absolutely necessary. If possible, replace it with type-safe alternatives.
- If reflection cannot be avoided, ensure its usage is limited and well-documented.
- Add comments explaining why reflection is needed and any potential risks.
To verify the usage of the "reflect" package:
This script will help identify where reflection is used and if there are any existing comments explaining its usage.
Also applies to: 11-11
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.
nice work!
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!
@hieuvubk could you fix the conflicts and let's merge 🚀 |
…os-sdk into hieu/bankv2/handlers
Description
Closes: #21705
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
New Features
Bug Fixes
Documentation