refactor(codec/unknownproto): use official descriptorpb types, do not rely on gogo code gen types.#18541
Conversation
WalkthroughWalkthroughThe changes involve refactoring the Changes
Assessment against linked issues
Related issues (Beta)
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 8
codec/unknownproto/unknown_fields.go (8)
10-19: The import of
github.com/cosmos/gogoproto/protoshould be removed if it is no longer used after the refactoring to usedescriptorpbtypes.100-113: The comment on lines 111-113 references
github.com/cosmos/gogoproto, which may no longer be relevant if the dependency ongogoprotobuf has been removed. Verify if this comment needs updating or removal.198-257: The
checksarray has been updated to usedescriptorpb.FieldDescriptorProto_Type. Ensure that all references tochecksthroughout the codebase are updated to use the correct index type (intinstead ofprotowire.Type).260-265: The
canEncodeTypefunction signature has been updated to useintforwireType. Ensure that all calls to this function are updated accordingly.364-370: The
extractFileDescMessageDescfunction is usingprotov2.Unmarshalwhich is correct as per the refactor. However, ensure that theprotoBlobis correctly formatted fordescriptorpb.FileDescriptorProtobefore unmarshalling.381-384: The
descriptorMatchstruct has been updated to usedescriptorpb.FieldDescriptorProto. Ensure that all usages ofdescriptorMatchare consistent with this change.440-483: The
findWireTypeFromFieldDescriptorProtoTypefunction should be reviewed to ensure that it returns the correctprotowire.Typefor eachdescriptorpb.FieldDescriptorProto_Type. This is critical as the function is used to determine the expected wire type for a given field descriptor type.486-509: The
isScalarfunction checks if a field is a scalar type. Ensure that the function's logic is still correct after the refactor and that it aligns with the updateddescriptorpb.FieldDescriptorProto_Typevalues.
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
- 67-67:
The changelog entry is clear and follows the repository's format for documenting changes.
There was a problem hiding this comment.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (1)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 7
codec/unknownproto/unknown_fields.go (7)
13-17: The import of
github.com/cosmos/gogoproto/protoshould be removed if it's no longer used after the refactor to usedescriptorpb.101-114: The comment on lines 112-113 seems to be outdated and should be updated or removed if it no longer applies to the current implementation.
199-258: The
checksarray is a good optimization for constant time lookups. Ensure that all wire types and descriptor types are correctly mapped and that no types are missing.365-371: Ensure that the error from
gzip.NewReaderandio.ReadAllare handled properly and that the resources are closed appropriately to avoid resource leaks.380-385: The
descriptorMatchstruct is used for caching, ensure that the cache is properly synchronized to prevent data races.407-413: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [392-413]
When caching descriptor information in
descprotoCache, ensure that the cache is invalidated or updated when descriptors change to prevent stale data issues.
- 487-510: The
isScalarfunction correctly identifies scalar types. Ensure that this function is used consistently throughout the codebase to determine scalar types.
| Type: reflect.ValueOf(msg).Type().String(), | ||
| TagNum: tagNum, | ||
| GotWireType: wireType, | ||
| WantWireType: protowire.Type(fieldDescProto.WireType()), | ||
| WantWireType: findWireTypeFromFieldDescriptorProtoType(fieldDescProto.GetType()), | ||
| } |
There was a problem hiding this comment.
The error struct errMismatchedWireType should include the expected and actual wire types using descriptorpb.FieldDescriptorProto_Type instead of protowire.Type to align with the refactor.
odeke-em
left a comment
There was a problem hiding this comment.
Thank you for this change @testinginprod. I've added some comments. Although what's the rationale behind this change? Is it to get rid of the protogen-gogo-descriptor package? If it is, I believe we forked an entire repository for which it'll still exist. Thank you
|
@odeke-em thank you for the review. This is a preliminary step PR to make a more significant change to unknownproto, specifically unknonwproto currently does not allow This is not desirable for two reasons:
Alongside enabling support for having non-interface-registry anys in TXs, we want to also be able to decode anys which have a protov2 counterparty but not a gogoproto one. Using default descriptorpb types makes this transition a lot more effortless otherwise we'd be forced to convert from gogo-protoc-gen.Descriptor into descriptorp.Descriptor . |
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 11
codec/unknownproto/unknown_fields.go (11)
12-20: The import changes align with the summary and the refactoring goal of using
descriptorpbtypes from the official protobuf library.69-72: The update to use
fieldTypeToProtowireTypefor determiningWantWireTypeis consistent with the refactoring goal and should ensure correct wire type matching.104-104: The update to use
isScalarfor checking if a field is scalar aligns with the refactoring goal and the summary.199-266: The refactoring of
checksto usedescriptorpb.FieldDescriptorProto_Typeis consistent with the goal of usingdescriptorpbtypes.333-335: The update of the global variable
protoFileToDescto usedescriptorpb.FileDescriptorProtois consistent with the refactoring goal.337-342: The update of the
unnestDescfunction signature to usedescriptorpb.DescriptorProtois consistent with the refactoring goal.347-350: The update of the
extractFileDescMessageDescfunction signature to usedescriptorpbtypes is consistent with the refactoring goal.393-396: The update of the
getDescriptorInfofunction signature to usedescriptorpbtypes is consistent with the refactoring goal.441-442: The
DefaultAnyResolver.Resolvefunction signature appears unchanged, which seems to be a no-op. Please verify if this was intentional or if changes were expected but not made.445-504: The addition of the
fieldTypeToProtowireTypeandisScalarfunctions is consistent with the refactoring goal and the summary.480-481: The citation for the
isScalarfunction is correctly included, addressing the previous review comment.
There was a problem hiding this comment.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- CHANGELOG.md (1 hunks)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 14
codec/unknownproto/unknown_fields.go (14)
12-20: The import changes align with the summary, replacing
github.com/cosmos/gogoproto/protoc-gen-gogo/descriptorwithprotov2 "google.golang.org/protobuf/proto"and"google.golang.org/protobuf/types/descriptorpb".69-72: The use of
fieldTypeToProtowireTypein theerrMismatchedWireTypestruct instantiation is consistent with the summary.104-104: The use of
isScalarin the condition withinRejectUnknownFieldsis consistent with the summary.199-258: The constants and maps have been correctly updated to use
descriptorpb.FieldDescriptorProto.199-258: The
protoMessageForTypeNamefunction has been updated to return an error, aligning with the summary.261-266: The
canEncodeTypefunction has been updated to takedescriptorpb.FieldDescriptorProto_Type, which is consistent with the summary.337-342: The
unnestDescfunction has been updated to takedescriptorpb.DescriptorProto, which is consistent with the summary.365-372: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [347-372]
The
extractFileDescMessageDescfunction has been updated to returndescriptorpb.FileDescriptorProtoanddescriptorpb.DescriptorProto, which is consistent with the summary.
383-384: The
cachefield in thedescriptorMatchstruct has been updated to usedescriptorpb.FieldDescriptorProto, which is consistent with the summary.393-396: The
getDescriptorInfofunction has been updated to returnmap[int32]*descriptorpb.FieldDescriptorProtoand*descriptorpb.DescriptorProto, which is consistent with the summary.333-334: The
protoFileToDescmap has been updated to usedescriptorpb.FileDescriptorProto, which is consistent with the summary.441-442: The
Resolvemethod inDefaultAnyResolverhas been updated to returnproto.Messageand an error, which is consistent with the summary.445-477: The new function
fieldTypeToProtowireType()has been added, aligning with the summary.479-505: The new function
isScalar()has been added, aligning with the summary. However, the comment indicates that the code was copied fromgogo/protobuf, which matches the existing comment from a previous review. This should be verified to ensure proper attribution is given.
odeke-em
left a comment
There was a problem hiding this comment.
Thank you @testinginprod, LGTM with some comments.
|
thank you @odeke-em, reviews have been addressed. |
|
Awesome, thank you and LGTM++ |
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 14
codec/unknownproto/unknown_fields.go (14)
13-17: The import changes are consistent with the summary and reflect the transition to official
descriptorpbtypes.69-72: The replacement of
protowire.Type(fieldDescProto.WireType())withtoProtowireType(fieldDescProto.GetType())is consistent with the summary.104-104: The replacement of
fieldDescProto.IsScalar()withisScalar(fieldDescProto)is consistent with the summary.202-258: The constants and maps have been correctly updated to use
descriptorpb.FieldDescriptorProto.263-266: The function signature for
canEncodeTypehas been correctly updated to usedescriptorpb.FieldDescriptorProto_Type.337-342: The function signature for
unnestDeschas been correctly updated to usedescriptorpb.DescriptorProto.365-372: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [347-372]
The function
extractFileDescMessageDeschas been correctly updated to returndescriptorpbtypes.
382-384: The type
descriptorMatchhas been correctly updated to usedescriptorpbtypes.407-413: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [392-413]
The function
getDescriptorInfohas been correctly updated to returndescriptorpbtypes.
333-333: The map
protoFileToDeschas been correctly updated to usedescriptorpb.FileDescriptorProto.445-480: The function
toProtowireTypehas been correctly added to the codebase.485-507: The function
isScalarhas been correctly added to the codebase.484-484: The citation for the
isScalarfunction has been added as requested in a previous review.459-459: The code has appropriate spacing between sections, which should aid in readability as suggested in a previous review.
|
@testinginprod please update with the latest from main. |
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- codec/unknownproto/unknown_fields.go (10 hunks)
Additional comments: 12
codec/unknownproto/unknown_fields.go (12)
13-17: The import changes are correctly reflected in the code, aligning with the summary.
69-74: The update to use
toProtowireTypein theRejectUnknownFieldsfunction is correctly implemented.105-115: The update to use
isScalarin theRejectUnknownFieldsfunction is correctly implemented.200-267: The constants and maps related to field types have been updated correctly, reflecting the changes from
descriptor.FieldDescriptorProto_Typetodescriptorpb.FieldDescriptorProto_Type.264-267: The function
canEncodeTypehas been correctly updated to takedescType descriptorpb.FieldDescriptorProto_Type.334-345: The map
protoFileToDeschas been correctly updated to usedescriptorpb.FileDescriptorProto.338-343: The function
unnestDeschas been correctly updated to takemdescs []*descriptorpb.DescriptorProto.366-373: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [348-373]
The function
extractFileDescMessageDeschas been correctly updated to return*descriptorpb.FileDescriptorProtoand*descriptorpb.DescriptorProto.
383-385: The type
descriptorMatchhas been correctly updated to use*descriptorpb.FieldDescriptorProtoand*descriptorpb.DescriptorProto.394-397: The function
getDescriptorInfohas been correctly updated to returnmap[int32]*descriptorpb.FieldDescriptorProtoand*descriptorpb.DescriptorProto.447-480: The function
toProtowireTypehas been correctly added to convertdescriptorpb.FieldDescriptorProto_Typetoprotowire.Type.486-508: The function
isScalarhas been correctly added to determine whether a field is a scalar type.
Description
Closes: #18540
This PR removes de gogo-proto-gen dependency from unknown proto and uses the official descriptor APIs living google.golang.org/protobuf.
This is a required step for a sub-sequent PR which will enable the usage of google.Protobuf.Anys in Txs without them being registered in the interface registry.
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...
!to the type prefix if API or client breaking changeCHANGELOG.mdmake lintandmake testReviewers 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...
!in the type prefix if API or client breaking changeSummary by CodeRabbit
Refactor
descriptorpbtypes for enhanced compatibility and future maintenance.Bug Fixes
New Features
Documentation
descriptorpbtypes and the removal of deprecatedprotoc-gen-gogo/descriptorusage.