-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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(depinject): Add gogo support for depinject #20403
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedReview was skipped due to path filters Files ignored due to path filters (2)
You can disable this status message by setting the WalkthroughThe changes introduce support for gogo protobuf in the Cosmos SDK's dependency injection (depinject) system, allowing users to avoid generating Pulsar types. This involves adding new methods for type URLs and Golang bindings in Changes
Assessment against linked issues
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Referencing this, as it is important too: #20389 (comment) |
…os/cosmos-sdk into hieu/depinject_gogo_support
@hieuvubk your pull request is missing a changelog! |
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: 1
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (5)
api/cosmos/app/v2/config.pb.go
is excluded by!**/*.pb.go
api/cosmos/app/v2/module.pb.go
is excluded by!**/*.pb.go
depinject/go.mod
is excluded by!**/*.mod
depinject/go.sum
is excluded by!**/*.sum
depinject/internal/appconfig/testpb/test.pb.go
is excluded by!**/*.pb.go
Files selected for processing (6)
- api/cosmos/app/v1alpha1/types.go (1 hunks)
- api/cosmos/app/v2/types.go (1 hunks)
- depinject/appconfig/config.go (3 hunks)
- depinject/appconfig/config_test.go (2 hunks)
- depinject/appconfig/module.go (1 hunks)
- depinject/internal/appconfig/registry.go (2 hunks)
Additional Context Used
Path-based Instructions (6)
api/cosmos/app/v2/types.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.api/cosmos/app/v1alpha1/types.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/internal/appconfig/registry.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/module.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/config.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/config_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"
Additional comments not posted (9)
api/cosmos/app/v2/types.go (2)
5-14
: The implementation ofGetTypeUrl
method correctly handles nil checks for both theModuleConfig
and itsConfig
field, providing appropriate error messages. This is a good practice for robust error handling.
16-28
: The methodGetGolangBindingsStrings
effectively extracts interface types and their implementations fromGolangBindings
. Using slices with pre-allocated lengths based on the input slice ensures efficient memory usage.api/cosmos/app/v1alpha1/types.go (2)
5-14
: TheGetTypeUrl
method is implemented consistently with the v2 version, including comprehensive nil handling and clear error messaging. This consistency across versions helps in maintaining a uniform interface.
16-28
: Similar to the v2 implementation,GetGolangBindingsStrings
is well-implemented with efficient memory management and clear structure in handling the bindings. Consistency in method implementations across versions is beneficial.depinject/internal/appconfig/registry.go (1)
35-50
: The logic to handle both v1 and v2 protobuf messages usingprotoadapt
is a clever use of the adapter pattern to ensure compatibility across different versions of protobuf messages. However, ensure that the error handling is robust enough to manage potential issues during the type assertions and conversions.#!/bin/bash # Description: Verify robust error handling for type assertions in registry.go. # Test: Search for error handling related to type assertions. Expect: Proper error checks after type assertions. rg --type go 'if _, ok := .*\.(.*); !ok {' ./depinject/internal/appconfig/registry.godepinject/appconfig/module.go (1)
7-7
: Switching the import togithub.com/cosmos/gogoproto/proto
aligns with the PR's goal to support gogo protobufs. This change should be reflected across all files that interact with protobufs to maintain consistency.depinject/appconfig/config.go (2)
20-40
: The updatedLoadJSON
function now supports both v1alpha1 and v2 configurations using respective unmarshalers. This dual support enhances the flexibility of the configuration loading but ensure that the error paths are thoroughly tested to handle any inconsistencies between the two versions.#!/bin/bash # Description: Verify thorough testing of error paths in LoadJSON function. # Test: Search for test cases covering error paths in LoadJSON. Expect: Comprehensive test cases in config_test.go. rg --type go 'LoadJSON' ./depinject/appconfig/config_test.go
63-190
: TheCompose
function has been significantly refactored to handle different versions of configurations and their modules. The use of interfaces and type assertions is appropriate, but it's crucial to ensure that all edge cases and error conditions are covered in unit tests, especially for the new branching logic introduced.#!/bin/bash # Description: Verify coverage of edge cases in Compose function. # Test: Search for test cases covering new logic in Compose. Expect: Specific tests for branching logic. rg --type go 'Compose' ./depinject/appconfig/config_test.godepinject/appconfig/config_test.go (1)
124-221
: The new testTestComposeGogoTypes
is crucial for verifying the integration of gogo types. It's well-structured to simulate various scenarios and error conditions. Ensure that these tests are comprehensive enough to cover all new logic introduced in theCompose
function.
fullName := descriptor.FullName() | ||
if _, ok := res[fullName]; ok { | ||
return nil, fmt.Errorf("duplicate module registration for %s", fullName) | ||
} | ||
|
||
modDesc := proto.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor) | ||
modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor) |
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.
The use of GetExtension
to fetch module descriptors is correctly implemented. However, consider adding null checks after retrieving the extension to prevent potential nil pointer dereferences.
- modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
+ modDesc, ok := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
+ if !ok {
+ return nil, fmt.Errorf("failed to get module descriptor for %s", fullName)
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor) | |
modDesc, ok := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor) | |
if !ok { | |
return nil, fmt.Errorf("failed to get module descriptor for %s", fullName) | |
} |
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.
Great start!
Looking for some clarification on code gen and design decision to use an interface.
api/cosmos/app/v2/config.pb.go
Outdated
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.
What command was run to generate these files? There must be counterparty protofiles in proto/cosmos/app/v2
which I don't see in this PR. Could you explain a bit on why a v2 API is needed?
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.
Its for appconfig.Compose
since rn it just supports appv1alpha1
types.
Also, regened module & config to api/cosmos/app/v2
with some changes in gen script cause we just want v2 as gogo types I think
# remove /api/cosmos/app/v2 folder since v2 not support pulsar
rm -rf $home/api/cosmos/app/v2/*.pulsar.go
api/cosmos/app/v1alpha1/types.go
Outdated
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.
This usage of interface implementation seems overly complex, can't we just type switch in depinject. We don't need support for n variations of generated proto types.
@@ -121,11 +121,122 @@ modules: | |||
expectContainerErrorContains(t, opt, "module should have ModuleDescriptor.go_import specified") | |||
} | |||
|
|||
func TestComposeGogoTypes(t *testing.T) { |
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.
How is this test different from TestCompose
? It looks like a lot of repeated code, maybe just include the new test cases which test the new code path, i.e. yamls like
"@type": type.googleapis.com/testpb.TestGogoUnregisteredModule
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.
yeah its quite same, cause Compose take v1 msg or v2 as input so I separate tests for each case
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: 3
Outside diff range and nitpick comments (1)
scripts/protocgen.sh (1)
Line range hint
19-19
: Ensure proper quoting to prevent globbing and word splitting.- find ./ -name "*.proto" -exec clang-format -i {} \; + find ./ -name "*.proto" -exec clang-format -i "{}" \; - if [ -d "../cosmos" -a "$dir" != "./proto" ]; then + if [ -d "../cosmos" ] && [ "$dir" != "./proto" ]; then - rm -rf $home/api/cosmos/app/v2/*.pulsar.go + rm -rf "$home/api/cosmos/app/v2"/*.pulsar.go - if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*cosmossdk.io/api' "$file" | grep -q ':0$'; then + if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*cosmossdk.io/api' "$file" | grep -q ':0$'; then - cp -r ../cosmossdk.io/* $home + cp -r ../cosmossdk.io/* "$home" - cp -r ../github.com/cosmos/cosmos-sdk/* $home + cp -r ../github.com/cosmos/cosmos-sdk/* "$home" - rm -rf github.com + rm -rf "github.com"Also applies to: 25-25, 29-29, 40-40, 46-46, 51-51, 56-56
Tools
Shellcheck
[warning] 24-24: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
[info] 25-25: Double quote to prevent globbing and word splitting.
[info] 29-29: Double quote to prevent globbing and word splitting.
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (9)
api/cosmos/app/v2/config.pb.go
is excluded by!**/*.pb.go
api/cosmos/app/v2/module.pb.go
is excluded by!**/*.pb.go
api/go.mod
is excluded by!**/*.mod
api/go.sum
is excluded by!**/*.sum
depinject/go.mod
is excluded by!**/*.mod
depinject/go.sum
is excluded by!**/*.sum
depinject/internal/appconfig/testpb/test_gogo.pb.go
is excluded by!**/*.pb.go
orm/go.mod
is excluded by!**/*.mod
orm/go.sum
is excluded by!**/*.sum
Files selected for processing (9)
- depinject/appconfig/config.go (4 hunks)
- depinject/appconfig/config_test.go (2 hunks)
- depinject/appconfig/module.go (1 hunks)
- depinject/internal/appconfig/buf.gen.gogo.yaml (1 hunks)
- depinject/internal/appconfig/registry.go (2 hunks)
- depinject/internal/appconfig/testpb/test_gogo.proto (1 hunks)
- proto/cosmos/app/v2/config.proto (1 hunks)
- proto/cosmos/app/v2/module.proto (1 hunks)
- scripts/protocgen.sh (1 hunks)
Additional context used
Path-based instructions (4)
depinject/internal/appconfig/registry.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/module.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/config.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.depinject/appconfig/config_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"
Shellcheck
scripts/protocgen.sh
[info] 19-19: Double quote to prevent globbing and word splitting.
[warning] 24-24: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
[info] 25-25: Double quote to prevent globbing and word splitting.
[info] 29-29: Double quote to prevent globbing and word splitting.
[warning] 35-35: For loops over find output are fragile. Use find -exec or a while read loop.
[info] 40-40: Double quote to prevent globbing and word splitting.
[warning] 45-45: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
[info] 46-46: Double quote to prevent globbing and word splitting.
[warning] 50-50: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
[info] 51-51: Double quote to prevent globbing and word splitting.
[info] 56-56: Double quote to prevent globbing and word splitting.
golangci-lint
depinject/internal/appconfig/registry.go
6-6: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
12-12: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
40-40: S1040: type assertion to the same type: initializer.ConfigProtoMessage already has type proto.Message
depinject/appconfig/module.go
8-8: use of internal package cosmossdk.io/depinject/internal/appconfig not allowed
depinject/appconfig/config.go
21-21: use of internal package cosmossdk.io/depinject/internal/appconfig not allowed
depinject/appconfig/config_test.go
15-15: use of internal package cosmossdk.io/depinject/internal/appconfig not allowed
Additional comments not posted (15)
depinject/internal/appconfig/buf.gen.gogo.yaml (1)
1-11
: Configuration settings for gogo support are correctly specified.depinject/internal/appconfig/testpb/test_gogo.proto (1)
1-38
: All protobuf message definitions are correctly configured withgo_import
options.depinject/internal/appconfig/registry.go (1)
50-50
: Consider adding null checks after retrieving the extension to prevent potential nil pointer dereferences.proto/cosmos/app/v2/config.proto (1)
1-57
: The new protobuf definitions forConfig
andModuleConfig
are correctly implemented to support the new functionality.proto/cosmos/app/v2/module.proto (3)
21-41
: AddedModuleDescriptor
message to describe app modules, including import paths and migration capabilities.
43-83
: IntroducedPackageReference
message to manage protobuf package versions used by modules.
86-93
: AddedMigrateFromInfo
message to handle module version migrations.depinject/appconfig/config.go (6)
8-10
: Added imports forgogoproto
to support the new gogo functionality.
19-19
: Importedappv2
to handle version 2 of app configurations.
28-37
: UpdatedLoadJSON
to handle bothappv1alpha1
andappv2
configurations using gogo's JSON parsing.
61-65
: DefinedModuleConfigI
interface to standardize module configuration interactions.
69-196
: RefactoredCompose
to support dynamic module configuration and binding based on the provided app configuration version.
210-213
: SimplifiedGetProtoV1MsgNameFromAnyTypeUrl
to extract message names from URLs.depinject/appconfig/config_test.go (2)
38-38
: Added a test case to handle unknown message types in YAML configurations.
124-221
: UpdatedTestComposeGogoTypes
to include tests for the new gogo types and error handling.
protov2 "google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/protoadapt" | ||
"google.golang.org/protobuf/reflect/protoreflect" | ||
|
||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
"github.com/cosmos/gogoproto/proto" |
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.
Ensure imports are grouped correctly according to the Golang style guide.
import (
"fmt"
"reflect"
protov2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/protoadapt"
"google.golang.org/protobuf/reflect/protoreflect"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"github.com/cosmos/gogoproto/proto"
)
Committable suggestion was skipped due low confidence.
Tools
golangci-lint
12-12: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
if ok { | ||
descriptor = v2Msg.ProtoReflect().Descriptor() | ||
} else { | ||
v1Msg, _ := initializer.ConfigProtoMessage.(proto.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.
Remove unnecessary type assertion, as it is redundant.
- v1Msg, _ := initializer.ConfigProtoMessage.(proto.Message)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
v1Msg, _ := initializer.ConfigProtoMessage.(proto.Message) |
Tools
golangci-lint
40-40: S1040: type assertion to the same type: initializer.ConfigProtoMessage already has type proto.Message
@@ -3,7 +3,7 @@ package appconfig | |||
import ( | |||
"reflect" | |||
|
|||
"google.golang.org/protobuf/proto" | |||
"github.com/cosmos/gogoproto/proto" |
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.
Avoid using internal packages in public API implementations to ensure proper encapsulation and package independence.
- import internal "cosmossdk.io/depinject/internal/appconfig"
Committable suggestion was skipped due low confidence.
} else { | ||
config := init.ConfigProtoMessage.(proto.Message) | ||
|
||
anyCfg := &gogotypes.Any{ |
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.
cast from gogoproto/types/any.Any
to gogoproto/types.Any
then UnmarshalAny
.
This codes can be replaced by
codectypes.NewInterfaceRegistry().UnpackAny()
but will make dependencies bigger as cosmos-sdk import
Description
Closes: #20134
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...
depinject.Compose
version that support gogoReviewers 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...
Summary by CodeRabbit
New Features
appv2
), alongside the existingappv1alpha1
.ModuleDescriptor
message to describe app modules and their migration information.Refactor
LoadJSON
andCompose
functions to support bothappv1alpha1
andappv2
configurations.Chores
google.golang.org/protobuf/proto
and addedgithub.com/cosmos/gogoproto/proto
.