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

refactor!: use x/tx/signing in client.TxConfig #15822

Merged
merged 66 commits into from
Apr 20, 2023

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Apr 12, 2023

Description

Closes: #15698

This patch changes the type of client.TxConfig.SignModeHandler from x/auth/tx/SignModeHandler to x/tx/SignModeHandler, then fixes all resulting breakage. This deprecates signing in x/auth/tx in favor of the packages in x/tx.


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)

@github-actions github-actions bot added C:CLI C:Rosetta Issues and PR related to Rosetta C:x/auth C:x/tx labels Apr 12, 2023
client/tx/tx.go Fixed Show fixed Hide fixed
@kocubinski kocubinski changed the title [WIP] refactor: break client.TxConfig API with x/tx signers refactor: [WIP] break client.TxConfig API with x/tx signers Apr 13, 2023
@kocubinski
Copy link
Member Author

kocubinski commented Apr 19, 2023

I would prefer to see the merged registry as a parameter rather than embedded as calls to functions, just as a general matter of avoiding global state. But if there are reasons we can't do that, oh well.

I 💯 agree with merged registry as a parameter. When code uses depinject this is doable, but if we're supporting non-depinject initialization we can only do this by introducing further API breakage, specifically NewTxConfig but I'm not sure if that's the best choice.

If we're willing to break NewTxConfig with changed arguments and add a signing.ProtoFileResolver to both sdk.Context and client.Context I think we could potentially remove the global. Maybe this could be a follow on PR?

@tac0turtle @aaronc curious your thoughts on breaking NewTxConfig?

@aaronc
Copy link
Member

aaronc commented Apr 19, 2023

I would prefer to see the merged registry as a parameter rather than embedded as calls to functions, just as a general matter of avoiding global state. But if there are reasons we can't do that, oh well.

I 💯 agree with merged registry as a parameter. When code uses depinject this is doable, but if we're supporting non-depinject initialization we can only do this by introducing further API breakage, specifically NewTxConfig but I'm not sure if that's the best choice.

If we're willing to break NewTxConfig with changed arguments and add a signing.ProtoFileResolver to both sdk.Context and client.Context I think we could potentially remove the global. Maybe this could be a follow on PR?

@tac0turtle @aaronc curious your thoughts on breaking NewTxConfig?

We don't need to change anything. NewTxConfig already gets ProtoCodecMarshaler which has an InterfaceRegistry which implements signing.ProtoFileResolver

) client.TxConfig {
// protoFiles should perhaps be a parameter to this function, but the choice was made here to not break the
// NewTxConfig API.
protoFiles := registry.MergedProtoRegistry()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protoFiles := registry.MergedProtoRegistry()

// NewTxConfig API.
protoFiles := registry.MergedProtoRegistry()
typeResolver := protoregistry.GlobalTypes
signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary because of #15873. Just use codec.InterfaceRegistry().SigningContext()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a compile error right now. I think it is OK to land this in main first then work on #15873 (which is still failing tests) then refactor?

@kocubinski
Copy link
Member Author

kocubinski commented Apr 19, 2023

We don't need to change anything. NewTxConfig already gets ProtoCodecMarshaler which has an InterfaceRegistry which implements signing.ProtoFileResolver

I hadn't noticed that InterfaceRegistry implements signing.ProtoFileResolver, good point. I think we're just pushing the problem around? I hadn't notice the ref to the global proto.MergedRegistry in the NewInterfaceRegistry either. So this constructor would need to tolerate an API break to have it injected, right?

Personally I'd prefer breaking the API, and maybe NewInterfaceRegistry is the right place.

@aaronc
Copy link
Member

aaronc commented Apr 19, 2023

See how it's handled in #15873. Changing NewInterfaceRegistry will be too painful on tests. We just have an overload with options to deal with this

@kocubinski
Copy link
Member Author

I am leaning toward merging and then refactoring out the global proto.MergedRegistry usages after #15873 lands since I'll be working on that anyway.

@aaronc
Copy link
Member

aaronc commented Apr 20, 2023

I am leaning toward merging and then refactoring out the global proto.MergedRegistry usages after #15873 lands since I'll be working on that anyway.

But if you have a Codec you already have the MergedRegistry, no need to wait for #15873 for that part

it is being called in init() lifecycle before all proto files are loaded.
the result is much wasted work right now.
@kocubinski kocubinski enabled auto-merge April 20, 2023 16:09
@kocubinski kocubinski added this pull request to the merge queue Apr 20, 2023
Merged via the queue into main with commit 86b88b1 Apr 20, 2023
@kocubinski kocubinski deleted the kocubinski/tx-config-break branch April 20, 2023 16:22
return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, textual, customSignModes...))
//
// Deprecated: use NewTxConfigWithOptions instead.
func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, _ []signingtypes.SignMode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has never been released, is there a reason to deprecate it instead of completely removing it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'll remove it in a follow up.

TypeResolver: typeResolver,
Encoder: &aminoJSONEncoder,
}
case signingtypes.SignMode_SIGN_MODE_TEXTUAL:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the panic message should be changed with the right function

@@ -27,25 +31,66 @@ type config struct {
// NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode
// is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). Use NewTxConfigWithTextual
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate SigVerificationDecorator AnteHandler to use x/tx legacy amino json sign mode
6 participants