-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: marshal old tx body if unordered not used #22723
Conversation
📝 WalkthroughWalkthroughThis pull request introduces changes across multiple files to enhance transaction compatibility and simplify codec implementation. The primary modifications include removing the Changes
Possibly related issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🧰 Additional context used📓 Path-based instructions (1)baseapp/abci_utils_test.go (2)Pattern Pattern ⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (5)
Finishing Touches
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
|
@julienrbrt 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
🧹 Outside diff range and nitpick comments (2)
client/tx/tx.go (1)
137-137
: Typo in comment: Change 'accross' to 'across'There's a typo in the comment on line 137; 'accross' should be 'across'.
Apply this diff to correct the typo:
-// It helps the client to be compatible accross SDK versions. +// It helps the client to be compatible across SDK versions.🧰 Tools
🪛 golangci-lint (1.62.2)
137-137:
accross
is a misspelling ofacross
(misspell)
client/v2/tx/encoder.go (1)
26-26
: Typo in comment: Change 'accross' to 'across'There's a typo in the comment on line 26; 'accross' should be 'across'.
Apply this diff to correct the typo:
-// It helps the client to be compatible accross SDK versions. +// It helps the client to be compatible across SDK versions.🧰 Tools
🪛 golangci-lint (1.62.2)
26-26:
accross
is a misspelling ofacross
(misspell)
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 Files selected for processing (6)
client/tx/factory.go
(1 hunks)client/tx/tx.go
(3 hunks)client/v2/tx/encoder.go
(1 hunks)codec/codec.go
(1 hunks)codec/json.go
(1 hunks)codec/proto_codec.go
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- client/tx/factory.go
🧰 Additional context used
📓 Path-based instructions (5)
client/v2/tx/encoder.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
codec/codec.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
codec/proto_codec.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
codec/json.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
client/tx/tx.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
🪛 golangci-lint (1.62.2)
client/v2/tx/encoder.go
26-26: accross
is a misspelling of across
(misspell)
client/tx/tx.go
137-137: accross
is a misspelling of across
(misspell)
🔇 Additional comments (6)
client/tx/tx.go (3)
12-12
: LGTM: Necessary imports added
The added imports are appropriate and necessary for the new functionalities introduced in the code.
Also applies to: 17-18, 25-25
136-149
: LGTM: Custom encoder implementation to skip unpopulated fields
The introduction of the custom encoder using clientProtoCodec
to avoid emitting unpopulated fields enhances compatibility across SDK versions. The fallback mechanism to the default encoder ensures robustness in case of any issues with the custom encoder.
🧰 Tools
🪛 golangci-lint (1.62.2)
137-137: accross
is a misspelling of across
(misspell)
456-468
: LGTM: Implementation of clientProtoCodec
and MarshalJSON
method
The clientProtoCodec
struct and its MarshalJSON
method are correctly implemented to marshal messages while skipping empty fields. This aligns with the goal of improving compatibility and reducing unnecessary data in transaction encoding.
client/v2/tx/encoder.go (1)
25-29
: LGTM: Setting EmitUnpopulated
to false
Setting EmitUnpopulated: false
in jsonMarshalOptions
appropriately configures the JSON marshaling to omit unpopulated fields. This change enhances compatibility across SDK versions by preventing the inclusion of zero-value fields.
🧰 Tools
🪛 golangci-lint (1.62.2)
26-26: accross
is a misspelling of across
(misspell)
codec/codec.go (1)
44-44
: Verify the impact of commenting out mustEmbedCodec()
By commenting out mustEmbedCodec()
in the Codec
interface, the requirement for implementations to embed an official codec is removed. Please verify that this modification does not affect backward compatibility or lead to unintended side effects in codec implementations.
codec/proto_codec.go (1)
24-24
: Confirm the removal of ProtoCodecMarshaler
interface
The removal of the ProtoCodecMarshaler
interface simplifies the codec structure. Ensure that this change does not impact any existing components that may rely on this interface and that all necessary functionalities are preserved.
codec/json.go
Outdated
jm := defaultJM | ||
jm.EmitDefaults = false |
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 modifying the shared defaultJM
variable
Modifying the shared defaultJM
variable by changing its EmitDefaults
field can introduce unintended side effects in other parts of the code that rely on defaultJM
. Instead, create a new instance of jsonpb.Marshaler
with the desired settings.
Apply this diff to fix the issue:
func ProtoMarshalJSONSkipEmpty(msg proto.Message, resolver jsonpb.AnyResolver) ([]byte, error) {
- jm := defaultJM
- jm.EmitDefaults = false
+ jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: false, AnyResolver: nil}
if resolver != nil {
jm = &jsonpb.Marshaler{OrigName: true, EmitDefaults: false, AnyResolver: resolver}
}
📝 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.
jm := defaultJM | |
jm.EmitDefaults = false | |
jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: false, AnyResolver: nil} | |
if resolver != nil { | |
jm = &jsonpb.Marshaler{OrigName: true, EmitDefaults: false, AnyResolver: resolver} | |
} |
Turned out that didn't work. I'll check another way. |
8b9f767
to
196a748
Compare
@@ -257,6 +257,7 @@ require ( | |||
// replace ( | |||
// <temporary replace> | |||
// ) | |||
replace cosmossdk.io/api => ../../api |
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.
I'll have a follow-up to tag v8.0.1 and and bump it here and in the SDK.
proto/cosmos/tx/v1beta1/tx.proto
Outdated
// This message is used to represent the transaction body before the unordered | ||
// features was added. It is used to support backwards compatibility when user a newer | ||
// client with an older chain. | ||
message TxBodyPreUnorderedTxs { |
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.
Can we name this Legacy*
to indicate that this is some kind of backwards compat struct?
Reading this name right now, it's unclear without reading the godoc what it actually is for
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.
Sure! I'll try to find a better name.
I am not sure about legacy however; it is too better
x.NonCriticalExtensionOptions = *clv.list | ||
default: | ||
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.v1beta1.TxBodyCompat")) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.v1beta1.TxBodyCompat")) | ||
} | ||
panic(fmt.Errorf("message cosmos.tx.v1beta1.TxBodyCompat does not contain field %s", fd.FullName())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
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: 0
🧹 Nitpick comments (1)
api/cosmos/tx/v1beta1/tx.pulsar.go (1)
9562-9569
: Consider adding validation for extension optionsWhile the implementation is correct, consider adding validation to ensure extension options don't contain features incompatible with older clients.
Consider adding validation logic to check extension options compatibility when marshaling/unmarshaling.
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
tests/go.sum
is excluded by!**/*.sum
types/tx/tx.pb.go
is excluded by!**/*.pb.go
📒 Files selected for processing (4)
api/cosmos/tx/v1beta1/tx.pulsar.go
(38 hunks)proto/cosmos/tx/v1beta1/tx.proto
(1 hunks)tests/go.mod
(1 hunks)x/auth/tx/builder.go
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- proto/cosmos/tx/v1beta1/tx.proto
🧰 Additional context used
📓 Path-based instructions (3)
tests/go.mod (1)
Pattern tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"
x/auth/tx/builder.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
api/cosmos/tx/v1beta1/tx.pulsar.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
🪛 GitHub Actions: CodeQL
x/auth/tx/builder.go
[error] 120-120: Undefined type error: txv1beta1.TxBodyCompat is not defined
🪛 GitHub Check: CodeQL
api/cosmos/tx/v1beta1/tx.pulsar.go
[warning] 4028-4028: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
[warning] 4030-4030: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (6)
x/auth/tx/builder.go (2)
119-136
: Verify backward compatibility with v0.50 clientsThe conditional logic for selecting between
TxBodyCompat
andTxBody
looks correct and aligns with the PR objective. This ensures compatibility with v0.50 clients when new features aren't used.Let's verify the transaction handling in v0.50:
✅ Verification successful
Backward compatibility with v0.50 clients is correctly implemented
The conditional logic for selecting between
TxBodyCompat
andTxBody
is properly implemented and aligns with the protobuf definitions in v0.50. The code ensures older clients can decode transactions by usingTxBodyCompat
when new features are not used.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for transaction body handling in v0.50 code rg "TxBody" -A 5 -g "*/tx/*.go"Length of output: 19718
🧰 Tools
🪛 GitHub Actions: CodeQL
[error] 120-120: Undefined type error: txv1beta1.TxBodyCompat is not defined
117-136
:⚠️ Potential issueFix undefined TxBodyCompat type error
The CodeQL analysis indicates that
txv1beta1.TxBodyCompat
is undefined. This type needs to be defined in the proto files before it can be used here.Let's verify if the proto definition exists:
🧰 Tools
🪛 GitHub Actions: CodeQL
[error] 120-120: Undefined type error: txv1beta1.TxBodyCompat is not defined
tests/go.mod (1)
238-238
: LGTM: Local API module replacementThe addition of the replace directive for
cosmossdk.io/api
is appropriate for testing the compatibility changes with the local API module.api/cosmos/tx/v1beta1/tx.pulsar.go (3)
9546-9553
: Good documentation of message handling in commentsThe comments clearly explain the purpose and behavior of the messages field, which is crucial for maintaining compatibility.
10197-10214
: Verify protobuf field numbers are preservedThe field numbers in TxBodyCompat match those in TxBody which is crucial for wire compatibility.
Let's verify the protobuf definitions:
✅ Verification successful
Field numbers and types are preserved correctly
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for protobuf definitions to compare field numbers rg "cosmos.tx.v1beta1.TxBody" -A 10 rg "cosmos.tx.v1beta1.TxBodyCompat" -A 10Length of output: 57401
9537-9570
: Implementation of TxBodyCompat looks correct for backwards compatibilityThe TxBodyCompat type properly excludes the new fields (unordered and timeout_timestamp) while maintaining all other fields from TxBody, which aligns with the goal of supporting older clients.
Let's verify that TxBodyCompat is used correctly in the codebase:
✅ Verification successful
TxBodyCompat implementation and usage verified
The implementation correctly supports backwards compatibility by:
- Excluding new fields (unordered, timeout_timestamp) while maintaining all other TxBody fields
- Proper integration in transaction builder (x/auth/tx/builder.go)
- Complete protobuf support for serialization/deserialization
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for TxBodyCompat usage to ensure proper integration rg -A 5 "TxBodyCompat"Length of output: 46783
(cherry picked from commit 9ca815c) # Conflicts: # api/cosmos/tx/v1beta1/tx.pulsar.go # go.mod # simapp/v2/go.mod # simapp/v2/go.sum
Description
Due to the new additions of two new fields in the tx body: unordered and timeout, v0.52 clients aren't compatible with lower version anymore.
While always checking unknown fields is crucial, the client library of the SDK doesn't need to marshal all fields of the tx.
Meaning, a tx where unordered and/or timeout are set, will fail in 0.50 with a v0.52 client, when you don't make use of that feature, you should still be able to use the v0.52 client.
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
New Features
TxBodyCompat
message type for backward compatibility in transaction handling.Refactor
ProtoCodecMarshaler
interface to simplify code structure.cosmossdk.io/api
module ingo.mod
.