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(runtime): message router service #19571

Merged
merged 20 commits into from
Mar 4, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Feb 26, 2024

Description

ref: #19542

Implement msg router service on main.
Once this is merged, I'll be adding the same in runtime/v2
Additionally, I'll update main to use the service in gov, group and authz


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
  • 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.

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 QR code display option for the keys show command.
    • Added new functionalities and improvements to the message routing system, including the ability to fetch response names based on request names and handle hybrid message types.
    • Implemented a new service handling mechanism across the application, enhancing modularity and service management.
  • Refactor
    • Refined the environment setup process to support custom services, improving flexibility and configuration options.
    • Updated and optimized various internal mechanisms, including memory storage service provisioning and message routing logic.
  • Dependencies
    • Added new dependencies to support enhanced functionality and updated existing ones for better performance and stability.
  • Bug Fixes
    • Adjusted the Keeper struct in various modules to correctly utilize the environment for event service access, addressing issues with message handling and routing.

Copy link
Contributor

coderabbitai bot commented Feb 26, 2024

Walkthrough

The recent updates introduce significant enhancements across the board, focusing on routing services, codec implementations, and command-line interface improvements. A notable addition is the router.Service in the core runtime, which impacts dependency injection and service handling mechanisms. Enhancements to the MessageRouter interface, new utility methods for types, and updates to dependency versions mark a comprehensive effort to refine functionality and expand capabilities within the system.

Changes

Files Change Summaries
CHANGELOG.md, core/CHANGELOG.md Introduced router.Service and its integration, added ValueCodec for math.Uint, new IsGT method for types.Coin, and a --qrcode flag for key display.
baseapp/..., runtime/..., x/counter/... Expanded MessageRouter interface, introduced Service interface for routing, updated environment structures to include MessageRouterService, and modified service handling. Refactored message and query routing with new methods and fields, including updates to GRPCQueryRouter and MsgServiceRouter.
core/appmodule/..., runtime/environment.go Added MessageRouterService to Environment struct, adjusted Logger position, and introduced EnvOption functions for custom service configuration.
core/go.mod, core/go.sum Added github.com/cosmos/gogoproto v1.4.11, github.com/google/go-cmp v0.6.0, updated github.com/stretchr/testify, and added corresponding modules in go.sum.
runtime/module.go, runtime/router.go, testutil/integration/router.go, runtime/router_test.go Updated service provision and environment configuration to accommodate new routing service. Introduced functionality for message handling with typed and untyped responses, including test setups for validating router service functionality.
client/grpc_query_test.go, x/accounts/... Adjusted initialization and struct fields to align with new routing and environment handling mechanisms. Indicated future changes for router interaction with the environment.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

core/go.mod Outdated
@@ -4,6 +4,7 @@ go 1.20

require (
cosmossdk.io/log v1.3.1
github.com/cosmos/gogoproto v1.4.11
Copy link
Member Author

Choose a reason for hiding this comment

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

@julienrbrt julienrbrt changed the title feat: message router service feat(runtime): message router service Feb 26, 2024
@julienrbrt julienrbrt marked this pull request as ready for review February 27, 2024 11:48
@julienrbrt julienrbrt requested a review from a team as a code owner February 27, 2024 11:48
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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 23359a0 and 9700f78.
Files selected for processing (11)
  • CHANGELOG.md (1 hunks)
  • baseapp/msg_service_router.go (1 hunks)
  • core/CHANGELOG.md (1 hunks)
  • core/appmodule/environment.go (1 hunks)
  • core/go.mod (2 hunks)
  • core/go.sum (3 hunks)
  • core/router/service.go (1 hunks)
  • runtime/environment.go (1 hunks)
  • runtime/module.go (2 hunks)
  • runtime/router.go (1 hunks)
  • testutil/integration/router.go (1 hunks)
Additional comments: 14
core/router/service.go (1)
  • 9-13: The introduction of the Service interface with InvokeTyped and InvokeUntyped methods is well-designed, adhering to Go's naming conventions and best practices for handling typed and untyped requests. The use of context.Context and protoiface.MessageV1 is appropriate for the operations being performed.
core/appmodule/environment.go (1)
  • 15-22: The addition of the MessageRouterService field to the Environment struct is well-integrated and follows Go's naming conventions and struct organization best practices. This change effectively incorporates the new message router service into the application's environment for broader access across modules.
core/go.mod (2)
  • 7-7: The addition of github.com/cosmos/gogoproto v1.4.11 is relevant for protobuf handling within the project. Ensure this aligns with the project's long-term dependencies strategy, especially considering the note about future removal in server modular updates.
  • 16-16: The addition of github.com/google/go-cmp v0.6.0 is suitable for implementing comparison functionality in tests or other parts of the project. This dependency should be used judiciously to avoid unnecessary complexity in comparisons.
runtime/environment.go (1)
  • 12-33: The introduction of EnvOption functions for configuring the Environment struct with optional services like the message router and memory store is a well-implemented use of the functional options pattern. This approach enhances flexibility and scalability for the Environment configuration.
runtime/router.go (1)
  • 19-77: The implementation of the msgRouterService struct and its methods InvokeTyped and InvokeUntyped is well-designed, adhering to best practices for error handling, context usage, and dynamic protobuf message handling. The use of protoregistry.GlobalTypes for message type resolution is appropriate and demonstrates a good understanding of protobuf's capabilities.
core/go.sum (1)
  • 12-18: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-43]

