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

refactor(serevr/v2/cometbft): update RegisterQueryHandlers and GRPC queries #22403

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Oct 31, 2024

Description

Closes: #XXXX


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 a new function for simplifying the creation of the stfRouterWrapper.
    • Enhanced error handling in the CheckTx method for better transaction validation.
  • Improvements

    • Updated logic for handling gRPC queries and refined error reporting during transaction decoding.
    • Adjusted initialization checks for the consensus process to ensure proper defaults.
  • Bug Fixes

    • Improved error handling in various methods to ensure clearer feedback and stability.

Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to the runtime/v2/manager.go and server/v2/cometbft/abci.go files. In manager.go, a new function newStfRouterWrapper is added for better initialization of the stfRouterWrapper, and error handling in the RegisterHandler method is improved. In abci.go, several methods in the Consensus struct are updated to enhance error handling and logic flow, particularly in query handling, transaction validation, and block finalization.

Changes

File Change Summary
runtime/v2/manager.go - Added function: newStfRouterWrapper for stfRouterWrapper initialization.
- Updated RegisterHandler method for improved error handling.
server/v2/cometbft/abci.go - Added variable handlerFullName in Consensus struct.
- Updated maybeRunGRPCQuery to use handlerFullName.
- Refined error handling in CheckTx, Info, InitChain, and FinalizeBlock methods.

Possibly related PRs

Suggested labels

C:server/v2 api

Suggested reviewers

  • kocubinski
  • testinginprod
  • sontrinh16
  • julienrbrt

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec0fb44 and 5852a7f.

📒 Files selected for processing (1)
  • runtime/v2/manager.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • runtime/v2/manager.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
Contributor

@hieuvubk your pull request is missing a changelog!

@hieuvubk hieuvubk changed the title [WIP]: Update v2 RegisterQueryHandlers and GRPC queries Update v2 RegisterQueryHandlers and GRPC queries Nov 4, 2024
@@ -282,7 +285,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
}

resp, err = queryResponse(res, req.Height)
return resp, isGRPC, err
return resp, true, err
Copy link
Member

Choose a reason for hiding this comment

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

why r we assume isGRPC here is true ?

Copy link
Member

Choose a reason for hiding this comment

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

