-
Notifications
You must be signed in to change notification settings - Fork 628
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
refactor!: adapt merkle path to use repeated bytes in favour of strings #6633
Conversation
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.
Excellent! ❤️
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.
Nice this refactor is started, @damiannolan!
I am wondering if it would help readability to have a type alias for [][]byte
?
Should we also mention in migration docs that KeyPath
type is changed from string to [][]byte
?
I mentioned something similar to @colin-axner yesterday in dms. I can explore that when the bulk of the code is updated.
Yes! I'll add it to the issue 👍🏻 |
I'll add a changelog to this before merging |
Quality Gate passed for 'ibc-go'Issues Measures |
@@ -26,7 +26,7 @@ message MerklePrefix { | |||
// arbitrary structured object (defined by a commitment type). | |||
// MerklePath is represented from root-to-leaf | |||
message MerklePath { | |||
repeated string key_path = 1; | |||
repeated bytes key_path = 1; |
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 is a proto breaking change, what's the tradeoff here vs. field deprecation?
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.
Hey @erwanor! Does this raise any concern in particular for you and do you depend on the message type?
This is a bit of a protobuf grey area. Myself and @colin-axner looked into this quite a bit to ensure it was okay to make this change in order to support proving kvs stored under non utf8 encoded keys (as requested by union).
Thus far we've considered this Go api breaking but not actually proto encoding breaking. Backwards compatibility should be maintained with this change. I wrote a quick test to validate this, introducing a temp LegacyMerklePath
type with repeated string
(old diff). I also tested for equality of bytes when both types are marshalled using proto codec.
func (suite *MerkleTestSuite) TestMerklePathEncoding() {
encodingCfg := moduletestutil.MakeTestEncodingConfig()
keyPath := []string{"ibc", "commitments/ports/transfer/channels/channel-0/sequences/1"}
merklePath := types.NewMerklePath(keyPath...)
bz, err := encodingCfg.Codec.Marshal(&merklePath)
suite.Require().NoError(err)
var legacy types.LegacyMerklePath
err = encodingCfg.Codec.Unmarshal(bz, &legacy)
suite.Require().NoError(err)
suite.Require().Equal(keyPath, legacy.KeyPath)
}
Some of the resources which helped us come to this conclusion:
https://protobuf.dev/programming-guides/encoding/#structure
The binary version of a message just uses the field’s number as the key – the name and declared type for each field can only be determined on the decoding end by referencing the message type’s definition (i.e. the .proto file).
https://protobuf.dev/programming-guides/proto2/#updating
string
andbytes
are compatible as long as the bytes are valid UTF-8.
It's possible that we may have overlooked something wrt to rust users/tooling, please let us know if you have any concerns!
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 biggest concern for me here was that when encoding to JSON you now end up with a key_path
field which is a base64 encoded byte string.
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.
Also happy to introduce a v2
proto pkg and adjust ibc-go code as necessary. If it makes things easier to keep the old type around! Let me know what you think!
…gs (#6633) * refactor: adapt merkle path to use repeated bytes in favour of strings * chore: add changelog
Description
Initial PR. Will break the API of
NewMerklePath
in a following PR.MerklePath
to userepeated bytes
in favour ofrepeated string
.ref: #6496
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
).godoc
comments.Files changed
in the GitHub PR explorer.SonarCloud Report
in the comment section below once CI passes.