Skip to content
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

Merged
merged 32 commits into from
Mar 20, 2023
Merged

Conversation

amaury1093
Copy link
Contributor

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@amaury1093 amaury1093 marked this pull request as ready for review March 8, 2023 11:45
@amaury1093 amaury1093 requested a review from a team as a code owner March 8, 2023 11:45
@amaury1093
Copy link
Contributor Author

amaury1093 commented Mar 8, 2023

I manually tested this the following way:

  • Apply the changes here to activate Textual
  • However, DON'T add the two lines in app_v2.go
	_ "cosmossdk.io/api/cosmos/bank/v1beta1"
	_ "cosmossdk.io/api/cosmos/crypto/secp256k1"
  • run the app, make sure Textual txs pass

@amaury1093 amaury1093 marked this pull request as draft March 9, 2023 11:11
@amaury1093
Copy link
Contributor Author

Converting to draft, let's wait for #15322 first

@amaury1093 amaury1093 marked this pull request as ready for review March 13, 2023 10:50
@amaury1093
Copy link
Contributor Author

R4R again using #15322 Unpack

// 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@amaury1093 amaury1093 Mar 15, 2023

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

Copy link
Contributor

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.

Copy link
Member

@facundomedica facundomedica left a 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 🙏

// 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@amaury1093 amaury1093 Mar 16, 2023

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.

@amaury1093 amaury1093 enabled auto-merge (squash) March 20, 2023 07:30
@amaury1093 amaury1093 merged commit 124aed4 into main Mar 20, 2023
@amaury1093 amaury1093 deleted the am/14647-textual-gogo branch March 20, 2023 08:13
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add support to plug gogo's registry into Textual
3 participants