-
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
feat(x/tx): Support gogo registry in Textual #15302
Conversation
I manually tested this the following way:
_ "cosmossdk.io/api/cosmos/bank/v1beta1"
_ "cosmossdk.io/api/cosmos/crypto/secp256k1"
|
Converting to draft, let's wait for #15322 first |
R4R again using #15322 Unpack |
x/tx/signing/textual/any.go
Outdated
// The input msg can be: | ||
// - either a anypb.Any already (in which case there's nothing to do), | ||
// - or a dynamicpb.Message. | ||
func toAny(msg proto.Message) (*anypb.Any, error) { |
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.
Here and below for similar converters - I'm quite confused by this. Don't we know that Any
, Duration
, etc, are in fact registered?
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 fact that we import google.golang.org/protobuf/types/known/{any,duration...}pb
indeed guarantees that Any
, Duration
are registered.
However, when they are nested in another message that's not registered, then they are dynamically created using dynamicpb. Consider a custom Msg, suppose it's only registered in gogo, and not in protov2:
message MsgCustom {
google.protobuf.Any a = 1;
}
Then when Textual receives this message, it sees MsgCustom
and will use dynamicpb to generate the whole proto.Message, including the nested field.
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.
We currently use dynamicpb.NewMessageType to do this. We could consider writing our own dynamicpb.NewMessageTypeV2
that uses known types when generating a field with a known name. I'm not sure if that would be more helpful or confusing though.
Created a new issue: cosmos/cosmos-proto#104
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.
Thanks for the explanation. It would be nice if we didn't have to complicate the textual code for this, but I don't know enough to second-guess the choices you've made here.
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.
LGTM, ty Amaury for the detailed walkthrough 🙏
x/tx/signing/textual/any.go
Outdated
// The input msg can be: | ||
// - either a anypb.Any already (in which case there's nothing to do), | ||
// - or a dynamicpb.Message. | ||
func toAny(msg proto.Message) (*anypb.Any, error) { |
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.
In the case of a dynamicpb.Messge
, this function and its brothers need to check that the dynamic message has an appropriate message name, not just one that has fields of the right name and type. (We could argue that the name was checked when we dispatched here, but it should be easy to check in this function.)
Even better, how about a single function coerceToMessage(givenMsg, desiredMsg proto.Message) error
that initializes a given desiredMsg
(presented as a protov2 concrete message), fast-paths the case where givenMsg
is a protov2 concrete message of the same type, for a dynamicpb it checks that the names match then uses proto reflection to initialize the fields of desiredMsg
, and otherwise throws an error. This should be much less error-prone and reduce the proliferation of dynamicpb
everywhere.
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.
That's a good suggestion, thanks. I applied it in fbe2ce6, and the code looks less scattered.
I'll see about moving coerceToMessage
to cosmos-proto.
…s-sdk into am/14647-textual-gogo
Description
Closes: #14647
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.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.
I have...
!
in the type prefix if API or client breaking change