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(baseapp)!: remove hybrid handlers #22831

Closed
wants to merge 1 commit into from

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Dec 11, 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

    • Streamlined message and request handling with updated handler retrieval methods.
  • Bug Fixes

    • Improved error handling and logic consistency in testing for message and query routers.
  • Documentation

    • Updated comments to clarify the roles of renamed handler maps and methods.
  • Tests

    • Adjusted test cases to reflect the new naming conventions for handler methods.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve renaming methods and variables across several files to simplify the handling of gRPC requests and message routing. The HybridHandlerByRequestName and HybridHandlerByMsgName methods have been renamed to HandlerByRequestName and HandlerByMsgName, respectively. Corresponding maps and functions have also been updated to reflect this new naming convention. The modifications aim to streamline the handler logic by consolidating it under a single naming scheme, while maintaining existing functionalities and testing structures.

Changes

File Change Summary
baseapp/grpcrouter.go Renamed HybridHandlerByRequestName to HandlerByRequestName; renamed hybridHandlers to handlers; updated NewGRPCQueryRouter and registerHandler methods.
baseapp/grpcrouter_test.go Updated test method from HybridHandlerByRequestName to HandlerByRequestName in TestGRPCRouterHybridHandlers.
baseapp/internal/protocompat/protocompat.go Renamed MakeHybridHandler to MakeHandler; removed makeProtoV2HybridHandler and makeGogoHybridHandler; added makeGogoHandler.
baseapp/msg_service_router.go Renamed HybridHandlerByMsgName to HandlerByMsgName; renamed hybridHandlers to handlers; updated NewMsgServiceRouter and registerHandler methods.
baseapp/msg_service_router_test.go Updated test method from HybridHandlerByMsgName to HandlerByMsgName in TestHybridHandlerByMsgName.
runtime/environment.go Renamed HybridHandlerByMsgName to HandlerByMsgName and HybridHandlerByRequestName to HandlerByRequestName in failingMsgRouter and failingQueryRouter.
runtime/router.go Updated method calls in msgRouterService and queryRouterService from HybridHandlerByMsgName and HybridHandlerByRequestName to their new counterparts.

Possibly related PRs

Suggested labels

C:server/v2, C:server/v2 api, C:server/v2 cometbft, C:server/v2 appmanager, backport/v0.52.x

Suggested reviewers

  • kocubinski
  • sontrinh16
  • tac0turtle
  • facundomedica

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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

@testinginprod 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 (2)
baseapp/msg_service_router_test.go (1)

Line range hint 103-115: Rename the test function to match the updated method name

The test function TestHybridHandlerByMsgName should be renamed to TestHandlerByMsgName to reflect the updated method name being tested.

baseapp/msg_service_router.go (1)

91-92: Consider renaming registerHybridHandler method

While the HandlerByMsgName method has been updated, the registerHybridHandler method name still contains "Hybrid". Consider renaming it to registerHandler for consistency with the rest of the changes.

-func (msr *MsgServiceRouter) registerHybridHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) error {
+func (msr *MsgServiceRouter) registerHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) error {

Also applies to: 108-108, 116-116, 131-131

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cef0f84 and 6dfc518.

📒 Files selected for processing (7)
  • baseapp/grpcrouter.go (6 hunks)
  • baseapp/grpcrouter_test.go (1 hunks)
  • baseapp/internal/protocompat/protocompat.go (2 hunks)
  • baseapp/msg_service_router.go (5 hunks)
  • baseapp/msg_service_router_test.go (1 hunks)
  • runtime/environment.go (2 hunks)
  • runtime/router.go (4 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
baseapp/msg_service_router_test.go (2)

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


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

runtime/router.go (1)

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

baseapp/grpcrouter_test.go (2)

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


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

baseapp/msg_service_router.go (1)

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

runtime/environment.go (1)

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

baseapp/internal/protocompat/protocompat.go (1)

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

baseapp/grpcrouter.go (1)

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

🔇 Additional comments (13)
baseapp/grpcrouter.go (4)

21-21: LGTM! Interface method renamed for clarity

The removal of "Hybrid" prefix simplifies the interface while maintaining the same functionality.


32-35: LGTM! Improved handler map documentation

The updated comments better explain the purpose of the handlers map, clarifying its generic nature versus ABCI-specific functionality.


61-61: LGTM! Constructor updated to match struct changes

The initialization is correctly updated to use the renamed handlers map.


147-148: LGTM! Methods renamed consistently with interface changes

The implementation correctly reflects the interface changes while maintaining proper error handling and registration logic.

Also applies to: 155-171

baseapp/grpcrouter_test.go (1)

59-59: LGTM! Tests updated to match API changes

The test correctly uses the renamed method while maintaining comprehensive coverage for both protov2 and gogoproto handlers.

baseapp/msg_service_router.go (3)

29-29: LGTM! Interface aligned with QueryRouter changes

The method renaming maintains consistency with the QueryRouter interface changes.


36-36: LGTM! Struct field aligned with GRPCQueryRouter changes

The handlers map renaming maintains consistency with similar changes in GRPCQueryRouter.


47-47: LGTM! Constructor updated to match struct changes

The initialization correctly uses the renamed handlers map.

runtime/environment.go (1)

94-96: LGTM! Verify consistent renaming across the codebase

The method rename from HybridHandlerByRequestName to HandlerByRequestName aligns with the PR objective of removing hybrid handlers.

✅ Verification successful

Method rename is consistently applied across the codebase

The verification shows that:

  • No references to the old HybridHandlerByRequestName method exist in the codebase
  • The new HandlerByRequestName method is properly defined in:
    • QueryRouter interface in baseapp/grpcrouter.go
    • Implementation in baseapp/grpcrouter.go
    • Failing implementation in runtime/environment.go
    • Used consistently in router implementations and tests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent renaming of HybridHandlerByRequestName across codebase
rg -l "HybridHandlerByRequestName"

Length of output: 34


Script:

#!/bin/bash
# Let's verify both the old and new method names in the interfaces and implementations
# First, check for any remaining references to the old name
rg "HybridHandlerByRequestName" -A 2 -B 2

# Then check the current usage of the new name to ensure consistency
rg "HandlerByRequestName" -A 2 -B 2

# Also check for any interface definitions that might be related
ast-grep --pattern 'interface { $$$ HandlerByRequestName($$$) $$$ }'

Length of output: 1947

runtime/router.go (4)

Line range hint 40-44: LGTM! Method call updated consistently

The handler retrieval call has been updated to use HandlerByMsgName, maintaining consistency with the interface changes.


Line range hint 66-73: LGTM! Method call updated consistently

The handler retrieval and execution logic has been updated to use HandlerByMsgName, maintaining consistency with the interface changes.


Line range hint 99-104: LGTM! Method call updated consistently

The handler retrieval and validation logic has been updated to use HandlerByRequestName, maintaining consistency with the interface changes.


Line range hint 127-134: LGTM! Method call updated consistently

The handler retrieval, validation, and execution logic has been updated to use HandlerByRequestName, maintaining consistency with the interface changes.

Comment on lines +22 to +24
// MakeHandler returns a handler that can handle both gogo and protov2 messages, no matter
// if the handler is a gogo or protov2 handler.
func MakeHybridHandler(cdc codec.BinaryCodec, sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) (Handler, error) {
func MakeHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) (Handler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update the function comment to accurately describe the function's behavior

The comment for MakeHandler suggests that it returns a handler capable of handling both gogo and protov2 messages. However, the implementation returns an error for protov2 handlers. Please update the comment to reflect that only gogo handlers are supported.

Comment on lines +84 to 86
func (failingMsgRouter) HandlerByMsgName(msgName string) func(ctx context.Context, req, resp protoiface.MessageV1) error {
panic("message router not set")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update test file to match the renamed method

The method HybridHandlerByMsgName has been renamed to HandlerByMsgName in runtime/environment.go, but there's still a test using the old name in baseapp/msg_service_router_test.go. Please update the test name to maintain consistency.

  • baseapp/msg_service_router_test.go: Rename TestHybridHandlerByMsgName to TestHandlerByMsgName
🔗 Analysis chain

LGTM! Verify consistent renaming across the codebase

The method rename from HybridHandlerByMsgName to HandlerByMsgName aligns with the PR objective of removing hybrid handlers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent renaming of HybridHandlerByMsgName across codebase
rg -l "HybridHandlerByMsgName"

Length of output: 65


Script:

#!/bin/bash
# Check the context of HybridHandlerByMsgName usage in the test file
rg -A 5 "HybridHandlerByMsgName" baseapp/msg_service_router_test.go

Length of output: 230

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 11, 2024
@@ -18,7 +18,7 @@ import (
)

type QueryRouter interface {
HybridHandlerByRequestName(name string) []func(ctx context.Context, req, resp protoiface.MessageV1) error
HandlerByRequestName(name string) []func(ctx context.Context, req, resp protoiface.MessageV1) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to break this interface name?

This is a public interface and could break consumers

Copy link
Member

Choose a reason for hiding this comment

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

I think it is fine, sourcegraph tells me there are no users.
We ask user to migrate to use core services anyway via environment, so those API should be hidden from them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but couldn't we lower the impact of this change by just maintaining the name of this function for the interface?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we gain anything by breaking this name?

Copy link
Member

Choose a reason for hiding this comment

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

The impact is low as there are no consumers. Hybrid handlers never got fully used as we decided after 0.50 to not support proto v1 & proto v2. Keeping such API name is more confusing than simplifying the API imho.

Copy link
Member

@tac0turtle tac0turtle Dec 11, 2024

Choose a reason for hiding this comment

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

since there are no consumers and the code is no longer working hybrid i feel like its fine. Currently users dont make it this far and the ones that do cant actually swap the router other than in 52+ because there was no interface before and the baseapp struct took the concrete implementation.

@julienrbrt julienrbrt changed the title remove(baseapp): hybrid handlers refactor(baseapp)!: remove hybrid handlers Dec 11, 2024
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.

cl please :)

@testinginprod
Copy link
Contributor Author

Nuking this for now:

  1. Removing HybridHandlers impossible due to gRPC v2 having leaked down the stack.
  2. BaseApp does not understand consensus queries vs non consensus queries
  3. Refactor too involved to backport.

Will come with a smarter and quick fix to the issue.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants