From 0b0db0867cebce0857d124f21bae6fad8b69e24d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Mar 2023 18:55:52 -0400 Subject: [PATCH] fix(x/tx)!: unexpected cast of interface to concrete type in GetSignersContext (#15581) --- x/tx/CHANGELOG.md | 13 ++++++++++--- x/tx/signing/direct_aux/direct_aux.go | 6 +++--- x/tx/signing/get_signers.go | 18 ++++++++++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 1e4a07892e..34b23bda8a 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -29,15 +29,22 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog -## [Unreleased] +## Unreleased -## API Breaking +### API Breaking + +* [#15581](https://github.com/cosmos/cosmos-sdk/pull/15581) `GetSignersOptions` and `directaux.SignModeHandlerOptions` now +require a `signing.ProtoFileResolver` interface instead of `protodesc.Resolver`. + +## v0.4.0 + +### API Breaking * [#13793](https://github.com/cosmos/cosmos-sdk/pull/13793) `direct_aux.NewSignModeHandler` constructor function now returns an additional error argument. * [#15278](https://github.com/cosmos/cosmos-sdk/pull/15278) Move `x/tx/{textual,aminojson}` into `x/tx/signing`. * [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) `textual.NewSignModeHandler` now takes an options struct instead of a simple coin querier argument. It also returns an error. -## Improvements +### Improvements * [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) Add support for a custom registry (e.g. gogo's MergedRegistry) to be plugged into SIGN_MODE_TEXTUAL. * [#15557](https://github.com/cosmos/cosmos-sdk/pull/15557) Implement unknown field filtering. diff --git a/x/tx/signing/direct_aux/direct_aux.go b/x/tx/signing/direct_aux/direct_aux.go index 7af3fc01ae..b3ac2c1332 100644 --- a/x/tx/signing/direct_aux/direct_aux.go +++ b/x/tx/signing/direct_aux/direct_aux.go @@ -6,25 +6,25 @@ import ( "github.com/cosmos/cosmos-proto/anyutil" "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoregistry" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/x/tx/signing" ) // SignModeHandler is the SIGN_MODE_DIRECT_AUX implementation of signing.SignModeHandler. type SignModeHandler struct { signersContext *signing.GetSignersContext - fileResolver protodesc.Resolver + fileResolver signing.ProtoFileResolver typeResolver protoregistry.MessageTypeResolver } // SignModeHandlerOptions are the options for the SignModeHandler. type SignModeHandlerOptions struct { // FileResolver is the protodesc.Resolver to use for resolving proto files when unpacking any messages. - FileResolver protodesc.Resolver + FileResolver signing.ProtoFileResolver // TypeResolver is the protoregistry.MessageTypeResolver to use for resolving proto types when unpacking any messages. TypeResolver protoregistry.MessageTypeResolver diff --git a/x/tx/signing/get_signers.go b/x/tx/signing/get_signers.go index 295f1b9ea4..77a632c336 100644 --- a/x/tx/signing/get_signers.go +++ b/x/tx/signing/get_signers.go @@ -17,7 +17,7 @@ import ( // message where signers are specified by the cosmos.msg.v1.signer protobuf // option. type GetSignersContext struct { - protoFiles protodesc.Resolver + protoFiles ProtoFileResolver getSignersFuncs map[protoreflect.FullName]getSignersFunc } @@ -25,7 +25,14 @@ type GetSignersContext struct { type GetSignersOptions struct { // ProtoFiles are the protobuf files to use for resolving message descriptors. // If it is nil, the global protobuf registry will be used. - ProtoFiles protodesc.Resolver + ProtoFiles ProtoFileResolver +} + +// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all +// files descriptors. It is a subset of the methods supported by protoregistry.Files. +type ProtoFileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) } // NewGetSignersContext creates a new GetSignersContext using the provided options. @@ -60,13 +67,8 @@ func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, // - it will pre-populate the context's internal cache for getSignersFuncs // so that calling it in antehandlers will be faster. func (c *GetSignersContext) init() error { - fs, ok := c.protoFiles.(*protoregistry.Files) - if !ok { - return fmt.Errorf("expected *protoregistry.Files in GetSignersContext, got %T", c.protoFiles) - } - var errs []error - fs.RangeFiles(func(fd protoreflect.FileDescriptor) bool { + c.protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { for i := 0; i < fd.Services().Len(); i++ { sd := fd.Services().Get(i) // We use the heuristic that services named "Msg" are exactly the