The updates to the go.sum file correctly reflect the addition of new dependencies and updates to existing ones as outlined in the go.mod file. These changes are essential for ensuring the integrity and reproducibility of builds.

testutil/integration/router.go (1)
  • 84-84: The integration of the message router service into the test application environment through the runtime.EnvWithMessageRouterService(router) option in the runtime.NewEnvironment function call is correctly implemented. This ensures that the message router service is available and properly configured during integration tests.
core/CHANGELOG.md (1)
  • 45-45: The changelog entry for PR feat(runtime): message router service #19571 is correctly formatted and accurately describes the addition of router.Service and its integration into appmodule.Environment. Good adherence to the changelog's guiding principles.
runtime/module.go (1)
  • 214-226: The changes made to ProvideEnvironment and the refactoring of ProvideMemoryStoreService improve the modularity and clarity of service provision within the module. These changes appear to be logically sound and correctly implemented.

Please verify the impact of these changes on modules that previously depended on ProvideMemoryStoreService to ensure they are still functioning as expected.

baseapp/msg_service_router.go (1)
  • 28-29: The addition of ResponseNameByRequestName and HybridHandlerByMsgName to the MessageRouter interface enhances the message router's functionality by allowing for more flexible and efficient message handling. These changes are correctly implemented and follow best practices.

Please verify the integration and testing of these new methods to ensure they work as expected in the broader system.

CHANGELOG.md (3)
  • 45-45: The entry for the implementation of core/router.Service is clear and correctly links to the PR. It succinctly describes the feature's impact on the runtime and its presence in all modules using dependency injection.
  • 45-45: The description of the new method IsGT for types.Coin is clear and straightforward. It's good that it specifies the method's functionality, making it easy for readers to understand its purpose.
  • 45-45: The addition of the --qrcode flag to the keys show command is a user-friendly feature that enhances the command's usability. The description is clear and directly states the new capability. However, ensuring that the documentation elsewhere (e.g., command help text or user guides) is updated to reflect this new flag would be important for user awareness.

CHANGELOG.md Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 9700f78 and c7b8a8a.
Files selected for processing (1)
  • runtime/router.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runtime/router.go