is it possible to change the return type to (resp *abciproto.QueryResponse, err error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we couldn't, its using as flag to run GRPC request or app/p2p/store. Can try by wrapping err with a special message.

@julienrbrt julienrbrt changed the title Update v2 RegisterQueryHandlers and GRPC queries refactor(serevr/v2/cometbft): update RegisterQueryHandlers and GRPC queries Nov 4, 2024
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Nov 4, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
server/v2/cometbft/abci.go (1)

Line range hint 276-280: Avoid variable shadowing of resp in error handling

In the if err != nil block, declaring resp shadows the outer resp return variable. This can lead to confusion and potential bugs. It's better to assign directly to the named return variable or use a different variable name.

Apply this diff to fix the issue:

 res, err := c.app.Query(ctx, uint64(req.Height), protoRequest)
 if err != nil {
-    resp := QueryResult(err, c.cfg.AppTomlConfig.Trace)
+    resp = QueryResult(err, c.cfg.AppTomlConfig.Trace)
     resp.Height = req.Height
     return resp, true, err
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c754b20 and fc99806.

📒 Files selected for processing (2)
  • runtime/v2/manager.go (4 hunks)
  • server/v2/cometbft/abci.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
runtime/v2/manager.go (1)

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

server/v2/cometbft/abci.go (1)

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

🔇 Additional comments (5)
runtime/v2/manager.go (3)

845-850: LGTM: Well-structured constructor function.

The new NewStfRouterWrapper function properly initializes all fields and improves code maintainability by centralizing the initialization logic.


Line range hint 645-649: LGTM: Improved service registration with proper error handling.

The changes to use NewStfRouterWrapper in both message and query handler registration improve code consistency and error handling.

Also applies to: 654-659


864-867: ⚠️ Potential issue

Verify the impact of resetting handlers on error.

The change to reset the entire handlers map when an error occurs (s.handlers = map[string]appmodulev2.Handler{}) is a significant behavioral change. This could potentially clear valid handlers that were registered before the error occurred.

Consider preserving previously registered handlers and only skipping the current registration instead of clearing all handlers.

-if s.error != nil {
-    s.handlers = map[string]appmodulev2.Handler{}
-}
+if s.error == nil {
+    s.handlers[requestName] = handler
+}
server/v2/cometbft/abci.go (2)

262-267: LGTM: Correct assignment of handlerFullName

The logic for determining handlerFullName based on whether the query is gRPC is correctly implemented.


Line range hint 270-288: LGTM: Proper handling of gRPC queries in maybeRunGRPCQuery

The updated code uses handlerFullName to retrieve the appropriate handler from queryHandlersMap and processes the gRPC query correctly.

@@ -842,6 +842,13 @@ type stfRouterWrapper struct {
handlers map[string]appmodulev2.Handler
}

func NewStfRouterWrapper(stfRouterBuilder *stf.MsgRouterBuilder) stfRouterWrapper {
Copy link
Member

@julienrbrt julienrbrt Nov 4, 2024

Choose a reason for hiding this comment

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

why is this public? it should be made private imho

@@ -854,7 +861,7 @@ func (s *stfRouterWrapper) RegisterHandler(handler appmodulev2.Handler) {
s.error = errors.Join(s.error, err)

// also make the decoder
if s.error == nil {
if s.error != nil {
Copy link
Member

Choose a reason for hiding this comment

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

shall we just check if s.handlers is nil? Checking the error doesn't seem related tbh

@julienrbrt julienrbrt added this pull request to the merge queue Nov 5, 2024
Merged via the queue into main with commit 55f7cfc Nov 5, 2024
72 of 73 checks passed
@julienrbrt julienrbrt deleted the hieu/fix-bankv2-grpc branch November 5, 2024 07:44
mergify bot pushed a commit that referenced this pull request Nov 5, 2024
… queries (#22403)

(cherry picked from commit 55f7cfc)

# Conflicts:
#	runtime/v2/manager.go
julienrbrt added a commit that referenced this pull request Nov 5, 2024
… queries (backport #22403) (#22429)

Co-authored-by: Hieu Vu <[email protected]>
Co-authored-by: Hieu Vu <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Nov 5, 2024
12 tasks
alpe added a commit that referenced this pull request Nov 6, 2024
* main: (24 commits)
  build(deps): upgrade to [email protected] (#22436)
  docs: Update tendermint validators query pagination documentation (#22412)
  refactor(client/v2): offchain uses client/v2/factory (#22344)
  feat: wire new handlers to grpc (#22333)
  fix(x/group): proper address rendering in error (#22425)
  refactor(serevr/v2/cometbft): update `RegisterQueryHandlers` and GRPC queries (#22403)
  docs: update ADR 59 (#22423)
  build(deps): Bump github.com/fsnotify/fsnotify from 1.7.0 to 1.8.0 in /tools/cosmovisor (#22407)
  docs: Module account address documentation (#22289)
  feat(baseapp): add per message telemetry (#22175)
  docs: Update Twitter Links to X in Documentation (#22408)
  docs: redirect the remote generation page (#22404)
  refactor(serverv2): remove unused interface methods, honuor context  (#22394)
  fix(server/v2): return ErrHelp (#22399)
  feat(indexer): implement `schema.HasModuleCodec` interface in the `bank` module (#22349)
  refactor(math): refactor ApproxRoot for readality (#22263)
  docs: fix KWallet Handbook (#22395)
  feat(client/v2): broadcast logic (#22282)
  refactor(server/v2): eager config loading (#22267)
  test(system): check feePayers signature (#22389)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants