-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(x/tx): fallback to injected resolver for placeholder descriptors #22852
Conversation
📝 WalkthroughWalkthroughThe pull request updates the changelog for the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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
🧹 Outside diff range and nitpick comments (2)
x/tx/decode/unknown.go (2)
90-93
: Enhance error message with more contextThe error message could be more helpful by including the full name of the descriptor being resolved.
Apply this diff to improve the error message:
- return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor: %v: %w", fieldMessage, err) + return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor %q: %w", fieldMessage.FullName(), err)
86-88
: Fix typo in commentThere's a typo in the word "registry" in the comment.
Apply this diff to fix the typo:
- // "google.golang.org/protobuf" resgistry but not in "github.com/cosmos/gogoproto". + // "google.golang.org/protobuf" registry but not in "github.com/cosmos/gogoproto".
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
x/tx/CHANGELOG.md
(1 hunks)x/tx/decode/unknown.go
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- x/tx/CHANGELOG.md
🧰 Additional context used
📓 Path-based instructions (1)
x/tx/decode/unknown.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
// if a message descriptor is a placeholder resolve it using the injected resolver. | ||
// this can happen when a descriptor has been registered in the | ||
// "google.golang.org/protobuf" resgistry but not in "github.com/cosmos/gogoproto". | ||
// fixes: https://github.com/cosmos/cosmos-sdk/issues/22574 | ||
if fieldMessage.IsPlaceholder() { | ||
gogoDesc, err := resolver.FindDescriptorByName(fieldMessage.FullName()) | ||
if err != nil { | ||
return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor: %v: %w", fieldMessage, err) | ||
} | ||
fieldMessage = gogoDesc.(protoreflect.MessageDescriptor) | ||
} |
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.
🛠️ Refactor suggestion
Add type assertion safety check
The implementation looks good overall, but the type assertion on line 94 could panic if the resolver returns an unexpected type. Consider adding a type safety check.
Apply this diff to add type safety:
if err != nil {
return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor: %v: %w", fieldMessage, err)
}
- fieldMessage = gogoDesc.(protoreflect.MessageDescriptor)
+ msgDesc, ok := gogoDesc.(protoreflect.MessageDescriptor)
+ if !ok {
+ return hasUnknownNonCriticals, fmt.Errorf("resolved descriptor is not a message descriptor: got %T", gogoDesc)
+ }
+ fieldMessage = msgDesc
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
// if a message descriptor is a placeholder resolve it using the injected resolver. | |
// this can happen when a descriptor has been registered in the | |
// "google.golang.org/protobuf" resgistry but not in "github.com/cosmos/gogoproto". | |
// fixes: https://github.com/cosmos/cosmos-sdk/issues/22574 | |
if fieldMessage.IsPlaceholder() { | |
gogoDesc, err := resolver.FindDescriptorByName(fieldMessage.FullName()) | |
if err != nil { | |
return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor: %v: %w", fieldMessage, err) | |
} | |
fieldMessage = gogoDesc.(protoreflect.MessageDescriptor) | |
} | |
// if a message descriptor is a placeholder resolve it using the injected resolver. | |
// this can happen when a descriptor has been registered in the | |
// "google.golang.org/protobuf" resgistry but not in "github.com/cosmos/gogoproto". | |
// fixes: https://github.com/cosmos/cosmos-sdk/issues/22574 | |
if fieldMessage.IsPlaceholder() { | |
gogoDesc, err := resolver.FindDescriptorByName(fieldMessage.FullName()) | |
if err != nil { | |
return hasUnknownNonCriticals, fmt.Errorf("could not resolve placeholder descriptor: %v: %w", fieldMessage, err) | |
} | |
msgDesc, ok := gogoDesc.(protoreflect.MessageDescriptor) | |
if !ok { | |
return hasUnknownNonCriticals, fmt.Errorf("resolved descriptor is not a message descriptor: got %T", gogoDesc) | |
} | |
fieldMessage = msgDesc | |
} |
Description
Closes: #22574
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
v1.0.0-alpha.3
and previous versions.