import (
"context"
"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
baseapp/msg_service_router.go Outdated Show resolved Hide resolved
runtime/router.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between c7b8a8a and 37c08d2.
Files selected for processing (2)
  • baseapp/msg_service_router.go (2 hunks)
  • runtime/router.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • baseapp/msg_service_router.go
  • runtime/router.go

runtime/router.go Outdated Show resolved Hide resolved
runtime/router.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 37c08d2 and ad4ec72.
Files selected for processing (2)
  • core/router/service.go (1 hunks)
  • runtime/router.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • core/router/service.go
  • runtime/router.go

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 64a92c4 and 092f902.
Files selected for processing (1)
  • runtime/router_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runtime/router_test.go

@julienrbrt julienrbrt marked this pull request as draft February 29, 2024 10:53
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 092f902 and dee1a22.
Files selected for processing (1)
  • runtime/router_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runtime/router_test.go

@julienrbrt julienrbrt marked this pull request as ready for review March 2, 2024 00:30
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between dee1a22 and c58a930.
Files selected for processing (15)
  • baseapp/baseapp.go (1 hunks)
  • baseapp/grpcrouter.go (3 hunks)
  • baseapp/grpcserver.go (1 hunks)
  • baseapp/msg_service_router.go (4 hunks)
  • baseapp/options.go (1 hunks)
  • core/appmodule/environment.go (1 hunks)
  • core/router/service.go (1 hunks)
  • runtime/app.go (1 hunks)
  • runtime/builder.go (1 hunks)
  • runtime/environment.go (1 hunks)
  • runtime/module.go (4 hunks)
  • runtime/router.go (1 hunks)
  • runtime/router_test.go (1 hunks)
  • testutil/integration/router.go (1 hunks)
  • x/accounts/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • baseapp/msg_service_router.go
  • core/appmodule/environment.go
  • core/router/service.go
  • runtime/environment.go
  • runtime/router.go
  • runtime/router_test.go
  • testutil/integration/router.go
Additional comments: 11
runtime/builder.go (1)
  • 34-34: The addition of SetGRPCQueryRouter correctly integrates the new grpcQueryRouter into the application's base setup, aligning with the PR's objectives to enhance message routing capabilities within the Cosmos SDK.
baseapp/grpcrouter.go (3)
  • 27-28: The addition of the responseByRequestName map in the GRPCQueryRouter struct is a valuable enhancement, enabling the mapping of request names to response names and supporting the PR's goal of improving message routing capabilities.
  • 139-141: The introduction of the ResponseNameByRequestName method is a logical extension of the responseByRequestName map, facilitating easy retrieval of response names by request names, which aligns with the PR's objectives.
  • 149-158: Updating the registerHybridHandler method to map input names to output names supports the enhanced message routing mechanism by ensuring the correct response type is associated with each request.
runtime/app.go (1)
  • 52-52: The addition of the grpcQueryRouter field to the App struct correctly integrates the new GRPCQueryRouter into the application, supporting the PR's goal of enhancing message routing capabilities.
runtime/module.go (1)
  • 217-236: The updates to the ProvideEnvironment function, including the addition of msgServiceRouter and queryServiceRouter parameters, correctly support the enhanced message routing mechanism by ensuring the necessary routers are available within the application's environment.
baseapp/options.go (2)
  • 390-392: The method SetMsgServiceRouter correctly assigns the provided MsgServiceRouter to the BaseApp instance. This change enhances the configurability of message routing within the SDK. The method is straightforward and adheres to Go best practices.
  • 395-397: The method SetGRPCQueryRouter correctly assigns the provided GRPCQueryRouter to the BaseApp instance. This addition allows for more flexible configuration of gRPC query routing, aligning with the SDK's goals of enhancing routing mechanisms. The implementation is concise and follows Go best practices.
x/accounts/keeper.go (2)
  • 107-107: The comment added to the msgRouter field indicates a future intention to utilize the environment for message routing. This comment is clear and provides valuable insight into planned architectural enhancements. It's important for future development to ensure that the transition to using the environment is seamless and well-documented.
  • 109-109: Similarly, the comment added to the queryRouter field suggests an intention to leverage the environment for query routing. This comment is concise and informative, highlighting a strategic direction for enhancing routing capabilities. Future implementations should carefully consider the impact on existing functionality and ensure backward compatibility.
baseapp/baseapp.go (1)
  • 284-285: The introduction of GRPCQueryRouter in place of MsgServiceRouter represents a significant change in how queries are routed within the application. This shift towards gRPC for query handling could enhance the application's scalability and performance by leveraging gRPC's efficient communication protocols. However, it's crucial to ensure that all existing functionalities that relied on MsgServiceRouter are adequately adapted to use GRPCQueryRouter. Additionally, thorough testing is necessary to verify that the new routing mechanism works as expected across different scenarios and does not introduce any regressions.

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between c58a930 and e38add9.
Files selected for processing (4)
  • core/CHANGELOG.md (1 hunks)
  • core/appmodule/v2/environment.go (1 hunks)
  • runtime/app.go (1 hunks)
  • x/accounts/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • core/CHANGELOG.md
  • runtime/app.go
  • x/accounts/keeper.go
Additional comments: 3
core/appmodule/v2/environment.go (3)
  • 8-8: The addition of the router package in the import statements is necessary for the new RouterService field. This change is correctly implemented.
  • 15-15: The addition of the Logger field to the Environment struct enhances logging capabilities within the SDK's runtime environment. This is a positive change for debugging and monitoring purposes.
  • 21-21: Introducing the RouterService field of type router.Router is a key part of this PR's objective to enhance message routing within the SDK. This change aligns with the PR's goals and is correctly implemented.

@tac0turtle
Copy link
Member

tac0turtle commented Mar 3, 2024

lint failure is unrelated

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between e38add9 and b3a330a.
Files selected for processing (5)
  • core/appmodule/v2/environment.go (1 hunks)
  • core/router/service.go (1 hunks)
  • runtime/router.go (1 hunks)
  • x/accounts/keeper.go (3 hunks)
  • x/accounts/utils_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • core/appmodule/v2/environment.go
  • core/router/service.go
  • runtime/router.go
  • x/accounts/keeper.go
Additional comments: 1
x/accounts/utils_test.go (1)
  • 92-92: The method ResponseNameByMsgName correctly reflects its purpose of determining the response name based on the message name. This change aligns with the broader PR objectives of enhancing message routing within the Cosmos SDK. The implementation appears straightforward and adheres to Go best practices. However, ensure that all references to the old method name ResponseNameByRequestName across the codebase have been updated to ResponseNameByMsgName to maintain consistency and avoid potential runtime errors.

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

lgtm, but i think we'll need to investigate if the InvokeUntyped API is good enough and safe

@julienrbrt julienrbrt added this pull request to the merge queue Mar 4, 2024
Merged via the queue into main with commit cfd426f Mar 4, 2024
61 of 63 checks passed
@julienrbrt julienrbrt deleted the julien/msgrouterservice branch March 4, 2024 10:29
@julienrbrt
Copy link
Member Author

lgtm, but i think we'll need to investigate if the InvokeUntyped API is good enough and safe

I have added tests, and migrating gov to use it here: #19481.
This will make us figure that out real fast :D

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.

5 participants