From ea8ed7ec86fcd3e8ee143d85bf8e09aeea35c66b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 6 Mar 2023 13:17:35 -0500 Subject: [PATCH 01/83] refactor!: deprecate sdk.Msg.GetSigners --- baseapp/baseapp.go | 27 ++- baseapp/msg_service_router.go | 2 +- client/tx/aux_builder.go | 2 +- client/tx/legacy.go | 26 --- client/tx/tx.go | 2 +- go.mod | 4 +- go.sum | 2 - server/mock/tx.go | 3 +- types/simulation/types.go | 4 +- types/tx/msgs.go | 8 +- types/tx/types.go | 34 ++-- types/tx_msg.go | 58 +++++- x/auth/ante/ante.go | 17 +- x/auth/ante/basic.go | 13 +- x/auth/ante/setup.go | 3 - x/auth/ante/sigverify.go | 3 - x/auth/client/tx.go | 13 -- x/auth/migrations/legacytx/amino_signing.go | 38 ---- x/auth/migrations/legacytx/codec.go | 9 - x/auth/migrations/legacytx/stdtx.go | 189 ------------------ x/auth/migrations/legacytx/stdtx_builder.go | 211 -------------------- x/auth/migrations/legacytx/stdtx_test.go | 140 ------------- x/auth/tx/direct_test.go | 8 +- x/auth/types/codec.go | 3 - x/authz/keeper/keeper.go | 21 +- x/authz/msgs.go | 4 +- x/genutil/types/genesis_state.go | 2 +- x/gov/migrations/v3/convert.go | 4 +- x/gov/types/v1/msgs.go | 2 +- x/group/msgs.go | 2 +- x/tx/signing/get_signers.go | 40 ++++ 31 files changed, 208 insertions(+), 686 deletions(-) delete mode 100644 x/auth/migrations/legacytx/codec.go delete mode 100644 x/auth/migrations/legacytx/stdtx_builder.go diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index cff907546447..4273a7e25636 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -20,6 +20,7 @@ import ( "cosmossdk.io/store/snapshots" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -145,6 +146,8 @@ type BaseApp struct { //nolint: maligned // abciListeners for hooking into the ABCI message processing of the BaseApp // and exposing the requests and responses to external consumers abciListeners []storetypes.ABCIListener + + getSignersCtx *signing.GetSignersContext } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -189,6 +192,16 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() + mergedProtoRegistry, err := proto.MergedRegistry() + if err != nil { + panic(err) + } + app.getSignersCtx = signing.NewGetSignersContext( + signing.GetSignersOptions{ + ProtoFiles: mergedProtoRegistry, + }, + ) + return app } @@ -528,7 +541,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } for _, msg := range msgs { - err := msg.ValidateBasic() + err := sdk.ValidateBasic(msg) if err != nil { return err } @@ -795,7 +808,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s } // create message events - msgEvents := createEvents(msgResult.GetEvents(), msg) + msgEvents := createEvents(app.getSignersCtx, msgResult.GetEvents(), msg) // append message events, data and logs // @@ -837,13 +850,17 @@ func makeABCIData(msgResponses []*codectypes.Any) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResponses}) } -func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events { +func createEvents(getSignersCtx *signing.GetSignersContext, events sdk.Events, msg sdk.Msg) sdk.Events { eventMsgName := sdk.MsgTypeURL(msg) msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)) // we set the signer attribute as the sender - if len(msg.GetSigners()) > 0 && !msg.GetSigners()[0].Empty() { - msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSigners()[0].String())) + signers, err := sdk.GetSigners(msg, getSignersCtx) + if err != nil { + panic(err) + } + if len(signers) > 0 && signers[0] != "" { + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, signers[0])) } // verify that events have no module attribute set diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index ed08986d47e7..fa4d77e1ff0f 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -122,7 +122,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter return handler(goCtx, req) } - if err := req.ValidateBasic(); err != nil { + if err := sdk.ValidateBasic(req); err != nil { return nil, err } // Call the method handler from the service description with the handler object. diff --git a/client/tx/aux_builder.go b/client/tx/aux_builder.go index 331f4a8459e1..608313f1f085 100644 --- a/client/tx/aux_builder.go +++ b/client/tx/aux_builder.go @@ -57,7 +57,7 @@ func (b *AuxTxBuilder) SetMsgs(msgs ...sdk.Msg) error { anys := make([]*codectypes.Any, len(msgs)) for i, msg := range msgs { var err error - anys[i], err = codectypes.NewAnyWithValue(msg) + anys[i], err = codectypes.NewAnyWithValue(msg.(proto.Message)) if err != nil { return err } diff --git a/client/tx/legacy.go b/client/tx/legacy.go index c07982a3fe4d..2e218dbcfde0 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -1,36 +1,10 @@ package tx import ( - "fmt" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -// ConvertTxToStdTx converts a transaction to the legacy StdTx format -func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, error) { - if stdTx, ok := tx.(legacytx.StdTx); ok { - return stdTx, nil - } - - aminoTxConfig := legacytx.StdTxConfig{Cdc: codec} - builder := aminoTxConfig.NewTxBuilder() - - err := CopyTx(tx, builder, true) - if err != nil { - return legacytx.StdTx{}, err - } - - stdTx, ok := builder.GetTx().(legacytx.StdTx) - if !ok { - return legacytx.StdTx{}, fmt.Errorf("expected %T, got %+v", legacytx.StdTx{}, builder.GetTx()) - } - - return stdTx, nil -} - // CopyTx copies a Tx to a new TxBuilder, allowing conversion between // different transaction formats. If ignoreSignatureError is true, copying will continue // tx even if the signature cannot be set in the target builder resulting in an unsigned tx. diff --git a/client/tx/tx.go b/client/tx/tx.go index 0e4e9ac96609..7a59fad03d5f 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -40,7 +40,7 @@ func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msg // Right now, we're factorizing that call inside this function. // ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504 for _, msg := range msgs { - if err := msg.ValidateBasic(); err != nil { + if err := sdk.ValidateBasic(msg); err != nil { return err } } diff --git a/go.mod b/go.mod index 64a7fc2431f4..be377c6ea283 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.0.0-20230305202224-89c956f8ed3a cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.0 + cosmossdk.io/x/tx v0.2.1 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 @@ -154,6 +154,8 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) +replace cosmossdk.io/x/tx => ./x/tx + // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/go.sum b/go.sum index 4a9a64e3c75e..f74fe4bd5bc8 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.0 h1:53f5TIXhpPYJGMm47SUslcV2i8JNBEN3eE08BmxE/Zg= -cosmossdk.io/x/tx v0.2.0/go.mod h1:CTko7wgt7aBdbxOesZ+Wo1uO/03ueKzIQ0iI323Rqgk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/server/mock/tx.go b/server/mock/tx.go index f9f1c394dc99..26136ad502b9 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" errorsmod "cosmossdk.io/errors" @@ -105,7 +106,7 @@ func (msg *KVStoreTx) GetSignBytes() []byte { } // Should the app be calling this? Or only handlers? -func (msg *KVStoreTx) ValidateBasic() error { +func (msg *KVStoreTx) ValidateBasic(*signing2.GetSignersContext) error { return nil } diff --git a/types/simulation/types.go b/types/simulation/types.go index 34d29d04e323..83e73f4f786e 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -5,6 +5,8 @@ import ( "math/rand" "time" + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -99,7 +101,7 @@ func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) } - return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg)) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg.(proto.Message))) } // NoOpMsg - create a no-operation message diff --git a/types/tx/msgs.go b/types/tx/msgs.go index 25e79c4457f8..539f99d6ddd0 100644 --- a/types/tx/msgs.go +++ b/types/tx/msgs.go @@ -3,6 +3,8 @@ package tx import ( fmt "fmt" + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -21,7 +23,11 @@ func SetMsgs(msgs []sdk.Msg) ([]*types.Any, error) { anys := make([]*types.Any, len(msgs)) for i, msg := range msgs { var err error - anys[i], err = types.NewAnyWithValue(msg) + msgProto, ok := msg.(proto.Message) + if !ok { + return nil, fmt.Errorf("%T is not a proto message", msg) + } + anys[i], err = types.NewAnyWithValue(msgProto) if err != nil { return nil, err } diff --git a/types/tx/types.go b/types/tx/types.go index 8ef5b915f0de..273ad8c397d7 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -5,6 +5,8 @@ import ( errorsmod "cosmossdk.io/errors" + "cosmossdk.io/x/tx/signing" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +37,7 @@ func (t *Tx) GetMsgs() []sdk.Msg { } // ValidateBasic implements the ValidateBasic method on sdk.Tx. -func (t *Tx) ValidateBasic() error { +func (t *Tx) ValidateBasic(getSignersContext *signing.GetSignersContext) error { if t == nil { return fmt.Errorf("bad Tx") } @@ -89,10 +91,11 @@ func (t *Tx) ValidateBasic() error { return sdkerrors.ErrNoSignatures } - if len(sigs) != len(t.GetSigners()) { + signers := t.GetSigners(getSignersContext) + if len(sigs) != len(signers) { return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, - "wrong number of signers; expected %d, got %d", len(t.GetSigners()), len(sigs), + "wrong number of signers; expected %d, got %d", len(signers), len(sigs), ) } @@ -102,15 +105,20 @@ func (t *Tx) ValidateBasic() error { // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). -func (t *Tx) GetSigners() []sdk.AccAddress { - var signers []sdk.AccAddress +func (t *Tx) GetSigners(ctx *signing.GetSignersContext) []string { + var signers []string seen := map[string]bool{} for _, msg := range t.GetMsgs() { - for _, addr := range msg.GetSigners() { - if !seen[addr.String()] { - signers = append(signers, addr) - seen[addr.String()] = true + signers, err := sdk.GetSigners(msg, ctx) + if err != nil { + panic(err) + } + + for _, signer := range signers { + if !seen[signer] { + signers = append(signers, signer) + seen[signer] = true } } } @@ -118,7 +126,7 @@ func (t *Tx) GetSigners() []sdk.AccAddress { // ensure any specified fee payer is included in the required signers (at the end) feePayer := t.AuthInfo.Fee.Payer if feePayer != "" && !seen[feePayer] { - payerAddr := sdk.MustAccAddressFromBech32(feePayer) + payerAddr := feePayer signers = append(signers, payerAddr) seen[feePayer] = true } @@ -134,13 +142,13 @@ func (t *Tx) GetFee() sdk.Coins { return t.AuthInfo.Fee.Amount } -func (t *Tx) FeePayer() sdk.AccAddress { +func (t *Tx) FeePayer(ctx *signing.GetSignersContext) string { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { - return sdk.MustAccAddressFromBech32(feePayer) + return feePayer } // use first signer as default if no payer specified - return t.GetSigners()[0] + return t.GetSigners(ctx)[0] } func (t *Tx) FeeGranter() sdk.AccAddress { diff --git a/types/tx_msg.go b/types/tx_msg.go index d0127a7b5b67..dc96625e7938 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -6,14 +6,22 @@ import ( strings "strings" "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" + + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) type ( - // Msg defines the interface a transaction message must fulfill. - Msg interface { + // Msg is an empty tag interface for transaction messages. + Msg interface{} + + // LegacyMsg defines the interface a transaction message needed to fulfill up through + // v0.47. + LegacyMsg interface { proto.Message // ValidateBasic does a simple validation check that @@ -47,7 +55,7 @@ type ( // ValidateBasic does a simple and lightweight validation check that doesn't // require access to any other information. - ValidateBasic() error + ValidateBasic(getSignersCtx *signing.GetSignersContext) error } // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators @@ -82,7 +90,13 @@ type TxEncoder func(tx Tx) ([]byte, error) // MsgTypeURL returns the TypeURL of a `sdk.Msg`. func MsgTypeURL(msg Msg) string { - return "/" + proto.MessageName(msg) + if msg, ok := msg.(protov2.Message); ok { + return "/" + string(msg.ProtoReflect().Descriptor().FullName()) + } else if msg, ok := msg.(proto.Message); ok { + return "/" + proto.MessageName(msg) + } else { + panic(fmt.Errorf("%T is not a proto message", msg)) + } } // GetMsgFromTypeURL returns a `sdk.Msg` message type from a type URL @@ -115,3 +129,39 @@ func GetModuleNameFromTypeURL(input string) string { return "" } + +func ValidateBasic(msg Msg) error { + if validateBasic, ok := msg.(interface{ ValidateBasic() error }); ok { + err := validateBasic.ValidateBasic() + if err != nil { + return err + } + } + + return nil +} + +func GetSigners(msg Msg, getSignersCtx *signing.GetSignersContext) ([]string, error) { + if legacyMsg, ok := msg.(LegacyMsg); ok { + var signers []string + for _, addr := range legacyMsg.GetSigners() { + signer := addr.String() + signers = append(signers, signer) + } + return signers, nil + } else if msgv2, ok := msg.(protov2.Message); ok { + return getSignersCtx.GetSigners(msgv2) + } else if msgv1, ok := msg.(proto.Message); ok { + bz, err := proto.Marshal(msgv1) + if err != nil { + return nil, err + } + + return getSignersCtx.GetSignersForAny(&anypb.Any{ + TypeUrl: MsgTypeURL(msgv1), + Value: bz, + }) + } else { + return nil, fmt.Errorf("%T is not a proto message", msg) + } +} diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index f3b4ebb6a1bf..1ff54987b3c8 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,9 +2,12 @@ package ante import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protoregistry" errorsmod "cosmossdk.io/errors" + signing2 "cosmossdk.io/x/tx/signing" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -21,6 +24,7 @@ type HandlerOptions struct { SignModeHandler authsigning.SignModeHandler SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker + ProtoFiles *protoregistry.Files } // NewAnteHandler returns an AnteHandler that checks and increments sequence @@ -39,10 +43,21 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } + protoFiles := options.ProtoFiles + if protoFiles == nil { + var err error + protoFiles, err = proto.MergedRegistry() + if err != nil { + return nil, err + } + } + anteDecorators := []sdk.AnteDecorator{ NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - NewValidateBasicDecorator(), + NewValidateBasicDecorator(signing2.NewGetSignersContext(signing2.GetSignersOptions{ + ProtoFiles: protoFiles, + })), NewTxTimeoutHeightDecorator(), NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 8d335fc32b01..ddafd5d80ebf 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -19,10 +20,14 @@ import ( // If ValidateBasic passes, decorator calls next AnteHandler in chain. Note, // ValidateBasicDecorator decorator will not get executed on ReCheckTx since it // is not dependent on application state. -type ValidateBasicDecorator struct{} +type ValidateBasicDecorator struct { + getSignersContext *signing2.GetSignersContext +} -func NewValidateBasicDecorator() ValidateBasicDecorator { - return ValidateBasicDecorator{} +func NewValidateBasicDecorator(getSignersContext *signing2.GetSignersContext) ValidateBasicDecorator { + return ValidateBasicDecorator{ + getSignersContext: getSignersContext, + } } func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { @@ -31,7 +36,7 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat return next(ctx, tx, simulate) } - if err := tx.ValidateBasic(); err != nil { + if err := tx.ValidateBasic(vbd.getSignersContext); err != nil { return ctx, err } diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 2cdb34558349..4b6e281ac394 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -9,11 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -var _ GasTx = (*legacytx.StdTx)(nil) // assert StdTx implements GasTx - // GasTx defines a Tx with a GetGas() method which is needed to use SetUpContextDecorator type GasTx interface { sdk.Tx diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 6eb29b2fc4e9..422dde1f9978 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -18,7 +18,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -28,8 +27,6 @@ var ( key = make([]byte, secp256k1.PubKeySize) simSecp256k1Pubkey = &secp256k1.PubKey{Key: key} simSecp256k1Sig [64]byte - - _ authsigning.SigVerifiableTx = (*legacytx.StdTx)(nil) // assert StdTx implements SigVerifiableTx ) func init() { diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 18935e92ba77..a5091de9e1ec 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -14,12 +14,10 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // GasEstimateResponse defines a response definition for tx gas estimation. @@ -185,17 +183,6 @@ func populateAccountFromState( return txBldr.WithAccountNumber(num).WithSequence(seq), nil } -// GetTxEncoder return tx encoder from global sdk configuration if ones is defined. -// Otherwise returns encoder with default logic. -func GetTxEncoder(cdc *codec.LegacyAmino) (encoder sdk.TxEncoder) { - encoder = sdk.GetConfig().GetTxEncoder() - if encoder == nil { - encoder = legacytx.DefaultTxEncoder(cdc) - } - - return encoder -} - func ParseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { var simRes sdk.SimulationResponse if err := jsonpb.Unmarshal(strings.NewReader(string(bz)), &simRes); err != nil { diff --git a/x/auth/migrations/legacytx/amino_signing.go b/x/auth/migrations/legacytx/amino_signing.go index f663d80c6323..851366aa9bd5 100644 --- a/x/auth/migrations/legacytx/amino_signing.go +++ b/x/auth/migrations/legacytx/amino_signing.go @@ -7,47 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" - sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -// stdTxSignModeHandler is a SignModeHandler that handles SIGN_MODE_LEGACY_AMINO_JSON -type stdTxSignModeHandler struct{} - -func NewStdTxSignModeHandler() signing.SignModeHandler { - return &stdTxSignModeHandler{} -} - -// assert interface implementation -var _ signing.SignModeHandler = stdTxSignModeHandler{} - -// DefaultMode implements SignModeHandler.DefaultMode -func (h stdTxSignModeHandler) DefaultMode() signingtypes.SignMode { - return signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON -} - -// Modes implements SignModeHandler.Modes -func (stdTxSignModeHandler) Modes() []signingtypes.SignMode { - return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} -} - -// DefaultMode implements SignModeHandler.GetSignBytes -func (stdTxSignModeHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) { - if mode != signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { - return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, mode) - } - - stdTx, ok := tx.(StdTx) - if !ok { - return nil, fmt.Errorf("expected %T, got %T", StdTx{}, tx) - } - - return StdSignBytes( - data.ChainID, data.AccountNumber, data.Sequence, stdTx.GetTimeoutHeight(), StdFee{Amount: stdTx.GetFee(), Gas: stdTx.GetGas()}, tx.GetMsgs(), stdTx.GetMemo(), nil, - ), nil -} - // SignatureDataToAminoSignature converts a SignatureData to amino-encoded signature bytes. // Only SIGN_MODE_LEGACY_AMINO_JSON is supported. func SignatureDataToAminoSignature(cdc *codec.LegacyAmino, data signingtypes.SignatureData) ([]byte, error) { diff --git a/x/auth/migrations/legacytx/codec.go b/x/auth/migrations/legacytx/codec.go deleted file mode 100644 index 2bad4718e1e6..000000000000 --- a/x/auth/migrations/legacytx/codec.go +++ /dev/null @@ -1,9 +0,0 @@ -package legacytx - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) -} diff --git a/x/auth/migrations/legacytx/stdtx.go b/x/auth/migrations/legacytx/stdtx.go index ec1412403745..75ad7d923c6b 100644 --- a/x/auth/migrations/legacytx/stdtx.go +++ b/x/auth/migrations/legacytx/stdtx.go @@ -1,26 +1,15 @@ package legacytx import ( - errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/types/tx/signing" ) // Interface implementation checks var ( - _ sdk.Tx = (*StdTx)(nil) - _ sdk.TxWithMemo = (*StdTx)(nil) - _ sdk.FeeTx = (*StdTx)(nil) - _ tx.TipTx = (*StdTx)(nil) - _ codectypes.UnpackInterfacesMessage = (*StdTx)(nil) - _ codectypes.UnpackInterfacesMessage = (*StdSignature)(nil) ) @@ -81,181 +70,3 @@ type StdTip struct { Amount sdk.Coins `json:"amount" yaml:"amount"` Tipper string `json:"tipper" yaml:"tipper"` } - -// StdTx is the legacy transaction format for wrapping a Msg with Fee and Signatures. -// It only works with Amino, please prefer the new protobuf Tx in types/tx. -// NOTE: the first signature is the fee payer (Signatures must not be nil). -// Deprecated -type StdTx struct { - Msgs []sdk.Msg `json:"msg" yaml:"msg"` - Fee StdFee `json:"fee" yaml:"fee"` - Signatures []StdSignature `json:"signatures" yaml:"signatures"` - Memo string `json:"memo" yaml:"memo"` - TimeoutHeight uint64 `json:"timeout_height" yaml:"timeout_height"` -} - -// Deprecated -func NewStdTx(msgs []sdk.Msg, fee StdFee, sigs []StdSignature, memo string) StdTx { - return StdTx{ - Msgs: msgs, - Fee: fee, - Signatures: sigs, - Memo: memo, - } -} - -// GetMsgs returns the all the transaction's messages. -func (tx StdTx) GetMsgs() []sdk.Msg { return tx.Msgs } - -// ValidateBasic does a simple and lightweight validation check that doesn't -// require access to any other information. -// -//nolint:revive // we need to change the receiver name here, because otherwise we conflict with tx.MaxGasWanted. -func (stdTx StdTx) ValidateBasic() error { - stdSigs := stdTx.GetSignatures() - - if stdTx.Fee.Gas > tx.MaxGasWanted { - return errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", stdTx.Fee.Gas, tx.MaxGasWanted, - ) - } - if stdTx.Fee.Amount.IsAnyNegative() { - return errorsmod.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: %s", stdTx.Fee.Amount, - ) - } - if len(stdSigs) == 0 { - return sdkerrors.ErrNoSignatures - } - if len(stdSigs) != len(stdTx.GetSigners()) { - return errorsmod.Wrapf( - sdkerrors.ErrUnauthorized, - "wrong number of signers; expected %d, got %d", len(stdTx.GetSigners()), len(stdSigs), - ) - } - - return nil -} - -// Deprecated: AsAny implements intoAny. It doesn't work for protobuf serialization, -// so it can't be saved into protobuf configured storage. We are using it only for API -// compatibility. -func (tx *StdTx) AsAny() *codectypes.Any { - return codectypes.UnsafePackAny(tx) -} - -// GetSigners returns the addresses that must sign the transaction. -// Addresses are returned in a deterministic order. -// They are accumulated from the GetSigners method for each Msg -// in the order they appear in tx.GetMsgs(). -// Duplicate addresses will be omitted. -func (tx StdTx) GetSigners() []sdk.AccAddress { - var signers []sdk.AccAddress - seen := map[string]bool{} - - for _, msg := range tx.GetMsgs() { - for _, addr := range msg.GetSigners() { - if !seen[addr.String()] { - signers = append(signers, addr) - seen[addr.String()] = true - } - } - } - - return signers -} - -// GetMemo returns the memo -func (tx StdTx) GetMemo() string { return tx.Memo } - -// GetTimeoutHeight returns the transaction's timeout height (if set). -func (tx StdTx) GetTimeoutHeight() uint64 { - return tx.TimeoutHeight -} - -// GetSignatures returns the signature of signers who signed the Msg. -// CONTRACT: Length returned is same as length of -// pubkeys returned from MsgKeySigners, and the order -// matches. -// CONTRACT: If the signature is missing (ie the Msg is -// invalid), then the corresponding signature is -// .Empty(). -func (tx StdTx) GetSignatures() [][]byte { - sigs := make([][]byte, len(tx.Signatures)) - for i, stdSig := range tx.Signatures { - sigs[i] = stdSig.Signature - } - return sigs -} - -// GetSignaturesV2 implements SigVerifiableTx.GetSignaturesV2 -func (tx StdTx) GetSignaturesV2() ([]signing.SignatureV2, error) { - res := make([]signing.SignatureV2, len(tx.Signatures)) - - for i, sig := range tx.Signatures { - var err error - res[i], err = StdSignatureToSignatureV2(legacy.Cdc, sig) - if err != nil { - return nil, errorsmod.Wrapf(err, "Unable to convert signature %v to V2", sig) - } - } - - return res, nil -} - -// GetPubkeys returns the pubkeys of signers if the pubkey is included in the signature -// If pubkey is not included in the signature, then nil is in the slice instead -func (tx StdTx) GetPubKeys() ([]cryptotypes.PubKey, error) { - pks := make([]cryptotypes.PubKey, len(tx.Signatures)) - - for i, stdSig := range tx.Signatures { - pks[i] = stdSig.GetPubKey() - } - - return pks, nil -} - -// GetGas returns the Gas in StdFee -func (tx StdTx) GetGas() uint64 { return tx.Fee.Gas } - -// GetFee returns the FeeAmount in StdFee -func (tx StdTx) GetFee() sdk.Coins { return tx.Fee.Amount } - -// FeePayer returns the address that is responsible for paying fee -// StdTx returns the first signer as the fee payer -// If no signers for tx, return empty address -func (tx StdTx) FeePayer() sdk.AccAddress { - if tx.GetSigners() != nil { - return tx.GetSigners()[0] - } - return sdk.AccAddress{} -} - -// FeeGranter always returns nil for StdTx -func (tx StdTx) FeeGranter() sdk.AccAddress { - return nil -} - -// GetTip always returns nil for StdTx -func (tx StdTx) GetTip() *tx.Tip { return nil } - -func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - for _, m := range tx.Msgs { - err := codectypes.UnpackInterfaces(m, unpacker) - if err != nil { - return err - } - } - - // Signatures contain PubKeys, which need to be unpacked. - for _, s := range tx.Signatures { - err := s.UnpackInterfaces(unpacker) - if err != nil { - return err - } - } - - return nil -} diff --git a/x/auth/migrations/legacytx/stdtx_builder.go b/x/auth/migrations/legacytx/stdtx_builder.go deleted file mode 100644 index df0b930b3980..000000000000 --- a/x/auth/migrations/legacytx/stdtx_builder.go +++ /dev/null @@ -1,211 +0,0 @@ -package legacytx - -import ( - "fmt" - - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" -) - -// StdTxBuilder wraps StdTx to implement to the context.TxBuilder interface. -// Note that this type just exists for backwards compatibility with amino StdTx -// and will not work for protobuf transactions. -type StdTxBuilder struct { - StdTx - cdc *codec.LegacyAmino -} - -// ensure interface implementation -var _ client.TxBuilder = &StdTxBuilder{} - -// GetTx implements TxBuilder.GetTx -func (s *StdTxBuilder) GetTx() authsigning.Tx { - return s.StdTx -} - -// SetMsgs implements TxBuilder.SetMsgs -func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { - s.Msgs = msgs - return nil -} - -// SetSignatures implements TxBuilder.SetSignatures. -func (s *StdTxBuilder) SetSignatures(signatures ...signing.SignatureV2) error { - sigs := make([]StdSignature, len(signatures)) - var err error - for i, sig := range signatures { - sigs[i], err = SignatureV2ToStdSignature(s.cdc, sig) - if err != nil { - return err - } - } - - s.Signatures = sigs - return nil -} - -func (s *StdTxBuilder) SetFeeAmount(amount sdk.Coins) { - s.StdTx.Fee.Amount = amount -} - -func (s *StdTxBuilder) SetGasLimit(limit uint64) { - s.StdTx.Fee.Gas = limit -} - -func (s *StdTxBuilder) SetTip(tip *tx.Tip) { - panic("StdTxBuilder does not support tips") -} - -// SetMemo implements TxBuilder.SetMemo -func (s *StdTxBuilder) SetMemo(memo string) { - s.Memo = memo -} - -// SetTimeoutHeight sets the transaction's height timeout. -func (s *StdTxBuilder) SetTimeoutHeight(height uint64) { - s.TimeoutHeight = height -} - -// SetFeeGranter does nothing for stdtx -func (s *StdTxBuilder) SetFeeGranter(_ sdk.AccAddress) {} - -// SetFeePayer does nothing for stdtx -func (s *StdTxBuilder) SetFeePayer(_ sdk.AccAddress) {} - -// AddAuxSignerData returns an error for StdTxBuilder. -func (s *StdTxBuilder) AddAuxSignerData(_ tx.AuxSignerData) error { - return sdkerrors.ErrLogic.Wrap("cannot use AuxSignerData with StdTxBuilder") -} - -// StdTxConfig is a context.TxConfig for StdTx -type StdTxConfig struct { - Cdc *codec.LegacyAmino -} - -var _ client.TxConfig = StdTxConfig{} - -// NewTxBuilder implements TxConfig.NewTxBuilder -func (s StdTxConfig) NewTxBuilder() client.TxBuilder { - return &StdTxBuilder{ - StdTx: StdTx{}, - cdc: s.Cdc, - } -} - -// WrapTxBuilder returns a StdTxBuilder from provided transaction -func (s StdTxConfig) WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) { - stdTx, ok := newTx.(StdTx) - if !ok { - return nil, fmt.Errorf("wrong type, expected %T, got %T", stdTx, newTx) - } - return &StdTxBuilder{StdTx: stdTx, cdc: s.Cdc}, nil -} - -// MarshalTx implements TxConfig.MarshalTx -func (s StdTxConfig) TxEncoder() sdk.TxEncoder { - return DefaultTxEncoder(s.Cdc) -} - -func (s StdTxConfig) TxDecoder() sdk.TxDecoder { - return mkDecoder(s.Cdc.Unmarshal) -} - -func (s StdTxConfig) TxJSONEncoder() sdk.TxEncoder { - return func(tx sdk.Tx) ([]byte, error) { - return s.Cdc.MarshalJSON(tx) - } -} - -func (s StdTxConfig) TxJSONDecoder() sdk.TxDecoder { - return mkDecoder(s.Cdc.UnmarshalJSON) -} - -func (s StdTxConfig) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error) { - stdSigs := make([]StdSignature, len(sigs)) - for i, sig := range sigs { - stdSig, err := SignatureV2ToStdSignature(s.Cdc, sig) - if err != nil { - return nil, err - } - - stdSigs[i] = stdSig - } - return s.Cdc.MarshalJSON(stdSigs) -} - -func (s StdTxConfig) UnmarshalSignatureJSON(bz []byte) ([]signing.SignatureV2, error) { - var stdSigs []StdSignature - err := s.Cdc.UnmarshalJSON(bz, &stdSigs) - if err != nil { - return nil, err - } - - sigs := make([]signing.SignatureV2, len(stdSigs)) - for i, stdSig := range stdSigs { - sig, err := StdSignatureToSignatureV2(s.Cdc, stdSig) - if err != nil { - return nil, err - } - sigs[i] = sig - } - - return sigs, nil -} - -func (s StdTxConfig) SignModeHandler() authsigning.SignModeHandler { - return stdTxSignModeHandler{} -} - -// SignatureV2ToStdSignature converts a SignatureV2 to a StdSignature -// [Deprecated] -func SignatureV2ToStdSignature(cdc *codec.LegacyAmino, sig signing.SignatureV2) (StdSignature, error) { - var ( - sigBz []byte - err error - ) - - if sig.Data != nil { - sigBz, err = SignatureDataToAminoSignature(cdc, sig.Data) - if err != nil { - return StdSignature{}, err - } - } - - return StdSignature{ - PubKey: sig.PubKey, - Signature: sigBz, - }, nil -} - -// Unmarshaler is a generic type for Unmarshal functions -type Unmarshaler func(bytes []byte, ptr interface{}) error - -func mkDecoder(unmarshaler Unmarshaler) sdk.TxDecoder { - return func(txBytes []byte) (sdk.Tx, error) { - if len(txBytes) == 0 { - return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty") - } - tx := StdTx{} - // StdTx.Msg is an interface. The concrete types - // are registered by MakeTxCodec - err := unmarshaler(txBytes, &tx) - if err != nil { - return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, err.Error()) - } - return tx, nil - } -} - -// DefaultTxEncoder logic for standard transaction encoding -func DefaultTxEncoder(cdc *codec.LegacyAmino) sdk.TxEncoder { - return func(tx sdk.Tx) ([]byte, error) { - return cdc.Marshal(tx) - } -} diff --git a/x/auth/migrations/legacytx/stdtx_test.go b/x/auth/migrations/legacytx/stdtx_test.go index f8fb9ee99b2c..37adbea2db6f 100644 --- a/x/auth/migrations/legacytx/stdtx_test.go +++ b/x/auth/migrations/legacytx/stdtx_test.go @@ -4,19 +4,14 @@ import ( "fmt" "testing" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -39,38 +34,6 @@ func NewTestStdFee() StdFee { } // Deprecated: use TxBuilder. -func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []cryptotypes.PrivKey, accNums []uint64, seqs []uint64, timeout uint64, fee StdFee) sdk.Tx { - sigs := make([]StdSignature, len(privs)) - for i, priv := range privs { - signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], timeout, fee, msgs, "", nil) - - sig, err := priv.Sign(signBytes) - if err != nil { - panic(err) - } - - sigs[i] = StdSignature{PubKey: priv.PubKey(), Signature: sig} - } - - tx := NewStdTx(msgs, fee, sigs, "") - return tx -} - -func TestStdTx(t *testing.T) { - msgs := []sdk.Msg{testdata.NewTestMsg(addr)} - fee := NewTestStdFee() - sigs := []StdSignature{} - - tx := NewStdTx(msgs, fee, sigs, "") - require.Equal(t, msgs, tx.GetMsgs()) - require.Equal(t, sigs, tx.Signatures) - - feePayer := tx.GetSigners()[0] - require.Equal(t, addr, feePayer) - - feeGranter := tx.FeeGranter() - require.Empty(t, feeGranter) -} func TestStdSignBytes(t *testing.T) { type args struct { @@ -150,86 +113,6 @@ func TestStdSignBytes(t *testing.T) { } } -func TestTxValidateBasic(t *testing.T) { - ctx := sdk.NewContext(nil, cmtproto.Header{ChainID: "mychainid"}, false, log.NewNopLogger()) - - // keys and addresses - priv1, _, addr1 := testdata.KeyTestPubAddr() - priv2, _, addr2 := testdata.KeyTestPubAddr() - - // msg and signatures - msg1 := testdata.NewTestMsg(addr1, addr2) - fee := NewTestStdFee() - - msgs := []sdk.Msg{msg1} - - // require to fail validation upon invalid fee - badFee := NewTestStdFee() - badFee.Amount[0].Amount = sdk.NewInt(-5) - tx := NewTestTx(ctx, nil, nil, nil, nil, 0, badFee) - - err := tx.ValidateBasic() - require.Error(t, err) - _, code, _ := errorsmod.ABCIInfo(err, false) - require.Equal(t, sdkerrors.ErrInsufficientFee.ABCICode(), code) - - // require to fail validation when no signatures exist - privs, accNums, seqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{} - tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee) - - err = tx.ValidateBasic() - require.Error(t, err) - _, code, _ = errorsmod.ABCIInfo(err, false) - require.Equal(t, sdkerrors.ErrNoSignatures.ABCICode(), code) - - // require to fail validation when signatures do not match expected signers - privs, accNums, seqs = []cryptotypes.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0} - tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee) - - err = tx.ValidateBasic() - require.Error(t, err) - _, code, _ = errorsmod.ABCIInfo(err, false) - require.Equal(t, sdkerrors.ErrUnauthorized.ABCICode(), code) - - // require to fail with invalid gas supplied - badFee = NewTestStdFee() - badFee.Gas = 9223372036854775808 - tx = NewTestTx(ctx, nil, nil, nil, nil, 0, badFee) - - err = tx.ValidateBasic() - require.Error(t, err) - _, code, _ = errorsmod.ABCIInfo(err, false) - require.Equal(t, sdkerrors.ErrInvalidRequest.ABCICode(), code) - - // require to pass when above criteria are matched - privs, accNums, seqs = []cryptotypes.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0} - tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee) - - err = tx.ValidateBasic() - require.NoError(t, err) -} - -func TestDefaultTxEncoder(t *testing.T) { - cdc := codec.NewLegacyAmino() - sdk.RegisterLegacyAminoCodec(cdc) - cdc.RegisterConcrete(testdata.TestMsg{}, "cosmos-sdk/Test", nil) - encoder := DefaultTxEncoder(cdc) - - msgs := []sdk.Msg{testdata.NewTestMsg(addr)} - fee := NewTestStdFee() - sigs := []StdSignature{} - - tx := NewStdTx(msgs, fee, sigs, "") - - cdcBytes, err := cdc.Marshal(tx) - - require.NoError(t, err) - encoderBytes, err := encoder(tx) - - require.NoError(t, err) - require.Equal(t, cdcBytes, encoderBytes) -} - func TestSignatureV2Conversions(t *testing.T) { _, pubKey, _ := testdata.KeyTestPubAddr() cdc := codec.NewLegacyAmino() @@ -283,26 +166,3 @@ func TestSignatureV2Conversions(t *testing.T) { require.Equal(t, multiPK, sigV2.PubKey) require.Equal(t, msigData, sigV2.Data) } - -func TestGetSignaturesV2(t *testing.T) { - _, pubKey, _ := testdata.KeyTestPubAddr() - dummy := []byte("dummySig") - - cdc := codec.NewLegacyAmino() - sdk.RegisterLegacyAminoCodec(cdc) - cryptocodec.RegisterCrypto(cdc) - - fee := NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)}) - sig := StdSignature{PubKey: pubKey, Signature: dummy} - stdTx := NewStdTx([]sdk.Msg{testdata.NewTestMsg()}, fee, []StdSignature{sig}, "testsigs") - - sigs, err := stdTx.GetSignaturesV2() - require.Nil(t, err) - require.Equal(t, len(sigs), 1) - - require.Equal(t, cdc.MustMarshal(sigs[0].PubKey), cdc.MustMarshal(sig.GetPubKey())) - require.Equal(t, sigs[0].Data, &signing.SingleSignatureData{ - SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - Signature: sig.GetSignature(), - }) -} diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 22309639656e..770ef1240270 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -4,8 +4,10 @@ import ( "fmt" "testing" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -91,7 +93,7 @@ func TestDirectModeHandler(t *testing.T) { for i, msg := range msgs { var err error - anys[i], err = codectypes.NewAnyWithValue(msg) + anys[i], err = codectypes.NewAnyWithValue(msg.(proto.Message)) if err != nil { panic(err) } @@ -151,8 +153,8 @@ func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) { type nonProtoTx int -func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } -func (npt *nonProtoTx) ValidateBasic() error { return nil } +func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } +func (npt *nonProtoTx) ValidateBasic(*signing2.GetSignersContext) error { return nil } var _ sdk.Tx = (*nonProtoTx)(nil) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 554e5dc73f5a..f5c6b5b4f036 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -7,7 +7,6 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" @@ -25,8 +24,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&ModuleCredential{}, "cosmos-sdk/GroupAccountCredential", nil) legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/auth/MsgUpdateParams") - - legacytx.RegisterLegacyAminoCodec(cdc) } // RegisterInterfaces associates protoName with AccountI interface diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 501da89035e9..5fe11bf7d5fa 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -12,6 +12,7 @@ import ( errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -26,10 +27,11 @@ import ( const gasCostPerIteration = uint64(20) type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - router baseapp.MessageRouter - authKeeper authz.AccountKeeper + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + router baseapp.MessageRouter + authKeeper authz.AccountKeeper + getSignersContext *signing.GetSignersContext } // NewKeeper constructs a message authorization Keeper @@ -89,12 +91,19 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] now := ctx.BlockTime() for i, msg := range msgs { - signers := msg.GetSigners() + signers, err := sdk.GetSigners(msg, k.getSignersContext) + if err != nil { + return nil, err + } + if len(signers) != 1 { return nil, authz.ErrAuthorizationNumOfSigners } - granter := signers[0] + granter, err := sdk.AccAddressFromBech32(signers[0]) + if err != nil { + return nil, err + } // If granter != grantee then check authorization.Accept, otherwise we // implicitly accept. diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 792120d6de71..590fd5380d48 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -158,7 +158,7 @@ func (msg MsgRevoke) GetSignBytes() []byte { func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExec { msgsAny := make([]*cdctypes.Any, len(msgs)) for i, msg := range msgs { - any, err := cdctypes.NewAnyWithValue(msg) + any, err := cdctypes.NewAnyWithValue(msg.(proto.Message)) if err != nil { panic(err) } @@ -207,7 +207,7 @@ func (msg MsgExec) ValidateBasic() error { return err } for _, msg := range msgs { - if err = msg.ValidateBasic(); err != nil { + if err = sdk.ValidateBasic(msg); err != nil { return err } } diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index 421319adc3a3..de41ec1424f5 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -109,7 +109,7 @@ func DefaultMessageValidator(msgs []sdk.Msg) error { if _, ok := msgs[0].(*stakingtypes.MsgCreateValidator); !ok { return fmt.Errorf("unexpected GenTx message type; expected: MsgCreateValidator, got: %T", msgs[0]) } - if err := msgs[0].ValidateBasic(); err != nil { + if err := sdk.ValidateBasic(msgs[0]); err != nil { return fmt.Errorf("invalid GenTx '%s': %w", msgs[0], err) } diff --git a/x/gov/migrations/v3/convert.go b/x/gov/migrations/v3/convert.go index 1c9879c0cf51..9aa7f8f72934 100644 --- a/x/gov/migrations/v3/convert.go +++ b/x/gov/migrations/v3/convert.go @@ -3,6 +3,8 @@ package v3 import ( "fmt" + "github.com/cosmos/gogoproto/proto" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -64,7 +66,7 @@ func ConvertToLegacyProposal(proposal v1.Proposal) (v1beta1.Proposal, error) { // this is to support clients that have not yet (properly) use gov/v1 endpoints // https://github.com/cosmos/cosmos-sdk/issues/14334 // VerifyBasic assures that we have at least one message. - legacyProposal.Content, err = codectypes.NewAnyWithValue(msgs[0]) + legacyProposal.Content, err = codectypes.NewAnyWithValue(msgs[0].(proto.Message)) return legacyProposal, err } diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index ac10428e23b2..6651efd96e61 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -100,7 +100,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { } for idx, msg := range msgs { - if err := msg.ValidateBasic(); err != nil { + if err := sdk.ValidateBasic(msg); err != nil { return errorsmod.Wrap(types.ErrInvalidProposalMsg, fmt.Sprintf("msg: %d, err: %s", idx, err.Error())) } diff --git a/x/group/msgs.go b/x/group/msgs.go index 426105c11393..384e84230d1c 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -588,7 +588,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { } for i, msg := range msgs { - if err := msg.ValidateBasic(); err != nil { + if err := sdk.ValidateBasic(msg); err != nil { return errorsmod.Wrapf(err, "msg %d", i) } } diff --git a/x/tx/signing/get_signers.go b/x/tx/signing/get_signers.go index a494ddcd821e..efd072cc0c75 100644 --- a/x/tx/signing/get_signers.go +++ b/x/tx/signing/get_signers.go @@ -2,11 +2,14 @@ package signing import ( "fmt" + "strings" msgv1 "cosmossdk.io/api/cosmos/msg/v1" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/dynamicpb" + "google.golang.org/protobuf/types/known/anypb" ) // GetSignersContext is a context for retrieving the list of signers from a @@ -14,6 +17,7 @@ import ( // option. type GetSignersContext struct { protoFiles *protoregistry.Files + protoTypes protoregistry.MessageTypeResolver getSignersFuncs map[protoreflect.FullName]getSignersFunc } @@ -22,6 +26,8 @@ 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 *protoregistry.Files + + ProtoTypes protoregistry.MessageTypeResolver } // NewGetSignersContext creates a new GetSignersContext using the provided options. @@ -31,8 +37,14 @@ func NewGetSignersContext(options GetSignersOptions) *GetSignersContext { protoFiles = protoregistry.GlobalFiles } + protoTypes := options.ProtoTypes + if protoTypes == nil { + protoTypes = protoregistry.GlobalTypes + } + return &GetSignersContext{ protoFiles: protoFiles, + protoTypes: protoTypes, getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, } } @@ -175,3 +187,31 @@ func (c *GetSignersContext) GetSigners(msg proto.Message) ([]string, error) { return f(msg), nil } + +func (c *GetSignersContext) GetSignersForAny(any *anypb.Any) ([]string, error) { + url := any.TypeUrl + typ, err := c.protoTypes.FindMessageByURL(url) + if err != nil { + if err == protoregistry.NotFound { + msgName := protoreflect.FullName(url) + if i := strings.LastIndexByte(url, '/'); i >= 0 { + msgName = msgName[i+len("/"):] + } + msgDesc, err := c.protoFiles.FindDescriptorByName(msgName) + if err != nil { + return nil, err + } + + typ = dynamicpb.NewMessageType(msgDesc.(protoreflect.MessageDescriptor)) + } + return nil, err + } + + msg := typ.New().Interface() + err = any.UnmarshalTo(msg) + if err != nil { + return nil, err + } + + return c.GetSigners(msg) +} From 20615e7e2c564d61e12362666466a3c80f321336 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 6 Mar 2023 13:28:54 -0500 Subject: [PATCH 02/83] reduce scope --- baseapp/baseapp.go | 2 +- baseapp/msg_service_router.go | 2 +- types/tx/msgs.go | 8 +----- types/tx_msg.go | 33 ++++++++---------------- x/auth/migrations/legacytx/stdtx_test.go | 5 ---- x/authz/msgs.go | 4 +-- x/genutil/types/genesis_state.go | 2 +- x/gov/migrations/v3/convert.go | 4 +-- x/gov/types/v1/msgs.go | 2 +- x/group/msgs.go | 2 +- 10 files changed, 20 insertions(+), 44 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 4273a7e25636..6b17d18d20d8 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -541,7 +541,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } for _, msg := range msgs { - err := sdk.ValidateBasic(msg) + err := msg.ValidateBasic() if err != nil { return err } diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index fa4d77e1ff0f..ed08986d47e7 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -122,7 +122,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter return handler(goCtx, req) } - if err := sdk.ValidateBasic(req); err != nil { + if err := req.ValidateBasic(); err != nil { return nil, err } // Call the method handler from the service description with the handler object. diff --git a/types/tx/msgs.go b/types/tx/msgs.go index 539f99d6ddd0..25e79c4457f8 100644 --- a/types/tx/msgs.go +++ b/types/tx/msgs.go @@ -3,8 +3,6 @@ package tx import ( fmt "fmt" - "github.com/cosmos/gogoproto/proto" - "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -23,11 +21,7 @@ func SetMsgs(msgs []sdk.Msg) ([]*types.Any, error) { anys := make([]*types.Any, len(msgs)) for i, msg := range msgs { var err error - msgProto, ok := msg.(proto.Message) - if !ok { - return nil, fmt.Errorf("%T is not a proto message", msg) - } - anys[i], err = types.NewAnyWithValue(msgProto) + anys[i], err = types.NewAnyWithValue(msg) if err != nil { return nil, err } diff --git a/types/tx_msg.go b/types/tx_msg.go index dc96625e7938..95e3674fd417 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -16,17 +16,19 @@ import ( ) type ( - // Msg is an empty tag interface for transaction messages. - Msg interface{} - - // LegacyMsg defines the interface a transaction message needed to fulfill up through - // v0.47. - LegacyMsg interface { + // Msg defines the interface a transaction message needed to fulfill. + Msg interface { proto.Message // ValidateBasic does a simple validation check that // doesn't require access to any other information. ValidateBasic() error + } + + // LegacyMsg defines the interface a transaction message needed to fulfill up through + // v0.47. + LegacyMsg interface { + Msg // GetSigners returns the addrs of signers that must sign. // CONTRACT: All signatures must be present to be valid. @@ -130,17 +132,6 @@ func GetModuleNameFromTypeURL(input string) string { return "" } -func ValidateBasic(msg Msg) error { - if validateBasic, ok := msg.(interface{ ValidateBasic() error }); ok { - err := validateBasic.ValidateBasic() - if err != nil { - return err - } - } - - return nil -} - func GetSigners(msg Msg, getSignersCtx *signing.GetSignersContext) ([]string, error) { if legacyMsg, ok := msg.(LegacyMsg); ok { var signers []string @@ -151,17 +142,15 @@ func GetSigners(msg Msg, getSignersCtx *signing.GetSignersContext) ([]string, er return signers, nil } else if msgv2, ok := msg.(protov2.Message); ok { return getSignersCtx.GetSigners(msgv2) - } else if msgv1, ok := msg.(proto.Message); ok { - bz, err := proto.Marshal(msgv1) + } else { + bz, err := proto.Marshal(msg) if err != nil { return nil, err } return getSignersCtx.GetSignersForAny(&anypb.Any{ - TypeUrl: MsgTypeURL(msgv1), + TypeUrl: MsgTypeURL(msg), Value: bz, }) - } else { - return nil, fmt.Errorf("%T is not a proto message", msg) } } diff --git a/x/auth/migrations/legacytx/stdtx_test.go b/x/auth/migrations/legacytx/stdtx_test.go index 37adbea2db6f..c249a8a61d89 100644 --- a/x/auth/migrations/legacytx/stdtx_test.go +++ b/x/auth/migrations/legacytx/stdtx_test.go @@ -21,11 +21,6 @@ var ( addr = sdk.AccAddress(priv.PubKey().Address()) ) -func init() { - amino := codec.NewLegacyAmino() - RegisterLegacyAminoCodec(amino) -} - // Deprecated: use fee amount and gas limit separately on TxBuilder. func NewTestStdFee() StdFee { return NewStdFee(100000, diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 590fd5380d48..792120d6de71 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -158,7 +158,7 @@ func (msg MsgRevoke) GetSignBytes() []byte { func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExec { msgsAny := make([]*cdctypes.Any, len(msgs)) for i, msg := range msgs { - any, err := cdctypes.NewAnyWithValue(msg.(proto.Message)) + any, err := cdctypes.NewAnyWithValue(msg) if err != nil { panic(err) } @@ -207,7 +207,7 @@ func (msg MsgExec) ValidateBasic() error { return err } for _, msg := range msgs { - if err = sdk.ValidateBasic(msg); err != nil { + if err = msg.ValidateBasic(); err != nil { return err } } diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index de41ec1424f5..421319adc3a3 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -109,7 +109,7 @@ func DefaultMessageValidator(msgs []sdk.Msg) error { if _, ok := msgs[0].(*stakingtypes.MsgCreateValidator); !ok { return fmt.Errorf("unexpected GenTx message type; expected: MsgCreateValidator, got: %T", msgs[0]) } - if err := sdk.ValidateBasic(msgs[0]); err != nil { + if err := msgs[0].ValidateBasic(); err != nil { return fmt.Errorf("invalid GenTx '%s': %w", msgs[0], err) } diff --git a/x/gov/migrations/v3/convert.go b/x/gov/migrations/v3/convert.go index 9aa7f8f72934..1c9879c0cf51 100644 --- a/x/gov/migrations/v3/convert.go +++ b/x/gov/migrations/v3/convert.go @@ -3,8 +3,6 @@ package v3 import ( "fmt" - "github.com/cosmos/gogoproto/proto" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -66,7 +64,7 @@ func ConvertToLegacyProposal(proposal v1.Proposal) (v1beta1.Proposal, error) { // this is to support clients that have not yet (properly) use gov/v1 endpoints // https://github.com/cosmos/cosmos-sdk/issues/14334 // VerifyBasic assures that we have at least one message. - legacyProposal.Content, err = codectypes.NewAnyWithValue(msgs[0].(proto.Message)) + legacyProposal.Content, err = codectypes.NewAnyWithValue(msgs[0]) return legacyProposal, err } diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index 6651efd96e61..ac10428e23b2 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -100,7 +100,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { } for idx, msg := range msgs { - if err := sdk.ValidateBasic(msg); err != nil { + if err := msg.ValidateBasic(); err != nil { return errorsmod.Wrap(types.ErrInvalidProposalMsg, fmt.Sprintf("msg: %d, err: %s", idx, err.Error())) } diff --git a/x/group/msgs.go b/x/group/msgs.go index 384e84230d1c..426105c11393 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -588,7 +588,7 @@ func (m MsgSubmitProposal) ValidateBasic() error { } for i, msg := range msgs { - if err := sdk.ValidateBasic(msg); err != nil { + if err := msg.ValidateBasic(); err != nil { return errorsmod.Wrapf(err, "msg %d", i) } } From f303a94496b9c0123f3517d151d08b20c71e1948 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 6 Mar 2023 13:30:54 -0500 Subject: [PATCH 03/83] reduce scope --- client/tx/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 7a59fad03d5f..0e4e9ac96609 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -40,7 +40,7 @@ func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msg // Right now, we're factorizing that call inside this function. // ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504 for _, msg := range msgs { - if err := sdk.ValidateBasic(msg); err != nil { + if err := msg.ValidateBasic(); err != nil { return err } } From dae1e0b580a51794e2f3a4bef1b6a85a266747a3 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 6 Mar 2023 16:38:24 -0500 Subject: [PATCH 04/83] WIP --- x/auth/tx/builder.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index e796f6884d0c..8888643fd3fa 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -68,8 +69,8 @@ func (w *wrapper) GetMsgs() []sdk.Msg { return w.tx.GetMsgs() } -func (w *wrapper) ValidateBasic() error { - return w.tx.ValidateBasic() +func (w *wrapper) ValidateBasic(ctx *signing2.GetSignersContext) error { + return w.tx.ValidateBasic(ctx) } func (w *wrapper) getBodyBytes() []byte { @@ -104,8 +105,8 @@ func (w *wrapper) getAuthInfoBytes() []byte { return w.authInfoBz } -func (w *wrapper) GetSigners() []sdk.AccAddress { - return w.tx.GetSigners() +func (w *wrapper) GetSigners(ctx *signing2.GetSignersContext) []string { + return w.tx.GetSigners(ctx) } func (w *wrapper) GetPubKeys() ([]cryptotypes.PubKey, error) { From 5f78ad0c08109228cd86c4649965f869d702da41 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 10:20:01 -0500 Subject: [PATCH 05/83] refactoring --- client/tx/aux_builder.go | 2 +- go.mod | 2 + go.sum | 2 - server/mock/tx.go | 3 +- types/mempool/mempool_test.go | 1 + types/simulation/types.go | 4 +- types/tx/types.go | 72 --------------------- types/tx_msg.go | 2 +- x/auth/ante/ante.go | 5 +- x/auth/ante/basic.go | 13 ++-- x/auth/client/tx.go | 4 +- x/auth/tx/builder.go | 97 ++++++++++++++++++++++++++--- x/auth/tx/builder_test.go | 8 +-- x/auth/tx/config.go | 16 ++--- x/auth/tx/direct_test.go | 6 +- x/auth/tx/encode_decode_test.go | 2 +- x/auth/tx/legacy_amino_json_test.go | 8 +-- 17 files changed, 122 insertions(+), 125 deletions(-) diff --git a/client/tx/aux_builder.go b/client/tx/aux_builder.go index 608313f1f085..331f4a8459e1 100644 --- a/client/tx/aux_builder.go +++ b/client/tx/aux_builder.go @@ -57,7 +57,7 @@ func (b *AuxTxBuilder) SetMsgs(msgs ...sdk.Msg) error { anys := make([]*codectypes.Any, len(msgs)) for i, msg := range msgs { var err error - anys[i], err = codectypes.NewAnyWithValue(msg.(proto.Message)) + anys[i], err = codectypes.NewAnyWithValue(msg) if err != nil { return err } diff --git a/go.mod b/go.mod index 44067b9ee33f..106d30300531 100644 --- a/go.mod +++ b/go.mod @@ -154,6 +154,8 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) +replace cosmossdk.io/x/tx => ./x/tx + // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/go.sum b/go.sum index 218a0243fd72..029d2e9635d3 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.2 h1:pD4TEbzOOerVQNI+M9anQIncl+4wFELpGds3N7RzPiQ= -cosmossdk.io/x/tx v0.2.2/go.mod h1:cur19OSg8P6ifrZ00yJOyY6HT75FEhLBX2Ir3Sl0ubY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/server/mock/tx.go b/server/mock/tx.go index 26136ad502b9..f9f1c394dc99 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" errorsmod "cosmossdk.io/errors" @@ -106,7 +105,7 @@ func (msg *KVStoreTx) GetSignBytes() []byte { } // Should the app be calling this? Or only handlers? -func (msg *KVStoreTx) ValidateBasic(*signing2.GetSignersContext) error { +func (msg *KVStoreTx) ValidateBasic() error { return nil } diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index 2d544192b87c..ce50199b162e 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/log" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" diff --git a/types/simulation/types.go b/types/simulation/types.go index 83e73f4f786e..34d29d04e323 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -5,8 +5,6 @@ import ( "math/rand" "time" - "github.com/cosmos/gogoproto/proto" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -101,7 +99,7 @@ func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) } - return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg.(proto.Message))) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg)) } // NoOpMsg - create a no-operation message diff --git a/types/tx/types.go b/types/tx/types.go index 273ad8c397d7..42eab60367b7 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -1,16 +1,11 @@ package tx import ( - "fmt" - - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // MaxGasWanted defines the max gas allowed. @@ -19,7 +14,6 @@ const MaxGasWanted = uint64((1 << 63) - 1) // Interface implementation checks. var ( _, _, _, _ codectypes.UnpackInterfacesMessage = &Tx{}, &TxBody{}, &AuthInfo{}, &SignerInfo{} - _ sdk.Tx = &Tx{} ) // GetMsgs implements the GetMsgs method on sdk.Tx. @@ -36,72 +30,6 @@ func (t *Tx) GetMsgs() []sdk.Msg { return res } -// ValidateBasic implements the ValidateBasic method on sdk.Tx. -func (t *Tx) ValidateBasic(getSignersContext *signing.GetSignersContext) error { - if t == nil { - return fmt.Errorf("bad Tx") - } - - body := t.Body - if body == nil { - return fmt.Errorf("missing TxBody") - } - - authInfo := t.AuthInfo - if authInfo == nil { - return fmt.Errorf("missing AuthInfo") - } - - fee := authInfo.Fee - if fee == nil { - return fmt.Errorf("missing fee") - } - - if fee.GasLimit > MaxGasWanted { - return errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", fee.GasLimit, MaxGasWanted, - ) - } - - if fee.Amount.IsAnyNil() { - return errorsmod.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: null", - ) - } - - if fee.Amount.IsAnyNegative() { - return errorsmod.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: %s", fee.Amount, - ) - } - - if fee.Payer != "" { - _, err := sdk.AccAddressFromBech32(fee.Payer) - if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid fee payer address (%s)", err) - } - } - - sigs := t.Signatures - - if len(sigs) == 0 { - return sdkerrors.ErrNoSignatures - } - - signers := t.GetSigners(getSignersContext) - if len(sigs) != len(signers) { - return errorsmod.Wrapf( - sdkerrors.ErrUnauthorized, - "wrong number of signers; expected %d, got %d", len(signers), len(sigs), - ) - } - - return nil -} - // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). diff --git a/types/tx_msg.go b/types/tx_msg.go index 95e3674fd417..9868ae2361c3 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -57,7 +57,7 @@ type ( // ValidateBasic does a simple and lightweight validation check that doesn't // require access to any other information. - ValidateBasic(getSignersCtx *signing.GetSignersContext) error + ValidateBasic() error } // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 1ff54987b3c8..420e719c909c 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -7,7 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" - signing2 "cosmossdk.io/x/tx/signing" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -55,9 +54,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { anteDecorators := []sdk.AnteDecorator{ NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - NewValidateBasicDecorator(signing2.NewGetSignersContext(signing2.GetSignersOptions{ - ProtoFiles: protoFiles, - })), + NewValidateBasicDecorator(), NewTxTimeoutHeightDecorator(), NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index ddafd5d80ebf..8d335fc32b01 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -20,14 +19,10 @@ import ( // If ValidateBasic passes, decorator calls next AnteHandler in chain. Note, // ValidateBasicDecorator decorator will not get executed on ReCheckTx since it // is not dependent on application state. -type ValidateBasicDecorator struct { - getSignersContext *signing2.GetSignersContext -} +type ValidateBasicDecorator struct{} -func NewValidateBasicDecorator(getSignersContext *signing2.GetSignersContext) ValidateBasicDecorator { - return ValidateBasicDecorator{ - getSignersContext: getSignersContext, - } +func NewValidateBasicDecorator() ValidateBasicDecorator { + return ValidateBasicDecorator{} } func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { @@ -36,7 +31,7 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat return next(ctx, tx, simulate) } - if err := tx.ValidateBasic(vbd.getSignersContext); err != nil { + if err := tx.ValidateBasic(); err != nil { return ctx, err } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index a5091de9e1ec..9e3920c69793 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -192,9 +192,9 @@ func ParseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { return simRes, nil } -func isTxSigner(user sdk.AccAddress, signers []sdk.AccAddress) bool { +func isTxSigner(user sdk.AccAddress, signers []string) bool { for _, s := range signers { - if bytes.Equal(user.Bytes(), s.Bytes()) { + if user.String() == s { return true } } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 8888643fd3fa..cd2a54dd59eb 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -1,6 +1,8 @@ package tx import ( + "fmt" + "github.com/cosmos/gogoproto/proto" errorsmod "cosmossdk.io/errors" @@ -21,7 +23,8 @@ import ( // wrapper is a wrapper around the tx.Tx proto.Message which retain the raw // body and auth_info bytes. type wrapper struct { - cdc codec.Codec + cdc codec.Codec + getSignersCtx *signing2.GetSignersContext tx *tx.Tx @@ -34,6 +37,8 @@ type wrapper struct { authInfoBz []byte txBodyHasUnknownNonCriticals bool + + signers []sdk.AccAddress } var ( @@ -53,9 +58,10 @@ type ExtensionOptionsTxBuilder interface { SetNonCriticalExtensionOptions(...*codectypes.Any) } -func newBuilder(cdc codec.Codec) *wrapper { +func newBuilder(cdc codec.Codec, getSignersCtx *signing2.GetSignersContext) *wrapper { return &wrapper{ - cdc: cdc, + getSignersCtx: getSignersCtx, + cdc: cdc, tx: &tx.Tx{ Body: &tx.TxBody{}, AuthInfo: &tx.AuthInfo{ @@ -69,8 +75,69 @@ func (w *wrapper) GetMsgs() []sdk.Msg { return w.tx.GetMsgs() } -func (w *wrapper) ValidateBasic(ctx *signing2.GetSignersContext) error { - return w.tx.ValidateBasic(ctx) +func (w *wrapper) ValidateBasic() error { + if w.tx == nil { + return fmt.Errorf("bad Tx") + } + + body := w.tx.Body + if body == nil { + return fmt.Errorf("missing TxBody") + } + + authInfo := w.tx.AuthInfo + if authInfo == nil { + return fmt.Errorf("missing AuthInfo") + } + + fee := authInfo.Fee + if fee == nil { + return fmt.Errorf("missing fee") + } + + if fee.GasLimit > tx.MaxGasWanted { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "invalid gas supplied; %d > %d", fee.GasLimit, tx.MaxGasWanted, + ) + } + + if fee.Amount.IsAnyNil() { + return errorsmod.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: null", + ) + } + + if fee.Amount.IsAnyNegative() { + return errorsmod.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: %s", fee.Amount, + ) + } + + if fee.Payer != "" { + _, err := sdk.AccAddressFromBech32(fee.Payer) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid fee payer address (%s)", err) + } + } + + sigs := w.tx.Signatures + + if len(sigs) == 0 { + return sdkerrors.ErrNoSignatures + } + + signers := w.GetSigners() + if len(sigs) != len(signers) { + return errorsmod.Wrapf( + sdkerrors.ErrUnauthorized, + "wrong number of signers; expected %d, got %d", len(signers), len(sigs), + ) + } + + return nil } func (w *wrapper) getBodyBytes() []byte { @@ -105,8 +172,15 @@ func (w *wrapper) getAuthInfoBytes() []byte { return w.authInfoBz } -func (w *wrapper) GetSigners(ctx *signing2.GetSignersContext) []string { - return w.tx.GetSigners(ctx) +func (w *wrapper) GetSigners() []sdk.AccAddress { + if w.signers == nil { + signers := w.tx.GetSigners(w.getSignersCtx) + for _, signer := range signers { + signerBz := sdk.MustAccAddressFromBech32(signer) + w.signers = append(w.signers, signerBz) + } + } + return w.signers } func (w *wrapper) GetPubKeys() ([]cryptotypes.PubKey, error) { @@ -294,12 +368,12 @@ func (w *wrapper) SetSignatures(signatures ...signing.SignatureV2) error { for i, sig := range signatures { var modeInfo *tx.ModeInfo modeInfo, rawSigs[i] = SignatureDataToModeInfoAndSig(sig.Data) - any, err := codectypes.NewAnyWithValue(sig.PubKey) + a, err := codectypes.NewAnyWithValue(sig.PubKey) if err != nil { return err } signerInfos[i] = &tx.SignerInfo{ - PublicKey: any, + PublicKey: a, ModeInfo: modeInfo, Sequence: sig.Sequence, } @@ -445,7 +519,10 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error { for i, msgAny := range body.Messages { msgs[i] = msgAny.GetCachedValue().(sdk.Msg) } - w.SetMsgs(msgs...) + err = w.SetMsgs(msgs...) + if err != nil { + return err + } w.SetTip(data.GetSignDoc().GetTip()) // Get the aux signer's index in GetSigners. diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 6b4fac958682..4f61a6f00290 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -21,7 +21,7 @@ func TestTxBuilder(t *testing.T) { _, pubkey, addr := testdata.KeyTestPubAddr() marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - txBuilder := newBuilder(nil) + txBuilder := newBuilder(nil, nil) memo := "sometestmemo" //nolint:goconst msgs := []sdk.Msg{testdata.NewTestMsg(addr)} @@ -138,7 +138,7 @@ func TestBuilderValidateBasic(t *testing.T) { // require to fail validation upon invalid fee badFeeAmount := testdata.NewTestFeeAmount() badFeeAmount[0].Amount = sdk.NewInt(-5) - txBuilder := newBuilder(nil) + txBuilder := newBuilder(nil, nil) var sig1, sig2 signing.SignatureV2 sig1 = signing.SignatureV2{ @@ -279,7 +279,7 @@ func TestBuilderFeePayer(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { // setup basic tx - txBuilder := newBuilder(nil) + txBuilder := newBuilder(nil, nil) err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) @@ -303,7 +303,7 @@ func TestBuilderFeeGranter(t *testing.T) { feeAmount := testdata.NewTestFeeAmount() msgs := []sdk.Msg{msg1} - txBuilder := newBuilder(nil) + txBuilder := newBuilder(nil, nil) err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 5cb00e96907d..a365eafcea77 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -3,6 +3,7 @@ package tx import ( "fmt" + signing2 "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/client" @@ -13,12 +14,13 @@ import ( ) type config struct { - handler signing.SignModeHandler - decoder sdk.TxDecoder - encoder sdk.TxEncoder - jsonDecoder sdk.TxDecoder - jsonEncoder sdk.TxEncoder - protoCodec codec.ProtoCodecMarshaler + handler signing.SignModeHandler + decoder sdk.TxDecoder + encoder sdk.TxEncoder + jsonDecoder sdk.TxDecoder + jsonEncoder sdk.TxEncoder + protoCodec codec.ProtoCodecMarshaler + getSignersCtx *signing2.GetSignersContext } // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The @@ -57,7 +59,7 @@ func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signin } func (g config) NewTxBuilder() client.TxBuilder { - return newBuilder(g.protoCodec) + return newBuilder(g.protoCodec, g.getSignersCtx) } // WrapTxBuilder returns a builder from provided transaction diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 770ef1240270..804dfad6fbf7 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -93,7 +93,7 @@ func TestDirectModeHandler(t *testing.T) { for i, msg := range msgs { var err error - anys[i], err = codectypes.NewAnyWithValue(msg.(proto.Message)) + anys[i], err = codectypes.NewAnyWithValue(msg) if err != nil { panic(err) } @@ -153,8 +153,8 @@ func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) { type nonProtoTx int -func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } -func (npt *nonProtoTx) ValidateBasic(*signing2.GetSignersContext) error { return nil } +func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } +func (npt *nonProtoTx) ValidateBasic() error { return nil } var _ sdk.Tx = (*nonProtoTx)(nil) diff --git a/x/auth/tx/encode_decode_test.go b/x/auth/tx/encode_decode_test.go index f4297770959c..25540d78858b 100644 --- a/x/auth/tx/encode_decode_test.go +++ b/x/auth/tx/encode_decode_test.go @@ -24,7 +24,7 @@ func TestDefaultTxDecoderError(t *testing.T) { encoder := DefaultTxEncoder() decoder := DefaultTxDecoder(cdc) - builder := newBuilder(nil) + builder := newBuilder(nil, nil) err := builder.SetMsgs(testdata.NewTestMsg()) require.NoError(t, err) diff --git a/x/auth/tx/legacy_amino_json_test.go b/x/auth/tx/legacy_amino_json_test.go index 63afe9dd5d36..4ab221bb555f 100644 --- a/x/auth/tx/legacy_amino_json_test.go +++ b/x/auth/tx/legacy_amino_json_test.go @@ -86,7 +86,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { for _, tc := range testcases { tc := tc t.Run(tc.name, func(t *testing.T) { - bldr := newBuilder(nil) + bldr := newBuilder(nil, nil) buildTx(t, bldr) tx := bldr.GetTx() tc.malleate(bldr) @@ -104,7 +104,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { }) } - bldr := newBuilder(nil) + bldr := newBuilder(nil, nil) buildTx(t, bldr) tx := bldr.GetTx() signingData := signing.SignerData{ @@ -120,7 +120,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { require.Error(t, err) // expect error with extension options - bldr = newBuilder(nil) + bldr = newBuilder(nil, nil) buildTx(t, bldr) any, err := cdctypes.NewAnyWithValue(testdata.NewTestMsg()) require.NoError(t, err) @@ -130,7 +130,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { require.Error(t, err) // expect error with non-critical extension options - bldr = newBuilder(nil) + bldr = newBuilder(nil, nil) buildTx(t, bldr) bldr.tx.Body.NonCriticalExtensionOptions = []*cdctypes.Any{any} tx = bldr.GetTx() From d3aa37c8cd78d12ce5dfedaf8e9661fd81a859eb Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 10:25:49 -0500 Subject: [PATCH 06/83] refactoring --- x/auth/client/tx.go | 4 +- x/auth/migrations/legacytx/codec.go | 9 ++ x/auth/migrations/legacytx/stdtx.go | 121 ++++++++++++++++ x/auth/migrations/legacytx/stdtx_builder.go | 150 ++++++++++++++++++++ x/auth/migrations/legacytx/stdtx_test.go | 31 +++- 5 files changed, 311 insertions(+), 4 deletions(-) create mode 100644 x/auth/migrations/legacytx/codec.go create mode 100644 x/auth/migrations/legacytx/stdtx_builder.go diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 9e3920c69793..a5091de9e1ec 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -192,9 +192,9 @@ func ParseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { return simRes, nil } -func isTxSigner(user sdk.AccAddress, signers []string) bool { +func isTxSigner(user sdk.AccAddress, signers []sdk.AccAddress) bool { for _, s := range signers { - if user.String() == s { + if bytes.Equal(user.Bytes(), s.Bytes()) { return true } } diff --git a/x/auth/migrations/legacytx/codec.go b/x/auth/migrations/legacytx/codec.go new file mode 100644 index 000000000000..2bad4718e1e6 --- /dev/null +++ b/x/auth/migrations/legacytx/codec.go @@ -0,0 +1,9 @@ +package legacytx + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) +} diff --git a/x/auth/migrations/legacytx/stdtx.go b/x/auth/migrations/legacytx/stdtx.go index 75ad7d923c6b..d2a16cfb0b14 100644 --- a/x/auth/migrations/legacytx/stdtx.go +++ b/x/auth/migrations/legacytx/stdtx.go @@ -1,15 +1,21 @@ package legacytx import ( + errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/signing" ) // Interface implementation checks var ( + _ codectypes.UnpackInterfacesMessage = (*StdTx)(nil) + _ codectypes.UnpackInterfacesMessage = (*StdSignature)(nil) ) @@ -70,3 +76,118 @@ type StdTip struct { Amount sdk.Coins `json:"amount" yaml:"amount"` Tipper string `json:"tipper" yaml:"tipper"` } + +// StdTx is the legacy transaction format for wrapping a Msg with Fee and Signatures. +// It only works with Amino, please prefer the new protobuf Tx in types/tx. +// NOTE: the first signature is the fee payer (Signatures must not be nil). +// Deprecated +type StdTx struct { + Msgs []sdk.Msg `json:"msg" yaml:"msg"` + Fee StdFee `json:"fee" yaml:"fee"` + Signatures []StdSignature `json:"signatures" yaml:"signatures"` + Memo string `json:"memo" yaml:"memo"` + TimeoutHeight uint64 `json:"timeout_height" yaml:"timeout_height"` +} + +// Deprecated +func NewStdTx(msgs []sdk.Msg, fee StdFee, sigs []StdSignature, memo string) StdTx { + return StdTx{ + Msgs: msgs, + Fee: fee, + Signatures: sigs, + Memo: memo, + } +} + +// GetMsgs returns the all the transaction's messages. +func (tx StdTx) GetMsgs() []sdk.Msg { return tx.Msgs } + +// Deprecated: AsAny implements intoAny. It doesn't work for protobuf serialization, +// so it can't be saved into protobuf configured storage. We are using it only for API +// compatibility. +func (tx *StdTx) AsAny() *codectypes.Any { + return codectypes.UnsafePackAny(tx) +} + +// GetMemo returns the memo +func (tx StdTx) GetMemo() string { return tx.Memo } + +// GetTimeoutHeight returns the transaction's timeout height (if set). +func (tx StdTx) GetTimeoutHeight() uint64 { + return tx.TimeoutHeight +} + +// GetSignatures returns the signature of signers who signed the Msg. +// CONTRACT: Length returned is same as length of +// pubkeys returned from MsgKeySigners, and the order +// matches. +// CONTRACT: If the signature is missing (ie the Msg is +// invalid), then the corresponding signature is +// .Empty(). +func (tx StdTx) GetSignatures() [][]byte { + sigs := make([][]byte, len(tx.Signatures)) + for i, stdSig := range tx.Signatures { + sigs[i] = stdSig.Signature + } + return sigs +} + +// GetSignaturesV2 implements SigVerifiableTx.GetSignaturesV2 +func (tx StdTx) GetSignaturesV2() ([]signing.SignatureV2, error) { + res := make([]signing.SignatureV2, len(tx.Signatures)) + + for i, sig := range tx.Signatures { + var err error + res[i], err = StdSignatureToSignatureV2(legacy.Cdc, sig) + if err != nil { + return nil, errorsmod.Wrapf(err, "Unable to convert signature %v to V2", sig) + } + } + + return res, nil +} + +// GetPubkeys returns the pubkeys of signers if the pubkey is included in the signature +// If pubkey is not included in the signature, then nil is in the slice instead +func (tx StdTx) GetPubKeys() ([]cryptotypes.PubKey, error) { + pks := make([]cryptotypes.PubKey, len(tx.Signatures)) + + for i, stdSig := range tx.Signatures { + pks[i] = stdSig.GetPubKey() + } + + return pks, nil +} + +// GetGas returns the Gas in StdFee +func (tx StdTx) GetGas() uint64 { return tx.Fee.Gas } + +// GetFee returns the FeeAmount in StdFee +func (tx StdTx) GetFee() sdk.Coins { return tx.Fee.Amount } + +// FeeGranter always returns nil for StdTx +func (tx StdTx) FeeGranter() sdk.AccAddress { + return nil +} + +// GetTip always returns nil for StdTx +func (tx StdTx) GetTip() *tx.Tip { return nil } + +func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, m := range tx.Msgs { + err := codectypes.UnpackInterfaces(m, unpacker) + if err != nil { + return err + } + } + + // Signatures contain PubKeys, which need to be unpacked. + for _, s := range tx.Signatures { + err := s.UnpackInterfaces(unpacker) + if err != nil { + return err + } + } + + return nil +} diff --git a/x/auth/migrations/legacytx/stdtx_builder.go b/x/auth/migrations/legacytx/stdtx_builder.go new file mode 100644 index 000000000000..80d3450a441b --- /dev/null +++ b/x/auth/migrations/legacytx/stdtx_builder.go @@ -0,0 +1,150 @@ +package legacytx + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/signing" +) + +// StdTxBuilder wraps StdTx to implement to the context.TxBuilder interface. +// Note that this type just exists for backwards compatibility with amino StdTx +// and will not work for protobuf transactions. +type StdTxBuilder struct { + StdTx + cdc *codec.LegacyAmino +} + +// SetMsgs implements TxBuilder.SetMsgs +func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { + s.Msgs = msgs + return nil +} + +// SetSignatures implements TxBuilder.SetSignatures. +func (s *StdTxBuilder) SetSignatures(signatures ...signing.SignatureV2) error { + sigs := make([]StdSignature, len(signatures)) + var err error + for i, sig := range signatures { + sigs[i], err = SignatureV2ToStdSignature(s.cdc, sig) + if err != nil { + return err + } + } + + s.Signatures = sigs + return nil +} + +func (s *StdTxBuilder) SetFeeAmount(amount sdk.Coins) { + s.StdTx.Fee.Amount = amount +} + +func (s *StdTxBuilder) SetGasLimit(limit uint64) { + s.StdTx.Fee.Gas = limit +} + +func (s *StdTxBuilder) SetTip(tip *tx.Tip) { + panic("StdTxBuilder does not support tips") +} + +// SetMemo implements TxBuilder.SetMemo +func (s *StdTxBuilder) SetMemo(memo string) { + s.Memo = memo +} + +// SetTimeoutHeight sets the transaction's height timeout. +func (s *StdTxBuilder) SetTimeoutHeight(height uint64) { + s.TimeoutHeight = height +} + +// SetFeeGranter does nothing for stdtx +func (s *StdTxBuilder) SetFeeGranter(_ sdk.AccAddress) {} + +// SetFeePayer does nothing for stdtx +func (s *StdTxBuilder) SetFeePayer(_ sdk.AccAddress) {} + +// AddAuxSignerData returns an error for StdTxBuilder. +func (s *StdTxBuilder) AddAuxSignerData(_ tx.AuxSignerData) error { + return sdkerrors.ErrLogic.Wrap("cannot use AuxSignerData with StdTxBuilder") +} + +// StdTxConfig is a context.TxConfig for StdTx +type StdTxConfig struct { + Cdc *codec.LegacyAmino +} + +// MarshalTx implements TxConfig.MarshalTx +func (s StdTxConfig) TxEncoder() sdk.TxEncoder { + return DefaultTxEncoder(s.Cdc) +} + +func (s StdTxConfig) TxJSONEncoder() sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + return s.Cdc.MarshalJSON(tx) + } +} + +func (s StdTxConfig) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error) { + stdSigs := make([]StdSignature, len(sigs)) + for i, sig := range sigs { + stdSig, err := SignatureV2ToStdSignature(s.Cdc, sig) + if err != nil { + return nil, err + } + + stdSigs[i] = stdSig + } + return s.Cdc.MarshalJSON(stdSigs) +} + +func (s StdTxConfig) UnmarshalSignatureJSON(bz []byte) ([]signing.SignatureV2, error) { + var stdSigs []StdSignature + err := s.Cdc.UnmarshalJSON(bz, &stdSigs) + if err != nil { + return nil, err + } + + sigs := make([]signing.SignatureV2, len(stdSigs)) + for i, stdSig := range stdSigs { + sig, err := StdSignatureToSignatureV2(s.Cdc, stdSig) + if err != nil { + return nil, err + } + sigs[i] = sig + } + + return sigs, nil +} + +// SignatureV2ToStdSignature converts a SignatureV2 to a StdSignature +// [Deprecated] +func SignatureV2ToStdSignature(cdc *codec.LegacyAmino, sig signing.SignatureV2) (StdSignature, error) { + var ( + sigBz []byte + err error + ) + + if sig.Data != nil { + sigBz, err = SignatureDataToAminoSignature(cdc, sig.Data) + if err != nil { + return StdSignature{}, err + } + } + + return StdSignature{ + PubKey: sig.PubKey, + Signature: sigBz, + }, nil +} + +// Unmarshaler is a generic type for Unmarshal functions +type Unmarshaler func(bytes []byte, ptr interface{}) error + +// DefaultTxEncoder logic for standard transaction encoding +func DefaultTxEncoder(cdc *codec.LegacyAmino) sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + return cdc.Marshal(tx) + } +} diff --git a/x/auth/migrations/legacytx/stdtx_test.go b/x/auth/migrations/legacytx/stdtx_test.go index c249a8a61d89..2e51ece29c2d 100644 --- a/x/auth/migrations/legacytx/stdtx_test.go +++ b/x/auth/migrations/legacytx/stdtx_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -21,6 +22,11 @@ var ( addr = sdk.AccAddress(priv.PubKey().Address()) ) +func init() { + amino := codec.NewLegacyAmino() + RegisterLegacyAminoCodec(amino) +} + // Deprecated: use fee amount and gas limit separately on TxBuilder. func NewTestStdFee() StdFee { return NewStdFee(100000, @@ -28,8 +34,6 @@ func NewTestStdFee() StdFee { ) } -// Deprecated: use TxBuilder. - func TestStdSignBytes(t *testing.T) { type args struct { chainID string @@ -161,3 +165,26 @@ func TestSignatureV2Conversions(t *testing.T) { require.Equal(t, multiPK, sigV2.PubKey) require.Equal(t, msigData, sigV2.Data) } + +func TestGetSignaturesV2(t *testing.T) { + _, pubKey, _ := testdata.KeyTestPubAddr() + dummy := []byte("dummySig") + + cdc := codec.NewLegacyAmino() + sdk.RegisterLegacyAminoCodec(cdc) + cryptocodec.RegisterCrypto(cdc) + + fee := NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)}) + sig := StdSignature{PubKey: pubKey, Signature: dummy} + stdTx := NewStdTx([]sdk.Msg{testdata.NewTestMsg()}, fee, []StdSignature{sig}, "testsigs") + + sigs, err := stdTx.GetSignaturesV2() + require.Nil(t, err) + require.Equal(t, len(sigs), 1) + + require.Equal(t, cdc.MustMarshal(sigs[0].PubKey), cdc.MustMarshal(sig.GetPubKey())) + require.Equal(t, sigs[0].Data, &signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + Signature: sig.GetSignature(), + }) +} From 924c22d686686f8cf92033c89d2304beeb7995b3 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 10:32:31 -0500 Subject: [PATCH 07/83] refactoring --- client/tx/legacy.go | 26 ++++++++++++++++++++++++++ x/auth/tx/encoder.go | 5 ----- x/gov/keeper/keeper.go | 3 +++ x/gov/keeper/proposal.go | 9 ++++++--- x/group/keeper/keeper.go | 3 +++ x/group/keeper/msg_server.go | 2 +- x/group/keeper/proposal_executor.go | 16 +++++++++++----- 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/client/tx/legacy.go b/client/tx/legacy.go index 2e218dbcfde0..c07982a3fe4d 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -1,10 +1,36 @@ package tx import ( + "fmt" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) +// ConvertTxToStdTx converts a transaction to the legacy StdTx format +func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, error) { + if stdTx, ok := tx.(legacytx.StdTx); ok { + return stdTx, nil + } + + aminoTxConfig := legacytx.StdTxConfig{Cdc: codec} + builder := aminoTxConfig.NewTxBuilder() + + err := CopyTx(tx, builder, true) + if err != nil { + return legacytx.StdTx{}, err + } + + stdTx, ok := builder.GetTx().(legacytx.StdTx) + if !ok { + return legacytx.StdTx{}, fmt.Errorf("expected %T, got %+v", legacytx.StdTx{}, builder.GetTx()) + } + + return stdTx, nil +} + // CopyTx copies a Tx to a new TxBuilder, allowing conversion between // different transaction formats. If ignoreSignatureError is true, copying will continue // tx even if the signature cannot be set in the target builder resulting in an unsigned tx. diff --git a/x/auth/tx/encoder.go b/x/auth/tx/encoder.go index e69b57ec8df5..e98106a89a82 100644 --- a/x/auth/tx/encoder.go +++ b/x/auth/tx/encoder.go @@ -36,11 +36,6 @@ func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder { return cdc.MarshalJSON(txWrapper.tx) } - protoTx, ok := tx.(*txtypes.Tx) - if ok { - return cdc.MarshalJSON(protoTx) - } - return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, tx) } } diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 399a4179fc8f..8ad41a4fa470 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -44,6 +45,8 @@ type Keeper struct { // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string + + getSignersCtx *signing2.GetSignersContext } // GetAuthority returns the x/gov module's authority. diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index adf5c227ad9e..00745a0329eb 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -46,14 +46,17 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) } - signers := msg.GetSigners() + signers, err := sdk.GetSigners(msg, keeper.getSignersCtx) + if err != nil { + return v1.Proposal{}, err + } if len(signers) != 1 { return v1.Proposal{}, types.ErrInvalidSigner } // assert that the governance module account is the only signer of the messages - if !signers[0].Equals(keeper.GetGovernanceAccount(ctx).GetAddress()) { - return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, signers[0].String()) + if signers[0] != keeper.GetGovernanceAccount(ctx).GetAddress().String() { + return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, signers[0]) } // use the msg service router to see that there is a valid route for that message. diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 73df21e9372f..6460454c96d0 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -9,6 +9,7 @@ import ( errorsmod "cosmossdk.io/errors" + signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -79,6 +80,8 @@ type Keeper struct { router baseapp.MessageRouter config group.Config + + getSignersCtx *signing2.GetSignersContext } // NewKeeper creates a new group keeper. diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 94feeaed3ee8..282b893fd013 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -502,7 +502,7 @@ func (k Keeper) SubmitProposal(goCtx context.Context, req *group.MsgSubmitPropos } // Check that if the messages require signers, they are all equal to the given account address of group policy. - if err := ensureMsgAuthZ(msgs, groupPolicyAddr); err != nil { + if err := ensureMsgAuthZ(msgs, groupPolicyAddr, k.getSignersCtx); err != nil { return nil, err } diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index abc2d86d8ba2..9f58ad24f646 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -37,7 +38,7 @@ func (s Keeper) doExecuteMsgs(ctx sdk.Context, router baseapp.MessageRouter, pro } results := make([]sdk.Result, len(msgs)) - if err := ensureMsgAuthZ(msgs, groupPolicyAcc); err != nil { + if err := ensureMsgAuthZ(msgs, groupPolicyAcc, s.getSignersCtx); err != nil { return nil, err } for i, msg := range msgs { @@ -61,15 +62,20 @@ func (s Keeper) doExecuteMsgs(ctx sdk.Context, router baseapp.MessageRouter, pro // ensureMsgAuthZ checks that if a message requires signers that all of them // are equal to the given account address of group policy. -func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress) error { +func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, getSignersCtx *signing.GetSignersContext) error { for i := range msgs { // In practice, GetSigners() should return a non-empty array without // duplicates, so the code below is equivalent to: // `msgs[i].GetSigners()[0] == groupPolicyAcc` // but we prefer to loop through all GetSigners just to be sure. - for _, acct := range msgs[i].GetSigners() { - if !groupPolicyAcc.Equals(acct) { - return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "msg does not have group policy authorization; expected %s, got %s", groupPolicyAcc.String(), acct.String()) + signers, err := sdk.GetSigners(msgs[i], getSignersCtx) + if err != nil { + return err + } + + for _, acct := range signers { + if groupPolicyAcc.String() != acct { + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "msg does not have group policy authorization; expected %s, got %s", groupPolicyAcc.String(), acct) } } } From 7828f38bbd5231023a153f1c13ca32c813a4ab81 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 13:01:38 -0500 Subject: [PATCH 08/83] refactoring --- client/tx/legacy.go | 26 ---------------- x/auth/client/cli/tx_multisign.go | 49 ++++--------------------------- x/auth/client/cli/tx_sign.go | 33 ++------------------- 3 files changed, 9 insertions(+), 99 deletions(-) diff --git a/client/tx/legacy.go b/client/tx/legacy.go index c07982a3fe4d..2e218dbcfde0 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -1,36 +1,10 @@ package tx import ( - "fmt" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -// ConvertTxToStdTx converts a transaction to the legacy StdTx format -func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, error) { - if stdTx, ok := tx.(legacytx.StdTx); ok { - return stdTx, nil - } - - aminoTxConfig := legacytx.StdTxConfig{Cdc: codec} - builder := aminoTxConfig.NewTxBuilder() - - err := CopyTx(tx, builder, true) - if err != nil { - return legacytx.StdTx{}, err - } - - stdTx, ok := builder.GetTx().(legacytx.StdTx) - if !ok { - return legacytx.StdTx{}, fmt.Errorf("expected %T, got %+v", legacytx.StdTx{}, builder.GetTx()) - } - - return stdTx, nil -} - // CopyTx copies a Tx to a new TxBuilder, allowing conversion between // different transaction formats. If ignoreSignatureError is true, copying will continue // tx even if the signature cannot be set in the target builder resulting in an unsigned tx. diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 58d9e5265989..cc6a55cdd5aa 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -65,7 +65,6 @@ The SIGN_MODE_DIRECT sign mode is not supported.' cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") - cmd.Flags().Bool(flagAmino, false, "Generate Amino-encoded JSON suitable for submitting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) return cmd @@ -167,28 +166,10 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(flagAmino) - var json []byte - - if aminoJSON { - stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx()) - if err != nil { - return err - } - - req := BroadcastReq{ - Tx: stdTx, - Mode: "sync|async", - } - - json, _ = clientCtx.LegacyAmino.MarshalJSON(req) - - } else { - json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly) - if err != nil { - return err - } + json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly) + if err != nil { + return err } outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) @@ -355,28 +336,10 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { } sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) - aminoJSON, _ := cmd.Flags().GetBool(flagAmino) - var json []byte - - if aminoJSON { - stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBldr.GetTx()) - if err != nil { - return err - } - - req := BroadcastReq{ - Tx: stdTx, - Mode: "sync|async", - } - - json, _ = clientCtx.LegacyAmino.MarshalJSON(req) - - } else { - json, err = marshalSignatureJSON(txCfg, txBldr, sigOnly) - if err != nil { - return err - } + json, err = marshalSignatureJSON(txCfg, txBldr, sigOnly) + if err != nil { + return err } err = clientCtx.PrintString(fmt.Sprintf("%s\n", json)) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 9b37937dc634..986ca95d6783 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -19,7 +19,6 @@ const ( flagMultisig = "multisig" flagOverwrite = "overwrite" flagSigOnly = "signature-only" - flagAmino = "amino" flagNoAutoIncrement = "no-auto-increment" flagAppend = "append" ) @@ -284,7 +283,6 @@ be generated via the 'multisign' command. cmd.Flags().Bool(flagOverwrite, false, "Overwrite existing signatures with a new one. If disabled, new signature will be appended") cmd.Flags().Bool(flagSigOnly, false, "Print only the signatures") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") - cmd.Flags().Bool(flagAmino, false, "Generate Amino encoded JSON suitable for submiting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) cmd.MarkFlagRequired(flags.FlagFrom) @@ -399,16 +397,6 @@ func signTx(cmd *cobra.Command, clientCtx client.Context, txF tx.Factory, newTx return err } - aminoJSON, err := f.GetBool(flagAmino) - if err != nil { - return err - } - - bMode, err := f.GetString(flags.FlagBroadcastMode) - if err != nil { - return err - } - // set output closeFunc, err := setOutputFile(cmd) if err != nil { @@ -419,24 +407,9 @@ func signTx(cmd *cobra.Command, clientCtx client.Context, txF tx.Factory, newTx clientCtx.WithOutput(cmd.OutOrStdout()) var json []byte - if aminoJSON { - stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx()) - if err != nil { - return err - } - req := BroadcastReq{ - Tx: stdTx, - Mode: bMode, - } - json, err = clientCtx.LegacyAmino.MarshalJSON(req) - if err != nil { - return err - } - } else { - json, err = marshalSignatureJSON(txCfg, txBuilder, printSignatureOnly) - if err != nil { - return err - } + json, err = marshalSignatureJSON(txCfg, txBuilder, printSignatureOnly) + if err != nil { + return err } cmd.Printf("%s\n", json) From a1d35d237ae796a0ff3e6ec0d7ebfdfcaf367a89 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 13:33:12 -0500 Subject: [PATCH 09/83] tests compile --- client/tx/legacy.go | 39 ------ client/tx/legacy_test.go | 130 ------------------ types/tx_msg.go | 10 +- x/auth/ante/sigverify_test.go | 95 ------------- x/auth/client/tx_test.go | 35 +---- .../migrations/legacytx/amino_signing_test.go | 75 ---------- x/auth/migrations/legacytx/config_test.go | 28 ---- x/auth/signing/handler_map_test.go | 92 ------------- x/auth/signing/verify_test.go | 117 ---------------- x/auth/tx/direct_test.go | 2 - 10 files changed, 6 insertions(+), 617 deletions(-) delete mode 100644 client/tx/legacy.go delete mode 100644 x/auth/migrations/legacytx/amino_signing_test.go delete mode 100644 x/auth/migrations/legacytx/config_test.go delete mode 100644 x/auth/signing/handler_map_test.go delete mode 100644 x/auth/signing/verify_test.go diff --git a/client/tx/legacy.go b/client/tx/legacy.go deleted file mode 100644 index 2e218dbcfde0..000000000000 --- a/client/tx/legacy.go +++ /dev/null @@ -1,39 +0,0 @@ -package tx - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/x/auth/signing" -) - -// CopyTx copies a Tx to a new TxBuilder, allowing conversion between -// different transaction formats. If ignoreSignatureError is true, copying will continue -// tx even if the signature cannot be set in the target builder resulting in an unsigned tx. -func CopyTx(tx signing.Tx, builder client.TxBuilder, ignoreSignatureError bool) error { - err := builder.SetMsgs(tx.GetMsgs()...) - if err != nil { - return err - } - - sigs, err := tx.GetSignaturesV2() - if err != nil { - return err - } - - err = builder.SetSignatures(sigs...) - if err != nil { - if ignoreSignatureError { - // we call SetSignatures() agan with no args to clear any signatures in case the - // previous call to SetSignatures() had any partial side-effects - _ = builder.SetSignatures() - } else { - return err - } - } - - builder.SetMemo(tx.GetMemo()) - builder.SetFeeAmount(tx.GetFee()) - builder.SetGasLimit(tx.GetGas()) - builder.SetTimeoutHeight(tx.GetTimeoutHeight()) - - return nil -} diff --git a/client/tx/legacy_test.go b/client/tx/legacy_test.go index c4c62711574c..3a9af642463f 100644 --- a/client/tx/legacy_test.go +++ b/client/tx/legacy_test.go @@ -1,23 +1,10 @@ package tx_test import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/client" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" - tx2 "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types" typestx "github.com/cosmos/cosmos-sdk/types/tx" signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - "github.com/cosmos/cosmos-sdk/x/auth/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -45,120 +32,3 @@ var ( chainID = "test-chain" tip = &typestx.Tip{Tipper: addr1.String(), Amount: testdata.NewTestFeeAmount()} ) - -func buildTestTx(t *testing.T, builder client.TxBuilder) { - builder.SetMemo(memo) - builder.SetGasLimit(gas) - builder.SetFeeAmount(fee) - err := builder.SetMsgs(msg0, msg1) - require.NoError(t, err) - err = builder.SetSignatures(sig) - require.NoError(t, err) - builder.SetTimeoutHeight(timeoutHeight) -} - -type TestSuite struct { - suite.Suite - amino *codec.LegacyAmino - protoCfg client.TxConfig - aminoCfg client.TxConfig -} - -func (s *TestSuite) SetupSuite() { - var ( - reg codectypes.InterfaceRegistry - amino *codec.LegacyAmino - ) - err := depinject.Inject(clienttestutil.TestConfig, ®, &amino) - require.NoError(s.T(), err) - - s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(reg), tx.DefaultSignModes) - s.aminoCfg = legacytx.StdTxConfig{Cdc: amino} -} - -func (s *TestSuite) TestCopyTx() { - // proto -> amino -> proto - protoBuilder := s.protoCfg.NewTxBuilder() - buildTestTx(s.T(), protoBuilder) - aminoBuilder := s.aminoCfg.NewTxBuilder() - err := tx2.CopyTx(protoBuilder.GetTx(), aminoBuilder, false) - s.Require().NoError(err) - protoBuilder2 := s.protoCfg.NewTxBuilder() - err = tx2.CopyTx(aminoBuilder.GetTx(), protoBuilder2, false) - s.Require().NoError(err) - // Check sigs, signers and msgs. - sigsV2_1, err := protoBuilder.GetTx().GetSignaturesV2() - s.Require().NoError(err) - sigsV2_2, err := protoBuilder2.GetTx().GetSignaturesV2() - s.Require().NoError(err) - s.Require().Equal(sigsV2_1, sigsV2_2) - s.Require().Equal(protoBuilder.GetTx().GetSigners(), protoBuilder2.GetTx().GetSigners()) - s.Require().Equal(protoBuilder.GetTx().GetMsgs()[0], protoBuilder2.GetTx().GetMsgs()[0]) - s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1], protoBuilder2.GetTx().GetMsgs()[1]) - - // amino -> proto -> amino - aminoBuilder = s.aminoCfg.NewTxBuilder() - buildTestTx(s.T(), aminoBuilder) - protoBuilder = s.protoCfg.NewTxBuilder() - err = tx2.CopyTx(aminoBuilder.GetTx(), protoBuilder, false) - s.Require().NoError(err) - aminoBuilder2 := s.aminoCfg.NewTxBuilder() - err = tx2.CopyTx(protoBuilder.GetTx(), aminoBuilder2, false) - s.Require().NoError(err) - // Check sigs, signers, and msgs - sigsV2_1, err = aminoBuilder.GetTx().GetSignaturesV2() - s.Require().NoError(err) - sigsV2_2, err = aminoBuilder2.GetTx().GetSignaturesV2() - s.Require().NoError(err) - s.Require().Equal(sigsV2_1, sigsV2_2) - s.Require().Equal(aminoBuilder.GetTx().GetSigners(), aminoBuilder2.GetTx().GetSigners()) - s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[0], aminoBuilder2.GetTx().GetMsgs()[0]) - s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[1], aminoBuilder2.GetTx().GetMsgs()[1]) -} - -func (s *TestSuite) TestConvertTxToStdTx() { - // proto tx - protoBuilder := s.protoCfg.NewTxBuilder() - buildTestTx(s.T(), protoBuilder) - stdTx, err := tx2.ConvertTxToStdTx(s.amino, protoBuilder.GetTx()) - s.Require().NoError(err) - s.Require().Equal(memo, stdTx.Memo) - s.Require().Equal(gas, stdTx.Fee.Gas) - s.Require().Equal(fee, stdTx.Fee.Amount) - s.Require().Equal(msg0, stdTx.Msgs[0]) - s.Require().Equal(msg1, stdTx.Msgs[1]) - s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight) - s.Require().Equal(sig.PubKey, stdTx.Signatures[0].PubKey) - s.Require().Equal(sig.Data.(*signing2.SingleSignatureData).Signature, stdTx.Signatures[0].Signature) - - // SIGN_MODE_DIRECT should fall back to an unsigned tx - err = protoBuilder.SetSignatures(signing2.SignatureV2{ - PubKey: pub1, - Data: &signing2.SingleSignatureData{ - SignMode: signing2.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("dummy"), - }, - }) - s.Require().NoError(err) - stdTx, err = tx2.ConvertTxToStdTx(s.amino, protoBuilder.GetTx()) - s.Require().NoError(err) - s.Require().Equal(memo, stdTx.Memo) - s.Require().Equal(gas, stdTx.Fee.Gas) - s.Require().Equal(fee, stdTx.Fee.Amount) - s.Require().Equal(msg0, stdTx.Msgs[0]) - s.Require().Equal(msg1, stdTx.Msgs[1]) - s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight) - s.Require().Empty(stdTx.Signatures) - - // std tx - aminoBuilder := s.aminoCfg.NewTxBuilder() - buildTestTx(s.T(), aminoBuilder) - stdTx = aminoBuilder.GetTx().(legacytx.StdTx) - stdTx2, err := tx2.ConvertTxToStdTx(s.amino, stdTx) - s.Require().NoError(err) - s.Require().Equal(stdTx, stdTx2) -} - -func TestTestSuite(t *testing.T) { - suite.Run(t, new(TestSuite)) -} diff --git a/types/tx_msg.go b/types/tx_msg.go index 9868ae2361c3..7d92642dd6f8 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -92,12 +92,12 @@ type TxEncoder func(tx Tx) ([]byte, error) // MsgTypeURL returns the TypeURL of a `sdk.Msg`. func MsgTypeURL(msg Msg) string { - if msg, ok := msg.(protov2.Message); ok { - return "/" + string(msg.ProtoReflect().Descriptor().FullName()) - } else if msg, ok := msg.(proto.Message); ok { - return "/" + proto.MessageName(msg) + if m, ok := msg.(protov2.Message); ok { + return "/" + string(m.ProtoReflect().Descriptor().FullName()) + } else if m, ok := msg.(proto.Message); ok { + return "/" + proto.MessageName(m) } else { - panic(fmt.Errorf("%T is not a proto message", msg)) + panic(fmt.Errorf("%T is not a proto message", m)) } } diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 33f9270fd208..68e38c926575 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -9,7 +9,6 @@ import ( storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -228,100 +227,6 @@ func TestSigVerification(t *testing.T) { } } -// This test is exactly like the one above, but we set the codec explicitly to -// Amino. -// Once https://github.com/cosmos/cosmos-sdk/issues/6190 is in, we can remove -// this, since it'll be handled by the test matrix. -// In the meantime, we want to make double-sure amino compatibility works. -// ref: https://github.com/cosmos/cosmos-sdk/issues/7229 -func TestSigVerification_ExplicitAmino(t *testing.T) { - suite := SetupTestSuite(t, true) - // Set up TxConfig. - aminoCdc := codec.NewLegacyAmino() - // We're using TestMsg amino encoding in some tests, so register it here. - txConfig := legacytx.StdTxConfig{Cdc: aminoCdc} - - suite.clientCtx = client.Context{}. - WithTxConfig(txConfig) - - anteHandler, err := ante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: suite.accountKeeper, - BankKeeper: suite.bankKeeper, - FeegrantKeeper: suite.feeGrantKeeper, - SignModeHandler: txConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - ) - - require.NoError(t, err) - suite.anteHandler = anteHandler - - suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - - // make block height non-zero to ensure account numbers part of signBytes - suite.ctx = suite.ctx.WithBlockHeight(1) - - // keys and addresses - priv1, _, addr1 := testdata.KeyTestPubAddr() - priv2, _, addr2 := testdata.KeyTestPubAddr() - priv3, _, addr3 := testdata.KeyTestPubAddr() - - addrs := []sdk.AccAddress{addr1, addr2, addr3} - - msgs := make([]sdk.Msg, len(addrs)) - // set accounts and create msg for each address - for i, addr := range addrs { - acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) - require.NoError(t, acc.SetAccountNumber(uint64(i))) - suite.accountKeeper.SetAccount(suite.ctx, acc) - msgs[i] = testdata.NewTestMsg(addr) - } - - feeAmount := testdata.NewTestFeeAmount() - gasLimit := testdata.NewTestGasLimit() - - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) - svd := ante.NewSigVerificationDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SignModeHandler()) - antehandler := sdk.ChainAnteDecorators(spkd, svd) - - type testCase struct { - name string - privs []cryptotypes.PrivKey - accNums []uint64 - accSeqs []uint64 - recheck bool - shouldErr bool - } - testCases := []testCase{ - {"no signers", []cryptotypes.PrivKey{}, []uint64{}, []uint64{}, false, true}, - {"not enough signers", []cryptotypes.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}, false, true}, - {"wrong order signers", []cryptotypes.PrivKey{priv3, priv2, priv1}, []uint64{2, 1, 0}, []uint64{0, 0, 0}, false, true}, - {"wrong accnums", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{7, 8, 9}, []uint64{0, 0, 0}, false, true}, - {"wrong sequences", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{3, 4, 5}, false, true}, - {"valid tx", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, false, false}, - {"no err on recheck", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, true, false}, - } - for i, tc := range testCases { - suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck) - suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test - - require.NoError(t, suite.txBuilder.SetMsgs(msgs...)) - suite.txBuilder.SetFeeAmount(feeAmount) - suite.txBuilder.SetGasLimit(gasLimit) - - tx, err := suite.CreateTestTx(suite.ctx, tc.privs, tc.accNums, tc.accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) - require.NoError(t, err) - - _, err = antehandler(suite.ctx, tx, false) - if tc.shouldErr { - require.NotNil(t, err, "TestCase %d: %s did not error as expected", i, tc.name) - } else { - require.Nil(t, err, "TestCase %d: %s errored unexpectedly. Err: %v", i, tc.name, err) - } - } -} - func TestSigIntegration(t *testing.T) { // generate private keys privs := []cryptotypes.PrivKey{ diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index b7f0f170aac2..8479d35b1e9d 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -8,18 +8,15 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) var ( @@ -45,16 +42,6 @@ func TestParseQueryResponse(t *testing.T) { require.Error(t, err) } -// TODO: remove this and authclient.GetTxEncoder after the proto tx migration is complete -func TestDefaultTxEncoder(t *testing.T) { - cdc := makeCodec() - - defaultEncoder := legacytx.DefaultTxEncoder(cdc) - encoder := authclient.GetTxEncoder(cdc) - - compareEncoders(t, defaultEncoder, encoder) -} - func TestReadTxFromFile(t *testing.T) { t.Parallel() var ( @@ -150,23 +137,3 @@ func TestBatchScanner_Scan(t *testing.T) { }) } } - -func compareEncoders(t *testing.T, expected sdk.TxEncoder, actual sdk.TxEncoder) { - msgs := []sdk.Msg{testdata.NewTestMsg(addr)} - tx := legacytx.NewStdTx(msgs, legacytx.StdFee{}, []legacytx.StdSignature{}, "") //nolint:staticcheck // SA1019: legacytx.StdFee is deprecated: use FeeTx interface instead - - defaultEncoderBytes, err := expected(tx) - require.NoError(t, err) - encoderBytes, err := actual(tx) - require.NoError(t, err) - require.Equal(t, defaultEncoderBytes, encoderBytes) -} - -func makeCodec() *codec.LegacyAmino { - cdc := codec.NewLegacyAmino() - sdk.RegisterLegacyAminoCodec(cdc) - cryptocodec.RegisterCrypto(cdc) - authtypes.RegisterLegacyAminoCodec(cdc) - cdc.RegisterConcrete(testdata.TestMsg{}, "cosmos-sdk/Test", nil) - return cdc -} diff --git a/x/auth/migrations/legacytx/amino_signing_test.go b/x/auth/migrations/legacytx/amino_signing_test.go deleted file mode 100644 index 98afa6aab454..000000000000 --- a/x/auth/migrations/legacytx/amino_signing_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package legacytx - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/signing" -) - -func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { - priv1 := secp256k1.GenPrivKey() - addr1 := sdk.AccAddress(priv1.PubKey().Address()) - priv2 := secp256k1.GenPrivKey() - addr2 := sdk.AccAddress(priv2.PubKey().Address()) - - coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} - - fee := StdFee{ - Amount: coins, - Gas: 10000, - } - memo := "foo" - msgs := []sdk.Msg{ - testdata.NewTestMsg(addr1, addr2), - } - - var ( - chainID = "test-chain" - accNum uint64 = 7 - seqNum uint64 = 7 - timeoutHeight uint64 = 10 - ) - - tx := StdTx{ - Msgs: msgs, - Fee: fee, - Signatures: nil, - Memo: memo, - TimeoutHeight: timeoutHeight, - } - - handler := stdTxSignModeHandler{} - signingData := signing.SignerData{ - Address: addr1.String(), - ChainID: chainID, - AccountNumber: accNum, - Sequence: seqNum, - PubKey: priv1.PubKey(), - } - signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx) - require.NoError(t, err) - - expectedSignBz := StdSignBytes(chainID, accNum, seqNum, timeoutHeight, fee, msgs, memo, nil) - - require.Equal(t, expectedSignBz, signBz) - - // expect error with wrong sign mode - _, err = handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx) - require.Error(t, err) -} - -func TestLegacyAminoJSONHandler_DefaultMode(t *testing.T) { - handler := stdTxSignModeHandler{} - require.Equal(t, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, handler.DefaultMode()) -} - -func TestLegacyAminoJSONHandler_Modes(t *testing.T) { - handler := stdTxSignModeHandler{} - require.Equal(t, []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON}, handler.Modes()) -} diff --git a/x/auth/migrations/legacytx/config_test.go b/x/auth/migrations/legacytx/config_test.go deleted file mode 100644 index 7704396c9a69..000000000000 --- a/x/auth/migrations/legacytx/config_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package legacytx_test - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/cosmos/cosmos-sdk/codec" - cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - txtestutil "github.com/cosmos/cosmos-sdk/x/auth/tx/testutil" -) - -func testCodec() *codec.LegacyAmino { - cdc := codec.NewLegacyAmino() - sdk.RegisterLegacyAminoCodec(cdc) - cryptoAmino.RegisterCrypto(cdc) - cdc.RegisterConcrete(&testdata.TestMsg{}, "cosmos-sdk/Test", nil) - return cdc -} - -func TestStdTxConfig(t *testing.T) { - cdc := testCodec() - txGen := legacytx.StdTxConfig{Cdc: cdc} - suite.Run(t, txtestutil.NewTxConfigTestSuite(txGen)) -} diff --git a/x/auth/signing/handler_map_test.go b/x/auth/signing/handler_map_test.go deleted file mode 100644 index 2e374019c26f..000000000000 --- a/x/auth/signing/handler_map_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package signing_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -func MakeTestHandlerMap() signing.SignModeHandler { - return signing.NewSignModeHandlerMap( - signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - []signing.SignModeHandler{ - legacytx.NewStdTxSignModeHandler(), - }, - ) -} - -func TestHandlerMap_GetSignBytes(t *testing.T) { - priv1 := secp256k1.GenPrivKey() - addr1 := sdk.AccAddress(priv1.PubKey().Address()) - priv2 := secp256k1.GenPrivKey() - addr2 := sdk.AccAddress(priv2.PubKey().Address()) - - coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} - - fee := legacytx.StdFee{ - Amount: coins, - Gas: 10000, - } - memo := "foo" - msgs := []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: addr1.String(), - ToAddress: addr2.String(), - Amount: coins, - }, - } - - tx := legacytx.StdTx{ - Msgs: msgs, - Fee: fee, - Signatures: nil, - Memo: memo, - } - - var ( - chainID = "test-chain" - accNum uint64 = 7 - seqNum uint64 = 7 - ) - - handler := MakeTestHandlerMap() - aminoJSONHandler := legacytx.NewStdTxSignModeHandler() - - signingData := signing.SignerData{ - Address: addr1.String(), - ChainID: chainID, - AccountNumber: accNum, - Sequence: seqNum, - PubKey: priv1.PubKey(), - } - signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx) - require.NoError(t, err) - - expectedSignBz, err := aminoJSONHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx) - require.NoError(t, err) - - require.Equal(t, expectedSignBz, signBz) - - // expect error with wrong sign mode - _, err = aminoJSONHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx) - require.Error(t, err) -} - -func TestHandlerMap_DefaultMode(t *testing.T) { - handler := MakeTestHandlerMap() - require.Equal(t, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, handler.DefaultMode()) -} - -func TestHandlerMap_Modes(t *testing.T) { - handler := MakeTestHandlerMap() - modes := handler.Modes() - require.Contains(t, modes, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) - require.Len(t, modes, 1) -} diff --git a/x/auth/signing/verify_test.go b/x/auth/signing/verify_test.go deleted file mode 100644 index 2d523fe83713..000000000000 --- a/x/auth/signing/verify_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package signing_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - storetypes "cosmossdk.io/store/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - - kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/crypto/types/multisig" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -func TestVerifySignature(t *testing.T) { - priv, pubKey, addr := testdata.KeyTestPubAddr() - priv1, pubKey1, addr1 := testdata.KeyTestPubAddr() - - const ( - memo = "testmemo" - chainID = "test-chain" - ) - - encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) - key := storetypes.NewKVStoreKey(types.StoreKey) - - maccPerms := map[string][]string{ - "fee_collector": nil, - "mint": {"minter"}, - "bonded_tokens_pool": {"burner", "staking"}, - "not_bonded_tokens_pool": {"burner", "staking"}, - "multiPerm": {"burner", "minter", "staking"}, - "random": {"random"}, - } - - accountKeeper := keeper.NewAccountKeeper( - encCfg.Codec, - key, - types.ProtoBaseAccount, - maccPerms, - "cosmos", - types.NewModuleAddress("gov").String(), - ) - - testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{}) - encCfg.Amino.RegisterConcrete(testdata.TestMsg{}, "cosmos-sdk/Test", nil) - - acc1 := accountKeeper.NewAccountWithAddress(ctx, addr) - _ = accountKeeper.NewAccountWithAddress(ctx, addr1) - accountKeeper.SetAccount(ctx, acc1) - acc, err := ante.GetSignerAcc(ctx, accountKeeper, addr) - require.NoError(t, err) - - msgs := []sdk.Msg{testdata.NewTestMsg(addr)} - fee := legacytx.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)}) //nolint:staticcheck // SA1019: legacytx.StdFee is deprecated: use StdFeeV2 - signerData := signing.SignerData{ - Address: addr.String(), - ChainID: chainID, - AccountNumber: acc.GetAccountNumber(), - Sequence: acc.GetSequence(), - PubKey: pubKey, - } - signBytes := legacytx.StdSignBytes(signerData.ChainID, signerData.AccountNumber, signerData.Sequence, 10, fee, msgs, memo, nil) - signature, err := priv.Sign(signBytes) - require.NoError(t, err) - - stdSig := legacytx.StdSignature{PubKey: pubKey, Signature: signature} //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - sigV2, err := legacytx.StdSignatureToSignatureV2(encCfg.Amino, stdSig) - require.NoError(t, err) - - handler := MakeTestHandlerMap() - stdTx := legacytx.NewStdTx(msgs, fee, []legacytx.StdSignature{stdSig}, memo) //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - stdTx.TimeoutHeight = 10 - err = signing.VerifySignature(nil, pubKey, signerData, sigV2.Data, handler, stdTx) //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - require.NoError(t, err) - - pkSet := []cryptotypes.PubKey{pubKey, pubKey1} - multisigKey := kmultisig.NewLegacyAminoPubKey(2, pkSet) - multisignature := multisig.NewMultisig(2) - msgs = []sdk.Msg{testdata.NewTestMsg(addr, addr1)} - multiSignBytes := legacytx.StdSignBytes(signerData.ChainID, signerData.AccountNumber, signerData.Sequence, 10, fee, msgs, memo, nil) - - sig1, err := priv.Sign(multiSignBytes) - require.NoError(t, err) - stdSig1 := legacytx.StdSignature{PubKey: pubKey, Signature: sig1} //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - sig1V2, err := legacytx.StdSignatureToSignatureV2(encCfg.Amino, stdSig1) - require.NoError(t, err) - - sig2, err := priv1.Sign(multiSignBytes) - require.NoError(t, err) - stdSig2 := legacytx.StdSignature{PubKey: pubKey, Signature: sig2} //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - sig2V2, err := legacytx.StdSignatureToSignatureV2(encCfg.Amino, stdSig2) - require.NoError(t, err) - - err = multisig.AddSignatureFromPubKey(multisignature, sig1V2.Data, pkSet[0], pkSet) - require.NoError(t, err) - err = multisig.AddSignatureFromPubKey(multisignature, sig2V2.Data, pkSet[1], pkSet) - require.NoError(t, err) - - stdTx = legacytx.NewStdTx(msgs, fee, []legacytx.StdSignature{stdSig1, stdSig2}, memo) //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - stdTx.TimeoutHeight = 10 - - err = signing.VerifySignature(nil, multisigKey, signerData, multisignature, handler, stdTx) //nolint:staticcheck // SA1019: legacytx.StdSignature is deprecated: use SignatureV2 - require.NoError(t, err) -} diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 804dfad6fbf7..22309639656e 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -4,10 +4,8 @@ import ( "fmt" "testing" - "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" From 46d95809c3fd4a6256ef54c5c78d9d9a555df840 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 13:54:21 -0500 Subject: [PATCH 10/83] interface registry serves proto files --- client/grpc_query.go | 37 +------------------------------ client/internal_client_test.go | 31 -------------------------- codec/types/interface_registry.go | 22 ++++++++++++++++++ types/module/testutil/codec.go | 2 +- x/auth/tx/config.go | 3 +++ x/gov/keeper/keeper.go | 5 ++++- x/gov/module.go | 2 +- x/group/keeper/keeper.go | 6 ++++- x/group/module/module.go | 2 +- 9 files changed, 38 insertions(+), 72 deletions(-) delete mode 100644 client/internal_client_test.go diff --git a/client/grpc_query.go b/client/grpc_query.go index 534211518367..b79e2a1f6845 100644 --- a/client/grpc_query.go +++ b/client/grpc_query.go @@ -7,7 +7,6 @@ import ( "reflect" "strconv" - proto "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" "github.com/cosmos/cosmos-sdk/codec" @@ -29,7 +28,7 @@ var _ gogogrpc.ClientConn = Context{} // fallBackCodec is used by Context in case Codec is not set. // it can process every gRPC type, except the ones which contain // interfaces in their types. -var fallBackCodec = codec.NewProtoCodec(failingInterfaceRegistry{}) +var fallBackCodec = codec.NewProtoCodec(types.NewInterfaceRegistry()) // Invoke implements the grpc ClientConn.Invoke method func (ctx Context) Invoke(grpcCtx gocontext.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { @@ -144,40 +143,6 @@ func (ctx Context) gRPCCodec() encoding.Codec { return pc.GRPCCodec() } -var _ types.InterfaceRegistry = failingInterfaceRegistry{} - -// failingInterfaceRegistry is used by the fallback codec -// in case Context's Codec is not set. -type failingInterfaceRegistry struct{} - // errCodecNotSet is return by failingInterfaceRegistry in case there are attempt to decode // or encode a type which contains an interface field. var errCodecNotSet = errors.New("client: cannot encode or decode type which requires the application specific codec") - -func (f failingInterfaceRegistry) UnpackAny(any *types.Any, iface interface{}) error { - return errCodecNotSet -} - -func (f failingInterfaceRegistry) Resolve(typeURL string) (proto.Message, error) { - return nil, errCodecNotSet -} - -func (f failingInterfaceRegistry) RegisterInterface(protoName string, iface interface{}, impls ...proto.Message) { - panic("cannot be called") -} - -func (f failingInterfaceRegistry) RegisterImplementations(iface interface{}, impls ...proto.Message) { - panic("cannot be called") -} - -func (f failingInterfaceRegistry) ListAllInterfaces() []string { - panic("cannot be called") -} - -func (f failingInterfaceRegistry) ListImplementations(ifaceTypeURL string) []string { - panic("cannot be called") -} - -func (f failingInterfaceRegistry) EnsureRegistered(iface interface{}) error { - panic("cannot be called") -} diff --git a/client/internal_client_test.go b/client/internal_client_test.go deleted file mode 100644 index 6d6cacb87f82..000000000000 --- a/client/internal_client_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package client - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestFailingInterfaceRegistry(t *testing.T) { - reg := failingInterfaceRegistry{} - - require.Error(t, reg.UnpackAny(nil, nil)) - _, err := reg.Resolve("") - require.Error(t, err) - - require.Panics(t, func() { - reg.RegisterInterface("", nil) - }) - require.Panics(t, func() { - reg.RegisterImplementations(nil, nil) - }) - require.Panics(t, func() { - reg.ListAllInterfaces() - }) - require.Panics(t, func() { - reg.ListImplementations("") - }) - require.Panics(t, func() { - reg.EnsureRegistered(nil) - }) -} diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index b911cb6bf6e9..e6324ec06802 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protoregistry" ) // AnyUnpacker is an interface which allows safely unpacking types packed @@ -54,6 +55,10 @@ type InterfaceRegistry interface { // EnsureRegistered ensures there is a registered interface for the given concrete type. EnsureRegistered(iface interface{}) error + + ProtoFiles() *protoregistry.Files + + private() } // UnpackInterfacesMessage is meant to extend protobuf types (which implement @@ -85,17 +90,28 @@ type interfaceRegistry struct { interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type typeURLMap map[string]reflect.Type + protoFiles *protoregistry.Files } type interfaceMap = map[string]reflect.Type // NewInterfaceRegistry returns a new InterfaceRegistry func NewInterfaceRegistry() InterfaceRegistry { + protoFiles, err := proto.MergedRegistry() + if err != nil { + panic(err) + } + return NewInterfaceRegistryWithProtoFiles(protoFiles) +} + +// NewInterfaceRegistry returns a new InterfaceRegistry with the specified *protoregistry.Files instance. +func NewInterfaceRegistryWithProtoFiles(files *protoregistry.Files) InterfaceRegistry { return &interfaceRegistry{ interfaceNames: map[string]reflect.Type{}, interfaceImpls: map[reflect.Type]interfaceMap{}, implInterfaces: map[reflect.Type]reflect.Type{}, typeURLMap: map[string]reflect.Type{}, + protoFiles: files, } } @@ -288,6 +304,12 @@ func (registry *interfaceRegistry) Resolve(typeURL string) (proto.Message, error return msg, nil } +func (registry *interfaceRegistry) ProtoFiles() *protoregistry.Files { + return registry.protoFiles +} + +func (registry *interfaceRegistry) private() {} + // UnpackInterfaces is a convenience function that calls UnpackInterfaces // on x if x implements UnpackInterfacesMessage func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error { diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index b54085c584e7..457f325e9693 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -15,7 +15,7 @@ import ( // dependencies. type TestEncodingConfig struct { InterfaceRegistry types.InterfaceRegistry - Codec codec.Codec + Codec codec.ProtoCodecMarshaler TxConfig client.TxConfig Amino *codec.LegacyAmino } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index a365eafcea77..48d5325704b7 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -55,6 +55,9 @@ func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signin jsonDecoder: DefaultJSONTxDecoder(protoCodec), jsonEncoder: DefaultJSONTxEncoder(protoCodec), protoCodec: protoCodec, + getSignersCtx: signing2.NewGetSignersContext( + signing2.GetSignersOptions{ProtoFiles: protoCodec.InterfaceRegistry().ProtoFiles()}, + ), } } diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 8ad41a4fa470..ac856fd5bc88 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -62,7 +62,7 @@ func (k Keeper) GetAuthority() string { // // CONTRACT: the parameter Subspace must have the param key table already initialized func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, authKeeper types.AccountKeeper, + cdc codec.ProtoCodecMarshaler, key storetypes.StoreKey, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, distrkeeper types.DistributionKeeper, router baseapp.MessageRouter, config types.Config, authority string, ) *Keeper { @@ -90,6 +90,9 @@ func NewKeeper( router: router, config: config, authority: authority, + getSignersCtx: signing2.NewGetSignersContext(signing2.GetSignersOptions{ + ProtoFiles: cdc.InterfaceRegistry().ProtoFiles(), + }), } } diff --git a/x/gov/module.go b/x/gov/module.go index c06da9eeb170..2b441a8d2bd4 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -166,7 +166,7 @@ type GovInputs struct { depinject.In Config *modulev1.Module - Cdc codec.Codec + Cdc codec.ProtoCodecMarshaler Key *store.KVStoreKey ModuleKey depinject.OwnModuleKey MsgServiceRouter baseapp.MessageRouter diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 6460454c96d0..3bf4ca835b8d 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -85,7 +85,7 @@ type Keeper struct { } // NewKeeper creates a new group keeper. -func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.MessageRouter, accKeeper group.AccountKeeper, config group.Config) Keeper { +func NewKeeper(storeKey storetypes.StoreKey, cdc codec.ProtoCodecMarshaler, router baseapp.MessageRouter, accKeeper group.AccountKeeper, config group.Config) Keeper { k := Keeper{ key: storeKey, router: router, @@ -214,6 +214,10 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes } k.config = config + k.getSignersCtx = signing2.NewGetSignersContext(signing2.GetSignersOptions{ + ProtoFiles: cdc.InterfaceRegistry().ProtoFiles(), + }) + return k } diff --git a/x/group/module/module.go b/x/group/module/module.go index ba35298ade70..9ceec08e4b1a 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -203,7 +203,7 @@ type GroupInputs struct { Config *modulev1.Module Key *store.KVStoreKey - Cdc codec.Codec + Cdc codec.ProtoCodecMarshaler AccountKeeper group.AccountKeeper BankKeeper group.BankKeeper Registry cdctypes.InterfaceRegistry From ec48afd8054fb4879dd2d3f259a8fdb875bff356 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 15:13:16 -0500 Subject: [PATCH 11/83] WIP on moving to codec --- codec/amino_codec.go | 8 ++++++++ codec/codec.go | 4 ++++ codec/proto_codec.go | 14 ++++++++++---- types/module/testutil/codec.go | 3 ++- types/tx/types.go | 11 ++++------- types/tx_msg.go | 27 +++++++++++++++++++++++++++ x/auth/tx/builder.go | 12 ++++-------- x/auth/tx/config.go | 11 +++++------ x/auth/tx/config/config.go | 10 +++++----- x/authz/simulation/operations.go | 12 ++++++------ x/group/simulation/operations.go | 28 ++++++++++++++-------------- x/slashing/simulation/operations.go | 4 ++-- 12 files changed, 91 insertions(+), 53 deletions(-) diff --git a/codec/amino_codec.go b/codec/amino_codec.go index d77acbc7e8e0..8f9c54786128 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -1,6 +1,8 @@ package codec import ( + "fmt" + "github.com/cosmos/gogoproto/proto" ) @@ -124,3 +126,9 @@ func (ac *AminoCodec) MarshalInterfaceJSON(i proto.Message) ([]byte, error) { func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } + +func (ac *AminoCodec) GetMsgSigners(msg interface{}) ([]string, error) { + return nil, fmt.Errorf("amino codec does not support getting msg signers") +} + +func (ac *AminoCodec) private() {} diff --git a/codec/codec.go b/codec/codec.go index 5fe0e98e89f3..bf9b77581afa 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -54,6 +54,8 @@ type ( UnmarshalInterface(bz []byte, ptr interface{}) error types.AnyUnpacker + + private() } JSONCodec interface { @@ -74,6 +76,8 @@ type ( UnmarshalJSON(bz []byte, ptr proto.Message) error // MustUnmarshalJSON calls Unmarshal and panics if error is returned. MustUnmarshalJSON(bz []byte, ptr proto.Message) + + private() } // ProtoMarshaler defines an interface a type must implement to serialize itself diff --git a/codec/proto_codec.go b/codec/proto_codec.go index ed71b8f897a3..d84ead9f2ac5 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -6,12 +6,12 @@ import ( "fmt" "strings" - "google.golang.org/grpc/encoding" - "google.golang.org/protobuf/proto" - "github.com/cosmos/gogoproto/jsonpb" gogoproto "github.com/cosmos/gogoproto/proto" + "google.golang.org/grpc/encoding" + "google.golang.org/protobuf/proto" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -26,6 +26,7 @@ type ProtoCodecMarshaler interface { // encoding. type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry + getSignersCtx *signing.GetSignersContext } var ( @@ -35,7 +36,10 @@ var ( // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - return &ProtoCodec{interfaceRegistry: interfaceRegistry} + return &ProtoCodec{ + interfaceRegistry: interfaceRegistry, + getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry.ProtoFiles()}), + } } // Marshal implements BinaryMarshaler.Marshal method. @@ -270,6 +274,8 @@ func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} } +func (pc *ProtoCodec) private() {} + var errUnknownProtoType = errors.New("codec: unknown proto type") // sentinel error // grpcProtoCodec is the implementation of the gRPC proto codec. diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 457f325e9693..30ebe7abfbc2 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth/tx" ) @@ -23,7 +24,7 @@ type TestEncodingConfig struct { func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { cdc := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() - codec := codec.NewProtoCodec(interfaceRegistry) + codec := sdk.NewMsgCodec(codec.NewProtoCodec(interfaceRegistry)) encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, diff --git a/types/tx/types.go b/types/tx/types.go index 42eab60367b7..4ada446be993 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -1,8 +1,6 @@ package tx import ( - "cosmossdk.io/x/tx/signing" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -33,12 +31,12 @@ func (t *Tx) GetMsgs() []sdk.Msg { // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). -func (t *Tx) GetSigners(ctx *signing.GetSignersContext) []string { +func (t *Tx) GetSigners(codec sdk.MsgCodec) []string { var signers []string seen := map[string]bool{} for _, msg := range t.GetMsgs() { - signers, err := sdk.GetSigners(msg, ctx) + signers, err := codec.GetMsgSigners(msg) if err != nil { panic(err) } @@ -70,13 +68,13 @@ func (t *Tx) GetFee() sdk.Coins { return t.AuthInfo.Fee.Amount } -func (t *Tx) FeePayer(ctx *signing.GetSignersContext) string { +func (t *Tx) FeePayer(codec sdk.MsgCodec) string { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { return feePayer } // use first signer as default if no payer specified - return t.GetSigners(ctx)[0] + return t.GetSigners(codec)[0] } func (t *Tx) FeeGranter() sdk.AccAddress { @@ -142,7 +140,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil)) - registry.RegisterImplementations((*sdk.Tx)(nil), &Tx{}) registry.RegisterInterface("cosmos.tx.v1beta1.TxExtensionOptionI", (*ExtensionOptionI)(nil)) } diff --git a/types/tx_msg.go b/types/tx_msg.go index 7d92642dd6f8..754f15165a4c 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -10,6 +10,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -154,3 +155,29 @@ func GetSigners(msg Msg, getSignersCtx *signing.GetSignersContext) ([]string, er }) } } + +type MsgCodec interface { + codec.ProtoCodecMarshaler + + GetMsgSigners(Msg) ([]string, error) + + private() +} + +type msgCodec struct { + codec.ProtoCodecMarshaler + getSignersCtx *signing.GetSignersContext +} + +func (m msgCodec) GetMsgSigners(msg Msg) ([]string, error) { + return GetSigners(msg, m.getSignersCtx) +} + +func (m msgCodec) private() {} + +func NewMsgCodec(ir types.InterfaceRegistry) MsgCodec { + return &msgCodec{ + ProtoCodecMarshaler: codec.NewProtoCodec(ir), + getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: ir.ProtoFiles()}), + } +} diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index cd2a54dd59eb..ad1284d24db3 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -7,9 +7,7 @@ import ( errorsmod "cosmossdk.io/errors" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,8 +21,7 @@ import ( // wrapper is a wrapper around the tx.Tx proto.Message which retain the raw // body and auth_info bytes. type wrapper struct { - cdc codec.Codec - getSignersCtx *signing2.GetSignersContext + cdc sdk.MsgCodec tx *tx.Tx @@ -58,10 +55,9 @@ type ExtensionOptionsTxBuilder interface { SetNonCriticalExtensionOptions(...*codectypes.Any) } -func newBuilder(cdc codec.Codec, getSignersCtx *signing2.GetSignersContext) *wrapper { +func newBuilder(cdc sdk.MsgCodec) *wrapper { return &wrapper{ - getSignersCtx: getSignersCtx, - cdc: cdc, + cdc: cdc, tx: &tx.Tx{ Body: &tx.TxBody{}, AuthInfo: &tx.AuthInfo{ @@ -174,7 +170,7 @@ func (w *wrapper) getAuthInfoBytes() []byte { func (w *wrapper) GetSigners() []sdk.AccAddress { if w.signers == nil { - signers := w.tx.GetSigners(w.getSignersCtx) + signers := w.tx.GetSigners(w.cdc) for _, signer := range signers { signerBz := sdk.MustAccAddressFromBech32(signer) w.signers = append(w.signers, signerBz) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 48d5325704b7..3a39af59b3e9 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -19,7 +18,7 @@ type config struct { encoder sdk.TxEncoder jsonDecoder sdk.TxDecoder jsonEncoder sdk.TxEncoder - protoCodec codec.ProtoCodecMarshaler + protoCodec sdk.MsgCodec getSignersCtx *signing2.GetSignersContext } @@ -29,7 +28,7 @@ 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 // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). -func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfig(protoCodec sdk.MsgCodec, enabledSignModes []signingtypes.SignMode, customSignModes ...signing.SignModeHandler) client.TxConfig { for _, m := range enabledSignModes { if m == signingtypes.SignMode_SIGN_MODE_TEXTUAL { panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") @@ -42,12 +41,12 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin // NewTxConfigWithTextual is like NewTxConfig with the ability to add // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. -func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, textual *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfigWithTextual(protoCodec sdk.MsgCodec, enabledSignModes []signingtypes.SignMode, textual *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) client.TxConfig { return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, textual, customSignModes...)) } // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. -func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler) client.TxConfig { +func NewTxConfigWithHandler(protoCodec sdk.MsgCodec, handler signing.SignModeHandler) client.TxConfig { return &config{ handler: handler, decoder: DefaultTxDecoder(protoCodec), @@ -62,7 +61,7 @@ func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signin } func (g config) NewTxBuilder() client.TxBuilder { - return newBuilder(g.protoCodec, g.getSignersCtx) + return newBuilder(g.protoCodec) } // WrapTxBuilder returns a builder from provided transaction diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index cbb55b92c9f6..0df4127f0d3f 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -6,9 +6,9 @@ import ( txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -28,8 +28,8 @@ func init() { type TxInputs struct { depinject.In - Config *txconfigv1.Config - ProtoCodecMarshaler codec.ProtoCodecMarshaler + Config *txconfigv1.Config + Codec sdk.MsgCodec AccountKeeper ante.AccountKeeper `optional:"true"` // BankKeeper is the expected bank keeper to be passed to AnteHandlers @@ -53,9 +53,9 @@ func ProvideModule(in TxInputs) TxOutputs { textual := NewTextualWithBankKeeper(in.TxBankKeeper) var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual) + txConfig = tx.NewTxConfigWithTextual(in.Codec, tx.DefaultSignModes, textual) } else { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual, in.CustomSignModeHandlers()...) + txConfig = tx.NewTxConfigWithTextual(in.Codec, tx.DefaultSignModes, textual, in.CustomSignModeHandlers()...) } baseAppOption := func(app *baseapp.BaseApp) { diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 33fe08dea025..e5155090c66f 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -75,21 +75,21 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgGrant, - SimulateMsgGrant(codec.NewProtoCodec(registry), ak, bk, k), + SimulateMsgGrant(sdk.NewMsgCodec(registry), ak, bk, k), ), simulation.NewWeightedOperation( weightExec, - SimulateMsgExec(codec.NewProtoCodec(registry), ak, bk, k, registry), + SimulateMsgExec(sdk.NewMsgCodec(registry), ak, bk, k, registry), ), simulation.NewWeightedOperation( weightRevoke, - SimulateMsgRevoke(codec.NewProtoCodec(registry), ak, bk, k), + SimulateMsgRevoke(sdk.NewMsgCodec(registry), ak, bk, k), ), } } // SimulateMsgGrant generates a MsgGrant with random values. -func SimulateMsgGrant(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper) simtypes.Operation { +func SimulateMsgGrant(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -157,7 +157,7 @@ func generateRandomAuthorization(r *rand.Rand, spendLimit sdk.Coins) authz.Autho } // SimulateMsgRevoke generates a MsgRevoke with random values. -func SimulateMsgRevoke(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgRevoke(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -221,7 +221,7 @@ func SimulateMsgRevoke(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.B } // SimulateMsgExec generates a MsgExec with random values. -func SimulateMsgExec(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, unpacker cdctypes.AnyUnpacker) simtypes.Operation { +func SimulateMsgExec(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, unpacker cdctypes.AnyUnpacker) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index 9b19fd692f46..cc5395bfe2c0 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -244,7 +244,7 @@ func WeightedOperations( } // SimulateMsgCreateGroup generates a MsgCreateGroup with random values -func SimulateMsgCreateGroup(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgCreateGroup(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -287,7 +287,7 @@ func SimulateMsgCreateGroup(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk gr } // SimulateMsgCreateGroupWithPolicy generates a MsgCreateGroupWithPolicy with random values -func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgCreateGroupWithPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -347,7 +347,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKee } // SimulateMsgCreateGroupPolicy generates a NewMsgCreateGroupPolicy with random values -func SimulateMsgCreateGroupPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCreateGroupPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -408,7 +408,7 @@ func SimulateMsgCreateGroupPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, } // SimulateMsgSubmitProposal generates a NewMsgSubmitProposal with random values -func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgSubmitProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -484,7 +484,7 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk } // SimulateMsgUpdateGroupAdmin generates a MsgUpdateGroupAdmin with random values -func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -544,7 +544,7 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, } // SimulateMsgUpdateGroupMetadata generates a MsgUpdateGroupMetadata with random values -func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupMetadata(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -595,7 +595,7 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe } // SimulateMsgUpdateGroupMembers generates a MsgUpdateGroupMembers with random values -func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupMembers(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -675,7 +675,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper } // SimulateMsgUpdateGroupPolicyAdmin generates a MsgUpdateGroupPolicyAdmin with random values -func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupPolicyAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -735,7 +735,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe } // // SimulateMsgUpdateGroupPolicyDecisionPolicy generates a NewMsgUpdateGroupPolicyDecisionPolicy with random values -func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -796,7 +796,7 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc *codec.ProtoCodec, ak group. } // // SimulateMsgUpdateGroupPolicyMetadata generates a MsgUpdateGroupPolicyMetadata with random values -func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupPolicyMetadata(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -849,7 +849,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun } // SimulateMsgWithdrawProposal generates a MsgWithdrawProposal with random values -func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgWithdrawProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -954,7 +954,7 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, } // SimulateMsgVote generates a MsgVote with random values -func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgVote(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -1059,7 +1059,7 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, } // // SimulateMsgExec generates a MsgExec with random values -func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, +func SimulateMsgExec(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -1136,7 +1136,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, } // SimulateMsgLeaveGroup generates a MsgLeaveGroup with random values -func SimulateMsgLeaveGroup(cdc *codec.ProtoCodec, k keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgLeaveGroup(cdc sdk.MsgCodec, k keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 41649e2793d1..9ed3aa59681f 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -41,13 +41,13 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgUnjail, - SimulateMsgUnjail(codec.NewProtoCodec(interfaceRegistry), ak, bk, k, sk), + SimulateMsgUnjail(sdk.NewMsgCodec(interfaceRegistry), ak, bk, k, sk), ), } } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { +func SimulateMsgUnjail(cdc sdk.MsgCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, From 43eab5f0e81210602dc0f532d49eb365c90cfb6d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 7 Mar 2023 15:55:14 -0500 Subject: [PATCH 12/83] refactor to codec-based API --- baseapp/baseapp.go | 20 +++-------- baseapp/options.go | 2 ++ codec/amino_codec.go | 2 +- codec/codec.go | 2 ++ codec/proto_codec.go | 20 +++++++++++ types/module/testutil/codec.go | 5 ++- types/tx/types.go | 5 +-- types/tx_msg.go | 53 ----------------------------- x/auth/ante/ante.go | 15 +------- x/auth/tx/builder.go | 5 +-- x/auth/tx/builder_test.go | 8 ++--- x/auth/tx/config.go | 24 ++++++------- x/auth/tx/config/config.go | 9 ++--- x/auth/tx/encode_decode_test.go | 2 +- x/auth/tx/legacy_amino_json_test.go | 8 ++--- x/authz/keeper/keeper.go | 14 ++++---- x/authz/simulation/operations.go | 12 +++---- x/gov/keeper/keeper.go | 10 ++---- x/gov/keeper/proposal.go | 2 +- x/gov/module.go | 2 +- x/group/keeper/keeper.go | 10 ++---- x/group/keeper/msg_server.go | 2 +- x/group/keeper/proposal_executor.go | 8 ++--- x/group/module/module.go | 2 +- x/group/simulation/operations.go | 28 +++++++-------- x/slashing/simulation/operations.go | 4 +-- 26 files changed, 104 insertions(+), 170 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 6b17d18d20d8..f1c00aafdb10 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -20,7 +20,7 @@ import ( "cosmossdk.io/store/snapshots" storetypes "cosmossdk.io/store/types" - "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -147,7 +147,7 @@ type BaseApp struct { //nolint: maligned // and exposing the requests and responses to external consumers abciListeners []storetypes.ABCIListener - getSignersCtx *signing.GetSignersContext + cdc codec.Codec } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -192,16 +192,6 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() - mergedProtoRegistry, err := proto.MergedRegistry() - if err != nil { - panic(err) - } - app.getSignersCtx = signing.NewGetSignersContext( - signing.GetSignersOptions{ - ProtoFiles: mergedProtoRegistry, - }, - ) - return app } @@ -808,7 +798,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s } // create message events - msgEvents := createEvents(app.getSignersCtx, msgResult.GetEvents(), msg) + msgEvents := createEvents(app.cdc, msgResult.GetEvents(), msg) // append message events, data and logs // @@ -850,12 +840,12 @@ func makeABCIData(msgResponses []*codectypes.Any) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResponses}) } -func createEvents(getSignersCtx *signing.GetSignersContext, events sdk.Events, msg sdk.Msg) sdk.Events { +func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg) sdk.Events { eventMsgName := sdk.MsgTypeURL(msg) msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)) // we set the signer attribute as the sender - signers, err := sdk.GetSigners(msg, getSignersCtx) + signers, err := cdc.GetMsgSigners(msg) if err != nil { panic(err) } diff --git a/baseapp/options.go b/baseapp/options.go index 39398826f60e..b932ec00216f 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cast" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -239,6 +240,7 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { app.interfaceRegistry = registry app.grpcQueryRouter.SetInterfaceRegistry(registry) app.msgServiceRouter.SetInterfaceRegistry(registry) + app.cdc = codec.NewProtoCodec(registry) } // SetStreamingService is used to set a streaming service into the BaseApp hooks and load the listeners into the multistore diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 8f9c54786128..24216322087c 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -127,7 +127,7 @@ func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } -func (ac *AminoCodec) GetMsgSigners(msg interface{}) ([]string, error) { +func (ac *AminoCodec) GetMsgSigners(msg any) ([]string, error) { return nil, fmt.Errorf("amino codec does not support getting msg signers") } diff --git a/codec/codec.go b/codec/codec.go index bf9b77581afa..0c8894d93975 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -18,6 +18,8 @@ type ( Codec interface { BinaryCodec JSONCodec + + GetMsgSigners(msg any) ([]string, error) } BinaryCodec interface { diff --git a/codec/proto_codec.go b/codec/proto_codec.go index d84ead9f2ac5..84f46c231159 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -10,6 +10,8 @@ import ( gogoproto "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" "google.golang.org/protobuf/proto" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec/types" @@ -269,6 +271,24 @@ func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry { return pc.interfaceRegistry } +func (pc ProtoCodec) GetMsgSigners(msg any) ([]string, error) { + if msgv2, ok := msg.(protov2.Message); ok { + return pc.getSignersCtx.GetSigners(msgv2) + } else if msgv1, ok := msg.(proto.Message); ok { + bz, err := proto.Marshal(msgv1) + if err != nil { + return nil, err + } + + return pc.getSignersCtx.GetSignersForAny(&anypb.Any{ + TypeUrl: string("/" + proto.MessageName(msgv1)), + Value: bz, + }) + } else { + return nil, fmt.Errorf("%T is not a proto.Message", msg) + } +} + // GRPCCodec returns the gRPC Codec for this specific ProtoCodec func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 30ebe7abfbc2..b54085c584e7 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth/tx" ) @@ -16,7 +15,7 @@ import ( // dependencies. type TestEncodingConfig struct { InterfaceRegistry types.InterfaceRegistry - Codec codec.ProtoCodecMarshaler + Codec codec.Codec TxConfig client.TxConfig Amino *codec.LegacyAmino } @@ -24,7 +23,7 @@ type TestEncodingConfig struct { func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { cdc := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() - codec := sdk.NewMsgCodec(codec.NewProtoCodec(interfaceRegistry)) + codec := codec.NewProtoCodec(interfaceRegistry) encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, diff --git a/types/tx/types.go b/types/tx/types.go index 4ada446be993..544c0befa577 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -1,6 +1,7 @@ package tx import ( + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ func (t *Tx) GetMsgs() []sdk.Msg { // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). -func (t *Tx) GetSigners(codec sdk.MsgCodec) []string { +func (t *Tx) GetSigners(codec codec.Codec) []string { var signers []string seen := map[string]bool{} @@ -68,7 +69,7 @@ func (t *Tx) GetFee() sdk.Coins { return t.AuthInfo.Fee.Amount } -func (t *Tx) FeePayer(codec sdk.MsgCodec) string { +func (t *Tx) FeePayer(codec codec.Codec) string { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { return feePayer diff --git a/types/tx_msg.go b/types/tx_msg.go index 754f15165a4c..ad5187352de9 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -7,10 +7,6 @@ import ( "github.com/cosmos/gogoproto/proto" protov2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/anypb" - - "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -132,52 +128,3 @@ func GetModuleNameFromTypeURL(input string) string { return "" } - -func GetSigners(msg Msg, getSignersCtx *signing.GetSignersContext) ([]string, error) { - if legacyMsg, ok := msg.(LegacyMsg); ok { - var signers []string - for _, addr := range legacyMsg.GetSigners() { - signer := addr.String() - signers = append(signers, signer) - } - return signers, nil - } else if msgv2, ok := msg.(protov2.Message); ok { - return getSignersCtx.GetSigners(msgv2) - } else { - bz, err := proto.Marshal(msg) - if err != nil { - return nil, err - } - - return getSignersCtx.GetSignersForAny(&anypb.Any{ - TypeUrl: MsgTypeURL(msg), - Value: bz, - }) - } -} - -type MsgCodec interface { - codec.ProtoCodecMarshaler - - GetMsgSigners(Msg) ([]string, error) - - private() -} - -type msgCodec struct { - codec.ProtoCodecMarshaler - getSignersCtx *signing.GetSignersContext -} - -func (m msgCodec) GetMsgSigners(msg Msg) ([]string, error) { - return GetSigners(msg, m.getSignersCtx) -} - -func (m msgCodec) private() {} - -func NewMsgCodec(ir types.InterfaceRegistry) MsgCodec { - return &msgCodec{ - ProtoCodecMarshaler: codec.NewProtoCodec(ir), - getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: ir.ProtoFiles()}), - } -} diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 420e719c909c..4607ba63d1e9 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -1,11 +1,8 @@ package ante import ( - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/gogoproto/proto" - "google.golang.org/protobuf/reflect/protoregistry" - errorsmod "cosmossdk.io/errors" + storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -23,7 +20,6 @@ type HandlerOptions struct { SignModeHandler authsigning.SignModeHandler SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker - ProtoFiles *protoregistry.Files } // NewAnteHandler returns an AnteHandler that checks and increments sequence @@ -42,15 +38,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } - protoFiles := options.ProtoFiles - if protoFiles == nil { - var err error - protoFiles, err = proto.MergedRegistry() - if err != nil { - return nil, err - } - } - anteDecorators := []sdk.AnteDecorator{ NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first NewExtensionOptionsDecorator(options.ExtensionOptionChecker), diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index ad1284d24db3..550ea7cc6a86 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -8,6 +8,7 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,7 +22,7 @@ import ( // wrapper is a wrapper around the tx.Tx proto.Message which retain the raw // body and auth_info bytes. type wrapper struct { - cdc sdk.MsgCodec + cdc codec.Codec tx *tx.Tx @@ -55,7 +56,7 @@ type ExtensionOptionsTxBuilder interface { SetNonCriticalExtensionOptions(...*codectypes.Any) } -func newBuilder(cdc sdk.MsgCodec) *wrapper { +func newBuilder(cdc codec.Codec) *wrapper { return &wrapper{ cdc: cdc, tx: &tx.Tx{ diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 4f61a6f00290..6b4fac958682 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -21,7 +21,7 @@ func TestTxBuilder(t *testing.T) { _, pubkey, addr := testdata.KeyTestPubAddr() marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - txBuilder := newBuilder(nil, nil) + txBuilder := newBuilder(nil) memo := "sometestmemo" //nolint:goconst msgs := []sdk.Msg{testdata.NewTestMsg(addr)} @@ -138,7 +138,7 @@ func TestBuilderValidateBasic(t *testing.T) { // require to fail validation upon invalid fee badFeeAmount := testdata.NewTestFeeAmount() badFeeAmount[0].Amount = sdk.NewInt(-5) - txBuilder := newBuilder(nil, nil) + txBuilder := newBuilder(nil) var sig1, sig2 signing.SignatureV2 sig1 = signing.SignatureV2{ @@ -279,7 +279,7 @@ func TestBuilderFeePayer(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { // setup basic tx - txBuilder := newBuilder(nil, nil) + txBuilder := newBuilder(nil) err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) @@ -303,7 +303,7 @@ func TestBuilderFeeGranter(t *testing.T) { feeAmount := testdata.NewTestFeeAmount() msgs := []sdk.Msg{msg1} - txBuilder := newBuilder(nil, nil) + txBuilder := newBuilder(nil) err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 3a39af59b3e9..5cb00e96907d 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -3,23 +3,22 @@ package tx import ( "fmt" - signing2 "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) type config struct { - handler signing.SignModeHandler - decoder sdk.TxDecoder - encoder sdk.TxEncoder - jsonDecoder sdk.TxDecoder - jsonEncoder sdk.TxEncoder - protoCodec sdk.MsgCodec - getSignersCtx *signing2.GetSignersContext + handler signing.SignModeHandler + decoder sdk.TxDecoder + encoder sdk.TxEncoder + jsonDecoder sdk.TxDecoder + jsonEncoder sdk.TxEncoder + protoCodec codec.ProtoCodecMarshaler } // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The @@ -28,7 +27,7 @@ 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 // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). -func NewTxConfig(protoCodec sdk.MsgCodec, enabledSignModes []signingtypes.SignMode, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...signing.SignModeHandler) client.TxConfig { for _, m := range enabledSignModes { if m == signingtypes.SignMode_SIGN_MODE_TEXTUAL { panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") @@ -41,12 +40,12 @@ func NewTxConfig(protoCodec sdk.MsgCodec, enabledSignModes []signingtypes.SignMo // NewTxConfigWithTextual is like NewTxConfig with the ability to add // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. -func NewTxConfigWithTextual(protoCodec sdk.MsgCodec, enabledSignModes []signingtypes.SignMode, textual *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, textual *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) client.TxConfig { return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, textual, customSignModes...)) } // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. -func NewTxConfigWithHandler(protoCodec sdk.MsgCodec, handler signing.SignModeHandler) client.TxConfig { +func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler) client.TxConfig { return &config{ handler: handler, decoder: DefaultTxDecoder(protoCodec), @@ -54,9 +53,6 @@ func NewTxConfigWithHandler(protoCodec sdk.MsgCodec, handler signing.SignModeHan jsonDecoder: DefaultJSONTxDecoder(protoCodec), jsonEncoder: DefaultJSONTxEncoder(protoCodec), protoCodec: protoCodec, - getSignersCtx: signing2.NewGetSignersContext( - signing2.GetSignersOptions{ProtoFiles: protoCodec.InterfaceRegistry().ProtoFiles()}, - ), } } diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 0df4127f0d3f..0fe557df5a7f 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -28,8 +29,8 @@ func init() { type TxInputs struct { depinject.In - Config *txconfigv1.Config - Codec sdk.MsgCodec + Config *txconfigv1.Config + ProtoCodecMarshaler codec.ProtoCodecMarshaler AccountKeeper ante.AccountKeeper `optional:"true"` // BankKeeper is the expected bank keeper to be passed to AnteHandlers @@ -53,9 +54,9 @@ func ProvideModule(in TxInputs) TxOutputs { textual := NewTextualWithBankKeeper(in.TxBankKeeper) var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithTextual(in.Codec, tx.DefaultSignModes, textual) + txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual) } else { - txConfig = tx.NewTxConfigWithTextual(in.Codec, tx.DefaultSignModes, textual, in.CustomSignModeHandlers()...) + txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual, in.CustomSignModeHandlers()...) } baseAppOption := func(app *baseapp.BaseApp) { diff --git a/x/auth/tx/encode_decode_test.go b/x/auth/tx/encode_decode_test.go index 25540d78858b..f4297770959c 100644 --- a/x/auth/tx/encode_decode_test.go +++ b/x/auth/tx/encode_decode_test.go @@ -24,7 +24,7 @@ func TestDefaultTxDecoderError(t *testing.T) { encoder := DefaultTxEncoder() decoder := DefaultTxDecoder(cdc) - builder := newBuilder(nil, nil) + builder := newBuilder(nil) err := builder.SetMsgs(testdata.NewTestMsg()) require.NoError(t, err) diff --git a/x/auth/tx/legacy_amino_json_test.go b/x/auth/tx/legacy_amino_json_test.go index 4ab221bb555f..63afe9dd5d36 100644 --- a/x/auth/tx/legacy_amino_json_test.go +++ b/x/auth/tx/legacy_amino_json_test.go @@ -86,7 +86,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { for _, tc := range testcases { tc := tc t.Run(tc.name, func(t *testing.T) { - bldr := newBuilder(nil, nil) + bldr := newBuilder(nil) buildTx(t, bldr) tx := bldr.GetTx() tc.malleate(bldr) @@ -104,7 +104,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { }) } - bldr := newBuilder(nil, nil) + bldr := newBuilder(nil) buildTx(t, bldr) tx := bldr.GetTx() signingData := signing.SignerData{ @@ -120,7 +120,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { require.Error(t, err) // expect error with extension options - bldr = newBuilder(nil, nil) + bldr = newBuilder(nil) buildTx(t, bldr) any, err := cdctypes.NewAnyWithValue(testdata.NewTestMsg()) require.NoError(t, err) @@ -130,7 +130,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { require.Error(t, err) // expect error with non-critical extension options - bldr = newBuilder(nil, nil) + bldr = newBuilder(nil) buildTx(t, bldr) bldr.tx.Body.NonCriticalExtensionOptions = []*cdctypes.Any{any} tx = bldr.GetTx() diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 5fe11bf7d5fa..0c92c28f34fa 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -12,7 +12,6 @@ import ( errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" - "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -27,15 +26,14 @@ import ( const gasCostPerIteration = uint64(20) type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - router baseapp.MessageRouter - authKeeper authz.AccountKeeper - getSignersContext *signing.GetSignersContext + storeKey storetypes.StoreKey + cdc codec.Codec + router baseapp.MessageRouter + authKeeper authz.AccountKeeper } // NewKeeper constructs a message authorization Keeper -func NewKeeper(storeKey storetypes.StoreKey, cdc codec.BinaryCodec, router baseapp.MessageRouter, ak authz.AccountKeeper) Keeper { +func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.MessageRouter, ak authz.AccountKeeper) Keeper { return Keeper{ storeKey: storeKey, cdc: cdc, @@ -91,7 +89,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] now := ctx.BlockTime() for i, msg := range msgs { - signers, err := sdk.GetSigners(msg, k.getSignersContext) + signers, err := k.cdc.GetMsgSigners(msg) if err != nil { return nil, err } diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index e5155090c66f..33fe08dea025 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -75,21 +75,21 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgGrant, - SimulateMsgGrant(sdk.NewMsgCodec(registry), ak, bk, k), + SimulateMsgGrant(codec.NewProtoCodec(registry), ak, bk, k), ), simulation.NewWeightedOperation( weightExec, - SimulateMsgExec(sdk.NewMsgCodec(registry), ak, bk, k, registry), + SimulateMsgExec(codec.NewProtoCodec(registry), ak, bk, k, registry), ), simulation.NewWeightedOperation( weightRevoke, - SimulateMsgRevoke(sdk.NewMsgCodec(registry), ak, bk, k), + SimulateMsgRevoke(codec.NewProtoCodec(registry), ak, bk, k), ), } } // SimulateMsgGrant generates a MsgGrant with random values. -func SimulateMsgGrant(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper) simtypes.Operation { +func SimulateMsgGrant(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -157,7 +157,7 @@ func generateRandomAuthorization(r *rand.Rand, spendLimit sdk.Coins) authz.Autho } // SimulateMsgRevoke generates a MsgRevoke with random values. -func SimulateMsgRevoke(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgRevoke(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -221,7 +221,7 @@ func SimulateMsgRevoke(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKe } // SimulateMsgExec generates a MsgExec with random values. -func SimulateMsgExec(cdc sdk.MsgCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, unpacker cdctypes.AnyUnpacker) simtypes.Operation { +func SimulateMsgExec(cdc *codec.ProtoCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, unpacker cdctypes.AnyUnpacker) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index ac856fd5bc88..840e983fdcdd 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +31,7 @@ type Keeper struct { storeKey storetypes.StoreKey // The codec for binary encoding/decoding. - cdc codec.BinaryCodec + cdc codec.Codec // Legacy Proposal router legacyRouter v1beta1.Router @@ -45,8 +44,6 @@ type Keeper struct { // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string - - getSignersCtx *signing2.GetSignersContext } // GetAuthority returns the x/gov module's authority. @@ -62,7 +59,7 @@ func (k Keeper) GetAuthority() string { // // CONTRACT: the parameter Subspace must have the param key table already initialized func NewKeeper( - cdc codec.ProtoCodecMarshaler, key storetypes.StoreKey, authKeeper types.AccountKeeper, + cdc codec.Codec, key storetypes.StoreKey, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, distrkeeper types.DistributionKeeper, router baseapp.MessageRouter, config types.Config, authority string, ) *Keeper { @@ -90,9 +87,6 @@ func NewKeeper( router: router, config: config, authority: authority, - getSignersCtx: signing2.NewGetSignersContext(signing2.GetSignersOptions{ - ProtoFiles: cdc.InterfaceRegistry().ProtoFiles(), - }), } } diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 00745a0329eb..92aac7fa321a 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -46,7 +46,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) } - signers, err := sdk.GetSigners(msg, keeper.getSignersCtx) + signers, err := keeper.cdc.GetMsgSigners(msg) if err != nil { return v1.Proposal{}, err } diff --git a/x/gov/module.go b/x/gov/module.go index 2b441a8d2bd4..c06da9eeb170 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -166,7 +166,7 @@ type GovInputs struct { depinject.In Config *modulev1.Module - Cdc codec.ProtoCodecMarshaler + Cdc codec.Codec Key *store.KVStoreKey ModuleKey depinject.OwnModuleKey MsgServiceRouter baseapp.MessageRouter diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 3bf4ca835b8d..da99a80f5e13 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -9,7 +9,6 @@ import ( errorsmod "cosmossdk.io/errors" - signing2 "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -81,15 +80,16 @@ type Keeper struct { config group.Config - getSignersCtx *signing2.GetSignersContext + cdc codec.Codec } // NewKeeper creates a new group keeper. -func NewKeeper(storeKey storetypes.StoreKey, cdc codec.ProtoCodecMarshaler, router baseapp.MessageRouter, accKeeper group.AccountKeeper, config group.Config) Keeper { +func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.MessageRouter, accKeeper group.AccountKeeper, config group.Config) Keeper { k := Keeper{ key: storeKey, router: router, accKeeper: accKeeper, + cdc: cdc, } groupTable, err := orm.NewAutoUInt64Table([2]byte{GroupTablePrefix}, GroupTableSeqPrefix, &group.GroupInfo{}, cdc) @@ -214,10 +214,6 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.ProtoCodecMarshaler, rout } k.config = config - k.getSignersCtx = signing2.NewGetSignersContext(signing2.GetSignersOptions{ - ProtoFiles: cdc.InterfaceRegistry().ProtoFiles(), - }) - return k } diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 282b893fd013..b9ebd3e1325e 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -502,7 +502,7 @@ func (k Keeper) SubmitProposal(goCtx context.Context, req *group.MsgSubmitPropos } // Check that if the messages require signers, they are all equal to the given account address of group policy. - if err := ensureMsgAuthZ(msgs, groupPolicyAddr, k.getSignersCtx); err != nil { + if err := ensureMsgAuthZ(msgs, groupPolicyAddr, k.cdc); err != nil { return nil, err } diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index 9f58ad24f646..311f8e6f6dd9 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -5,8 +5,8 @@ import ( errorsmod "cosmossdk.io/errors" - "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group" @@ -38,7 +38,7 @@ func (s Keeper) doExecuteMsgs(ctx sdk.Context, router baseapp.MessageRouter, pro } results := make([]sdk.Result, len(msgs)) - if err := ensureMsgAuthZ(msgs, groupPolicyAcc, s.getSignersCtx); err != nil { + if err := ensureMsgAuthZ(msgs, groupPolicyAcc, s.cdc); err != nil { return nil, err } for i, msg := range msgs { @@ -62,13 +62,13 @@ func (s Keeper) doExecuteMsgs(ctx sdk.Context, router baseapp.MessageRouter, pro // ensureMsgAuthZ checks that if a message requires signers that all of them // are equal to the given account address of group policy. -func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, getSignersCtx *signing.GetSignersContext) error { +func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, cdc codec.Codec) error { for i := range msgs { // In practice, GetSigners() should return a non-empty array without // duplicates, so the code below is equivalent to: // `msgs[i].GetSigners()[0] == groupPolicyAcc` // but we prefer to loop through all GetSigners just to be sure. - signers, err := sdk.GetSigners(msgs[i], getSignersCtx) + signers, err := cdc.GetMsgSigners(msgs[i]) if err != nil { return err } diff --git a/x/group/module/module.go b/x/group/module/module.go index 9ceec08e4b1a..ba35298ade70 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -203,7 +203,7 @@ type GroupInputs struct { Config *modulev1.Module Key *store.KVStoreKey - Cdc codec.ProtoCodecMarshaler + Cdc codec.Codec AccountKeeper group.AccountKeeper BankKeeper group.BankKeeper Registry cdctypes.InterfaceRegistry diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index cc5395bfe2c0..9b19fd692f46 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -244,7 +244,7 @@ func WeightedOperations( } // SimulateMsgCreateGroup generates a MsgCreateGroup with random values -func SimulateMsgCreateGroup(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgCreateGroup(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -287,7 +287,7 @@ func SimulateMsgCreateGroup(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.B } // SimulateMsgCreateGroupWithPolicy generates a MsgCreateGroupWithPolicy with random values -func SimulateMsgCreateGroupWithPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -347,7 +347,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, } // SimulateMsgCreateGroupPolicy generates a NewMsgCreateGroupPolicy with random values -func SimulateMsgCreateGroupPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCreateGroupPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -408,7 +408,7 @@ func SimulateMsgCreateGroupPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, bk g } // SimulateMsgSubmitProposal generates a NewMsgSubmitProposal with random values -func SimulateMsgSubmitProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -484,7 +484,7 @@ func SimulateMsgSubmitProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, bk grou } // SimulateMsgUpdateGroupAdmin generates a MsgUpdateGroupAdmin with random values -func SimulateMsgUpdateGroupAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -544,7 +544,7 @@ func SimulateMsgUpdateGroupAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, bk gr } // SimulateMsgUpdateGroupMetadata generates a MsgUpdateGroupMetadata with random values -func SimulateMsgUpdateGroupMetadata(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -595,7 +595,7 @@ func SimulateMsgUpdateGroupMetadata(cdc sdk.MsgCodec, ak group.AccountKeeper, bk } // SimulateMsgUpdateGroupMembers generates a MsgUpdateGroupMembers with random values -func SimulateMsgUpdateGroupMembers(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -675,7 +675,7 @@ func SimulateMsgUpdateGroupMembers(cdc sdk.MsgCodec, ak group.AccountKeeper, } // SimulateMsgUpdateGroupPolicyAdmin generates a MsgUpdateGroupPolicyAdmin with random values -func SimulateMsgUpdateGroupPolicyAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -735,7 +735,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc sdk.MsgCodec, ak group.AccountKeeper, } // // SimulateMsgUpdateGroupPolicyDecisionPolicy generates a NewMsgUpdateGroupPolicyDecisionPolicy with random values -func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -796,7 +796,7 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc sdk.MsgCodec, ak group.Accou } // // SimulateMsgUpdateGroupPolicyMetadata generates a MsgUpdateGroupPolicyMetadata with random values -func SimulateMsgUpdateGroupPolicyMetadata(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -849,7 +849,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc sdk.MsgCodec, ak group.AccountKeep } // SimulateMsgWithdrawProposal generates a MsgWithdrawProposal with random values -func SimulateMsgWithdrawProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -954,7 +954,7 @@ func SimulateMsgWithdrawProposal(cdc sdk.MsgCodec, ak group.AccountKeeper, } // SimulateMsgVote generates a MsgVote with random values -func SimulateMsgVote(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -1059,7 +1059,7 @@ func SimulateMsgVote(cdc sdk.MsgCodec, ak group.AccountKeeper, } // // SimulateMsgExec generates a MsgExec with random values -func SimulateMsgExec(cdc sdk.MsgCodec, ak group.AccountKeeper, +func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper, ) simtypes.Operation { return func( @@ -1136,7 +1136,7 @@ func SimulateMsgExec(cdc sdk.MsgCodec, ak group.AccountKeeper, } // SimulateMsgLeaveGroup generates a MsgLeaveGroup with random values -func SimulateMsgLeaveGroup(cdc sdk.MsgCodec, k keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { +func SimulateMsgLeaveGroup(cdc *codec.ProtoCodec, k keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 9ed3aa59681f..41649e2793d1 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -41,13 +41,13 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgUnjail, - SimulateMsgUnjail(sdk.NewMsgCodec(interfaceRegistry), ak, bk, k, sk), + SimulateMsgUnjail(codec.NewProtoCodec(interfaceRegistry), ak, bk, k, sk), ), } } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(cdc sdk.MsgCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { +func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, From a63d8b53937756d57ed0846d3ec091136cb2700c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 13 Mar 2023 10:54:23 -0400 Subject: [PATCH 13/83] WIP update to anyutil --- baseapp/baseapp.go | 15 ++++++++--- codec/amino_codec.go | 4 ++- codec/codec.go | 4 ++- codec/proto_codec.go | 44 ++++++++++++++++++------------ codec/types/interface_registry.go | 13 +++++---- types/tx/types.go | 2 +- x/tx/signing/get_signers.go | 45 +++---------------------------- 7 files changed, 54 insertions(+), 73 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 80fd8578d76d..f154598015da 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/gogoproto/proto" "golang.org/x/exp/maps" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -144,6 +145,8 @@ type BaseApp struct { //nolint: maligned // abciListeners for hooking into the ABCI message processing of the BaseApp // and exposing the requests and responses to external consumers abciListeners []storetypes.ABCIListener + + cdc codec.Codec } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -796,7 +799,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s } // create message events - msgEvents := createEvents(msgResult.GetEvents(), msg) + msgEvents := createEvents(app.cdc, msgResult.GetEvents(), msg) // append message events, data and logs // @@ -838,13 +841,17 @@ func makeABCIData(msgResponses []*codectypes.Any) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResponses}) } -func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events { +func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg) sdk.Events { eventMsgName := sdk.MsgTypeURL(msg) msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)) // we set the signer attribute as the sender - if len(msg.GetSigners()) > 0 && !msg.GetSigners()[0].Empty() { - msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSigners()[0].String())) + signers, err := cdc.GetMsgSigners(msg) + if err != nil { + panic(err) + } + if len(signers) > 0 && signers[0] != "" { + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, signers[0])) } // verify that events have no module attribute set diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 24216322087c..076e883a5083 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/cosmos/gogoproto/proto" + + "github.com/cosmos/cosmos-sdk/codec/types" ) // AminoCodec defines a codec that utilizes Codec for both binary and JSON @@ -127,7 +129,7 @@ func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } -func (ac *AminoCodec) GetMsgSigners(msg any) ([]string, error) { +func (ac *AminoCodec) GetMsgSigners(*types.Any) ([]string, error) { return nil, fmt.Errorf("amino codec does not support getting msg signers") } diff --git a/codec/codec.go b/codec/codec.go index 0c8894d93975..3ccd9927a7f0 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -19,7 +19,9 @@ type ( BinaryCodec JSONCodec - GetMsgSigners(msg any) ([]string, error) + GetMsgSigners(msg *types.Any) ([]string, error) + + private() } BinaryCodec interface { diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 84f46c231159..00cb50a60c0f 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -6,14 +6,15 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-proto/anyutil" "github.com/cosmos/gogoproto/jsonpb" gogoproto "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" "google.golang.org/protobuf/proto" - protov2 "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -40,7 +41,7 @@ var ( func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { return &ProtoCodec{ interfaceRegistry: interfaceRegistry, - getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry.ProtoFiles()}), + getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry}), } } @@ -271,22 +272,31 @@ func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry { return pc.interfaceRegistry } -func (pc ProtoCodec) GetMsgSigners(msg any) ([]string, error) { - if msgv2, ok := msg.(protov2.Message); ok { - return pc.getSignersCtx.GetSigners(msgv2) - } else if msgv1, ok := msg.(proto.Message); ok { - bz, err := proto.Marshal(msgv1) - if err != nil { - return nil, err - } - - return pc.getSignersCtx.GetSignersForAny(&anypb.Any{ - TypeUrl: string("/" + proto.MessageName(msgv1)), - Value: bz, - }) - } else { - return nil, fmt.Errorf("%T is not a proto.Message", msg) +func (pc ProtoCodec) GetMsgSigners(msg *types.Any) ([]string, error) { + //if msgv2, ok := msg.(protov2.Message); ok { + // return pc.getSignersCtx.GetSigners(msgv2) + //} else if msgv1, ok := msg.(proto.Message); ok { + // bz, err := proto.Marshal(msgv1) + // if err != nil { + // return nil, err + // } + // + // return pc.getSignersCtx.GetSignersForAny(&anypb.Any{ + // TypeUrl: string("/" + proto.MessageName(msgv1)), + // Value: bz, + // }) + //} else { + // return nil, fmt.Errorf("%T is not a proto.Message", msg) + //} + msgv2, err := anyutil.Unpack(&anypb.Any{ + TypeUrl: msg.TypeUrl, + Value: msg.Value, + }, pc.interfaceRegistry, nil) + if err != nil { + return nil, err } + + return pc.getSignersCtx.GetSigners(msgv2) } // GRPCCodec returns the gRPC Codec for this specific ProtoCodec diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index e6324ec06802..7346972a3922 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -6,6 +6,8 @@ import ( "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" ) @@ -56,7 +58,8 @@ type InterfaceRegistry interface { // EnsureRegistered ensures there is a registered interface for the given concrete type. EnsureRegistered(iface interface{}) error - ProtoFiles() *protoregistry.Files + protodesc.Resolver + RangeFiles(f func(protoreflect.FileDescriptor) bool) private() } @@ -86,11 +89,11 @@ type UnpackInterfacesMessage interface { } type interfaceRegistry struct { + *protoregistry.Files interfaceNames map[string]reflect.Type interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type typeURLMap map[string]reflect.Type - protoFiles *protoregistry.Files } type interfaceMap = map[string]reflect.Type @@ -111,7 +114,7 @@ func NewInterfaceRegistryWithProtoFiles(files *protoregistry.Files) InterfaceReg interfaceImpls: map[reflect.Type]interfaceMap{}, implInterfaces: map[reflect.Type]reflect.Type{}, typeURLMap: map[string]reflect.Type{}, - protoFiles: files, + Files: files, } } @@ -304,10 +307,6 @@ func (registry *interfaceRegistry) Resolve(typeURL string) (proto.Message, error return msg, nil } -func (registry *interfaceRegistry) ProtoFiles() *protoregistry.Files { - return registry.protoFiles -} - func (registry *interfaceRegistry) private() {} // UnpackInterfaces is a convenience function that calls UnpackInterfaces diff --git a/types/tx/types.go b/types/tx/types.go index 544c0befa577..c842eef12011 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -36,7 +36,7 @@ func (t *Tx) GetSigners(codec codec.Codec) []string { var signers []string seen := map[string]bool{} - for _, msg := range t.GetMsgs() { + for _, msg := range t.Body.Messages { signers, err := codec.GetMsgSigners(msg) if err != nil { panic(err) diff --git a/x/tx/signing/get_signers.go b/x/tx/signing/get_signers.go index efd072cc0c75..8ad36ce8ccd6 100644 --- a/x/tx/signing/get_signers.go +++ b/x/tx/signing/get_signers.go @@ -2,22 +2,19 @@ package signing import ( "fmt" - "strings" msgv1 "cosmossdk.io/api/cosmos/msg/v1" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/types/dynamicpb" - "google.golang.org/protobuf/types/known/anypb" ) // GetSignersContext is a context for retrieving the list of signers from a // message where signers are specified by the cosmos.msg.v1.signer protobuf // option. type GetSignersContext struct { - protoFiles *protoregistry.Files - protoTypes protoregistry.MessageTypeResolver + protoFiles protodesc.Resolver getSignersFuncs map[protoreflect.FullName]getSignersFunc } @@ -25,9 +22,7 @@ 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 *protoregistry.Files - - ProtoTypes protoregistry.MessageTypeResolver + ProtoFiles protodesc.Resolver } // NewGetSignersContext creates a new GetSignersContext using the provided options. @@ -37,14 +32,8 @@ func NewGetSignersContext(options GetSignersOptions) *GetSignersContext { protoFiles = protoregistry.GlobalFiles } - protoTypes := options.ProtoTypes - if protoTypes == nil { - protoTypes = protoregistry.GlobalTypes - } - return &GetSignersContext{ protoFiles: protoFiles, - protoTypes: protoTypes, getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, } } @@ -187,31 +176,3 @@ func (c *GetSignersContext) GetSigners(msg proto.Message) ([]string, error) { return f(msg), nil } - -func (c *GetSignersContext) GetSignersForAny(any *anypb.Any) ([]string, error) { - url := any.TypeUrl - typ, err := c.protoTypes.FindMessageByURL(url) - if err != nil { - if err == protoregistry.NotFound { - msgName := protoreflect.FullName(url) - if i := strings.LastIndexByte(url, '/'); i >= 0 { - msgName = msgName[i+len("/"):] - } - msgDesc, err := c.protoFiles.FindDescriptorByName(msgName) - if err != nil { - return nil, err - } - - typ = dynamicpb.NewMessageType(msgDesc.(protoreflect.MessageDescriptor)) - } - return nil, err - } - - msg := typ.New().Interface() - err = any.UnmarshalTo(msg) - if err != nil { - return nil, err - } - - return c.GetSigners(msg) -} From a33c09823ccb863fc55a94f62a42da08a461ff35 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 13 Mar 2023 12:35:32 -0400 Subject: [PATCH 14/83] WIP --- baseapp/baseapp.go | 18 +++++++++++++----- codec/amino_codec.go | 7 ++++++- codec/codec.go | 7 ++++++- codec/proto_codec.go | 26 ++++++++------------------ types/tx/types.go | 20 +++++++++++++++----- x/auth/tx/builder.go | 14 +++++++++++++- x/authz/keeper/keeper.go | 2 +- x/gov/keeper/proposal.go | 2 +- x/group/keeper/proposal_executor.go | 2 +- 9 files changed, 64 insertions(+), 34 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index f154598015da..5b5331da3d1e 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -18,6 +18,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" "golang.org/x/exp/maps" + protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -674,6 +675,13 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re return sdk.GasInfo{}, nil, nil, 0, err } + var msgsV2 []protov2.Message + if hasMsgsV2, ok := tx.(interface{ GetMsgsV2() []protov2.Message }); ok { + msgsV2 = hasMsgsV2.GetMsgsV2() + } else { + panic("tx does not implement GetMsgsV2") + } + if app.anteHandler != nil { var ( anteCtx sdk.Context @@ -736,7 +744,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re // Attempt to execute all messages and only update state if all messages pass // and we're in DeliverTx. Note, runMsgs will never return a reference to a // Result if any single message fails or does not have a registered Handler. - result, err = app.runMsgs(runMsgCtx, msgs, mode) + result, err = app.runMsgs(runMsgCtx, msgs, msgsV2, mode) if err == nil { // Run optional postHandlers. // @@ -776,7 +784,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re // and DeliverTx. An error is returned if any single message fails or if a // Handler does not exist for a given message route. Otherwise, a reference to a // Result is returned. The caller must not commit state if an error is returned. -func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*sdk.Result, error) { +func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, msgsV2 []protov2.Message, mode runTxMode) (*sdk.Result, error) { msgLogs := make(sdk.ABCIMessageLogs, 0, len(msgs)) events := sdk.EmptyEvents() var msgResponses []*codectypes.Any @@ -799,7 +807,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s } // create message events - msgEvents := createEvents(app.cdc, msgResult.GetEvents(), msg) + msgEvents := createEvents(app.cdc, msgResult.GetEvents(), msg, msgsV2[i]) // append message events, data and logs // @@ -841,12 +849,12 @@ func makeABCIData(msgResponses []*codectypes.Any) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResponses}) } -func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg) sdk.Events { +func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, msgV2 protov2.Message) sdk.Events { eventMsgName := sdk.MsgTypeURL(msg) msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)) // we set the signer attribute as the sender - signers, err := cdc.GetMsgSigners(msg) + signers, err := cdc.GetMsgSigners(msgV2) if err != nil { panic(err) } diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 076e883a5083..0efd00003adf 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -129,7 +130,11 @@ func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } -func (ac *AminoCodec) GetMsgSigners(*types.Any) ([]string, error) { +func (ac *AminoCodec) GetMsgAnySigners(*types.Any) ([]string, protov2.Message, error) { + return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") +} + +func (ac *AminoCodec) GetMsgSigners(protov2.Message) ([]string, error) { return nil, fmt.Errorf("amino codec does not support getting msg signers") } diff --git a/codec/codec.go b/codec/codec.go index 3ccd9927a7f0..9793fbad5494 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -3,6 +3,7 @@ package codec import ( "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" + protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -19,7 +20,11 @@ type ( BinaryCodec JSONCodec - GetMsgSigners(msg *types.Any) ([]string, error) + // GetMsgAnySigners returns the signers of a given message as well as the + // decoded google.golang.org/protobuf/proto.Message that was used to + // extract the signers so that this can be used in other contexts. + GetMsgAnySigners(msg *types.Any) ([]string, protov2.Message, error) + GetMsgSigners(msg protov2.Message) ([]string, error) private() } diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 00cb50a60c0f..ffe06c132b15 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -272,31 +272,21 @@ func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry { return pc.interfaceRegistry } -func (pc ProtoCodec) GetMsgSigners(msg *types.Any) ([]string, error) { - //if msgv2, ok := msg.(protov2.Message); ok { - // return pc.getSignersCtx.GetSigners(msgv2) - //} else if msgv1, ok := msg.(proto.Message); ok { - // bz, err := proto.Marshal(msgv1) - // if err != nil { - // return nil, err - // } - // - // return pc.getSignersCtx.GetSignersForAny(&anypb.Any{ - // TypeUrl: string("/" + proto.MessageName(msgv1)), - // Value: bz, - // }) - //} else { - // return nil, fmt.Errorf("%T is not a proto.Message", msg) - //} +func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, error) { msgv2, err := anyutil.Unpack(&anypb.Any{ TypeUrl: msg.TypeUrl, Value: msg.Value, }, pc.interfaceRegistry, nil) if err != nil { - return nil, err + return nil, nil, err } - return pc.getSignersCtx.GetSigners(msgv2) + signers, err := pc.getSignersCtx.GetSigners(msgv2) + return signers, msgv2, err +} + +func (pc *ProtoCodec) GetMsgSigners(msg proto.Message) ([]string, error) { + return pc.getSignersCtx.GetSigners(msg) } // GRPCCodec returns the gRPC Codec for this specific ProtoCodec diff --git a/types/tx/types.go b/types/tx/types.go index c842eef12011..ffef137d299f 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -1,6 +1,8 @@ package tx import ( + protov2 "google.golang.org/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -32,16 +34,19 @@ func (t *Tx) GetMsgs() []sdk.Msg { // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). -func (t *Tx) GetSigners(codec codec.Codec) []string { +func (t *Tx) GetSigners(codec codec.Codec) ([]string, []protov2.Message, error) { var signers []string seen := map[string]bool{} + var msgsv2 []protov2.Message for _, msg := range t.Body.Messages { - signers, err := codec.GetMsgSigners(msg) + signers, msgv2, err := codec.GetMsgAnySigners(msg) if err != nil { - panic(err) + return nil, nil, err } + msgsv2 = append(msgsv2, msgv2) + for _, signer := range signers { if !seen[signer] { signers = append(signers, signer) @@ -58,7 +63,7 @@ func (t *Tx) GetSigners(codec codec.Codec) []string { seen[feePayer] = true } - return signers + return signers, msgsv2, nil } func (t *Tx) GetGas() uint64 { @@ -75,7 +80,12 @@ func (t *Tx) FeePayer(codec codec.Codec) string { return feePayer } // use first signer as default if no payer specified - return t.GetSigners(codec)[0] + signers, _, err := t.GetSigners(codec) + if err != nil { + panic(err) + } + + return signers[0] } func (t *Tx) FeeGranter() sdk.AccAddress { diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 550ea7cc6a86..70ad8df61ea5 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" errorsmod "cosmossdk.io/errors" @@ -37,6 +38,7 @@ type wrapper struct { txBodyHasUnknownNonCriticals bool signers []sdk.AccAddress + msgsV2 []protov2.Message } var ( @@ -72,6 +74,10 @@ func (w *wrapper) GetMsgs() []sdk.Msg { return w.tx.GetMsgs() } +func (w *wrapper) GetMsgsV2() []protov2.Message { + return w.msgsV2 +} + func (w *wrapper) ValidateBasic() error { if w.tx == nil { return fmt.Errorf("bad Tx") @@ -171,7 +177,13 @@ func (w *wrapper) getAuthInfoBytes() []byte { func (w *wrapper) GetSigners() []sdk.AccAddress { if w.signers == nil { - signers := w.tx.GetSigners(w.cdc) + signers, msgV2, err := w.tx.GetSigners(w.cdc) + if err != nil { + panic(err) + } + + w.msgsV2 = msgV2 + for _, signer := range signers { signerBz := sdk.MustAccAddressFromBech32(signer) w.signers = append(w.signers, signerBz) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 0c92c28f34fa..df7527334c83 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -89,7 +89,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] now := ctx.BlockTime() for i, msg := range msgs { - signers, err := k.cdc.GetMsgSigners(msg) + signers, _, err := k.cdc.GetMsgAnySigners(msg) if err != nil { return nil, err } diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 28f1ea0eb0ae..a954a28d6adc 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -46,7 +46,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) } - signers, err := keeper.cdc.GetMsgSigners(msg) + signers, _, err := keeper.cdc.GetMsgAnySigners(msg) if err != nil { return v1.Proposal{}, err } diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index 311f8e6f6dd9..4cb6cd80436c 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -68,7 +68,7 @@ func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, cdc codec.Cod // duplicates, so the code below is equivalent to: // `msgs[i].GetSigners()[0] == groupPolicyAcc` // but we prefer to loop through all GetSigners just to be sure. - signers, err := cdc.GetMsgSigners(msgs[i]) + signers, _, err := cdc.GetMsgAnySigners(msgs[i]) if err != nil { return err } From a9d12bcc8fd13ded616573c2269e9813703e84fa Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 13 Mar 2023 13:18:24 -0400 Subject: [PATCH 15/83] building --- baseapp/baseapp.go | 2 +- codec/amino_codec.go | 6 +++++- codec/codec.go | 13 ++++++++++--- codec/proto_codec.go | 15 ++++++++++++++- x/authz/keeper/keeper.go | 2 +- x/gov/keeper/proposal.go | 2 +- x/group/keeper/proposal_executor.go | 2 +- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 5b5331da3d1e..380faa4690a2 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -854,7 +854,7 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, msgV2 protov2 msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)) // we set the signer attribute as the sender - signers, err := cdc.GetMsgSigners(msgV2) + signers, err := cdc.GetMsgV2Signers(msgV2) if err != nil { panic(err) } diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 0efd00003adf..cbec5d37af46 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -134,7 +134,11 @@ func (ac *AminoCodec) GetMsgAnySigners(*types.Any) ([]string, protov2.Message, e return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") } -func (ac *AminoCodec) GetMsgSigners(protov2.Message) ([]string, error) { +func (ac *AminoCodec) GetMsgV1Signers(proto.Message) ([]string, protov2.Message, error) { + return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") +} + +func (ac *AminoCodec) GetMsgV2Signers(protov2.Message) ([]string, error) { return nil, fmt.Errorf("amino codec does not support getting msg signers") } diff --git a/codec/codec.go b/codec/codec.go index 9793fbad5494..7943844e9efa 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -20,11 +20,18 @@ type ( BinaryCodec JSONCodec - // GetMsgAnySigners returns the signers of a given message as well as the - // decoded google.golang.org/protobuf/proto.Message that was used to + // GetMsgAnySigners returns the signers of the given message encoded in a protobuf Any + // as well as the decoded google.golang.org/protobuf/proto.Message that was used to // extract the signers so that this can be used in other contexts. GetMsgAnySigners(msg *types.Any) ([]string, protov2.Message, error) - GetMsgSigners(msg protov2.Message) ([]string, error) + + // GetMsgV2Signers returns the signers of the given message. + GetMsgV2Signers(msg protov2.Message) ([]string, error) + + // GetMsgV1Signers returns the signers of the given message plus the + // decoded google.golang.org/protobuf/proto.Message that was used to extract the + // signers so that this can be used in other contexts. + GetMsgV1Signers(msg proto.Message) ([]string, protov2.Message, error) private() } diff --git a/codec/proto_codec.go b/codec/proto_codec.go index ffe06c132b15..9ccbd77b8a4b 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -285,10 +285,23 @@ func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, return signers, msgv2, err } -func (pc *ProtoCodec) GetMsgSigners(msg proto.Message) ([]string, error) { +func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([]string, error) { return pc.getSignersCtx.GetSigners(msg) } +func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([]string, proto.Message, error) { + if msgV2, ok := msg.(proto.Message); ok { + signers, err := pc.getSignersCtx.GetSigners(msgV2) + return signers, msgV2, err + } else { + a, err := types.NewAnyWithValue(msg) + if err != nil { + return nil, nil, err + } + return pc.GetMsgAnySigners(a) + } +} + // GRPCCodec returns the gRPC Codec for this specific ProtoCodec func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index df7527334c83..7d1d14c35504 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -89,7 +89,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] now := ctx.BlockTime() for i, msg := range msgs { - signers, _, err := k.cdc.GetMsgAnySigners(msg) + signers, _, err := k.cdc.GetMsgV1Signers(msg) if err != nil { return nil, err } diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index a954a28d6adc..b23630ac21f7 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -46,7 +46,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) } - signers, _, err := keeper.cdc.GetMsgAnySigners(msg) + signers, _, err := keeper.cdc.GetMsgV1Signers(msg) if err != nil { return v1.Proposal{}, err } diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index 4cb6cd80436c..6620e80ef272 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -68,7 +68,7 @@ func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, cdc codec.Cod // duplicates, so the code below is equivalent to: // `msgs[i].GetSigners()[0] == groupPolicyAcc` // but we prefer to loop through all GetSigners just to be sure. - signers, _, err := cdc.GetMsgAnySigners(msgs[i]) + signers, _, err := cdc.GetMsgV1Signers(msgs[i]) if err != nil { return err } From 4c3e3340d4e9cd34077efd0155b6951e3060f3ab Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 13 Mar 2023 13:30:30 -0400 Subject: [PATCH 16/83] start removing GetSigners --- baseapp/testutil/messages.go | 10 ------ server/mock/tx.go | 4 --- testutil/testdata/tx.go | 3 +- x/auth/vesting/types/msgs.go | 21 ------------ x/authz/msgs.go | 18 ---------- x/bank/types/msgs.go | 23 ------------- x/distribution/types/msg.go | 27 --------------- x/gov/types/v1/msgs.go | 24 -------------- x/gov/types/v1beta1/msgs.go | 12 ------- x/group/msgs.go | 64 ------------------------------------ x/slashing/types/msg.go | 6 ---- x/staking/types/msg.go | 42 ----------------------- 12 files changed, 1 insertion(+), 253 deletions(-) diff --git a/baseapp/testutil/messages.go b/baseapp/testutil/messages.go index a4b1cd9abbcb..aae1fa901df1 100644 --- a/baseapp/testutil/messages.go +++ b/baseapp/testutil/messages.go @@ -26,7 +26,6 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { var _ sdk.Msg = &MsgCounter{} -func (msg *MsgCounter) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } func (msg *MsgCounter) ValidateBasic() error { if msg.Counter >= 0 { return nil @@ -36,7 +35,6 @@ func (msg *MsgCounter) ValidateBasic() error { var _ sdk.Msg = &MsgCounter2{} -func (msg *MsgCounter2) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } func (msg *MsgCounter2) ValidateBasic() error { if msg.Counter >= 0 { return nil @@ -46,14 +44,6 @@ func (msg *MsgCounter2) ValidateBasic() error { var _ sdk.Msg = &MsgKeyValue{} -func (msg *MsgKeyValue) GetSigners() []sdk.AccAddress { - if len(msg.Signer) == 0 { - return []sdk.AccAddress{} - } - - return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Signer)} -} - func (msg *MsgKeyValue) ValidateBasic() error { if msg.Key == nil { return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "key cannot be nil") diff --git a/server/mock/tx.go b/server/mock/tx.go index f9f1c394dc99..ca70e4ab6785 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -109,10 +109,6 @@ func (msg *KVStoreTx) ValidateBasic() error { return nil } -func (msg *KVStoreTx) GetSigners() []sdk.AccAddress { - return nil -} - func (msg *KVStoreTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } // takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 9b4e081253ff..859fb05a43f6 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -106,5 +106,4 @@ func (msg *TestMsg) ValidateBasic() error { var _ sdk.Msg = &MsgCreateDog{} -func (msg *MsgCreateDog) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } -func (msg *MsgCreateDog) ValidateBasic() error { return nil } +func (msg *MsgCreateDog) ValidateBasic() error { return nil } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 4bd31fdb9afc..c7c8f3c0efc0 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -63,12 +63,6 @@ func (msg MsgCreateVestingAccount) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -// GetSigners returns the expected signers for a MsgCreateVestingAccount. -func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{addr} -} - // NewMsgCreatePermanentLockedAccount returns a reference to a new MsgCreatePermanentLockedAccount. // //nolint:interfacer @@ -106,12 +100,6 @@ func (msg MsgCreatePermanentLockedAccount) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -// GetSigners returns the expected signers for a MsgCreatePermanentLockedAccount. -func (msg MsgCreatePermanentLockedAccount) GetSigners() []sdk.AccAddress { - from, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{from} -} - // NewMsgCreatePeriodicVestingAccount returns a reference to a new MsgCreatePeriodicVestingAccount. // //nolint:interfacer @@ -124,15 +112,6 @@ func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTi } } -// GetSigners returns the expected signers for a MsgCreatePeriodicVestingAccount. -func (msg MsgCreatePeriodicVestingAccount) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{from} -} - // GetSignBytes returns the bytes all expected signers must sign over for a // MsgCreatePeriodicVestingAccount. func (msg MsgCreatePeriodicVestingAccount) GetSignBytes() []byte { diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 792120d6de71..572e193fffc9 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -43,12 +43,6 @@ func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a Authorization return m, nil } -// GetSigners implements Msg -func (msg MsgGrant) GetSigners() []sdk.AccAddress { - granter, _ := sdk.AccAddressFromBech32(msg.Granter) - return []sdk.AccAddress{granter} -} - // ValidateBasic implements Msg func (msg MsgGrant) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) @@ -119,12 +113,6 @@ func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL str } } -// GetSigners implements Msg -func (msg MsgRevoke) GetSigners() []sdk.AccAddress { - granter, _ := sdk.AccAddressFromBech32(msg.Granter) - return []sdk.AccAddress{granter} -} - // ValidateBasic implements MsgRequest.ValidateBasic func (msg MsgRevoke) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) @@ -186,12 +174,6 @@ func (msg MsgExec) GetMessages() ([]sdk.Msg, error) { return msgs, nil } -// GetSigners implements Msg -func (msg MsgExec) GetSigners() []sdk.AccAddress { - grantee, _ := sdk.AccAddressFromBech32(msg.Grantee) - return []sdk.AccAddress{grantee} -} - // ValidateBasic implements Msg func (msg MsgExec) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Grantee); err != nil { diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 592f6baed4c8..010e391bd509 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -51,12 +51,6 @@ func (msg MsgSend) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -// GetSigners Implements Msg. -func (msg MsgSend) GetSigners() []sdk.AccAddress { - fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{fromAddress} -} - // NewMsgMultiSend - construct arbitrary multi-in, multi-out send msg. func NewMsgMultiSend(in []Input, out []Output) *MsgMultiSend { return &MsgMultiSend{Inputs: in, Outputs: out} @@ -87,17 +81,6 @@ func (msg MsgMultiSend) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -// GetSigners Implements Msg. -func (msg MsgMultiSend) GetSigners() []sdk.AccAddress { - addrs := make([]sdk.AccAddress, len(msg.Inputs)) - for i, in := range msg.Inputs { - inAddr, _ := sdk.AccAddressFromBech32(in.Address) - addrs[i] = inAddr - } - - return addrs -} - // ValidateBasic - validate transaction input func (in Input) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(in.Address); err != nil { @@ -213,12 +196,6 @@ func (msg MsgSetSendEnabled) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -// GetSigners returns the expected signers for MsgSoftwareUpgrade. -func (msg MsgSetSendEnabled) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.Authority) - return []sdk.AccAddress{addr} -} - // ValidateBasic runs basic validation on this MsgSetSendEnabled. func (msg MsgSetSendEnabled) ValidateBasic() error { if len(msg.Authority) > 0 { diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index 9e5038664b32..51deb084fad8 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -34,12 +34,6 @@ func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithd } } -// Return address that must sign over msg.GetSignBytes() -func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { - delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) - return []sdk.AccAddress{delegator} -} - // get the bytes for the message signer to sign on func (msg MsgSetWithdrawAddress) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -123,13 +117,6 @@ func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFun } } -// GetSigners returns the signer addresses that are expected to sign the result -// of GetSignBytes. -func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { - depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) - return []sdk.AccAddress{depositor} -} - // GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that // the expected signer needs to sign. func (msg MsgFundCommunityPool) GetSignBytes() []byte { @@ -176,13 +163,6 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.ValidateBasic() } -// GetSigners returns the signer addresses that are expected to sign the result -// of GetSignBytes, which is the authority. -func (msg MsgCommunityPoolSpend) GetSigners() []sdk.AccAddress { - authority, _ := sdk.AccAddressFromBech32(msg.Authority) - return []sdk.AccAddress{authority} -} - // GetSignBytes returns the raw bytes for a MsgCommunityPoolSpend message that // the expected signer needs to sign. func (msg MsgCommunityPoolSpend) GetSignBytes() []byte { @@ -209,13 +189,6 @@ func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.Val } } -// GetSigners returns the signer addresses that are expected to sign the result -// of GetSignBytes, which is the authority. -func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress { - authority, _ := sdk.AccAddressFromBech32(msg.Authority) - return []sdk.AccAddress{authority} -} - // GetSignBytes returns the raw bytes for a MsgDepositValidatorRewardsPool message // that the expected signer needs to sign. func (msg MsgDepositValidatorRewardsPool) GetSignBytes() []byte { diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index ac10428e23b2..deb24934c124 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -115,12 +115,6 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -// GetSigners returns the expected signers for a MsgSubmitProposal. -func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { - proposer, _ := sdk.AccAddressFromBech32(m.Proposer) - return []sdk.AccAddress{proposer} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { return sdktx.UnpackInterfaces(unpacker, m.Messages) @@ -155,12 +149,6 @@ func (msg MsgDeposit) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -// GetSigners returns the expected signers for a MsgDeposit. -func (msg MsgDeposit) GetSigners() []sdk.AccAddress { - depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) - return []sdk.AccAddress{depositor} -} - // NewMsgVote creates a message to cast a vote on an active proposal // //nolint:interfacer @@ -264,12 +252,6 @@ func (c MsgExecLegacyContent) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -// GetSigners returns the expected signers for a MsgExecLegacyContent. -func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress { - authority, _ := sdk.AccAddressFromBech32(c.Authority) - return []sdk.AccAddress{authority} -} - // ValidateBasic implements the sdk.Msg interface. func (c MsgExecLegacyContent) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(c.Authority) @@ -331,9 +313,3 @@ func (msg MsgCancelProposal) GetSignBytes() []byte { bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } - -// GetSigners implements Msg -func (msg MsgCancelProposal) GetSigners() []sdk.AccAddress { - proposer, _ := sdk.AccAddressFromBech32(msg.Proposer) - return []sdk.AccAddress{proposer} -} diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index c02b93fd9bd7..a0622febc6f8 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -120,12 +120,6 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -// GetSigners returns the expected signers for a MsgSubmitProposal. -func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { - proposer, _ := sdk.AccAddressFromBech32(m.Proposer) - return []sdk.AccAddress{proposer} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var content Content @@ -160,12 +154,6 @@ func (msg MsgDeposit) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -// GetSigners returns the expected signers for a MsgDeposit. -func (msg MsgDeposit) GetSigners() []sdk.AccAddress { - depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) - return []sdk.AccAddress{depositor} -} - // NewMsgVote creates a message to cast a vote on an active proposal // //nolint:interfacer diff --git a/x/group/msgs.go b/x/group/msgs.go index 426105c11393..d4a892dd486a 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -25,13 +25,6 @@ func (m MsgCreateGroup) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgCreateGroup. -func (m MsgCreateGroup) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroup) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -70,13 +63,6 @@ func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgUpdateGroupAdmin. -func (m MsgUpdateGroupAdmin) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data. func (m MsgUpdateGroupAdmin) ValidateBasic() error { if m.GroupId == 0 { @@ -114,13 +100,6 @@ func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgUpdateGroupMetadata. -func (m MsgUpdateGroupMetadata) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data func (m MsgUpdateGroupMetadata) ValidateBasic() error { if m.GroupId == 0 { @@ -151,13 +130,6 @@ func (m MsgUpdateGroupMembers) GetSignBytes() []byte { var _ sdk.Msg = &MsgUpdateGroupMembers{} -// GetSigners returns the expected signers for a MsgUpdateGroupMembers. -func (m MsgUpdateGroupMembers) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data func (m MsgUpdateGroupMembers) ValidateBasic() error { if m.GroupId == 0 { @@ -236,12 +208,6 @@ func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgCreateGroupWithPolicy. -func (m MsgCreateGroupWithPolicy) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroupWithPolicy) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -269,12 +235,6 @@ func (m MsgCreateGroupPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgCreateGroupPolicy. -func (m MsgCreateGroupPolicy) GetSigners() []sdk.AccAddress { - admin := sdk.MustAccAddressFromBech32(m.Admin) - return []sdk.AccAddress{admin} -} - // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroupPolicy) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -542,16 +502,6 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgSubmitProposal. -func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { - addrs, err := m.getProposerAccAddresses() - if err != nil { - panic(err) - } - - return addrs -} - // ValidateBasic does a sanity check on the provided proposal, such as // verifying proposer addresses, and performing ValidateBasic on each // individual `sdk.Msg`. @@ -705,13 +655,6 @@ func (m MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgExec. -func (m MsgExec) GetSigners() []sdk.AccAddress { - signer := sdk.MustAccAddressFromBech32(m.Executor) - - return []sdk.AccAddress{signer} -} - // ValidateBasic does a sanity check on the provided data func (m MsgExec) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Executor) @@ -734,13 +677,6 @@ func (m MsgLeaveGroup) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } -// GetSigners returns the expected signers for a MsgLeaveGroup -func (m MsgLeaveGroup) GetSigners() []sdk.AccAddress { - signer := sdk.MustAccAddressFromBech32(m.Address) - - return []sdk.AccAddress{signer} -} - // ValidateBasic does a sanity check on the provided data func (m MsgLeaveGroup) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Address) diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 416e9b3077f9..001088b1fd1c 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -26,12 +26,6 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { } } -// GetSigners returns the expected signers for MsgUnjail. -func (msg MsgUnjail) GetSigners() []sdk.AccAddress { - valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddr) - return []sdk.AccAddress{sdk.AccAddress(valAddr)} -} - // GetSignBytes gets the bytes for the message signer to sign on func (msg MsgUnjail) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 1cd7767266aa..b9b2f3421747 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -53,18 +53,6 @@ func NewMsgCreateValidator( }, nil } -// GetSigners implements the sdk.Msg interface. It returns the address(es) that -// must sign over msg.GetSignBytes(). -// If the validator address is not same as delegator's, then the validator must -// sign the msg as well. -func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { - valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) - - valAccAddr := sdk.AccAddress(valAddr) - - return []sdk.AccAddress{valAccAddr} -} - // GetSignBytes returns the message bytes to sign over. func (msg MsgCreateValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -131,12 +119,6 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat } } -// GetSigners implements the sdk.Msg interface. -func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { - valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) - return []sdk.AccAddress{sdk.AccAddress(valAddr)} -} - // GetSignBytes implements the sdk.Msg interface. func (msg MsgEditValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -180,12 +162,6 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C } } -// GetSigners implements the sdk.Msg interface. -func (msg MsgDelegate) GetSigners() []sdk.AccAddress { - delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) - return []sdk.AccAddress{delegator} -} - // GetSignBytes implements the sdk.Msg interface. func (msg MsgDelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -225,12 +201,6 @@ func NewMsgBeginRedelegate( } } -// GetSigners implements the sdk.Msg interface -func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { - delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) - return []sdk.AccAddress{delegator} -} - // GetSignBytes implements the sdk.Msg interface. func (msg MsgBeginRedelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -270,12 +240,6 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk } } -// GetSigners implements the sdk.Msg interface. -func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { - delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) - return []sdk.AccAddress{delegator} -} - // GetSignBytes implements the sdk.Msg interface. func (msg MsgUndelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -313,12 +277,6 @@ func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddr } } -// GetSigners implements the sdk.Msg interface. -func (msg MsgCancelUnbondingDelegation) GetSigners() []sdk.AccAddress { - delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) - return []sdk.AccAddress{delegator} -} - // GetSignBytes implements the sdk.Msg interface. func (msg MsgCancelUnbondingDelegation) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) From 5474a26e332e6e6bdae538fa75b9b17db448449b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 16:37:47 -0400 Subject: [PATCH 17/83] Revert "start removing GetSigners" This reverts commit 4c3e3340d4e9cd34077efd0155b6951e3060f3ab. --- baseapp/testutil/messages.go | 10 ++++++ server/mock/tx.go | 4 +++ testutil/testdata/tx.go | 3 +- x/auth/vesting/types/msgs.go | 21 ++++++++++++ x/authz/msgs.go | 18 ++++++++++ x/bank/types/msgs.go | 23 +++++++++++++ x/distribution/types/msg.go | 27 +++++++++++++++ x/gov/types/v1/msgs.go | 24 ++++++++++++++ x/gov/types/v1beta1/msgs.go | 12 +++++++ x/group/msgs.go | 64 ++++++++++++++++++++++++++++++++++++ x/slashing/types/msg.go | 6 ++++ x/staking/types/msg.go | 42 +++++++++++++++++++++++ 12 files changed, 253 insertions(+), 1 deletion(-) diff --git a/baseapp/testutil/messages.go b/baseapp/testutil/messages.go index aae1fa901df1..a4b1cd9abbcb 100644 --- a/baseapp/testutil/messages.go +++ b/baseapp/testutil/messages.go @@ -26,6 +26,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { var _ sdk.Msg = &MsgCounter{} +func (msg *MsgCounter) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } func (msg *MsgCounter) ValidateBasic() error { if msg.Counter >= 0 { return nil @@ -35,6 +36,7 @@ func (msg *MsgCounter) ValidateBasic() error { var _ sdk.Msg = &MsgCounter2{} +func (msg *MsgCounter2) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } func (msg *MsgCounter2) ValidateBasic() error { if msg.Counter >= 0 { return nil @@ -44,6 +46,14 @@ func (msg *MsgCounter2) ValidateBasic() error { var _ sdk.Msg = &MsgKeyValue{} +func (msg *MsgKeyValue) GetSigners() []sdk.AccAddress { + if len(msg.Signer) == 0 { + return []sdk.AccAddress{} + } + + return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Signer)} +} + func (msg *MsgKeyValue) ValidateBasic() error { if msg.Key == nil { return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "key cannot be nil") diff --git a/server/mock/tx.go b/server/mock/tx.go index ca70e4ab6785..f9f1c394dc99 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -109,6 +109,10 @@ func (msg *KVStoreTx) ValidateBasic() error { return nil } +func (msg *KVStoreTx) GetSigners() []sdk.AccAddress { + return nil +} + func (msg *KVStoreTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } // takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 859fb05a43f6..9b4e081253ff 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -106,4 +106,5 @@ func (msg *TestMsg) ValidateBasic() error { var _ sdk.Msg = &MsgCreateDog{} -func (msg *MsgCreateDog) ValidateBasic() error { return nil } +func (msg *MsgCreateDog) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} } +func (msg *MsgCreateDog) ValidateBasic() error { return nil } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index c7c8f3c0efc0..4bd31fdb9afc 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -63,6 +63,12 @@ func (msg MsgCreateVestingAccount) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +// GetSigners returns the expected signers for a MsgCreateVestingAccount. +func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{addr} +} + // NewMsgCreatePermanentLockedAccount returns a reference to a new MsgCreatePermanentLockedAccount. // //nolint:interfacer @@ -100,6 +106,12 @@ func (msg MsgCreatePermanentLockedAccount) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +// GetSigners returns the expected signers for a MsgCreatePermanentLockedAccount. +func (msg MsgCreatePermanentLockedAccount) GetSigners() []sdk.AccAddress { + from, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{from} +} + // NewMsgCreatePeriodicVestingAccount returns a reference to a new MsgCreatePeriodicVestingAccount. // //nolint:interfacer @@ -112,6 +124,15 @@ func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTi } } +// GetSigners returns the expected signers for a MsgCreatePeriodicVestingAccount. +func (msg MsgCreatePeriodicVestingAccount) GetSigners() []sdk.AccAddress { + from, err := sdk.AccAddressFromBech32(msg.FromAddress) + if err != nil { + panic(err) + } + return []sdk.AccAddress{from} +} + // GetSignBytes returns the bytes all expected signers must sign over for a // MsgCreatePeriodicVestingAccount. func (msg MsgCreatePeriodicVestingAccount) GetSignBytes() []byte { diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 572e193fffc9..792120d6de71 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -43,6 +43,12 @@ func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a Authorization return m, nil } +// GetSigners implements Msg +func (msg MsgGrant) GetSigners() []sdk.AccAddress { + granter, _ := sdk.AccAddressFromBech32(msg.Granter) + return []sdk.AccAddress{granter} +} + // ValidateBasic implements Msg func (msg MsgGrant) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) @@ -113,6 +119,12 @@ func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL str } } +// GetSigners implements Msg +func (msg MsgRevoke) GetSigners() []sdk.AccAddress { + granter, _ := sdk.AccAddressFromBech32(msg.Granter) + return []sdk.AccAddress{granter} +} + // ValidateBasic implements MsgRequest.ValidateBasic func (msg MsgRevoke) ValidateBasic() error { granter, err := sdk.AccAddressFromBech32(msg.Granter) @@ -174,6 +186,12 @@ func (msg MsgExec) GetMessages() ([]sdk.Msg, error) { return msgs, nil } +// GetSigners implements Msg +func (msg MsgExec) GetSigners() []sdk.AccAddress { + grantee, _ := sdk.AccAddressFromBech32(msg.Grantee) + return []sdk.AccAddress{grantee} +} + // ValidateBasic implements Msg func (msg MsgExec) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Grantee); err != nil { diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 010e391bd509..592f6baed4c8 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -51,6 +51,12 @@ func (msg MsgSend) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +// GetSigners Implements Msg. +func (msg MsgSend) GetSigners() []sdk.AccAddress { + fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{fromAddress} +} + // NewMsgMultiSend - construct arbitrary multi-in, multi-out send msg. func NewMsgMultiSend(in []Input, out []Output) *MsgMultiSend { return &MsgMultiSend{Inputs: in, Outputs: out} @@ -81,6 +87,17 @@ func (msg MsgMultiSend) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +// GetSigners Implements Msg. +func (msg MsgMultiSend) GetSigners() []sdk.AccAddress { + addrs := make([]sdk.AccAddress, len(msg.Inputs)) + for i, in := range msg.Inputs { + inAddr, _ := sdk.AccAddressFromBech32(in.Address) + addrs[i] = inAddr + } + + return addrs +} + // ValidateBasic - validate transaction input func (in Input) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(in.Address); err != nil { @@ -196,6 +213,12 @@ func (msg MsgSetSendEnabled) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +// GetSigners returns the expected signers for MsgSoftwareUpgrade. +func (msg MsgSetSendEnabled) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + // ValidateBasic runs basic validation on this MsgSetSendEnabled. func (msg MsgSetSendEnabled) ValidateBasic() error { if len(msg.Authority) > 0 { diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index 51deb084fad8..9e5038664b32 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -34,6 +34,12 @@ func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithd } } +// Return address that must sign over msg.GetSignBytes() +func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{delegator} +} + // get the bytes for the message signer to sign on func (msg MsgSetWithdrawAddress) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -117,6 +123,13 @@ func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFun } } +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes. +func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { + depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) + return []sdk.AccAddress{depositor} +} + // GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that // the expected signer needs to sign. func (msg MsgFundCommunityPool) GetSignBytes() []byte { @@ -163,6 +176,13 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.ValidateBasic() } +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes, which is the authority. +func (msg MsgCommunityPoolSpend) GetSigners() []sdk.AccAddress { + authority, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{authority} +} + // GetSignBytes returns the raw bytes for a MsgCommunityPoolSpend message that // the expected signer needs to sign. func (msg MsgCommunityPoolSpend) GetSignBytes() []byte { @@ -189,6 +209,13 @@ func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.Val } } +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes, which is the authority. +func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress { + authority, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{authority} +} + // GetSignBytes returns the raw bytes for a MsgDepositValidatorRewardsPool message // that the expected signer needs to sign. func (msg MsgDepositValidatorRewardsPool) GetSignBytes() []byte { diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index deb24934c124..ac10428e23b2 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -115,6 +115,12 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } +// GetSigners returns the expected signers for a MsgSubmitProposal. +func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { + proposer, _ := sdk.AccAddressFromBech32(m.Proposer) + return []sdk.AccAddress{proposer} +} + // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { return sdktx.UnpackInterfaces(unpacker, m.Messages) @@ -149,6 +155,12 @@ func (msg MsgDeposit) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } +// GetSigners returns the expected signers for a MsgDeposit. +func (msg MsgDeposit) GetSigners() []sdk.AccAddress { + depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) + return []sdk.AccAddress{depositor} +} + // NewMsgVote creates a message to cast a vote on an active proposal // //nolint:interfacer @@ -252,6 +264,12 @@ func (c MsgExecLegacyContent) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } +// GetSigners returns the expected signers for a MsgExecLegacyContent. +func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress { + authority, _ := sdk.AccAddressFromBech32(c.Authority) + return []sdk.AccAddress{authority} +} + // ValidateBasic implements the sdk.Msg interface. func (c MsgExecLegacyContent) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(c.Authority) @@ -313,3 +331,9 @@ func (msg MsgCancelProposal) GetSignBytes() []byte { bz := codec.ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } + +// GetSigners implements Msg +func (msg MsgCancelProposal) GetSigners() []sdk.AccAddress { + proposer, _ := sdk.AccAddressFromBech32(msg.Proposer) + return []sdk.AccAddress{proposer} +} diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index a0622febc6f8..c02b93fd9bd7 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -120,6 +120,12 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } +// GetSigners returns the expected signers for a MsgSubmitProposal. +func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { + proposer, _ := sdk.AccAddressFromBech32(m.Proposer) + return []sdk.AccAddress{proposer} +} + // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var content Content @@ -154,6 +160,12 @@ func (msg MsgDeposit) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } +// GetSigners returns the expected signers for a MsgDeposit. +func (msg MsgDeposit) GetSigners() []sdk.AccAddress { + depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) + return []sdk.AccAddress{depositor} +} + // NewMsgVote creates a message to cast a vote on an active proposal // //nolint:interfacer diff --git a/x/group/msgs.go b/x/group/msgs.go index d4a892dd486a..426105c11393 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -25,6 +25,13 @@ func (m MsgCreateGroup) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgCreateGroup. +func (m MsgCreateGroup) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroup) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -63,6 +70,13 @@ func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgUpdateGroupAdmin. +func (m MsgUpdateGroupAdmin) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data. func (m MsgUpdateGroupAdmin) ValidateBasic() error { if m.GroupId == 0 { @@ -100,6 +114,13 @@ func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgUpdateGroupMetadata. +func (m MsgUpdateGroupMetadata) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data func (m MsgUpdateGroupMetadata) ValidateBasic() error { if m.GroupId == 0 { @@ -130,6 +151,13 @@ func (m MsgUpdateGroupMembers) GetSignBytes() []byte { var _ sdk.Msg = &MsgUpdateGroupMembers{} +// GetSigners returns the expected signers for a MsgUpdateGroupMembers. +func (m MsgUpdateGroupMembers) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data func (m MsgUpdateGroupMembers) ValidateBasic() error { if m.GroupId == 0 { @@ -208,6 +236,12 @@ func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgCreateGroupWithPolicy. +func (m MsgCreateGroupWithPolicy) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroupWithPolicy) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -235,6 +269,12 @@ func (m MsgCreateGroupPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgCreateGroupPolicy. +func (m MsgCreateGroupPolicy) GetSigners() []sdk.AccAddress { + admin := sdk.MustAccAddressFromBech32(m.Admin) + return []sdk.AccAddress{admin} +} + // ValidateBasic does a sanity check on the provided data func (m MsgCreateGroupPolicy) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Admin) @@ -502,6 +542,16 @@ func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgSubmitProposal. +func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress { + addrs, err := m.getProposerAccAddresses() + if err != nil { + panic(err) + } + + return addrs +} + // ValidateBasic does a sanity check on the provided proposal, such as // verifying proposer addresses, and performing ValidateBasic on each // individual `sdk.Msg`. @@ -655,6 +705,13 @@ func (m MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgExec. +func (m MsgExec) GetSigners() []sdk.AccAddress { + signer := sdk.MustAccAddressFromBech32(m.Executor) + + return []sdk.AccAddress{signer} +} + // ValidateBasic does a sanity check on the provided data func (m MsgExec) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Executor) @@ -677,6 +734,13 @@ func (m MsgLeaveGroup) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } +// GetSigners returns the expected signers for a MsgLeaveGroup +func (m MsgLeaveGroup) GetSigners() []sdk.AccAddress { + signer := sdk.MustAccAddressFromBech32(m.Address) + + return []sdk.AccAddress{signer} +} + // ValidateBasic does a sanity check on the provided data func (m MsgLeaveGroup) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.Address) diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 001088b1fd1c..416e9b3077f9 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -26,6 +26,12 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { } } +// GetSigners returns the expected signers for MsgUnjail. +func (msg MsgUnjail) GetSigners() []sdk.AccAddress { + valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddr) + return []sdk.AccAddress{sdk.AccAddress(valAddr)} +} + // GetSignBytes gets the bytes for the message signer to sign on func (msg MsgUnjail) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index b9b2f3421747..1cd7767266aa 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -53,6 +53,18 @@ func NewMsgCreateValidator( }, nil } +// GetSigners implements the sdk.Msg interface. It returns the address(es) that +// must sign over msg.GetSignBytes(). +// If the validator address is not same as delegator's, then the validator must +// sign the msg as well. +func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { + valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) + + valAccAddr := sdk.AccAddress(valAddr) + + return []sdk.AccAddress{valAccAddr} +} + // GetSignBytes returns the message bytes to sign over. func (msg MsgCreateValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -119,6 +131,12 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat } } +// GetSigners implements the sdk.Msg interface. +func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { + valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) + return []sdk.AccAddress{sdk.AccAddress(valAddr)} +} + // GetSignBytes implements the sdk.Msg interface. func (msg MsgEditValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -162,6 +180,12 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C } } +// GetSigners implements the sdk.Msg interface. +func (msg MsgDelegate) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{delegator} +} + // GetSignBytes implements the sdk.Msg interface. func (msg MsgDelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -201,6 +225,12 @@ func NewMsgBeginRedelegate( } } +// GetSigners implements the sdk.Msg interface +func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{delegator} +} + // GetSignBytes implements the sdk.Msg interface. func (msg MsgBeginRedelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -240,6 +270,12 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk } } +// GetSigners implements the sdk.Msg interface. +func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{delegator} +} + // GetSignBytes implements the sdk.Msg interface. func (msg MsgUndelegate) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -277,6 +313,12 @@ func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddr } } +// GetSigners implements the sdk.Msg interface. +func (msg MsgCancelUnbondingDelegation) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{delegator} +} + // GetSignBytes implements the sdk.Msg interface. func (msg MsgCancelUnbondingDelegation) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) From 65050eb03e296239191aa14b9f1674c4e82f9ca3 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 16:53:51 -0400 Subject: [PATCH 18/83] fix --- baseapp/options.go | 1 - 1 file changed, 1 deletion(-) diff --git a/baseapp/options.go b/baseapp/options.go index d9173cbb548f..68656aca3ca0 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -11,7 +11,6 @@ import ( storetypes "cosmossdk.io/store/types" dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" From 954122017ccfc873b2bbd00fd8a6e66869ee50f1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 16:58:43 -0400 Subject: [PATCH 19/83] update CHANGELOG.md and remove some breakage --- CHANGELOG.md | 4 ++++ codec/codec.go | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af35701bdf3a..d485df4280ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,6 +141,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client) [#15123](https://github.com/cosmos/cosmos-sdk/pull/15123) `NewFactoryCLI` now returns an error, in addition to the `Factory`. * (x/capability) [#15344](https://github.com/cosmos/cosmos-sdk/pull/15344) Capability module was removed and is now housed in [IBC-GO](https://github.com/cosmos/ibc-go). * [#15299](https://github.com/cosmos/cosmos-sdk/pull/15299) remove `StdTx` transaction and signing APIs. No SDK version has actually supported `StdTx` since before Stargate. +* [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) + * `sdk.Msg.GetSigners` was deprecated and no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. + * the `codec` types are `Codec` and `InterfaceRegistry` can no longer be overriden without embedding an existing codec type and new methods have been added. + * `types/tx.Tx` no longer implements `sdk.Tx` ### Client Breaking Changes diff --git a/codec/codec.go b/codec/codec.go index 7943844e9efa..08b71eb58d52 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -70,8 +70,6 @@ type ( UnmarshalInterface(bz []byte, ptr interface{}) error types.AnyUnpacker - - private() } JSONCodec interface { @@ -92,8 +90,6 @@ type ( UnmarshalJSON(bz []byte, ptr proto.Message) error // MustUnmarshalJSON calls Unmarshal and panics if error is returned. MustUnmarshalJSON(bz []byte, ptr proto.Message) - - private() } // ProtoMarshaler defines an interface a type must implement to serialize itself From aa21cea2e2246fdafbe48235956e18fb2f8b24f0 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 17:03:44 -0400 Subject: [PATCH 20/83] update CHANGELOG.md and update some breakage --- CHANGELOG.md | 3 ++- baseapp/baseapp.go | 9 +-------- types/mempool/mempool_test.go | 5 +++++ types/tx_msg.go | 3 +++ x/auth/tx/direct_test.go | 6 ++++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d485df4280ca..5cc20506aea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,7 +144,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) * `sdk.Msg.GetSigners` was deprecated and no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. * the `codec` types are `Codec` and `InterfaceRegistry` can no longer be overriden without embedding an existing codec type and new methods have been added. - * `types/tx.Tx` no longer implements `sdk.Tx` + * `types/tx.Tx` no longer implements `sdk.Tx`. + * `sdk.Tx` now requires a new methods `GetMsgsV2()`. ### Client Breaking Changes diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0fd3422e91a8..8704846e3853 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -676,13 +676,6 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re return sdk.GasInfo{}, nil, nil, 0, err } - var msgsV2 []protov2.Message - if hasMsgsV2, ok := tx.(interface{ GetMsgsV2() []protov2.Message }); ok { - msgsV2 = hasMsgsV2.GetMsgsV2() - } else { - panic("tx does not implement GetMsgsV2") - } - if app.anteHandler != nil { var ( anteCtx sdk.Context @@ -745,7 +738,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re // Attempt to execute all messages and only update state if all messages pass // and we're in DeliverTx. Note, runMsgs will never return a reference to a // Result if any single message fails or does not have a registered Handler. - result, err = app.runMsgs(runMsgCtx, msgs, msgsV2, mode) + result, err = app.runMsgs(runMsgCtx, msgs, tx.GetMsgsV2(), mode) if err == nil { // Run optional postHandlers. // diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index ce50199b162e..de712f7dcd3d 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -8,6 +8,7 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + protov2 "google.golang.org/protobuf/proto" "cosmossdk.io/log" @@ -75,6 +76,8 @@ var ( func (tx testTx) GetMsgs() []sdk.Msg { return nil } +func (tx testTx) GetMsgsV2() []protov2.Message { return nil } + func (tx testTx) ValidateBasic() error { return nil } func (tx testTx) String() string { @@ -89,6 +92,8 @@ func (sigErrTx) Size() int64 { return 0 } func (sigErrTx) GetMsgs() []sdk.Msg { return nil } +func (sigErrTx) GetMsgsV2() []protov2.Message { return nil } + func (sigErrTx) ValidateBasic() error { return nil } func (sigErrTx) GetSigners() []sdk.AccAddress { return nil } diff --git a/types/tx_msg.go b/types/tx_msg.go index ad5187352de9..2068f7396fbb 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -52,6 +52,9 @@ type ( // GetMsgs gets the all the transaction's messages. GetMsgs() []Msg + // GetMsgsV2 gets the transaction's messages as google.golang.org/protobuf/proto.Message's. + GetMsgsV2() []protov2.Message + // ValidateBasic does a simple and lightweight validation check that doesn't // require access to any other information. ValidateBasic() error diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 22309639656e..c842f766930d 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" + protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -151,8 +152,9 @@ func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) { type nonProtoTx int -func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } -func (npt *nonProtoTx) ValidateBasic() error { return nil } +func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } +func (npt *nonProtoTx) GetMsgsV2() []protov2.Message { return nil } +func (npt *nonProtoTx) ValidateBasic() error { return nil } var _ sdk.Tx = (*nonProtoTx)(nil) From c67dace73415cce1280d427956ad3d7302f66796 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 17:06:04 -0400 Subject: [PATCH 21/83] update runtime module --- runtime/module.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index c64c7b472197..a3d2155a9ee5 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -4,6 +4,7 @@ import ( "fmt" "cosmossdk.io/core/store" + "github.com/cosmos/gogoproto/proto" abci "github.com/cometbft/cometbft/abci/types" @@ -71,8 +72,14 @@ func ProvideApp() ( codec.ProtoCodecMarshaler, *baseapp.MsgServiceRouter, appmodule.AppModule, + error, ) { - interfaceRegistry := codectypes.NewInterfaceRegistry() + protoFiles, err := proto.MergedRegistry() + if err != nil { + return nil, nil, nil, nil, nil, nil, nil, err + } + + interfaceRegistry := codectypes.NewInterfaceRegistryWithProtoFiles(protoFiles) amino := codec.NewLegacyAmino() std.RegisterInterfaces(interfaceRegistry) @@ -90,7 +97,7 @@ func ProvideApp() ( } appBuilder := &AppBuilder{app} - return interfaceRegistry, cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app} + return interfaceRegistry, cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app}, nil } type AppInputs struct { From 4b5de9ea8dd6ca604fe8c6debd4f45e05e884f77 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 17:12:04 -0400 Subject: [PATCH 22/83] updates --- CHANGELOG.md | 2 ++ types/tx_msg.go | 2 +- types/tx_msg_test.go | 2 ++ x/auth/ante/ante.go | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc20506aea3..b1f5425e9a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,6 +146,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * the `codec` types are `Codec` and `InterfaceRegistry` can no longer be overriden without embedding an existing codec type and new methods have been added. * `types/tx.Tx` no longer implements `sdk.Tx`. * `sdk.Tx` now requires a new methods `GetMsgsV2()`. +* (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. +* (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. ### Client Breaking Changes diff --git a/types/tx_msg.go b/types/tx_msg.go index 2068f7396fbb..97f0e6ee0fb0 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -91,7 +91,7 @@ type TxDecoder func(txBytes []byte) (Tx, error) type TxEncoder func(tx Tx) ([]byte, error) // MsgTypeURL returns the TypeURL of a `sdk.Msg`. -func MsgTypeURL(msg Msg) string { +func MsgTypeURL(msg proto.Message) string { if m, ok := msg.(protov2.Message); ok { return "/" + string(m.ProtoReflect().Descriptor().FullName()) } else if m, ok := msg.(proto.Message); ok { diff --git a/types/tx_msg_test.go b/types/tx_msg_test.go index ab12c4554639..6843af7d352f 100644 --- a/types/tx_msg_test.go +++ b/types/tx_msg_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + "google.golang.org/protobuf/types/known/anypb" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -31,6 +32,7 @@ func (s *testMsgSuite) TestMsg() { func (s *testMsgSuite) TestMsgTypeURL() { s.Require().Equal("/testpb.TestMsg", sdk.MsgTypeURL(new(testdata.TestMsg))) + s.Require().Equal("/google.protobuf.Any", sdk.MsgTypeURL(&anypb.Any{})) } func (s *testMsgSuite) TestGetMsgFromTypeURL() { diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 4607ba63d1e9..f3b4ebb6a1bf 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -1,9 +1,10 @@ package ante import ( - errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" From 4d412da40afd30a094184c1d9f473f8195d89d27 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 17:27:44 -0400 Subject: [PATCH 23/83] fix --- server/mock/tx.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/mock/tx.go b/server/mock/tx.go index f9f1c394dc99..4a46060a2ea9 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" + protov2 "google.golang.org/protobuf/proto" + "github.com/cosmos/cosmos-sdk/x/auth/signing" errorsmod "cosmossdk.io/errors" @@ -100,6 +102,10 @@ func (msg *KVStoreTx) GetMsgs() []sdk.Msg { return []sdk.Msg{msg} } +func (msg *KVStoreTx) GetMsgsV2() []protov2.Message { + return []protov2.Message{} +} + func (msg *KVStoreTx) GetSignBytes() []byte { return msg.bytes } From 6c4cb00bb13cefcbc8c27608555314d0231d8c86 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 17:32:52 -0400 Subject: [PATCH 24/83] test fix --- baseapp/baseapp.go | 3 +++ server/mock/tx.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 8704846e3853..877bda951472 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -195,6 +195,9 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() + // initialize with an empty interface registry to avoid nil pointer dereference + app.SetInterfaceRegistry(codectypes.NewInterfaceRegistry()) + return app } diff --git a/server/mock/tx.go b/server/mock/tx.go index 4a46060a2ea9..ded6269ab4dc 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -103,7 +104,7 @@ func (msg *KVStoreTx) GetMsgs() []sdk.Msg { } func (msg *KVStoreTx) GetMsgsV2() []protov2.Message { - return []protov2.Message{} + return []protov2.Message{&bankv1beta1.MsgSend{FromAddress: "test"}} // this is a hack for tests } func (msg *KVStoreTx) GetSignBytes() []byte { From 161ab16d705775acc9eed1ab04fa1d689713c98a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 15 Mar 2023 18:06:07 -0400 Subject: [PATCH 25/83] update x/tx dep --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7f7dbb839e92..e338c901e11c 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f - cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba + cosmossdk.io/x/tx v0.3.0 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 @@ -158,8 +158,6 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) -replace cosmossdk.io/x/tx => ./x/tx - // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/go.sum b/go.sum index 4d1a73892cba..bfb9822b1abb 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.3.0 h1:AgVYy6bxL3XqEV7RLyxFh1uT+wywsrbgVMmYnL3FgWM= +cosmossdk.io/x/tx v0.3.0/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 840e10616682b085b0e579e5f1feda5c22069432 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Mar 2023 11:31:59 -0400 Subject: [PATCH 26/83] update runtime --- runtime/module.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index bb05d19ba4ac..5150e6539512 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -24,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/gogoproto/proto" ) type appModule struct { @@ -83,7 +82,16 @@ func ProvideApp() ( ) { protoFiles, err := proto.MergedRegistry() if err != nil { - return nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, err + } + protoTypes := protoregistry.GlobalTypes + + // At startup, check that all proto annotations are correct. + err = msgservice.ValidateProtoAnnotations(protoFiles) + if err != nil { + // Once we switch to using protoreflect-based antehandlers, we might + // want to panic here instead of logging a warning. + _, _ = fmt.Fprintln(os.Stderr, err.Error()) } interfaceRegistry := codectypes.NewInterfaceRegistryWithProtoFiles(protoFiles) @@ -104,20 +112,6 @@ func ProvideApp() ( } appBuilder := &AppBuilder{app} - protoFiles, err := proto.MergedRegistry() - if err != nil { - panic(err) - } - protoTypes := protoregistry.GlobalTypes - - // At startup, check that all proto annotations are correct. - err = msgservice.ValidateProtoAnnotations(protoFiles) - if err != nil { - // Once we switch to using protoreflect-based antehandlers, we might - // want to panic here instead of logging a warning. - fmt.Fprintln(os.Stderr, err.Error()) - } - return interfaceRegistry, cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app}, protoFiles, protoTypes, nil } From 1c915398ebb57927a3be82fd31ebe5eb40b29e21 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Mar 2023 14:29:42 -0400 Subject: [PATCH 27/83] WIP --- codec/proto_codec.go | 6 +++++- go.mod | 1 - go.sum | 2 ++ x/feegrant/go.sum | 4 ---- x/nft/go.sum | 2 -- x/tx/go.mod | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 9ccbd77b8a4b..f51e79a760ae 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -39,9 +39,13 @@ var ( // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { + getSignersCtx, err := signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry}) + if err != nil { + panic(err) + } return &ProtoCodec{ interfaceRegistry: interfaceRegistry, - getSignersCtx: signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry}), + getSignersCtx: getSignersCtx, } } diff --git a/go.mod b/go.mod index fd1569288350..ff316d070cfc 100644 --- a/go.mod +++ b/go.mod @@ -161,7 +161,6 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( cosmossdk.io/store => ./store - cosmossdk.io/x/tx => ./x/tx // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 992684dfa70f..ef6dce54f15e 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,8 @@ cosmossdk.io/log v0.1.0 h1:Vnexi+KzUCjmqq/m93teAxjt5biWFfZ5PI1imx2IJw8= cosmossdk.io/log v0.1.0/go.mod h1:p95Wq6mDY3SREMc4y7+QU9Uwy3nyvfpWGD1iSaFkVFs= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= +cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= +cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 0547d7286470..2e6b47511eb2 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -186,10 +186,6 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230322203107-65e40ff4dacb h1:EaISkBPki6apzaD2Yjw3HtCOOj/yW4OuG6V3Oig2HlA= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230322203107-65e40ff4dacb/go.mod h1:9zqhqPooktWYyV2CiTFh+uQBVbR+Ozy9cr3KrY5UNHQ= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230324171029-0176e313261d h1:FmHvrGoLwiF/4UviweBbWtpEXcNo6IOjnZMgNHcP4mU= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230324171029-0176e313261d/go.mod h1:X5eCGsQaPQWvFwRzAbneZZaLjnZcral+yoLqAN2QTRI= github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230327134358-9689f9993c7e h1:n3/Z5dwxBnPLrcUiudoxAhASuz7DCGdLQNBpc9dt4jU= github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230327134358-9689f9993c7e/go.mod h1:X5eCGsQaPQWvFwRzAbneZZaLjnZcral+yoLqAN2QTRI= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= diff --git a/x/nft/go.sum b/x/nft/go.sum index 155440b33bbc..1d00ad68797a 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -181,8 +181,6 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230322203107-65e40ff4dacb h1:EaISkBPki6apzaD2Yjw3HtCOOj/yW4OuG6V3Oig2HlA= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230322203107-65e40ff4dacb/go.mod h1:9zqhqPooktWYyV2CiTFh+uQBVbR+Ozy9cr3KrY5UNHQ= github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230327134358-9689f9993c7e h1:n3/Z5dwxBnPLrcUiudoxAhASuz7DCGdLQNBpc9dt4jU= github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230327134358-9689f9993c7e/go.mod h1:X5eCGsQaPQWvFwRzAbneZZaLjnZcral+yoLqAN2QTRI= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= diff --git a/x/tx/go.mod b/x/tx/go.mod index 28b554c90d65..63cefa0c9a99 100644 --- a/x/tx/go.mod +++ b/x/tx/go.mod @@ -8,6 +8,7 @@ require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 + github.com/cosmos/gogoproto v1.4.6 github.com/google/go-cmp v0.5.9 github.com/iancoleman/strcase v0.2.0 github.com/pkg/errors v0.9.1 @@ -19,7 +20,6 @@ require ( ) require ( - github.com/cosmos/gogoproto v1.4.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect From 20d581df701c42b56775fc1779696e2054416a43 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Mar 2023 14:43:03 -0400 Subject: [PATCH 28/83] WIP --- codec/proto_codec.go | 5 ++++- go.mod | 2 +- go.sum | 2 ++ simapp/go.mod | 2 +- simapp/go.sum | 2 ++ tests/go.mod | 2 +- tests/go.sum | 2 ++ tools/confix/go.mod | 2 +- tools/confix/go.sum | 2 ++ tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 2 ++ x/evidence/go.mod | 2 +- x/evidence/go.sum | 2 ++ x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 2 ++ x/nft/go.mod | 2 +- x/nft/go.sum | 2 ++ x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 2 ++ 19 files changed, 31 insertions(+), 10 deletions(-) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index f51e79a760ae..eafb525b6bd1 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -39,7 +39,10 @@ var ( // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - getSignersCtx, err := signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: interfaceRegistry}) + getSignersCtx, err := signing.NewGetSignersContext( + signing.GetSignersOptions{ + ProtoFiles: interfaceRegistry, + }) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index ff316d070cfc..c4712c90ebc8 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1 - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 + cosmossdk.io/x/tx v0.4.0 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index ef6dce54f15e..4eee8409ba70 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index bf109dbdc8d2..9285f6f6ab0f 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 2b051bd0fb4a..aaaa5df1e314 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -204,6 +204,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/go.mod b/tests/go.mod index 24898d3dc262..cc4e9dc3fb7b 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 + cosmossdk.io/x/tx v0.4.0 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index b03bf9d6617e..36e14f5f2090 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,6 +206,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/confix/go.mod b/tools/confix/go.mod index 1dc9827fab71..6e0b581892a7 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -21,7 +21,7 @@ require ( cosmossdk.io/log v0.1.0 // indirect cosmossdk.io/math v1.0.0 // indirect cosmossdk.io/store v0.1.0-alpha.1 // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index 74af7b830697..828d8161c849 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 8d84c9c2468a..de030a10231c 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1 // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index cb891a2e2a63..0b780bb8c8f9 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index a8a20173f532..a7ae75a13f79 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -26,7 +26,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index f043bbb643f9..d6d43b3cf5d6 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 218708d9c3ea..860e6f8b447e 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -27,7 +27,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 2e6b47511eb2..fa070ae20ddd 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/nft/go.mod b/x/nft/go.mod index 2f053b58e05e..12c77c114500 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -25,7 +25,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/log v0.1.0 // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 1d00ad68797a..9cfb33a1e28e 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index d6e62f308625..a2991a4c63f8 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -34,7 +34,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/math v1.0.0 // indirect - cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 // indirect + cosmossdk.io/x/tx v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index dd416155b43f..c615fd9aae09 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -206,6 +206,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5 h1:AlvyRc7f7Py1mv254vrqjIIuykCnitHIz2T+nup3bU0= cosmossdk.io/x/tx v0.3.1-0.20230321155358-6522dd1731b5/go.mod h1:FNkSEMbLP9NFdTfrbslNUtNS7OXf3wgZeJyXzfRPa4c= +cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= +cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 82ba59ed3c5f9e60ea065364ce4bfc4080c723c5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 29 Mar 2023 10:47:52 -0400 Subject: [PATCH 29/83] update x/tx --- go.mod | 2 +- go.sum | 2 ++ simapp/go.mod | 2 +- simapp/go.sum | 2 ++ tests/go.mod | 2 +- tests/go.sum | 2 ++ tools/confix/go.mod | 2 +- tools/confix/go.sum | 2 ++ tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 2 ++ x/evidence/go.mod | 2 +- x/evidence/go.sum | 2 ++ x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 2 ++ x/nft/go.mod | 2 +- x/nft/go.sum | 2 ++ x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 2 ++ 18 files changed, 27 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 70ab9d28e0c1..01f485864673 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.4.0 + cosmossdk.io/x/tx v0.5.0 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 29c5061b81fb..97cee0f011a7 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index c388754ef5fb..40c47b069f24 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 0548a0e0787d..f522bfbb2c43 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -204,6 +204,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/go.mod b/tests/go.mod index 1abc6115f46d..d22869e6ab6c 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.4.0 + cosmossdk.io/x/tx v0.5.0 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index c13fd1d7eae8..9de26481cb0f 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,6 +206,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/confix/go.mod b/tools/confix/go.mod index 6e0b581892a7..866fade48c54 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -21,7 +21,7 @@ require ( cosmossdk.io/log v0.1.0 // indirect cosmossdk.io/math v1.0.0 // indirect cosmossdk.io/store v0.1.0-alpha.1 // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index b611b4b61d74..34fb3af841d9 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index de030a10231c..7aca2dc2c9e5 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1 // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 87701741b522..c6950bbbf15a 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index a7ae75a13f79..35a34032b99b 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -26,7 +26,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 650f2e5a7dfd..937bc85969a3 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index ded4f38fe69d..900e7f01ee1a 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -27,7 +27,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 12e4e9f3f3ce..f23801764ba3 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/nft/go.mod b/x/nft/go.mod index 45ec1665fe61..9573551176a9 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -25,7 +25,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/log v0.1.0 // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 75eb1c8a34e0..b503475a86a6 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index a2991a4c63f8..46896adf7ed1 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -34,7 +34,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/math v1.0.0 // indirect - cosmossdk.io/x/tx v0.4.0 // indirect + cosmossdk.io/x/tx v0.5.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 90140b54f94c..99b609ab8135 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -206,6 +206,8 @@ cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= cosmossdk.io/x/tx v0.4.0 h1:+3dJtaBqd1E7l29xw92SeJRlV018ojiwP7fM9JIEAbk= cosmossdk.io/x/tx v0.4.0/go.mod h1:neRweAjkOjJbHloobxMSnIWtZNvVCc3R8ruDsVdJmEY= +cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= +cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From e5b17aaf36a038acac7ba55b4c540da8f8a983f2 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 3 Apr 2023 12:02:14 -0400 Subject: [PATCH 30/83] WIP on bug fixes --- baseapp/baseapp.go | 2 +- baseapp/testutil/messages.pb.go | 161 ++++++++++++++++++++++++++------ baseapp/testutil/messages.proto | 8 ++ go.mod | 2 +- types/tx/types.go | 4 +- x/auth/tx/builder.go | 38 +++++--- x/auth/tx/decoder.go | 1 + 7 files changed, 172 insertions(+), 44 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 9d31705ddaa0..d6f76b06d28f 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -196,7 +196,7 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() // initialize with an empty interface registry to avoid nil pointer dereference - app.SetInterfaceRegistry(codectypes.NewInterfaceRegistry()) + app.cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) return app } diff --git a/baseapp/testutil/messages.pb.go b/baseapp/testutil/messages.pb.go index 6ab32a7ce418..2884ff0f649a 100644 --- a/baseapp/testutil/messages.pb.go +++ b/baseapp/testutil/messages.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -30,8 +31,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MsgCounter struct { - Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` - FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` + FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgCounter) Reset() { *m = MsgCounter{} } @@ -81,9 +83,17 @@ func (m *MsgCounter) GetFailOnHandler() bool { return false } +func (m *MsgCounter) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + type MsgCounter2 struct { - Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` - FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` + FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgCounter2) Reset() { *m = MsgCounter2{} } @@ -133,6 +143,13 @@ func (m *MsgCounter2) GetFailOnHandler() bool { return false } +func (m *MsgCounter2) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + type MsgCreateCounterResponse struct { } @@ -276,30 +293,32 @@ func init() { func init() { proto.RegisterFile("messages.proto", fileDescriptor_4dc296cbfe5ffcd5) } var fileDescriptor_4dc296cbfe5ffcd5 = []byte{ - // 364 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x4f, 0x6b, 0xe2, 0x50, - 0x14, 0xc5, 0xcd, 0x84, 0x51, 0xe7, 0xea, 0xcc, 0x48, 0x90, 0x21, 0x66, 0x20, 0x48, 0x16, 0x83, - 0x1b, 0x13, 0xc8, 0xec, 0xc6, 0xdd, 0x0c, 0x83, 0x2d, 0xc5, 0x0a, 0x29, 0x74, 0xd1, 0x8d, 0xbc, - 0xc4, 0xeb, 0x33, 0x98, 0xbc, 0x17, 0xf2, 0x5e, 0x0a, 0x7e, 0x8b, 0x7e, 0xac, 0x2e, 0x5d, 0x76, - 0x59, 0xf4, 0x8b, 0x94, 0xfc, 0xd3, 0x2e, 0x6a, 0x57, 0x5d, 0xe5, 0x9c, 0x73, 0xc9, 0xef, 0xe4, - 0x5e, 0x02, 0xdf, 0x62, 0x14, 0x82, 0x50, 0x14, 0x76, 0x92, 0x72, 0xc9, 0x8d, 0x3e, 0xe5, 0x94, - 0x17, 0xd2, 0xc9, 0x55, 0x95, 0x0e, 0x28, 0xe7, 0x34, 0x42, 0xa7, 0x70, 0x7e, 0xb6, 0x72, 0x08, - 0xdb, 0x96, 0x23, 0xeb, 0x1a, 0x60, 0x26, 0xe8, 0x3f, 0x9e, 0x31, 0x89, 0xa9, 0xa6, 0x43, 0x2b, - 0x28, 0xa5, 0xae, 0x0c, 0x95, 0x91, 0xea, 0xd5, 0x56, 0xfb, 0x05, 0xdf, 0x57, 0x24, 0x8c, 0x16, - 0x9c, 0x2d, 0xd6, 0x84, 0x2d, 0x23, 0x4c, 0xf5, 0x4f, 0x43, 0x65, 0xd4, 0xf6, 0xbe, 0xe6, 0xf1, - 0x9c, 0x5d, 0x94, 0xa1, 0x35, 0x87, 0xce, 0x89, 0xe7, 0x7e, 0x00, 0xd0, 0x00, 0x3d, 0x07, 0xa6, - 0x48, 0x24, 0x56, 0x58, 0x0f, 0x45, 0xc2, 0x99, 0x40, 0x6b, 0x56, 0x94, 0x5d, 0xe1, 0xf6, 0x96, - 0x44, 0x19, 0x6a, 0x3d, 0x50, 0x37, 0xb8, 0x2d, 0x8a, 0xba, 0x5e, 0x2e, 0xb5, 0x3e, 0x7c, 0xbe, - 0xcf, 0x47, 0x05, 0xba, 0xeb, 0x95, 0x46, 0xfb, 0x01, 0x4d, 0x11, 0x52, 0x86, 0xa9, 0xae, 0x0e, - 0x95, 0xd1, 0x17, 0xaf, 0x72, 0xd6, 0x4f, 0x18, 0x1c, 0xab, 0x6a, 0x68, 0xdd, 0xe5, 0xfe, 0x87, - 0x56, 0x7d, 0xa5, 0x3f, 0xd0, 0xbb, 0x64, 0x41, 0x8a, 0x31, 0x32, 0x59, 0x67, 0x1d, 0xfb, 0xb4, - 0xb6, 0x31, 0xb0, 0xcf, 0x7d, 0xb2, 0x3b, 0x85, 0xf6, 0xf1, 0x38, 0x93, 0x37, 0x38, 0xdd, 0x57, - 0x1c, 0xf7, 0x3d, 0xd0, 0x04, 0xda, 0xc7, 0xc5, 0x1d, 0x50, 0x6f, 0x50, 0x96, 0xef, 0xd6, 0xa1, - 0x61, 0xd8, 0x67, 0x97, 0xf9, 0x3b, 0x7d, 0xdc, 0x9b, 0xca, 0x6e, 0x6f, 0x2a, 0xcf, 0x7b, 0x53, - 0x79, 0x38, 0x98, 0x8d, 0xdd, 0xc1, 0x6c, 0x3c, 0x1d, 0xcc, 0xc6, 0xdd, 0x98, 0x86, 0x72, 0x9d, - 0xf9, 0x76, 0xc0, 0x63, 0x27, 0xe0, 0x22, 0xe6, 0xa2, 0x7a, 0x8c, 0xc5, 0x72, 0xe3, 0xf8, 0x44, - 0x20, 0x49, 0x12, 0x47, 0xa2, 0x90, 0x99, 0x0c, 0x23, 0xbf, 0x59, 0xfc, 0x45, 0xbf, 0x5f, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x23, 0xdc, 0x12, 0x4d, 0x88, 0x02, 0x00, 0x00, + // 390 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x92, 0xcf, 0xaa, 0xd3, 0x40, + 0x14, 0xc6, 0x1b, 0x83, 0x6d, 0x3d, 0xad, 0x5a, 0x42, 0xd1, 0x34, 0x42, 0x28, 0x5d, 0x48, 0x11, + 0x9a, 0xc1, 0xb8, 0x6b, 0x77, 0x8a, 0x54, 0x11, 0x11, 0x22, 0xb8, 0xe8, 0xa6, 0x4c, 0xd2, 0xd3, + 0x69, 0x68, 0x32, 0x13, 0x32, 0x93, 0x42, 0xb7, 0x3e, 0x81, 0x8f, 0xe2, 0x63, 0xb8, 0xec, 0xd2, + 0xa5, 0xb4, 0x0b, 0x5f, 0x43, 0xf2, 0xaf, 0x75, 0x71, 0x7b, 0xb9, 0xab, 0xbb, 0x9a, 0xf3, 0x7d, + 0x87, 0x9c, 0xdf, 0xc9, 0xc7, 0x81, 0x27, 0x31, 0x4a, 0x49, 0x19, 0x4a, 0x27, 0x49, 0x85, 0x12, + 0x56, 0x9f, 0x09, 0x26, 0x8a, 0x92, 0xe4, 0x55, 0xe5, 0x0e, 0x98, 0x10, 0x2c, 0x42, 0x52, 0x28, + 0x3f, 0x5b, 0x13, 0xca, 0xf7, 0x55, 0xeb, 0x79, 0x20, 0x64, 0x2c, 0x24, 0x89, 0x25, 0x23, 0xbb, + 0xd7, 0xf9, 0x53, 0x36, 0x46, 0x12, 0xe0, 0xb3, 0x64, 0xef, 0x44, 0xc6, 0x15, 0xa6, 0x86, 0x09, + 0xad, 0xa0, 0x2c, 0x4d, 0x6d, 0xa8, 0x8d, 0x75, 0xaf, 0x96, 0xc6, 0x4b, 0x78, 0xba, 0xa6, 0x61, + 0xb4, 0x14, 0x7c, 0xb9, 0xa1, 0x7c, 0x15, 0x61, 0x6a, 0x3e, 0x18, 0x6a, 0xe3, 0xb6, 0xf7, 0x38, + 0xb7, 0xbf, 0xf0, 0x0f, 0xa5, 0x69, 0x3c, 0x83, 0xa6, 0x0c, 0x19, 0xc7, 0xd4, 0xd4, 0x87, 0xda, + 0xf8, 0x91, 0x57, 0xa9, 0x69, 0xe7, 0xfb, 0xdf, 0x9f, 0xaf, 0x2a, 0x31, 0x52, 0xd0, 0xb9, 0x40, + 0xdd, 0xfb, 0xa2, 0x5a, 0x60, 0xe6, 0xd4, 0x14, 0xa9, 0xc2, 0x8a, 0xed, 0xa1, 0x4c, 0x04, 0x97, + 0x38, 0x5a, 0x14, 0x1b, 0x7d, 0xc2, 0xfd, 0x37, 0x1a, 0x65, 0x68, 0xf4, 0x40, 0xdf, 0xe2, 0xbe, + 0xd8, 0xa6, 0xeb, 0xe5, 0xa5, 0xd1, 0x87, 0x87, 0xbb, 0xbc, 0x55, 0xf0, 0xbb, 0x5e, 0x29, 0xee, + 0xc6, 0x7d, 0x01, 0x83, 0x33, 0xb7, 0x26, 0xd4, 0x60, 0xf7, 0x3d, 0xb4, 0xea, 0xf0, 0xa7, 0xd0, + 0xfb, 0xc8, 0x83, 0x14, 0x63, 0xe4, 0xaa, 0xf6, 0x3a, 0xce, 0x25, 0x28, 0x6b, 0xe0, 0x5c, 0xdb, + 0xdf, 0x9d, 0x43, 0xfb, 0x1c, 0xe7, 0xec, 0x86, 0x39, 0xdd, 0xff, 0xe6, 0xb8, 0xb7, 0x0d, 0x9a, + 0x41, 0xfb, 0x9c, 0x02, 0x01, 0xfd, 0x2b, 0xaa, 0xf2, 0xdb, 0xda, 0xb4, 0x2c, 0xe7, 0xea, 0xcf, + 0xbc, 0x9d, 0xff, 0x3a, 0xda, 0xda, 0xe1, 0x68, 0x6b, 0x7f, 0x8e, 0xb6, 0xf6, 0xe3, 0x64, 0x37, + 0x0e, 0x27, 0xbb, 0xf1, 0xfb, 0x64, 0x37, 0x16, 0x13, 0x16, 0xaa, 0x4d, 0xe6, 0x3b, 0x81, 0x88, + 0x49, 0x75, 0x8a, 0xe5, 0x33, 0x91, 0xab, 0x2d, 0xf1, 0xa9, 0x44, 0x9a, 0x24, 0x44, 0xa1, 0x54, + 0x99, 0x0a, 0x23, 0xbf, 0x59, 0x1c, 0xe7, 0x9b, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x44, 0x91, + 0x2d, 0xb3, 0xf8, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -546,6 +565,13 @@ func (m *MsgCounter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintMessages(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } if m.FailOnHandler { i-- if m.FailOnHandler { @@ -584,6 +610,13 @@ func (m *MsgCounter2) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintMessages(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } if m.FailOnHandler { i-- if m.FailOnHandler { @@ -715,6 +748,10 @@ func (m *MsgCounter) Size() (n int) { if m.FailOnHandler { n += 2 } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovMessages(uint64(l)) + } return n } @@ -730,6 +767,10 @@ func (m *MsgCounter2) Size() (n int) { if m.FailOnHandler { n += 2 } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovMessages(uint64(l)) + } return n } @@ -846,6 +887,38 @@ func (m *MsgCounter) Unmarshal(dAtA []byte) error { } } m.FailOnHandler = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessages + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMessages + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMessages + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMessages(dAtA[iNdEx:]) @@ -935,6 +1008,38 @@ func (m *MsgCounter2) Unmarshal(dAtA []byte) error { } } m.FailOnHandler = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessages + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMessages + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMessages + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMessages(dAtA[iNdEx:]) diff --git a/baseapp/testutil/messages.proto b/baseapp/testutil/messages.proto index 6a04a94e5c2b..c707f9ab88e3 100644 --- a/baseapp/testutil/messages.proto +++ b/baseapp/testutil/messages.proto @@ -2,22 +2,30 @@ syntax = "proto3"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; +import "cosmos/msg/v1/msg.proto"; option go_package = "github.com/cosmos/cosmos-sdk/baseapp/testutil"; message MsgCounter { + option (cosmos.msg.v1.signer) = "signer"; + int64 counter = 1; bool fail_on_handler = 2; + string signer = 3; } message MsgCounter2 { + option (cosmos.msg.v1.signer) = "signer"; + int64 counter = 1; bool fail_on_handler = 2; + string signer = 3; } message MsgCreateCounterResponse {} message MsgKeyValue { + option (cosmos.msg.v1.signer) = "signer"; bytes key = 1; bytes value = 2; string signer = 3; diff --git a/go.mod b/go.mod index e518e9532b7d..0125d45cd732 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 + github.com/google/go-cmp v0.5.9 github.com/google/gofuzz v1.2.0 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 @@ -102,7 +103,6 @@ require ( github.com/golang/glog v1.0.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect - github.com/google/go-cmp v0.5.9 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect diff --git a/types/tx/types.go b/types/tx/types.go index ffef137d299f..0d41ed53d96a 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -40,14 +40,14 @@ func (t *Tx) GetSigners(codec codec.Codec) ([]string, []protov2.Message, error) var msgsv2 []protov2.Message for _, msg := range t.Body.Messages { - signers, msgv2, err := codec.GetMsgAnySigners(msg) + xs, msgv2, err := codec.GetMsgAnySigners(msg) if err != nil { return nil, nil, err } msgsv2 = append(msgsv2, msgv2) - for _, signer := range signers { + for _, signer := range xs { if !seen[signer] { signers = append(signers, signer) seen[signer] = true diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 70ad8df61ea5..4bcfe0b8c658 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -59,7 +59,7 @@ type ExtensionOptionsTxBuilder interface { } func newBuilder(cdc codec.Codec) *wrapper { - return &wrapper{ + w := &wrapper{ cdc: cdc, tx: &tx.Tx{ Body: &tx.TxBody{}, @@ -68,6 +68,7 @@ func newBuilder(cdc codec.Codec) *wrapper { }, }, } + return w } func (w *wrapper) GetMsgs() []sdk.Msg { @@ -75,6 +76,10 @@ func (w *wrapper) GetMsgs() []sdk.Msg { } func (w *wrapper) GetMsgsV2() []protov2.Message { + if w.msgsV2 == nil { + w.initSignersAndMsgsV2() + } + return w.msgsV2 } @@ -175,19 +180,24 @@ func (w *wrapper) getAuthInfoBytes() []byte { return w.authInfoBz } -func (w *wrapper) GetSigners() []sdk.AccAddress { - if w.signers == nil { - signers, msgV2, err := w.tx.GetSigners(w.cdc) - if err != nil { - panic(err) - } +func (w *wrapper) initSignersAndMsgsV2() { + signers, msgV2, err := w.tx.GetSigners(w.cdc) + if err != nil { + panic(err) + } - w.msgsV2 = msgV2 + w.msgsV2 = msgV2 + w.signers = nil - for _, signer := range signers { - signerBz := sdk.MustAccAddressFromBech32(signer) - w.signers = append(w.signers, signerBz) - } + for _, signer := range signers { + signerBz := sdk.MustAccAddressFromBech32(signer) + w.signers = append(w.signers, signerBz) + } +} + +func (w *wrapper) GetSigners() []sdk.AccAddress { + if w.signers == nil { + w.initSignersAndMsgsV2() } return w.signers } @@ -300,6 +310,10 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { // set bodyBz to nil because the cached bodyBz no longer matches tx.Body w.bodyBz = nil + // reset signers and msgsV2 + w.signers = nil + w.msgsV2 = nil + return nil } diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index 2bfd2fbe95e2..0315205288a9 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -73,6 +73,7 @@ func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder { bodyBz: raw.BodyBytes, authInfoBz: raw.AuthInfoBytes, txBodyHasUnknownNonCriticals: txBodyHasUnknownNonCriticals, + cdc: cdc, }, nil } } From ad6af682da775220ea62b643de1f0c8087b9471b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 3 Apr 2023 12:43:36 -0400 Subject: [PATCH 31/83] refactor sdk.AccAddress usages to string --- server/mock/tx.go | 2 +- tests/e2e/auth/suite.go | 4 +-- tests/e2e/tx/service_test.go | 2 +- types/mempool/mempool_test.go | 4 +-- types/result.go | 5 ++-- types/tx_msg.go | 13 +++++++--- x/auth/ante/ante_test.go | 2 +- x/auth/ante/basic.go | 7 ++++- x/auth/ante/fee.go | 10 ++++---- x/auth/ante/sigverify.go | 40 +++++++++++++++++++++-------- x/auth/client/cli/suite_test.go | 4 +-- x/auth/client/cli/validate_sigs.go | 4 +-- x/auth/client/tx.go | 8 +++--- x/auth/posthandler/tips.go | 2 +- x/auth/signing/sig_verifiable_tx.go | 2 +- x/auth/tx/aux_test.go | 2 +- x/auth/tx/builder.go | 31 +++++++++------------- x/auth/tx/direct_aux.go | 2 +- x/auth/tx/testutil/suite.go | 2 +- 19 files changed, 85 insertions(+), 61 deletions(-) diff --git a/server/mock/tx.go b/server/mock/tx.go index 33c65ea1e3cc..003d2f24f501 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -116,7 +116,7 @@ func (msg *KVStoreTx) ValidateBasic() error { return nil } -func (msg *KVStoreTx) GetSigners() []sdk.AccAddress { +func (msg *KVStoreTx) GetSigners() []string { return nil } diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 7097851bad74..aaa352f4cea7 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -741,7 +741,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal(val1.Address.String(), txBuilder.GetTx().GetSigners()[0].String()) + s.Require().Equal(val1.Address.String(), txBuilder.GetTx().GetSigners()[0]) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -1572,7 +1572,7 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - require.Equal([]sdk.AccAddress{val0.Address, val1.Address}, txBuilder.GetTx().GetSigners()) + require.Equal([]string{val0.Address.String(), val1.Address.String()}, txBuilder.GetTx().GetSigners()) // Write the unsigned tx into a file. txJSON, err := val0.ClientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 3295032363d1..fb876162940a 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -1097,7 +1097,7 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo("foobar") - s.Require().Equal([]sdk.AccAddress{val.Address}, txBuilder.GetTx().GetSigners()) + s.Require().Equal([]string{val.Address.String()}, txBuilder.GetTx().GetSigners()) // setup txFactory txFactory := clienttx.Factory{}. diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index 9a08c1b92872..5845a2e80f0b 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -54,7 +54,7 @@ type testTx struct { strAddress string } -func (tx testTx) GetSigners() []sdk.AccAddress { panic("not implemented") } +func (tx testTx) GetSigners() []string { panic("not implemented") } func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("not implemented") } @@ -96,7 +96,7 @@ func (sigErrTx) GetMsgsV2() []protov2.Message { return nil } func (sigErrTx) ValidateBasic() error { return nil } -func (sigErrTx) GetSigners() []sdk.AccAddress { return nil } +func (sigErrTx) GetSigners() []string { return nil } func (sigErrTx) GetPubKeys() ([]cryptotypes.PubKey, error) { return nil, nil } diff --git a/types/result.go b/types/result.go index 56e3ef7879ed..31d3784799a9 100644 --- a/types/result.go +++ b/types/result.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/gogoproto/proto" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -189,8 +190,8 @@ func (r TxResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } // GetTx unpacks the Tx from within a TxResponse and returns it -func (r TxResponse) GetTx() Tx { - if tx, ok := r.Tx.GetCachedValue().(Tx); ok { +func (r TxResponse) GetTx() HasMsgs { + if tx, ok := r.Tx.GetCachedValue().(HasMsgs); ok { return tx } return nil diff --git a/types/tx_msg.go b/types/tx_msg.go index 97f0e6ee0fb0..69deb2b22b22 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -47,10 +47,15 @@ type ( GetSignature() []byte } - // Tx defines the interface a transaction must fulfill. - Tx interface { + // HasMsgs defines an interface a transaction must fulfill. + HasMsgs interface { // GetMsgs gets the all the transaction's messages. GetMsgs() []Msg + } + + // Tx defines an interface a transaction must fulfill. + Tx interface { + HasMsgs // GetMsgsV2 gets the transaction's messages as google.golang.org/protobuf/proto.Message's. GetMsgsV2() []protov2.Message @@ -65,8 +70,8 @@ type ( Tx GetGas() uint64 GetFee() Coins - FeePayer() AccAddress - FeeGranter() AccAddress + FeePayer() string + FeeGranter() string } // TxWithMemo must have GetMemo() method to use ValidateMemoDecorator diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index dd6d2dd5a149..f23247835fdf 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -125,7 +125,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { require.NoError(t, err) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 - expectedSigners := []sdk.AccAddress{addr0, addr1, addr2} + expectedSigners := []string{addr0.String(), addr1.String(), addr2.String()} require.Equal(t, expectedSigners, tx.GetSigners()) return TestCaseArgs{ diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 8d335fc32b01..8bc80d3c28bd 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -116,7 +116,12 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim var pubkey cryptotypes.PubKey - acc := cgts.ak.GetAccount(ctx, signer) + signerAddr, err := sdk.AccAddressFromBech32(signer) + if err != nil { + return ctx, err + } + + acc := cgts.ak.GetAccount(ctx, signerAddr) // use placeholder simSecp256k1Pubkey if sig is nil if acc == nil || acc.GetPubKey() == nil { diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index c7404a5d6ed0..7aa627e3335b 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -85,11 +85,11 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee // if feegranter set deduct fee from feegranter account. // this works with only when feegrant enabled. - if feeGranter != nil { + if feeGranter != "" { if dfd.feegrantKeeper == nil { return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled") - } else if !feeGranter.Equals(feePayer) { - err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, sdkTx.GetMsgs()) + } else if feeGranter != feePayer { + err := dfd.feegrantKeeper.UseGrantedFees(ctx, sdk.MustAccAddressFromBech32(feeGranter), sdk.MustAccAddressFromBech32(feePayer), fee, sdkTx.GetMsgs()) if err != nil { return errorsmod.Wrapf(err, "%s does not allow to pay fees for %s", feeGranter, feePayer) } @@ -98,7 +98,7 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee deductFeesFrom = feeGranter } - deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, deductFeesFrom) + deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, sdk.MustAccAddressFromBech32(deductFeesFrom)) if deductFeesFromAcc == nil { return sdkerrors.ErrUnknownAddress.Wrapf("fee payer address: %s does not exist", deductFeesFrom) } @@ -115,7 +115,7 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.NewEvent( sdk.EventTypeTx, sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), - sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom.String()), + sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom), ), } ctx.EventManager().EmitEvents(events) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 422dde1f9978..932bbfdae148 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -75,12 +75,17 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b pk = simSecp256k1Pubkey } // Only make check if simulate=false - if !simulate && !bytes.Equal(pk.Address(), signers[i]) { + signerAddr, err := sdk.AccAddressFromBech32(signers[i]) + if err != nil { + return ctx, err + } + + if !simulate && !bytes.Equal(pk.Address(), signerAddr) { return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "pubKey does not match signer address %s with signer index: %d", signers[i], i) } - acc, err := GetSignerAcc(ctx, spkd.ak, signers[i]) + acc, err := GetSignerAcc(ctx, spkd.ak, signerAddr) if err != nil { return ctx, err } @@ -160,10 +165,15 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. - signerAddrs := sigTx.GetSigners() + signers := sigTx.GetSigners() for i, sig := range sigs { - signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signerAddrs[i]) + signerAddr, err := sdk.AccAddressFromBech32(signers[i]) + if err != nil { + return ctx, err + } + + signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signerAddr) if err != nil { return ctx, err } @@ -245,15 +255,20 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul return ctx, err } - signerAddrs := sigTx.GetSigners() + signers := sigTx.GetSigners() // check that signer length and signature length are the same - if len(sigs) != len(signerAddrs) { - return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) + if len(sigs) != len(signers) { + return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signers), len(sigs)) } for i, sig := range sigs { - acc, err := GetSignerAcc(ctx, svd.ak, signerAddrs[i]) + signerAddr, err := sdk.AccAddressFromBech32(signers[i]) + if err != nil { + return ctx, err + } + + acc, err := GetSignerAcc(ctx, svd.ak, signerAddr) if err != nil { return ctx, err } @@ -334,8 +349,13 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } // increment sequence of all signers - for _, addr := range sigTx.GetSigners() { - acc := isd.ak.GetAccount(ctx, addr) + for _, signer := range sigTx.GetSigners() { + signerAddr, err := sdk.AccAddressFromBech32(signer) + if err != nil { + return ctx, err + } + + acc := isd.ak.GetAccount(ctx, signerAddr) if err := acc.SetSequence(acc.GetSequence() + 1); err != nil { panic(err) } diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index cf40d0a258e6..b7ead6e564db 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -405,7 +405,7 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal(s.val.String(), txBuilder.GetTx().GetSigners()[0].String()) + s.Require().Equal(s.val.String(), txBuilder.GetTx().GetSigners()[0]) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -913,7 +913,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - s.Require().Equal([]sdk.AccAddress{val0, val1}, txBuilder.GetTx().GetSigners()) + s.Require().Equal([]string{val0.String(), val1.String()}, txBuilder.GetTx().GetSigners()) // Write the unsigned tx into a file. txJSON, err := s.clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 6a0b8156c7ff..b0b4820be546 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -66,7 +66,7 @@ func printAndValidateSigs( cmd.Println("Signers:") signers := sigTx.GetSigners() for i, signer := range signers { - cmd.Printf(" %v: %v\n", i, signer.String()) + cmd.Printf(" %v: %v\n", i, signer) } success := true @@ -90,7 +90,7 @@ func printAndValidateSigs( sigSanity = "OK" ) - if i >= len(signers) || !sigAddr.Equals(signers[i]) { + if i >= len(signers) || sigAddr.String() != signers[i] { sigSanity = "ERROR: signature does not match its respective signer" success = false } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 7a3cf8863618..6e0dc162fdeb 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -48,7 +48,7 @@ func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuild return err } addr := sdk.AccAddress(pubKey.Address()) - if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { + if !isTxSigner(addr.String(), txBuilder.GetTx().GetSigners()) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } if !offline { @@ -75,7 +75,7 @@ func SignTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, add } // check whether the address is a signer - if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { + if !isTxSigner(addr.String(), txBuilder.GetTx().GetSigners()) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } @@ -189,9 +189,9 @@ func ParseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { return simRes, nil } -func isTxSigner(user sdk.AccAddress, signers []sdk.AccAddress) bool { +func isTxSigner(user string, signers []string) bool { for _, s := range signers { - if bytes.Equal(user.Bytes(), s.Bytes()) { + if user == s { return true } } diff --git a/x/auth/posthandler/tips.go b/x/auth/posthandler/tips.go index 33a5f69e9081..231322bc45b4 100644 --- a/x/auth/posthandler/tips.go +++ b/x/auth/posthandler/tips.go @@ -54,5 +54,5 @@ func (d tipDecorator) transferTip(ctx sdk.Context, sdkTx sdk.Tx) error { return fmt.Errorf("cannot tip these coins: %w", err) } - return d.bankKeeper.SendCoins(ctx, tipper, tipTx.FeePayer(), coins) + return d.bankKeeper.SendCoins(ctx, tipper, sdk.MustAccAddressFromBech32(tipTx.FeePayer()), coins) } diff --git a/x/auth/signing/sig_verifiable_tx.go b/x/auth/signing/sig_verifiable_tx.go index 1686ab93bd32..15406723d2a3 100644 --- a/x/auth/signing/sig_verifiable_tx.go +++ b/x/auth/signing/sig_verifiable_tx.go @@ -11,7 +11,7 @@ import ( // handlers. type SigVerifiableTx interface { types.Tx - GetSigners() []types.AccAddress + GetSigners() []string GetPubKeys() ([]cryptotypes.PubKey, error) // If signer already has pubkey in context, this list will have nil in its place GetSignaturesV2() ([]signing.SignatureV2, error) } diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 97416a9df891..eef7d1afe67f 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -159,7 +159,7 @@ func TestBuilderWithAux(t *testing.T) { require.NoError(t, err) tx, err := txConfig.TxDecoder()(txBz) require.NoError(t, err) - require.Equal(t, tx.(sdk.FeeTx).FeePayer(), feepayerAddr) + require.Equal(t, tx.(sdk.FeeTx).FeePayer(), feepayerAddr.String()) require.Equal(t, tx.(sdk.FeeTx).GetFee(), fee) require.Equal(t, tx.(sdk.FeeTx).GetGas(), gas) require.Equal(t, tip, tx.(txtypes.TipTx).GetTip()) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 4bcfe0b8c658..c9cbbb0514a2 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -37,7 +37,7 @@ type wrapper struct { txBodyHasUnknownNonCriticals bool - signers []sdk.AccAddress + signers []string msgsV2 []protov2.Message } @@ -181,21 +181,14 @@ func (w *wrapper) getAuthInfoBytes() []byte { } func (w *wrapper) initSignersAndMsgsV2() { - signers, msgV2, err := w.tx.GetSigners(w.cdc) + var err error + w.signers, w.msgsV2, err = w.tx.GetSigners(w.cdc) if err != nil { panic(err) } - - w.msgsV2 = msgV2 - w.signers = nil - - for _, signer := range signers { - signerBz := sdk.MustAccAddressFromBech32(signer) - w.signers = append(w.signers, signerBz) - } } -func (w *wrapper) GetSigners() []sdk.AccAddress { +func (w *wrapper) GetSigners() []string { if w.signers == nil { w.initSignersAndMsgsV2() } @@ -233,21 +226,21 @@ func (w *wrapper) GetFee() sdk.Coins { return w.tx.AuthInfo.Fee.Amount } -func (w *wrapper) FeePayer() sdk.AccAddress { +func (w *wrapper) FeePayer() string { feePayer := w.tx.AuthInfo.Fee.Payer if feePayer != "" { - return sdk.MustAccAddressFromBech32(feePayer) + return feePayer } // use first signer as default if no payer specified return w.GetSigners()[0] } -func (w *wrapper) FeeGranter() sdk.AccAddress { - feePayer := w.tx.AuthInfo.Fee.Granter - if feePayer != "" { - return sdk.MustAccAddressFromBech32(feePayer) +func (w *wrapper) FeeGranter() string { + feeGranter := w.tx.AuthInfo.Fee.Granter + if feeGranter != "" { + return feeGranter } - return nil + return "" } func (w *wrapper) GetTip() *tx.Tip { @@ -551,7 +544,7 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error { // Get the aux signer's index in GetSigners. signerIndex := -1 for i, signer := range w.GetSigners() { - if signer.String() == data.Address { + if signer == data.Address { signerIndex = i } } diff --git a/x/auth/tx/direct_aux.go b/x/auth/tx/direct_aux.go index ff09cfd2b81c..702ef7b8d1d4 100644 --- a/x/auth/tx/direct_aux.go +++ b/x/auth/tx/direct_aux.go @@ -51,7 +51,7 @@ func (signModeDirectAuxHandler) GetSignBytes( return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "got empty address in %s handler", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX) } - feePayer := protoTx.FeePayer().String() + feePayer := protoTx.FeePayer() // Fee payer cannot use SIGN_MODE_DIRECT_AUX, because SIGN_MODE_DIRECT_AUX // does not sign over fees, which would create malleability issues. diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 924f2366ca3b..371b609e9e3f 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -73,7 +73,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { tx := txBuilder.GetTx() s.Require().Equal(msgs, tx.GetMsgs()) s.Require().Equal([]sdk.AccAddress{addr1, addr2}, tx.GetSigners()) - s.Require().Equal(addr1, tx.FeePayer()) + s.Require().Equal(addr1.String(), tx.FeePayer()) s.Require().Error(tx.ValidateBasic()) // should fail because of no signatures } From b618ad4ef7fe87af09131008ae93bfb88e703c61 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 3 Apr 2023 15:55:56 -0400 Subject: [PATCH 32/83] refactor MsgCreateValidator.validator_address to use account address --- CHANGELOG.md | 1 + proto/cosmos/staking/v1beta1/tx.proto | 2 ++ x/genutil/collect.go | 6 +++--- x/staking/keeper/msg_server.go | 4 +++- x/staking/simulation/operations_test.go | 7 ++++--- x/staking/types/msg.go | 16 ++-------------- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9987126c06f9..edafea95ba5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/feegrant) [#14294](https://github.com/cosmos/cosmos-sdk/pull/14294) Moved the logic of rejecting duplicate grant from `msg_server` to `keeper` method. * (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) `MsgUndelegateResponse` now includes undelegated amount. `x/staking` module's `keeper.Undelegate` now returns 3 values (completionTime,undelegateAmount,error) instead of 2. +* (x/staking) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `MsgCreateValidator.validator_address` must now be encoded as a bech32 account address instead of a bech32 `valoper` address. ### API Breaking Changes diff --git a/proto/cosmos/staking/v1beta1/tx.proto b/proto/cosmos/staking/v1beta1/tx.proto index 0c6a7b19bcd7..133b52c91242 100644 --- a/proto/cosmos/staking/v1beta1/tx.proto +++ b/proto/cosmos/staking/v1beta1/tx.proto @@ -67,6 +67,8 @@ message MsgCreateValidator { // The validator address bytes and delegator address bytes refer to the same account while creating validator (defer // only in bech32 notation). string delegator_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString", deprecated = true]; + + // validator_address is the address of the validator encoded as a bech32 account address. string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 9d99559375c2..e0b19698744b 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -132,14 +132,14 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx msg := msgs[0].(*stakingtypes.MsgCreateValidator) // validate validator addresses and funds against the accounts in the state - valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + valAccAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) if err != nil { return appGenTxs, persistentPeers, err } - valAccAddr := sdk.AccAddress(valAddr).String() + valAddr := sdk.ValAddress(valAccAddr) - delBal, delOk := balancesMap[valAccAddr] + delBal, delOk := balancesMap[msg.ValidatorAddress] if !delOk { _, file, no, ok := runtime.Caller(1) if ok { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 8f97e1d0ac7a..5d6a2318041d 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -35,11 +35,13 @@ var _ types.MsgServer = msgServer{} func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + valAccAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) if err != nil { return nil, err } + valAddr := sdk.ValAddress(valAccAddr) + if msg.Commission.Rate.LT(k.MinCommissionRate(ctx)) { return nil, errorsmod.Wrapf(types.ErrCommissionLTMinRate, "cannot set validator commission to less than minimum rate of %s", k.MinCommissionRate(ctx)) } diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 2ccfe937d738..dbb324734de8 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -13,6 +13,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" @@ -169,10 +170,10 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { require.True(operationMsg.OK) require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(&msg)) - valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + valaddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) require.NoError(err) - require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) - require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) + require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ValidatorAddress) + require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", sdk.ValAddress(valaddr).String()) require.Len(futureOperations, 0) } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 5a8a765020e3..54230bc48e1b 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -45,7 +45,7 @@ func NewMsgCreateValidator( } return &MsgCreateValidator{ Description: description, - ValidatorAddress: valAddr.String(), + ValidatorAddress: sdk.AccAddress(valAddr).String(), Pubkey: pkAny, Value: selfDelegation, Commission: commission, @@ -53,18 +53,6 @@ func NewMsgCreateValidator( }, nil } -// GetSigners implements the sdk.Msg interface. It returns the address(es) that -// must sign over msg.GetSignBytes(). -// If the validator address is not same as delegator's, then the validator must -// sign the msg as well. -func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { - valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) - - valAccAddr := sdk.AccAddress(valAddr) - - return []sdk.AccAddress{valAccAddr} -} - // GetSignBytes returns the message bytes to sign over. func (msg MsgCreateValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -74,7 +62,7 @@ func (msg MsgCreateValidator) GetSignBytes() []byte { // ValidateBasic implements the sdk.Msg interface. func (msg MsgCreateValidator) ValidateBasic() error { // note that unmarshaling from bech32 ensures both non-empty and valid - _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + _, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) if err != nil { return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) } From 843f04fec810130dc062011020515fd5fbd0628c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 3 Apr 2023 16:24:22 -0400 Subject: [PATCH 33/83] test fixes --- api/cosmos/staking/v1beta1/tx.pulsar.go | 3 ++- testutil/testdata/testpb/tx.proto | 2 ++ testutil/testdata/testpb/tx.pulsar.go | 33 +++++++++++++------------ testutil/testdata/tx.pb.go | 20 +++++++-------- x/auth/tx/decoder.go | 3 ++- x/staking/types/tx.pb.go | 3 ++- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/api/cosmos/staking/v1beta1/tx.pulsar.go b/api/cosmos/staking/v1beta1/tx.pulsar.go index 2dbf1af29ab5..f1e0387cde3f 100644 --- a/api/cosmos/staking/v1beta1/tx.pulsar.go +++ b/api/cosmos/staking/v1beta1/tx.pulsar.go @@ -7129,7 +7129,8 @@ type MsgCreateValidator struct { // only in bech32 notation). // // Deprecated: Do not use. - DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + // validator_address is the address of the validator encoded as a bech32 account address. ValidatorAddress string `protobuf:"bytes,5,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` Pubkey *anypb.Any `protobuf:"bytes,6,opt,name=pubkey,proto3" json:"pubkey,omitempty"` Value *v1beta1.Coin `protobuf:"bytes,7,opt,name=value,proto3" json:"value,omitempty"` diff --git a/testutil/testdata/testpb/tx.proto b/testutil/testdata/testpb/tx.proto index 464e3390478b..74aae2363eaf 100644 --- a/testutil/testdata/testpb/tx.proto +++ b/testutil/testdata/testpb/tx.proto @@ -29,6 +29,8 @@ message MsgCreateDogResponse { // TestMsg is msg type for testing protobuf message using any, as defined in // https://github.com/cosmos/cosmos-sdk/issues/6213. message TestMsg { + option (cosmos.msg.v1.signer) = "signers"; + option (gogoproto.goproto_getters) = false; repeated string signers = 1; } diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index b0d653076627..217cad7c6c83 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -1557,24 +1557,25 @@ var file_testpb_tx_proto_rawDesc = []byte{ 0x77, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, 0x07, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x73, 0x3a, 0x04, 0x88, 0xa0, 0x1f, 0x00, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, - 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, - 0x67, 0x1a, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, - 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, - 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, - 0x65, 0x73, 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, - 0x5f, 0x70, 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, - 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, - 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x3a, 0x10, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x73, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, + 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, + 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, + 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, + 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, + 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index b12e6fa2eb3c..664d22c5cce1 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -173,7 +173,7 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 313 bytes of a gzipped FileDescriptorProto + // 317 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x85, 0xf4, 0x41, 0x2c, 0x88, 0xac, 0x94, 0x28, 0x4c, 0x79, @@ -184,16 +184,16 @@ var fileDescriptor_1c54006dba274b2e = []byte{ 0x07, 0x81, 0xc4, 0x85, 0x44, 0xb8, 0x58, 0xf3, 0xcb, 0xf3, 0x52, 0x8b, 0x24, 0x98, 0x14, 0x18, 0x35, 0x38, 0x83, 0x20, 0x1c, 0x2b, 0xae, 0xa6, 0xe7, 0x1b, 0xb4, 0x20, 0x6c, 0x25, 0x2d, 0x2e, 0x11, 0x64, 0x03, 0x83, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0x84, 0xb8, 0x58, 0xf2, - 0x12, 0x73, 0x53, 0xc1, 0x26, 0x73, 0x06, 0x81, 0xd9, 0x4a, 0x9a, 0x5c, 0xec, 0x21, 0xa9, 0xc5, + 0x12, 0x73, 0x53, 0xc1, 0x26, 0x73, 0x06, 0x81, 0xd9, 0x4a, 0xa6, 0x5c, 0xec, 0x21, 0xa9, 0xc5, 0x25, 0xbe, 0xc5, 0xe9, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, 0xc5, 0x12, - 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x15, 0x4b, 0xc7, 0x02, 0x79, 0x06, 0x23, 0x5f, - 0x2e, 0x66, 0x90, 0x32, 0x7b, 0x2e, 0x4e, 0x84, 0x5b, 0x45, 0x60, 0xce, 0x43, 0xb6, 0x50, 0x4a, - 0x06, 0x9b, 0x28, 0xcc, 0x19, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, 0x3a, 0x79, 0x9c, 0x78, - 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, - 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, - 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0xd0, 0x20, 0x94, 0x6e, 0x71, 0x4a, 0x36, 0x38, 0x58, 0x4b, - 0x4b, 0x32, 0x73, 0xe0, 0xe1, 0x9b, 0xc4, 0x06, 0x0e, 0x47, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x0a, 0x96, 0x8c, 0x83, 0xa8, 0x01, 0x00, 0x00, + 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x95, 0x40, 0xc7, 0x02, 0x79, 0x06, 0x90, 0x05, + 0x30, 0x11, 0x23, 0x5f, 0x2e, 0x66, 0x90, 0x16, 0x7b, 0x2e, 0x4e, 0x84, 0xbb, 0x45, 0x60, 0x4e, + 0x45, 0xb6, 0x5c, 0x4a, 0x06, 0x9b, 0x28, 0xcc, 0x49, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, + 0x3a, 0x79, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, + 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, 0x66, + 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0x00, 0x21, 0x94, 0x6e, 0x71, 0x4a, + 0x36, 0x38, 0x88, 0x4b, 0x4b, 0x32, 0x73, 0xe0, 0x61, 0x9d, 0xc4, 0x06, 0x0e, 0x53, 0x63, 0x40, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xc4, 0x88, 0xf7, 0xab, 0xb4, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index 0315205288a9..16253a4ba154 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -88,7 +88,8 @@ func DefaultJSONTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder { } return &wrapper{ - tx: &theTx, + tx: &theTx, + cdc: cdc, }, nil } } diff --git a/x/staking/types/tx.pb.go b/x/staking/types/tx.pb.go index 077153172927..e834ca20269f 100644 --- a/x/staking/types/tx.pb.go +++ b/x/staking/types/tx.pb.go @@ -46,7 +46,8 @@ type MsgCreateValidator struct { // Deprecated: Use of Delegator Address in MsgCreateValidator is deprecated. // The validator address bytes and delegator address bytes refer to the same account while creating validator (defer // only in bech32 notation). - DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` // Deprecated: Do not use. + DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` // Deprecated: Do not use. + // validator_address is the address of the validator encoded as a bech32 account address. ValidatorAddress string `protobuf:"bytes,5,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` Pubkey *types.Any `protobuf:"bytes,6,opt,name=pubkey,proto3" json:"pubkey,omitempty"` Value types1.Coin `protobuf:"bytes,7,opt,name=value,proto3" json:"value"` From 4255b823845172929ce7eda7b4ed04572cca07ac Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 3 Apr 2023 17:19:50 -0400 Subject: [PATCH 34/83] migrate MsgUnjail to use account bech32 --- x/auth/tx/builder_test.go | 2 +- x/slashing/app_test.go | 3 ++- x/slashing/keeper/msg_server_test.go | 12 ++++++------ x/slashing/types/msg.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 68e13ebe3de6..5abf6a0317a1 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -22,7 +22,7 @@ func TestTxBuilder(t *testing.T) { _, pubkey, addr := testdata.KeyTestPubAddr() marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - txBuilder := newBuilder(nil) + txBuilder := newBuilder(marshaler) memo := "sometestmemo" //nolint:goconst msgs := []sdk.Msg{testdata.NewTestMsg(addr)} diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index d95c8c5692ac..8f8f575b4fe1 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/configurator" @@ -91,7 +92,7 @@ func TestSlashingMsgs(t *testing.T) { require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress) require.Equal(t, stakingtypes.Bonded, validator.Status) require.True(math.IntEq(t, bondTokens, validator.BondedTokens())) - unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(addr1).String()} + unjailMsg := &types.MsgUnjail{ValidatorAddr: addr1.String()} ctxCheck = app.BaseApp.NewContext(true, cmtproto.Header{}) _, found = slashingKeeper.GetValidatorSigningInfo(ctxCheck, sdk.ConsAddress(valAddr)) diff --git a/x/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go index 5db479c20976..c22e9ef27e74 100644 --- a/x/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -162,7 +162,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(nil) return &slashingtypes.MsgUnjail{ - ValidatorAddr: sdk.ValAddress(addr).String(), + ValidatorAddr: addr.String(), } }, expErr: true, @@ -177,7 +177,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Validator(s.ctx, valAddr).Return(nil) return &slashingtypes.MsgUnjail{ - ValidatorAddr: valAddr.String(), + ValidatorAddr: addr.String(), } }, expErr: true, @@ -207,7 +207,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: sdk.ValAddress(addr).String(), + ValidatorAddr: addr.String(), } }, expErr: true, @@ -237,7 +237,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: sdk.ValAddress(addr).String(), + ValidatorAddr: addr.String(), } }, expErr: true, @@ -267,7 +267,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: sdk.ValAddress(addr).String(), + ValidatorAddr: addr.String(), } }, expErr: true, @@ -298,7 +298,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Unjail(s.ctx, sdk.ConsAddress(addr)).Return() return &slashingtypes.MsgUnjail{ - ValidatorAddr: sdk.ValAddress(addr).String(), + ValidatorAddr: addr.String(), } }, expErr: false, diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index db8dc4c489d0..933e6e9fb4f2 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -20,7 +20,7 @@ var ( // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { return &MsgUnjail{ - ValidatorAddr: validatorAddr.String(), + ValidatorAddr: sdk.AccAddress(validatorAddr).String(), } } @@ -38,7 +38,7 @@ func (msg MsgUnjail) GetSignBytes() []byte { // ValidateBasic does a sanity check on the provided message. func (msg MsgUnjail) ValidateBasic() error { - if _, err := sdk.ValAddressFromBech32(msg.ValidatorAddr); err != nil { + if _, err := sdk.AccAddressFromBech32(msg.ValidatorAddr); err != nil { return sdkerrors.ErrInvalidAddress.Wrapf("validator input address: %s", err) } return nil From 1b8cfe2b98a2454974d9a18ecde3cac94d3f3a7f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 12 Apr 2023 13:36:21 -0400 Subject: [PATCH 35/83] WIP on refactoring --- baseapp/baseapp.go | 8 ++++-- codec/amino_codec.go | 26 ++--------------- codec/codec.go | 9 ++++-- codec/proto_codec.go | 43 +++++++++++++++++++++++------ go.mod | 2 +- go.sum | 2 ++ server/mock/tx.go | 2 +- simapp/go.mod | 2 +- simapp/go.sum | 2 ++ tests/go.mod | 2 +- tests/go.sum | 2 ++ tools/confix/go.mod | 2 +- tools/confix/go.sum | 2 ++ tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 2 ++ types/tx/types.go | 35 +++++++++++++++-------- x/auth/ante/basic.go | 7 +---- x/auth/ante/sigverify.go | 30 ++++---------------- x/auth/signing/sig_verifiable_tx.go | 2 +- x/auth/tx/builder.go | 4 +-- x/evidence/go.mod | 2 +- x/evidence/go.sum | 2 ++ x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 2 ++ x/nft/go.mod | 2 +- x/nft/go.sum | 2 ++ x/tx/CHANGELOG.md | 2 +- x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 2 ++ 29 files changed, 110 insertions(+), 94 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index bd17c7c17b1a..b461f9c82e2a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -853,8 +853,12 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, msgV2 protov2 if err != nil { panic(err) } - if len(signers) > 0 && signers[0] != "" { - msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, signers[0])) + if len(signers) > 0 && signers[0] != nil { + addrStr, err := cdc.GetSigningContext().AddressCodec().BytesToString(signers[0]) + if err != nil { + panic(err) + } + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, addrStr)) } // verify that events have no module attribute set diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 2b1e02864513..167e64b34759 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -1,12 +1,7 @@ package codec import ( - "fmt" - "github.com/cosmos/gogoproto/proto" - protov2 "google.golang.org/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/codec/types" ) // Deprecated: AminoCodec defines a codec that utilizes Codec for both binary and JSON @@ -16,7 +11,8 @@ type AminoCodec struct { *LegacyAmino } -var _ Codec = &AminoCodec{} +var _ BinaryCodec = &AminoCodec{} +var _ JSONCodec = &AminoCodec{} // Deprecated: NewAminoCodec returns a reference to a new AminoCodec. // Use NewLegacyAmino instead. @@ -131,21 +127,3 @@ func (ac *AminoCodec) MarshalInterfaceJSON(i proto.Message) ([]byte, error) { func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } - -func (ac *AminoCodec) GetMsgAnySigners(*types.Any) ([]string, protov2.Message, error) { - return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) GetMsgV1Signers(proto.Message) ([]string, protov2.Message, error) { - return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) GetMsgV2Signers(protov2.Message) ([]string, error) { - return nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) InterfaceRegistry() types.InterfaceRegistry { - panic("amino codec does not support interface registry") -} - -func (ac *AminoCodec) mustEmbedCodec() {} diff --git a/codec/codec.go b/codec/codec.go index 7bdaffa69bf5..288fd7ac8d49 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -1,6 +1,7 @@ package codec import ( + "cosmossdk.io/x/tx/signing" "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" protov2 "google.golang.org/protobuf/proto" @@ -26,15 +27,17 @@ type ( // GetMsgAnySigners returns the signers of the given message encoded in a protobuf Any // as well as the decoded google.golang.org/protobuf/proto.Message that was used to // extract the signers so that this can be used in other contexts. - GetMsgAnySigners(msg *types.Any) ([]string, protov2.Message, error) + GetMsgAnySigners(msg *types.Any) ([][]byte, protov2.Message, error) // GetMsgV2Signers returns the signers of the given message. - GetMsgV2Signers(msg protov2.Message) ([]string, error) + GetMsgV2Signers(msg protov2.Message) ([][]byte, error) // GetMsgV1Signers returns the signers of the given message plus the // decoded google.golang.org/protobuf/proto.Message that was used to extract the // signers so that this can be used in other contexts. - GetMsgV1Signers(msg proto.Message) ([]string, protov2.Message, error) + GetMsgV1Signers(msg proto.Message) ([][]byte, protov2.Message, error) + + GetSigningContext() *signing.Context // mustEmbedCodec requires that all implementations of Codec embed an official implementation from the codec // package. This allows new methods to be added to the Codec interface without breaking backwards compatibility. diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 965954ae2df0..cac295450ac6 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-proto/anyutil" "github.com/cosmos/gogoproto/jsonpb" gogoproto "github.com/cosmos/gogoproto/proto" @@ -29,7 +30,7 @@ type ProtoCodecMarshaler interface { // encoding. type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry - getSignersCtx *signing.GetSignersContext + getSignersCtx *signing.Context } var ( @@ -37,11 +38,13 @@ var ( _ ProtoCodecMarshaler = &ProtoCodec{} ) -// NewProtoCodec returns a reference to a new ProtoCodec +// Deprecated: NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - getSignersCtx, err := signing.NewGetSignersContext( - signing.GetSignersOptions{ - ProtoFiles: interfaceRegistry, + getSignersCtx, err := signing.NewContext( + signing.Options{ + FileResolver: interfaceRegistry, + AddressCodec: failingAddressCodec{}, + ValidatorAddressCodec: failingAddressCodec{}, }) if err != nil { panic(err) @@ -52,6 +55,16 @@ func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { } } +type Options struct { + InterfaceRegistry types.InterfaceRegistry + AddressCodec address.Codec + ValidatorAddressCodec address.Codec +} + +func NewProtoCodecWithOptions(options Options) *ProtoCodec { + panic("TODO") +} + // Marshal implements BinaryMarshaler.Marshal method. // NOTE: this function must be used with a concrete type which // implements proto.Message. For interface please use the codec.MarshalInterface @@ -277,7 +290,7 @@ func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry { return pc.interfaceRegistry } -func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, error) { +func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([][]byte, proto.Message, error) { msgv2, err := anyutil.Unpack(&anypb.Any{ TypeUrl: msg.TypeUrl, Value: msg.Value, @@ -290,11 +303,11 @@ func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, return signers, msgv2, err } -func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([]string, error) { +func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([][]byte, error) { return pc.getSignersCtx.GetSigners(msg) } -func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([]string, proto.Message, error) { +func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([][]byte, proto.Message, error) { if msgV2, ok := msg.(proto.Message); ok { signers, err := pc.getSignersCtx.GetSigners(msgV2) return signers, msgV2, err @@ -311,6 +324,10 @@ func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} } +func (pc *ProtoCodec) GetSigningContext() *signing.Context { + return pc.getSignersCtx +} + func (pc *ProtoCodec) mustEmbedCodec() {} var errUnknownProtoType = errors.New("codec: unknown proto type") // sentinel error @@ -352,3 +369,13 @@ func assertNotNil(i interface{}) error { } return nil } + +type failingAddressCodec struct{} + +func (f failingAddressCodec) StringToBytes(text string) ([]byte, error) { + return nil, fmt.Errorf("ProtoCodec requires a proper address codec implementation") +} + +func (f failingAddressCodec) BytesToString(bz []byte) (string, error) { + return "", fmt.Errorf("ProtoCodec requires a proper address codec implementation") +} diff --git a/go.mod b/go.mod index 3d278dae0a1a..e3dc778af78d 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 + cosmossdk.io/x/tx v0.6.0 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 992a527fec0e..219999fd4bb5 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/server/mock/tx.go b/server/mock/tx.go index ac311acaf8b9..15479a227d2e 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -116,7 +116,7 @@ func (msg *KVStoreTx) ValidateBasic() error { return nil } -func (msg *KVStoreTx) GetSigners() []string { +func (msg *KVStoreTx) GetSigners() [][]byte { return nil } diff --git a/simapp/go.mod b/simapp/go.mod index bc6e72db56ce..14f3c776892a 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 23c91cbbe3de..07a8acd73187 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -204,6 +204,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/go.mod b/tests/go.mod index 935c9bde0caf..1d85b6f0f011 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.1 + cosmossdk.io/x/tx v0.6.0 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index a6ed45a16c79..463a992dda6b 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -204,6 +204,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/confix/go.mod b/tools/confix/go.mod index c4bef91a5f04..8f186c0c06b0 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -21,7 +21,7 @@ require ( cosmossdk.io/log v1.0.0 // indirect cosmossdk.io/math v1.0.0 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index 1f41b0df7d58..54a7c11106ff 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 2c7d8eb3c1c3..2705c5418da8 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 37504dea060b..6857722f4d9d 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/types/tx/types.go b/types/tx/types.go index 0d41ed53d96a..cc16c19f0840 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -34,13 +34,13 @@ func (t *Tx) GetMsgs() []sdk.Msg { // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). -func (t *Tx) GetSigners(codec codec.Codec) ([]string, []protov2.Message, error) { - var signers []string +func (t *Tx) GetSigners(cdc codec.Codec) ([][]byte, []protov2.Message, error) { + var signers [][]byte seen := map[string]bool{} var msgsv2 []protov2.Message for _, msg := range t.Body.Messages { - xs, msgv2, err := codec.GetMsgAnySigners(msg) + xs, msgv2, err := cdc.GetMsgAnySigners(msg) if err != nil { return nil, nil, err } @@ -48,19 +48,26 @@ func (t *Tx) GetSigners(codec codec.Codec) ([]string, []protov2.Message, error) msgsv2 = append(msgsv2, msgv2) for _, signer := range xs { - if !seen[signer] { + if !seen[string(signer)] { signers = append(signers, signer) - seen[signer] = true + seen[string(signer)] = true } } } // ensure any specified fee payer is included in the required signers (at the end) feePayer := t.AuthInfo.Fee.Payer - if feePayer != "" && !seen[feePayer] { - payerAddr := feePayer - signers = append(signers, payerAddr) - seen[feePayer] = true + var feePayerAddr []byte + if feePayer != "" { + var err error + feePayerAddr, err = cdc.GetSigningContext().AddressCodec().StringToBytes(feePayer) + if err != nil { + return nil, nil, err + } + } + if feePayerAddr != nil && !seen[string(feePayerAddr)] { + signers = append(signers, feePayerAddr) + seen[string(feePayerAddr)] = true } return signers, msgsv2, nil @@ -74,13 +81,17 @@ func (t *Tx) GetFee() sdk.Coins { return t.AuthInfo.Fee.Amount } -func (t *Tx) FeePayer(codec codec.Codec) string { +func (t *Tx) FeePayer(cdc codec.Codec) []byte { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { - return feePayer + feePayerAddr, err := cdc.GetSigningContext().AddressCodec().StringToBytes(feePayer) + if err != nil { + panic(err) + } + return feePayerAddr } // use first signer as default if no payer specified - signers, _, err := t.GetSigners(codec) + signers, _, err := t.GetSigners(cdc) if err != nil { panic(err) } diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 8bc80d3c28bd..8d335fc32b01 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -116,12 +116,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim var pubkey cryptotypes.PubKey - signerAddr, err := sdk.AccAddressFromBech32(signer) - if err != nil { - return ctx, err - } - - acc := cgts.ak.GetAccount(ctx, signerAddr) + acc := cgts.ak.GetAccount(ctx, signer) // use placeholder simSecp256k1Pubkey if sig is nil if acc == nil || acc.GetPubKey() == nil { diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 932bbfdae148..2ea6a3006894 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -75,17 +75,12 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b pk = simSecp256k1Pubkey } // Only make check if simulate=false - signerAddr, err := sdk.AccAddressFromBech32(signers[i]) - if err != nil { - return ctx, err - } - - if !simulate && !bytes.Equal(pk.Address(), signerAddr) { + if !simulate && !bytes.Equal(pk.Address(), signers[i]) { return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "pubKey does not match signer address %s with signer index: %d", signers[i], i) } - acc, err := GetSignerAcc(ctx, spkd.ak, signerAddr) + acc, err := GetSignerAcc(ctx, spkd.ak, signers[i]) if err != nil { return ctx, err } @@ -168,12 +163,7 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula signers := sigTx.GetSigners() for i, sig := range sigs { - signerAddr, err := sdk.AccAddressFromBech32(signers[i]) - if err != nil { - return ctx, err - } - - signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signerAddr) + signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signers[i]) if err != nil { return ctx, err } @@ -263,12 +253,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } for i, sig := range sigs { - signerAddr, err := sdk.AccAddressFromBech32(signers[i]) - if err != nil { - return ctx, err - } - - acc, err := GetSignerAcc(ctx, svd.ak, signerAddr) + acc, err := GetSignerAcc(ctx, svd.ak, signers[i]) if err != nil { return ctx, err } @@ -350,12 +335,7 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim // increment sequence of all signers for _, signer := range sigTx.GetSigners() { - signerAddr, err := sdk.AccAddressFromBech32(signer) - if err != nil { - return ctx, err - } - - acc := isd.ak.GetAccount(ctx, signerAddr) + acc := isd.ak.GetAccount(ctx, signer) if err := acc.SetSequence(acc.GetSequence() + 1); err != nil { panic(err) } diff --git a/x/auth/signing/sig_verifiable_tx.go b/x/auth/signing/sig_verifiable_tx.go index 15406723d2a3..bfb736833f3b 100644 --- a/x/auth/signing/sig_verifiable_tx.go +++ b/x/auth/signing/sig_verifiable_tx.go @@ -11,7 +11,7 @@ import ( // handlers. type SigVerifiableTx interface { types.Tx - GetSigners() []string + GetSigners() [][]byte GetPubKeys() ([]cryptotypes.PubKey, error) // If signer already has pubkey in context, this list will have nil in its place GetSignaturesV2() ([]signing.SignatureV2, error) } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index c9cbbb0514a2..dcc454532256 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -37,7 +37,7 @@ type wrapper struct { txBodyHasUnknownNonCriticals bool - signers []string + signers [][]byte msgsV2 []protov2.Message } @@ -188,7 +188,7 @@ func (w *wrapper) initSignersAndMsgsV2() { } } -func (w *wrapper) GetSigners() []string { +func (w *wrapper) GetSigners() [][]byte { if w.signers == nil { w.initSignersAndMsgsV2() } diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 229913dbb99e..381550373822 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -26,7 +26,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 949c3d82b6c9..57d8f597ea90 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index f1965d9432b1..f32dfb45944e 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -27,7 +27,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index e9a1ce027538..d8f454570467 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/nft/go.mod b/x/nft/go.mod index 53c9699094e5..f93d48b35ee0 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -25,7 +25,7 @@ require ( require ( cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/log v1.0.0 // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 949c3d82b6c9..57d8f597ea90 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -53,6 +53,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 2b5921d98676..3bc69a67fc4e 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -29,7 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog -## Unreleased +## v0.6.0 ### API Breaking diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 136d0743eda1..0066412781db 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -35,7 +35,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/math v1.0.0 // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.6.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 781d1517d2e7..963044292ef3 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -206,6 +206,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+S cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.6.0 h1:nUeW2WuDbeufGZiq7ojqpgIXhTrcXjJBxtq0fHzEDtw= +cosmossdk.io/x/tx v0.6.0/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From ffbcb8006695187f9d3e87245c6782afbf9ba165 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 12 Apr 2023 13:39:47 -0400 Subject: [PATCH 36/83] WIP on refactoring --- baseapp/baseapp.go | 2 +- codec/codec.go | 2 +- codec/proto_codec.go | 2 +- types/tx/types.go | 4 ++-- types/tx_msg.go | 2 +- x/auth/tx/builder.go | 15 ++++++++++++--- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index b461f9c82e2a..ac914e33c2a5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -854,7 +854,7 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, msgV2 protov2 panic(err) } if len(signers) > 0 && signers[0] != nil { - addrStr, err := cdc.GetSigningContext().AddressCodec().BytesToString(signers[0]) + addrStr, err := cdc.SigningContext().AddressCodec().BytesToString(signers[0]) if err != nil { panic(err) } diff --git a/codec/codec.go b/codec/codec.go index 288fd7ac8d49..67ea8952d1d2 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -37,7 +37,7 @@ type ( // signers so that this can be used in other contexts. GetMsgV1Signers(msg proto.Message) ([][]byte, protov2.Message, error) - GetSigningContext() *signing.Context + SigningContext() *signing.Context // mustEmbedCodec requires that all implementations of Codec embed an official implementation from the codec // package. This allows new methods to be added to the Codec interface without breaking backwards compatibility. diff --git a/codec/proto_codec.go b/codec/proto_codec.go index cac295450ac6..6b8927da0017 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -324,7 +324,7 @@ func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} } -func (pc *ProtoCodec) GetSigningContext() *signing.Context { +func (pc *ProtoCodec) SigningContext() *signing.Context { return pc.getSignersCtx } diff --git a/types/tx/types.go b/types/tx/types.go index cc16c19f0840..184c6753d50f 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -60,7 +60,7 @@ func (t *Tx) GetSigners(cdc codec.Codec) ([][]byte, []protov2.Message, error) { var feePayerAddr []byte if feePayer != "" { var err error - feePayerAddr, err = cdc.GetSigningContext().AddressCodec().StringToBytes(feePayer) + feePayerAddr, err = cdc.SigningContext().AddressCodec().StringToBytes(feePayer) if err != nil { return nil, nil, err } @@ -84,7 +84,7 @@ func (t *Tx) GetFee() sdk.Coins { func (t *Tx) FeePayer(cdc codec.Codec) []byte { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { - feePayerAddr, err := cdc.GetSigningContext().AddressCodec().StringToBytes(feePayer) + feePayerAddr, err := cdc.SigningContext().AddressCodec().StringToBytes(feePayer) if err != nil { panic(err) } diff --git a/types/tx_msg.go b/types/tx_msg.go index fb4d5e8e2607..ec1e6646d22a 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -61,7 +61,7 @@ type ( Tx GetGas() uint64 GetFee() Coins - FeePayer() string + FeePayer() []byte FeeGranter() string } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index dcc454532256..514b869af757 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -1,6 +1,7 @@ package tx import ( + "bytes" "fmt" "github.com/cosmos/gogoproto/proto" @@ -226,10 +227,14 @@ func (w *wrapper) GetFee() sdk.Coins { return w.tx.AuthInfo.Fee.Amount } -func (w *wrapper) FeePayer() string { +func (w *wrapper) FeePayer() []byte { feePayer := w.tx.AuthInfo.Fee.Payer if feePayer != "" { - return feePayer + feePayerAddr, err := w.cdc.SigningContext().AddressCodec().StringToBytes(feePayer) + if err != nil { + panic(err) + } + return feePayerAddr } // use first signer as default if no payer specified return w.GetSigners()[0] @@ -544,7 +549,11 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error { // Get the aux signer's index in GetSigners. signerIndex := -1 for i, signer := range w.GetSigners() { - if signer == data.Address { + addrBz, err := w.cdc.SigningContext().AddressCodec().StringToBytes(data.Address) + if err != nil { + return err + } + if bytes.Equal(signer, addrBz) { signerIndex = i } } From 46a5f38b74792e5446b28c9135be9e4b1d631573 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 13 Apr 2023 16:57:49 -0400 Subject: [PATCH 37/83] refactor codec & interface registry --- codec/codec.go | 3 -- codec/proto_codec.go | 44 ++---------------------- codec/types/interface_registry.go | 57 ++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/codec/codec.go b/codec/codec.go index 67ea8952d1d2..6256f78a80a7 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -1,7 +1,6 @@ package codec import ( - "cosmossdk.io/x/tx/signing" "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/encoding" protov2 "google.golang.org/protobuf/proto" @@ -37,8 +36,6 @@ type ( // signers so that this can be used in other contexts. GetMsgV1Signers(msg proto.Message) ([][]byte, protov2.Message, error) - SigningContext() *signing.Context - // mustEmbedCodec requires that all implementations of Codec embed an official implementation from the codec // package. This allows new methods to be added to the Codec interface without breaking backwards compatibility. mustEmbedCodec() diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 6b8927da0017..f1cdd5a6caea 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -6,7 +6,6 @@ import ( "fmt" "strings" - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-proto/anyutil" "github.com/cosmos/gogoproto/jsonpb" gogoproto "github.com/cosmos/gogoproto/proto" @@ -14,8 +13,6 @@ import ( "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" - "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -30,7 +27,6 @@ type ProtoCodecMarshaler interface { // encoding. type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry - getSignersCtx *signing.Context } var ( @@ -40,31 +36,11 @@ var ( // Deprecated: NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - getSignersCtx, err := signing.NewContext( - signing.Options{ - FileResolver: interfaceRegistry, - AddressCodec: failingAddressCodec{}, - ValidatorAddressCodec: failingAddressCodec{}, - }) - if err != nil { - panic(err) - } return &ProtoCodec{ interfaceRegistry: interfaceRegistry, - getSignersCtx: getSignersCtx, } } -type Options struct { - InterfaceRegistry types.InterfaceRegistry - AddressCodec address.Codec - ValidatorAddressCodec address.Codec -} - -func NewProtoCodecWithOptions(options Options) *ProtoCodec { - panic("TODO") -} - // Marshal implements BinaryMarshaler.Marshal method. // NOTE: this function must be used with a concrete type which // implements proto.Message. For interface please use the codec.MarshalInterface @@ -299,17 +275,17 @@ func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([][]byte, proto.Message, return nil, nil, err } - signers, err := pc.getSignersCtx.GetSigners(msgv2) + signers, err := pc.interfaceRegistry.SigningContext().GetSigners(msgv2) return signers, msgv2, err } func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([][]byte, error) { - return pc.getSignersCtx.GetSigners(msg) + return pc.interfaceRegistry.SigningContext().GetSigners(msg) } func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([][]byte, proto.Message, error) { if msgV2, ok := msg.(proto.Message); ok { - signers, err := pc.getSignersCtx.GetSigners(msgV2) + signers, err := pc.interfaceRegistry.SigningContext().GetSigners(msgV2) return signers, msgV2, err } a, err := types.NewAnyWithValue(msg) @@ -324,10 +300,6 @@ func (pc *ProtoCodec) GRPCCodec() encoding.Codec { return &grpcProtoCodec{cdc: pc} } -func (pc *ProtoCodec) SigningContext() *signing.Context { - return pc.getSignersCtx -} - func (pc *ProtoCodec) mustEmbedCodec() {} var errUnknownProtoType = errors.New("codec: unknown proto type") // sentinel error @@ -369,13 +341,3 @@ func assertNotNil(i interface{}) error { } return nil } - -type failingAddressCodec struct{} - -func (f failingAddressCodec) StringToBytes(text string) ([]byte, error) { - return nil, fmt.Errorf("ProtoCodec requires a proper address codec implementation") -} - -func (f failingAddressCodec) BytesToString(bz []byte) (string, error) { - return "", fmt.Errorf("ProtoCodec requires a proper address codec implementation") -} diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 57a098e0cbe4..881057a1d5d0 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -4,6 +4,8 @@ import ( "fmt" "reflect" + "cosmossdk.io/core/address" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" @@ -65,6 +67,8 @@ type InterfaceRegistry interface { // the entire FileDescriptorSet. RangeFiles(f func(protoreflect.FileDescriptor) bool) + SigningContext() *signing.Context + // mustEmbedInterfaceRegistry requires that all implementations of InterfaceRegistry embed an official implementation // from this package. This allows new methods to be added to the InterfaceRegistry interface without breaking // backwards compatibility. @@ -101,6 +105,7 @@ type interfaceRegistry struct { interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type typeURLMap map[string]reflect.Type + signingCtx *signing.Context } type interfaceMap = map[string]reflect.Type @@ -111,18 +116,46 @@ func NewInterfaceRegistry() InterfaceRegistry { if err != nil { panic(err) } - return NewInterfaceRegistryWithProtoFiles(protoFiles) + registry, err := NewInterfaceRegistryWithOptions(Options{ + ProtoFiles: protoFiles, + AddressCodec: failingAddressCodec{}, + ValidatorAddressCodec: failingAddressCodec{}, + }) + if err != nil { + panic(err) + } + return registry +} + +type Options struct { + ProtoFiles *protoregistry.Files + AddressCodec address.Codec + ValidatorAddressCodec address.Codec } -// NewInterfaceRegistryWithProtoFiles returns a new InterfaceRegistry with the specified *protoregistry.Files instance. -func NewInterfaceRegistryWithProtoFiles(files *protoregistry.Files) InterfaceRegistry { +func NewInterfaceRegistryWithOptions(options Options) (InterfaceRegistry, error) { + if options.ProtoFiles == nil { + return nil, fmt.Errorf("proto files must be provided") + } + + signingCtx, err := signing.NewContext(signing.Options{ + FileResolver: options.ProtoFiles, + TypeResolver: nil, + AddressCodec: options.AddressCodec, + ValidatorAddressCodec: options.ValidatorAddressCodec, + }) + if err != nil { + return nil, err + } + return &interfaceRegistry{ interfaceNames: map[string]reflect.Type{}, interfaceImpls: map[reflect.Type]interfaceMap{}, implInterfaces: map[reflect.Type]reflect.Type{}, typeURLMap: map[string]reflect.Type{}, - Files: files, - } + Files: options.ProtoFiles, + signingCtx: signingCtx, + }, nil } func (registry *interfaceRegistry) RegisterInterface(protoName string, iface interface{}, impls ...proto.Message) { @@ -314,6 +347,10 @@ func (registry *interfaceRegistry) Resolve(typeURL string) (proto.Message, error return msg, nil } +func (registry *interfaceRegistry) SigningContext() *signing.Context { + return registry.signingCtx +} + func (registry *interfaceRegistry) mustEmbedInterfaceRegistry() {} // UnpackInterfaces is a convenience function that calls UnpackInterfaces @@ -324,3 +361,13 @@ func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error { } return nil } + +type failingAddressCodec struct{} + +func (f failingAddressCodec) StringToBytes(string) ([]byte, error) { + return nil, fmt.Errorf("InterfaceRefactory requires a proper address codec implementation to do address conversion") +} + +func (f failingAddressCodec) BytesToString([]byte) (string, error) { + return "", fmt.Errorf("InterfaceRefactory requires a proper address codec implementation to do address conversion") +} From 0c7fb0bf1e4a434ac7529fe5885430773a93c1c7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 13 Apr 2023 16:59:43 -0400 Subject: [PATCH 38/83] revert staking and slashing changes --- CHANGELOG.md | 1 - x/slashing/app_test.go | 2 +- x/slashing/keeper/msg_server_test.go | 2 +- x/staking/keeper/msg_server.go | 4 +--- x/staking/types/msg.go | 16 ++++++++++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6c807320b7..dcfe19806b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,7 +103,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/slashing) [#15580](https://github.com/cosmos/cosmos-sdk/pull/15580) The validator slashing window now stores "chunked" bitmap entries for each validator's signing window instead of a single boolean entry per signing window index. * (x/feegrant) [#14294](https://github.com/cosmos/cosmos-sdk/pull/14294) Moved the logic of rejecting duplicate grant from `msg_server` to `keeper` method. * (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) `MsgUndelegateResponse` now includes undelegated amount. `x/staking` module's `keeper.Undelegate` now returns 3 values (completionTime,undelegateAmount,error) instead of 2. -* (x/staking) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `MsgCreateValidator.validator_address` must now be encoded as a bech32 account address instead of a bech32 `valoper` address. ### API Breaking Changes diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 4a8a95069e53..455f5eac6887 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -92,7 +92,7 @@ func TestSlashingMsgs(t *testing.T) { require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress) require.Equal(t, stakingtypes.Bonded, validator.Status) require.True(math.IntEq(t, bondTokens, validator.BondedTokens())) - unjailMsg := &types.MsgUnjail{ValidatorAddr: addr1.String()} + unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(addr1).String()} ctxCheck = app.BaseApp.NewContext(true, cmtproto.Header{}) _, found = slashingKeeper.GetValidatorSigningInfo(ctxCheck, sdk.ConsAddress(valAddr)) diff --git a/x/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go index 329086c3f584..b12e5b43097f 100644 --- a/x/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -172,7 +172,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(nil) return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: sdk.ValAddress(addr).String(), } }, expErr: true, diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 5d6a2318041d..8f97e1d0ac7a 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -35,13 +35,11 @@ var _ types.MsgServer = msgServer{} func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - valAccAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) if err != nil { return nil, err } - valAddr := sdk.ValAddress(valAccAddr) - if msg.Commission.Rate.LT(k.MinCommissionRate(ctx)) { return nil, errorsmod.Wrapf(types.ErrCommissionLTMinRate, "cannot set validator commission to less than minimum rate of %s", k.MinCommissionRate(ctx)) } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 54230bc48e1b..5a8a765020e3 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -45,7 +45,7 @@ func NewMsgCreateValidator( } return &MsgCreateValidator{ Description: description, - ValidatorAddress: sdk.AccAddress(valAddr).String(), + ValidatorAddress: valAddr.String(), Pubkey: pkAny, Value: selfDelegation, Commission: commission, @@ -53,6 +53,18 @@ func NewMsgCreateValidator( }, nil } +// GetSigners implements the sdk.Msg interface. It returns the address(es) that +// must sign over msg.GetSignBytes(). +// If the validator address is not same as delegator's, then the validator must +// sign the msg as well. +func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { + valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) + + valAccAddr := sdk.AccAddress(valAddr) + + return []sdk.AccAddress{valAccAddr} +} + // GetSignBytes returns the message bytes to sign over. func (msg MsgCreateValidator) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(&msg) @@ -62,7 +74,7 @@ func (msg MsgCreateValidator) GetSignBytes() []byte { // ValidateBasic implements the sdk.Msg interface. func (msg MsgCreateValidator) ValidateBasic() error { // note that unmarshaling from bech32 ensures both non-empty and valid - _, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) + _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) if err != nil { return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) } From 11c37bdb0b3ce230efeb78d50c1d96c050c4a960 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 17 Apr 2023 16:31:05 -0400 Subject: [PATCH 39/83] building --- baseapp/baseapp.go | 2 +- codec/codec_common_test.go | 5 ++++- codec/proto_codec.go | 2 +- runtime/module.go | 30 ++++++++++++++++++++++++++++- types/mempool/mempool_test.go | 4 ++-- types/tx/types.go | 4 ++-- x/auth/ante/fee.go | 16 ++++++++++----- x/auth/client/cli/validate_sigs.go | 3 ++- x/auth/client/tx.go | 8 ++++---- x/auth/posthandler/tips.go | 2 +- x/auth/tx/builder.go | 4 ++-- x/auth/tx/direct_aux.go | 8 +++++++- x/authz/keeper/keeper.go | 8 +++----- x/gov/keeper/proposal.go | 5 +++-- x/group/keeper/proposal_executor.go | 3 ++- 15 files changed, 74 insertions(+), 30 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index ac914e33c2a5..2cc28cc73556 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -854,7 +854,7 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, msgV2 protov2 panic(err) } if len(signers) > 0 && signers[0] != nil { - addrStr, err := cdc.SigningContext().AddressCodec().BytesToString(signers[0]) + addrStr, err := cdc.InterfaceRegistry().SigningContext().AddressCodec().BytesToString(signers[0]) if err != nil { panic(err) } diff --git a/codec/codec_common_test.go b/codec/codec_common_test.go index 6c793fe172e0..923b01f8cc8d 100644 --- a/codec/codec_common_test.go +++ b/codec/codec_common_test.go @@ -87,7 +87,10 @@ func testMarshalingTestCase(require *require.Assertions, tc testCase, m mustMars } } -func testMarshaling(t *testing.T, cdc codec.Codec) { +func testMarshaling(t *testing.T, cdc interface { + codec.BinaryCodec + codec.JSONCodec +}) { any, err := types.NewAnyWithValue(&testdata.Dog{Name: "rufus"}) require.NoError(t, err) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index f1cdd5a6caea..732a222d580d 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -34,7 +34,7 @@ var ( _ ProtoCodecMarshaler = &ProtoCodec{} ) -// Deprecated: NewProtoCodec returns a reference to a new ProtoCodec +// NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { return &ProtoCodec{ interfaceRegistry: interfaceRegistry, diff --git a/runtime/module.go b/runtime/module.go index 82ee40470fba..83f7101a1815 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/msgservice" ) @@ -96,7 +97,14 @@ func ProvideApp() ( _, _ = fmt.Fprintln(os.Stderr, err.Error()) } - interfaceRegistry := codectypes.NewInterfaceRegistryWithProtoFiles(protoFiles) + interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.Options{ + ProtoFiles: protoFiles, + AddressCodec: globalAccAddressCodec{}, + ValidatorAddressCodec: globalValAddressCodec{}, + }) + if err != nil { + return nil, nil, nil, nil, nil, nil, nil, nil, nil, err + } amino := codec.NewLegacyAmino() std.RegisterInterfaces(interfaceRegistry) @@ -209,3 +217,23 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor func ProvideEventService() event.Service { return EventService{} } + +type globalAccAddressCodec struct{} + +func (g globalAccAddressCodec) StringToBytes(text string) ([]byte, error) { + return sdk.AccAddressFromBech32(text) +} + +func (g globalAccAddressCodec) BytesToString(bz []byte) (string, error) { + return sdk.AccAddress(bz).String(), nil +} + +type globalValAddressCodec struct{} + +func (g globalValAddressCodec) StringToBytes(text string) ([]byte, error) { + return sdk.ValAddressFromBech32(text) +} + +func (g globalValAddressCodec) BytesToString(bz []byte) (string, error) { + return sdk.ValAddress(bz).String(), nil +} diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index 5845a2e80f0b..e154d714c4ef 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -54,7 +54,7 @@ type testTx struct { strAddress string } -func (tx testTx) GetSigners() []string { panic("not implemented") } +func (tx testTx) GetSigners() [][]byte { panic("not implemented") } func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("not implemented") } @@ -96,7 +96,7 @@ func (sigErrTx) GetMsgsV2() []protov2.Message { return nil } func (sigErrTx) ValidateBasic() error { return nil } -func (sigErrTx) GetSigners() []string { return nil } +func (sigErrTx) GetSigners() [][]byte { return nil } func (sigErrTx) GetPubKeys() ([]cryptotypes.PubKey, error) { return nil, nil } diff --git a/types/tx/types.go b/types/tx/types.go index 184c6753d50f..838f3e198129 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -60,7 +60,7 @@ func (t *Tx) GetSigners(cdc codec.Codec) ([][]byte, []protov2.Message, error) { var feePayerAddr []byte if feePayer != "" { var err error - feePayerAddr, err = cdc.SigningContext().AddressCodec().StringToBytes(feePayer) + feePayerAddr, err = cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(feePayer) if err != nil { return nil, nil, err } @@ -84,7 +84,7 @@ func (t *Tx) GetFee() sdk.Coins { func (t *Tx) FeePayer(cdc codec.Codec) []byte { feePayer := t.AuthInfo.Fee.Payer if feePayer != "" { - feePayerAddr, err := cdc.SigningContext().AddressCodec().StringToBytes(feePayer) + feePayerAddr, err := cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(feePayer) if err != nil { panic(err) } diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 7aa627e3335b..b6131d59e1fc 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -1,6 +1,7 @@ package ante import ( + "bytes" "fmt" errorsmod "cosmossdk.io/errors" @@ -86,19 +87,24 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee // if feegranter set deduct fee from feegranter account. // this works with only when feegrant enabled. if feeGranter != "" { + feeGranterAddr, err := sdk.AccAddressFromBech32(feeGranter) + if err != nil { + return err + } + if dfd.feegrantKeeper == nil { return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled") - } else if feeGranter != feePayer { - err := dfd.feegrantKeeper.UseGrantedFees(ctx, sdk.MustAccAddressFromBech32(feeGranter), sdk.MustAccAddressFromBech32(feePayer), fee, sdkTx.GetMsgs()) + } else if !bytes.Equal(feeGranterAddr, feePayer) { + err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranterAddr, feePayer, fee, sdkTx.GetMsgs()) if err != nil { return errorsmod.Wrapf(err, "%s does not allow to pay fees for %s", feeGranter, feePayer) } } - deductFeesFrom = feeGranter + deductFeesFrom = feeGranterAddr } - deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, sdk.MustAccAddressFromBech32(deductFeesFrom)) + deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, deductFeesFrom) if deductFeesFromAcc == nil { return sdkerrors.ErrUnknownAddress.Wrapf("fee payer address: %s does not exist", deductFeesFrom) } @@ -115,7 +121,7 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.NewEvent( sdk.EventTypeTx, sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), - sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom), + sdk.NewAttribute(sdk.AttributeKeyFeePayer, sdk.AccAddress(deductFeesFrom).String()), ), } ctx.EventManager().EmitEvents(events) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index b0b4820be546..1318a2a62935 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -1,6 +1,7 @@ package cli import ( + "bytes" "fmt" "github.com/spf13/cobra" @@ -90,7 +91,7 @@ func printAndValidateSigs( sigSanity = "OK" ) - if i >= len(signers) || sigAddr.String() != signers[i] { + if i >= len(signers) || !bytes.Equal(sigAddr, signers[i]) { sigSanity = "ERROR: signature does not match its respective signer" success = false } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 6e0dc162fdeb..032e2b7c1d23 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -48,7 +48,7 @@ func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuild return err } addr := sdk.AccAddress(pubKey.Address()) - if !isTxSigner(addr.String(), txBuilder.GetTx().GetSigners()) { + if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } if !offline { @@ -75,7 +75,7 @@ func SignTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, add } // check whether the address is a signer - if !isTxSigner(addr.String(), txBuilder.GetTx().GetSigners()) { + if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } @@ -189,9 +189,9 @@ func ParseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { return simRes, nil } -func isTxSigner(user string, signers []string) bool { +func isTxSigner(user []byte, signers [][]byte) bool { for _, s := range signers { - if user == s { + if bytes.Equal(user, s) { return true } } diff --git a/x/auth/posthandler/tips.go b/x/auth/posthandler/tips.go index 231322bc45b4..33a5f69e9081 100644 --- a/x/auth/posthandler/tips.go +++ b/x/auth/posthandler/tips.go @@ -54,5 +54,5 @@ func (d tipDecorator) transferTip(ctx sdk.Context, sdkTx sdk.Tx) error { return fmt.Errorf("cannot tip these coins: %w", err) } - return d.bankKeeper.SendCoins(ctx, tipper, sdk.MustAccAddressFromBech32(tipTx.FeePayer()), coins) + return d.bankKeeper.SendCoins(ctx, tipper, tipTx.FeePayer(), coins) } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 514b869af757..4880136e6ad2 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -230,7 +230,7 @@ func (w *wrapper) GetFee() sdk.Coins { func (w *wrapper) FeePayer() []byte { feePayer := w.tx.AuthInfo.Fee.Payer if feePayer != "" { - feePayerAddr, err := w.cdc.SigningContext().AddressCodec().StringToBytes(feePayer) + feePayerAddr, err := w.cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(feePayer) if err != nil { panic(err) } @@ -549,7 +549,7 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error { // Get the aux signer's index in GetSigners. signerIndex := -1 for i, signer := range w.GetSigners() { - addrBz, err := w.cdc.SigningContext().AddressCodec().StringToBytes(data.Address) + addrBz, err := w.cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(data.Address) if err != nil { return err } diff --git a/x/auth/tx/direct_aux.go b/x/auth/tx/direct_aux.go index 702ef7b8d1d4..75671a0fc409 100644 --- a/x/auth/tx/direct_aux.go +++ b/x/auth/tx/direct_aux.go @@ -1,6 +1,7 @@ package tx import ( + "bytes" "fmt" errorsmod "cosmossdk.io/errors" @@ -55,7 +56,12 @@ func (signModeDirectAuxHandler) GetSignBytes( // Fee payer cannot use SIGN_MODE_DIRECT_AUX, because SIGN_MODE_DIRECT_AUX // does not sign over fees, which would create malleability issues. - if feePayer == data.Address { + addrBz, err := sdk.AccAddressFromBech32(data.Address) + if err != nil { + return nil, err + } + + if bytes.Equal(feePayer, addrBz) { return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", feePayer, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX) } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index f7e964e23c4f..bee8ec85be00 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "fmt" "strconv" "time" @@ -98,14 +99,11 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] return nil, authz.ErrAuthorizationNumOfSigners } - granter, err := sdk.AccAddressFromBech32(signers[0]) - if err != nil { - return nil, err - } + granter := signers[0] // If granter != grantee then check authorization.Accept, otherwise we // implicitly accept. - if !granter.Equals(grantee) { + if !bytes.Equal(granter, grantee) { skey := grantStoreKey(grantee, granter, sdk.MsgTypeURL(msg)) grant, found := k.getGrant(ctx, skey) diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 683172b08cbc..cca299ef137e 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "errors" "fmt" "time" @@ -57,8 +58,8 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat } // assert that the governance module account is the only signer of the messages - if signers[0] != keeper.GetGovernanceAccount(ctx).GetAddress().String() { - return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, signers[0]) + if !bytes.Equal(signers[0], keeper.GetGovernanceAccount(ctx).GetAddress()) { + return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, sdk.AccAddress(signers[0]).String()) } // use the msg service router to see that there is a valid route for that message. diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index 6620e80ef272..8f2b9165f5aa 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "fmt" errorsmod "cosmossdk.io/errors" @@ -74,7 +75,7 @@ func ensureMsgAuthZ(msgs []sdk.Msg, groupPolicyAcc sdk.AccAddress, cdc codec.Cod } for _, acct := range signers { - if groupPolicyAcc.String() != acct { + if !bytes.Equal(groupPolicyAcc, acct) { return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "msg does not have group policy authorization; expected %s, got %s", groupPolicyAcc.String(), acct) } } From edce1783968aec356e99eb1afcbc0b206ada0848 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 18 Apr 2023 13:44:50 -0400 Subject: [PATCH 40/83] revert --- api/cosmos/staking/v1beta1/tx.pulsar.go | 3 +-- proto/cosmos/staking/v1beta1/tx.proto | 2 -- x/genutil/collect.go | 6 +++--- x/slashing/app_test.go | 1 - x/slashing/keeper/msg_server_test.go | 10 +++++----- x/staking/simulation/operations_test.go | 7 +++---- x/staking/types/tx.pb.go | 3 +-- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/api/cosmos/staking/v1beta1/tx.pulsar.go b/api/cosmos/staking/v1beta1/tx.pulsar.go index f1e0387cde3f..2dbf1af29ab5 100644 --- a/api/cosmos/staking/v1beta1/tx.pulsar.go +++ b/api/cosmos/staking/v1beta1/tx.pulsar.go @@ -7129,8 +7129,7 @@ type MsgCreateValidator struct { // only in bech32 notation). // // Deprecated: Do not use. - DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` - // validator_address is the address of the validator encoded as a bech32 account address. + DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` ValidatorAddress string `protobuf:"bytes,5,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` Pubkey *anypb.Any `protobuf:"bytes,6,opt,name=pubkey,proto3" json:"pubkey,omitempty"` Value *v1beta1.Coin `protobuf:"bytes,7,opt,name=value,proto3" json:"value,omitempty"` diff --git a/proto/cosmos/staking/v1beta1/tx.proto b/proto/cosmos/staking/v1beta1/tx.proto index 133b52c91242..0c6a7b19bcd7 100644 --- a/proto/cosmos/staking/v1beta1/tx.proto +++ b/proto/cosmos/staking/v1beta1/tx.proto @@ -67,8 +67,6 @@ message MsgCreateValidator { // The validator address bytes and delegator address bytes refer to the same account while creating validator (defer // only in bech32 notation). string delegator_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString", deprecated = true]; - - // validator_address is the address of the validator encoded as a bech32 account address. string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; diff --git a/x/genutil/collect.go b/x/genutil/collect.go index e0b19698744b..9d99559375c2 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -132,14 +132,14 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx msg := msgs[0].(*stakingtypes.MsgCreateValidator) // validate validator addresses and funds against the accounts in the state - valAccAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) if err != nil { return appGenTxs, persistentPeers, err } - valAddr := sdk.ValAddress(valAccAddr) + valAccAddr := sdk.AccAddress(valAddr).String() - delBal, delOk := balancesMap[msg.ValidatorAddress] + delBal, delOk := balancesMap[valAccAddr] if !delOk { _, file, no, ok := runtime.Caller(1) if ok { diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 455f5eac6887..aa5ac935f197 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/configurator" diff --git a/x/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go index b12e5b43097f..2fa9bc681638 100644 --- a/x/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -187,7 +187,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Validator(s.ctx, valAddr).Return(nil) return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: valAddr.String(), } }, expErr: true, @@ -217,7 +217,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: sdk.ValAddress(addr).String(), } }, expErr: true, @@ -247,7 +247,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: sdk.ValAddress(addr).String(), } }, expErr: true, @@ -277,7 +277,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del) return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: sdk.ValAddress(addr).String(), } }, expErr: true, @@ -308,7 +308,7 @@ func (s *KeeperTestSuite) TestUnjail() { s.stakingKeeper.EXPECT().Unjail(s.ctx, sdk.ConsAddress(addr)).Return() return &slashingtypes.MsgUnjail{ - ValidatorAddr: addr.String(), + ValidatorAddr: sdk.ValAddress(addr).String(), } }, expErr: false, diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index dbb324734de8..2ccfe937d738 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -13,7 +13,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" @@ -170,10 +169,10 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { require.True(operationMsg.OK) require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(&msg)) - valaddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddress) + valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) require.NoError(err) - require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ValidatorAddress) - require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", sdk.ValAddress(valaddr).String()) + require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) + require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } diff --git a/x/staking/types/tx.pb.go b/x/staking/types/tx.pb.go index e834ca20269f..077153172927 100644 --- a/x/staking/types/tx.pb.go +++ b/x/staking/types/tx.pb.go @@ -46,8 +46,7 @@ type MsgCreateValidator struct { // Deprecated: Use of Delegator Address in MsgCreateValidator is deprecated. // The validator address bytes and delegator address bytes refer to the same account while creating validator (defer // only in bech32 notation). - DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` // Deprecated: Do not use. - // validator_address is the address of the validator encoded as a bech32 account address. + DelegatorAddress string `protobuf:"bytes,4,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` // Deprecated: Do not use. ValidatorAddress string `protobuf:"bytes,5,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` Pubkey *types.Any `protobuf:"bytes,6,opt,name=pubkey,proto3" json:"pubkey,omitempty"` Value types1.Coin `protobuf:"bytes,7,opt,name=value,proto3" json:"value"` From c8de2387d0b3b4e6c5aab91e6546555dfa1a8f09 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 May 2023 14:25:05 -0400 Subject: [PATCH 41/83] fixes --- baseapp/baseapp_test.go | 32 ++++- baseapp/testutil/messages.pb.go | 162 +++++++++++++++++++++----- baseapp/testutil/messages.proto | 1 - codec/amino_codec.go | 18 --- codec/types/interface_registry.go | 16 +-- tests/e2e/tx/service_test.go | 2 +- testutil/testdata/testpb/tx.pulsar.go | 37 +++--- testutil/testdata/tx.pb.go | 46 ++++---- x/auth/ante/ante_test.go | 2 +- x/auth/client/cli/suite_test.go | 4 +- x/gov/types/v1/gov.pb.go | 2 +- x/gov/types/v1/tx.pb.go | 2 +- x/gov/types/v1beta1/gov.pb.go | 2 +- x/gov/types/v1beta1/tx.pb.go | 2 +- 14 files changed, 217 insertions(+), 111 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index f5fe99d10881..346ed312aafb 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -8,16 +8,18 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" + abci "github.com/cometbft/cometbft/abci/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/require" + "cosmossdk.io/store/metrics" pruningtypes "cosmossdk.io/store/pruning/types" "cosmossdk.io/store/rootmulti" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" - abci "github.com/cometbft/cometbft/abci/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - dbm "github.com/cosmos/cosmos-db" - "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" @@ -55,7 +57,17 @@ type ( ) func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { - cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + protoRegistry, err := proto.MergedRegistry() + require.NoError(t, err) + interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions( + codectypes.InterfaceRegistryOptions{ + ProtoFiles: protoRegistry, + AddressCodec: testAddressCodec{}, + ValidatorAddressCodec: testAddressCodec{}, + }, + ) + require.NoError(t, err) + cdc := codec.NewProtoCodec(interfaceRegistry) baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) @@ -657,3 +669,13 @@ func TestLoadVersionPruning(t *testing.T) { require.Nil(t, err) testLoadVersionHelper(t, app, int64(7), lastCommitID) } + +type testAddressCodec struct{} + +func (t testAddressCodec) StringToBytes(text string) ([]byte, error) { + return []byte(text), nil +} + +func (t testAddressCodec) BytesToString(bz []byte) (string, error) { + return string(bz), nil +} diff --git a/baseapp/testutil/messages.pb.go b/baseapp/testutil/messages.pb.go index 533a75289217..2884ff0f649a 100644 --- a/baseapp/testutil/messages.pb.go +++ b/baseapp/testutil/messages.pb.go @@ -31,8 +31,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MsgCounter struct { - Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` - FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` + FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgCounter) Reset() { *m = MsgCounter{} } @@ -82,9 +83,17 @@ func (m *MsgCounter) GetFailOnHandler() bool { return false } +func (m *MsgCounter) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + type MsgCounter2 struct { - Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` - FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Counter int64 `protobuf:"varint,1,opt,name=counter,proto3" json:"counter,omitempty"` + FailOnHandler bool `protobuf:"varint,2,opt,name=fail_on_handler,json=failOnHandler,proto3" json:"fail_on_handler,omitempty"` + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgCounter2) Reset() { *m = MsgCounter2{} } @@ -134,6 +143,13 @@ func (m *MsgCounter2) GetFailOnHandler() bool { return false } +func (m *MsgCounter2) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + type MsgCreateCounterResponse struct { } @@ -277,32 +293,32 @@ func init() { func init() { proto.RegisterFile("messages.proto", fileDescriptor_4dc296cbfe5ffcd5) } var fileDescriptor_4dc296cbfe5ffcd5 = []byte{ - // 387 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xcf, 0xca, 0xd3, 0x40, - 0x14, 0xc5, 0x1b, 0x83, 0xdf, 0x57, 0x6f, 0xab, 0x96, 0x50, 0x34, 0x8d, 0x10, 0x4a, 0x16, 0x52, - 0x84, 0x66, 0x30, 0xee, 0xda, 0x9d, 0x22, 0x55, 0x44, 0x0b, 0x11, 0x5c, 0x74, 0x53, 0x26, 0xe9, - 0xed, 0x34, 0x34, 0x99, 0x09, 0x99, 0x49, 0xa1, 0x5b, 0x9f, 0xc0, 0x47, 0xf1, 0x31, 0x5c, 0x76, - 0xe9, 0x52, 0xda, 0x85, 0xaf, 0x21, 0xf9, 0xd7, 0xba, 0xb0, 0xae, 0xbe, 0xd5, 0xdc, 0x73, 0x2e, - 0xf9, 0x9d, 0xcc, 0x61, 0xe0, 0x51, 0x82, 0x52, 0x52, 0x86, 0xd2, 0x4d, 0x33, 0xa1, 0x84, 0xf5, - 0x34, 0x14, 0x32, 0x11, 0x92, 0x24, 0x92, 0x91, 0xdd, 0xcb, 0xe2, 0xa8, 0x17, 0x7d, 0x26, 0x98, - 0x28, 0x47, 0x52, 0x4c, 0xb5, 0x3b, 0x60, 0x42, 0xb0, 0x18, 0x49, 0xa9, 0x82, 0x7c, 0x4d, 0x28, - 0xdf, 0x57, 0x2b, 0xe7, 0x13, 0xc0, 0x47, 0xc9, 0xde, 0x88, 0x9c, 0x2b, 0xcc, 0x0c, 0x13, 0x6e, - 0xc3, 0x6a, 0x34, 0xb5, 0xa1, 0x36, 0xd2, 0xfd, 0x46, 0x1a, 0xcf, 0xe1, 0xf1, 0x9a, 0x46, 0xf1, - 0x52, 0xf0, 0xe5, 0x86, 0xf2, 0x55, 0x8c, 0x99, 0x79, 0x6f, 0xa8, 0x8d, 0xda, 0xfe, 0xc3, 0xc2, - 0x9e, 0xf3, 0x77, 0x95, 0xe9, 0xcc, 0xa1, 0x73, 0xe1, 0x79, 0x77, 0x00, 0xb4, 0xc0, 0x2c, 0x80, - 0x19, 0x52, 0x85, 0x35, 0xd6, 0x47, 0x99, 0x0a, 0x2e, 0xd1, 0x59, 0x94, 0x61, 0x1f, 0x70, 0xff, - 0x85, 0xc6, 0x39, 0x1a, 0x3d, 0xd0, 0xb7, 0xb8, 0x2f, 0x83, 0xba, 0x7e, 0x31, 0x1a, 0x7d, 0xb8, - 0xbf, 0x2b, 0x56, 0x25, 0xba, 0xeb, 0x57, 0xc2, 0x78, 0x02, 0x37, 0x32, 0x62, 0x1c, 0x33, 0x53, - 0x1f, 0x6a, 0xa3, 0x07, 0x7e, 0xad, 0x26, 0x9d, 0xaf, 0xbf, 0xbf, 0xbf, 0xa8, 0x85, 0xf3, 0x0c, - 0x06, 0xe7, 0xdc, 0x26, 0xa1, 0x09, 0xf6, 0xde, 0xc2, 0x6d, 0x53, 0xd9, 0x04, 0x7a, 0xef, 0x79, - 0x98, 0x61, 0x82, 0x5c, 0x35, 0x5e, 0xc7, 0xbd, 0x74, 0x60, 0x0d, 0xdc, 0x6b, 0xff, 0xef, 0xcd, - 0xa0, 0x7d, 0x6e, 0x6a, 0xfa, 0x0f, 0x4e, 0xf7, 0x2f, 0x8e, 0xf7, 0x3f, 0xd0, 0x14, 0xda, 0xe7, - 0x16, 0x08, 0xe8, 0x9f, 0x51, 0x55, 0xdf, 0x36, 0xa6, 0x65, 0xb9, 0x57, 0x2f, 0xf3, 0x7a, 0xf6, - 0xe3, 0x68, 0x6b, 0x87, 0xa3, 0xad, 0xfd, 0x3a, 0xda, 0xda, 0xb7, 0x93, 0xdd, 0x3a, 0x9c, 0xec, - 0xd6, 0xcf, 0x93, 0xdd, 0x5a, 0x8c, 0x59, 0xa4, 0x36, 0x79, 0xe0, 0x86, 0x22, 0x21, 0xf5, 0x8b, - 0xab, 0x8e, 0xb1, 0x5c, 0x6d, 0x49, 0x40, 0x25, 0xd2, 0x34, 0x25, 0x0a, 0xa5, 0xca, 0x55, 0x14, - 0x07, 0x37, 0xe5, 0x93, 0x7a, 0xf5, 0x27, 0x00, 0x00, 0xff, 0xff, 0xea, 0x9d, 0x1c, 0xeb, 0xae, - 0x02, 0x00, 0x00, + // 390 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x92, 0xcf, 0xaa, 0xd3, 0x40, + 0x14, 0xc6, 0x1b, 0x83, 0x6d, 0x3d, 0xad, 0x5a, 0x42, 0xd1, 0x34, 0x42, 0x28, 0x5d, 0x48, 0x11, + 0x9a, 0xc1, 0xb8, 0x6b, 0x77, 0x8a, 0x54, 0x11, 0x11, 0x22, 0xb8, 0xe8, 0xa6, 0x4c, 0xd2, 0xd3, + 0x69, 0x68, 0x32, 0x13, 0x32, 0x93, 0x42, 0xb7, 0x3e, 0x81, 0x8f, 0xe2, 0x63, 0xb8, 0xec, 0xd2, + 0xa5, 0xb4, 0x0b, 0x5f, 0x43, 0xf2, 0xaf, 0x75, 0x71, 0x7b, 0xb9, 0xab, 0xbb, 0x9a, 0xf3, 0x7d, + 0x87, 0x9c, 0xdf, 0xc9, 0xc7, 0x81, 0x27, 0x31, 0x4a, 0x49, 0x19, 0x4a, 0x27, 0x49, 0x85, 0x12, + 0x56, 0x9f, 0x09, 0x26, 0x8a, 0x92, 0xe4, 0x55, 0xe5, 0x0e, 0x98, 0x10, 0x2c, 0x42, 0x52, 0x28, + 0x3f, 0x5b, 0x13, 0xca, 0xf7, 0x55, 0xeb, 0x79, 0x20, 0x64, 0x2c, 0x24, 0x89, 0x25, 0x23, 0xbb, + 0xd7, 0xf9, 0x53, 0x36, 0x46, 0x12, 0xe0, 0xb3, 0x64, 0xef, 0x44, 0xc6, 0x15, 0xa6, 0x86, 0x09, + 0xad, 0xa0, 0x2c, 0x4d, 0x6d, 0xa8, 0x8d, 0x75, 0xaf, 0x96, 0xc6, 0x4b, 0x78, 0xba, 0xa6, 0x61, + 0xb4, 0x14, 0x7c, 0xb9, 0xa1, 0x7c, 0x15, 0x61, 0x6a, 0x3e, 0x18, 0x6a, 0xe3, 0xb6, 0xf7, 0x38, + 0xb7, 0xbf, 0xf0, 0x0f, 0xa5, 0x69, 0x3c, 0x83, 0xa6, 0x0c, 0x19, 0xc7, 0xd4, 0xd4, 0x87, 0xda, + 0xf8, 0x91, 0x57, 0xa9, 0x69, 0xe7, 0xfb, 0xdf, 0x9f, 0xaf, 0x2a, 0x31, 0x52, 0xd0, 0xb9, 0x40, + 0xdd, 0xfb, 0xa2, 0x5a, 0x60, 0xe6, 0xd4, 0x14, 0xa9, 0xc2, 0x8a, 0xed, 0xa1, 0x4c, 0x04, 0x97, + 0x38, 0x5a, 0x14, 0x1b, 0x7d, 0xc2, 0xfd, 0x37, 0x1a, 0x65, 0x68, 0xf4, 0x40, 0xdf, 0xe2, 0xbe, + 0xd8, 0xa6, 0xeb, 0xe5, 0xa5, 0xd1, 0x87, 0x87, 0xbb, 0xbc, 0x55, 0xf0, 0xbb, 0x5e, 0x29, 0xee, + 0xc6, 0x7d, 0x01, 0x83, 0x33, 0xb7, 0x26, 0xd4, 0x60, 0xf7, 0x3d, 0xb4, 0xea, 0xf0, 0xa7, 0xd0, + 0xfb, 0xc8, 0x83, 0x14, 0x63, 0xe4, 0xaa, 0xf6, 0x3a, 0xce, 0x25, 0x28, 0x6b, 0xe0, 0x5c, 0xdb, + 0xdf, 0x9d, 0x43, 0xfb, 0x1c, 0xe7, 0xec, 0x86, 0x39, 0xdd, 0xff, 0xe6, 0xb8, 0xb7, 0x0d, 0x9a, + 0x41, 0xfb, 0x9c, 0x02, 0x01, 0xfd, 0x2b, 0xaa, 0xf2, 0xdb, 0xda, 0xb4, 0x2c, 0xe7, 0xea, 0xcf, + 0xbc, 0x9d, 0xff, 0x3a, 0xda, 0xda, 0xe1, 0x68, 0x6b, 0x7f, 0x8e, 0xb6, 0xf6, 0xe3, 0x64, 0x37, + 0x0e, 0x27, 0xbb, 0xf1, 0xfb, 0x64, 0x37, 0x16, 0x13, 0x16, 0xaa, 0x4d, 0xe6, 0x3b, 0x81, 0x88, + 0x49, 0x75, 0x8a, 0xe5, 0x33, 0x91, 0xab, 0x2d, 0xf1, 0xa9, 0x44, 0x9a, 0x24, 0x44, 0xa1, 0x54, + 0x99, 0x0a, 0x23, 0xbf, 0x59, 0x1c, 0xe7, 0x9b, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x44, 0x91, + 0x2d, 0xb3, 0xf8, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -549,6 +565,13 @@ func (m *MsgCounter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintMessages(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } if m.FailOnHandler { i-- if m.FailOnHandler { @@ -587,6 +610,13 @@ func (m *MsgCounter2) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintMessages(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } if m.FailOnHandler { i-- if m.FailOnHandler { @@ -718,6 +748,10 @@ func (m *MsgCounter) Size() (n int) { if m.FailOnHandler { n += 2 } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovMessages(uint64(l)) + } return n } @@ -733,6 +767,10 @@ func (m *MsgCounter2) Size() (n int) { if m.FailOnHandler { n += 2 } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovMessages(uint64(l)) + } return n } @@ -849,6 +887,38 @@ func (m *MsgCounter) Unmarshal(dAtA []byte) error { } } m.FailOnHandler = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessages + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMessages + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMessages + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMessages(dAtA[iNdEx:]) @@ -938,6 +1008,38 @@ func (m *MsgCounter2) Unmarshal(dAtA []byte) error { } } m.FailOnHandler = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessages + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMessages + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMessages + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMessages(dAtA[iNdEx:]) diff --git a/baseapp/testutil/messages.proto b/baseapp/testutil/messages.proto index ebf03189eec9..1cce9dba5ded 100644 --- a/baseapp/testutil/messages.proto +++ b/baseapp/testutil/messages.proto @@ -1,6 +1,5 @@ syntax = "proto3"; -import "cosmos/msg/v1/msg.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; import "cosmos/msg/v1/msg.proto"; diff --git a/codec/amino_codec.go b/codec/amino_codec.go index 690f849e5f04..c4bc0bd0d106 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -129,21 +129,3 @@ func (ac *AminoCodec) MarshalInterfaceJSON(i proto.Message) ([]byte, error) { func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error { return ac.LegacyAmino.UnmarshalJSON(bz, ptr) } - -func (ac *AminoCodec) GetMsgAnySigners(*types.Any) ([]string, protov2.Message, error) { - return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) GetMsgV1Signers(proto.Message) ([]string, protov2.Message, error) { - return nil, nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) GetMsgV2Signers(protov2.Message) ([]string, error) { - return nil, fmt.Errorf("amino codec does not support getting msg signers") -} - -func (ac *AminoCodec) InterfaceRegistry() types.InterfaceRegistry { - panic("amino codec does not support interface registry") -} - -func (ac *AminoCodec) mustEmbedCodec() {} diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 6d216b36f57f..c2a2ae57db08 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -102,7 +102,7 @@ type UnpackInterfacesMessage interface { } type interfaceRegistry struct { - *protoregistry.Files + signing.ProtoFileResolver interfaceNames map[string]reflect.Type interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type @@ -128,7 +128,7 @@ func NewInterfaceRegistry() InterfaceRegistry { // InterfaceRegistryOptions are options for creating a new InterfaceRegistry. type InterfaceRegistryOptions struct { // ProtoFiles is the set of files to use for the registry. It is required. - ProtoFiles *protoregistry.Files + ProtoFiles signing.ProtoFileResolver // AddressCodec is the address codec to use for the registry. It is required. AddressCodec address.Codec @@ -154,12 +154,12 @@ func NewInterfaceRegistryWithOptions(options InterfaceRegistryOptions) (Interfac } return &interfaceRegistry{ - interfaceNames: map[string]reflect.Type{}, - interfaceImpls: map[reflect.Type]interfaceMap{}, - implInterfaces: map[reflect.Type]reflect.Type{}, - typeURLMap: map[string]reflect.Type{}, - Files: options.ProtoFiles, - signingCtx: signingCtx, + interfaceNames: map[string]reflect.Type{}, + interfaceImpls: map[reflect.Type]interfaceMap{}, + implInterfaces: map[reflect.Type]reflect.Type{}, + typeURLMap: map[string]reflect.Type{}, + ProtoFileResolver: options.ProtoFiles, + signingCtx: signingCtx, }, nil } diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index a8fbc9fdde3a..ab650e8ea7c6 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -1097,7 +1097,7 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo("foobar") - s.Require().Equal([]string{val.Address.String()}, txBuilder.GetTx().GetSigners()) + s.Require().Equal([]sdk.AccAddress{val.Address}, txBuilder.GetTx().GetSigners()) // setup txFactory txFactory := clienttx.Factory{}. diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index 5e4213c4802a..b8ecd5e33e56 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -1560,25 +1560,26 @@ var file_testpb_tx_proto_rawDesc = []byte{ 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, - 0x48, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, + 0x54, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x23, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, - 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x2f, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, - 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, - 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, - 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, - 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, - 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, - 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, - 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, - 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x2f, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, + 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x54, 0x65, + 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, + 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x1a, + 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, + 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x65, 0x73, + 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, + 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, + 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, + 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index e2d416faa41e..192354be6122 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -174,29 +174,29 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 337 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x31, 0x4b, 0xc3, 0x40, - 0x14, 0xc7, 0x73, 0xd6, 0xb6, 0xe4, 0x2a, 0x8a, 0x21, 0x62, 0x08, 0x1a, 0x4b, 0x5d, 0x4a, 0xc0, - 0x1c, 0xd6, 0xad, 0x8b, 0xa0, 0x1d, 0xba, 0x14, 0x21, 0x38, 0xb9, 0xa5, 0xed, 0x71, 0x06, 0x4d, - 0x5e, 0xc9, 0xbb, 0xaa, 0xa3, 0x38, 0x89, 0x93, 0x1f, 0xc1, 0x8f, 0xd0, 0x8f, 0xe1, 0xd8, 0xd1, - 0x51, 0xda, 0xa1, 0x5f, 0x43, 0x72, 0x97, 0x68, 0x07, 0x97, 0xbc, 0xff, 0xfb, 0x3d, 0xf2, 0xbf, - 0xf7, 0xfe, 0x74, 0x47, 0x72, 0x94, 0x93, 0x21, 0x93, 0x4f, 0xc1, 0x24, 0x03, 0x09, 0x56, 0x4d, - 0x03, 0x77, 0x37, 0x4a, 0xe2, 0x14, 0x98, 0xfa, 0xea, 0x91, 0x6b, 0x0b, 0x10, 0xa0, 0x24, 0xcb, - 0x55, 0x41, 0xf7, 0x4a, 0x07, 0x8e, 0x72, 0x1c, 0xc9, 0xa8, 0xc0, 0xfb, 0x23, 0xc0, 0x04, 0x90, - 0x25, 0x28, 0xd8, 0xc3, 0x69, 0x5e, 0xf4, 0xa0, 0x75, 0x45, 0xb7, 0x06, 0x28, 0x2e, 0x33, 0x1e, - 0x49, 0xde, 0x03, 0x61, 0x1d, 0xd2, 0xca, 0x18, 0x84, 0x43, 0x9a, 0xa4, 0xdd, 0xe8, 0x34, 0x02, - 0xed, 0x16, 0xf4, 0x40, 0x84, 0x39, 0xb7, 0x6c, 0x5a, 0x85, 0xc7, 0x94, 0x67, 0xce, 0x46, 0x93, - 0xb4, 0xcd, 0x50, 0x37, 0x5d, 0xfa, 0xb2, 0x9a, 0xf9, 0x5a, 0xb7, 0x7c, 0x6a, 0xaf, 0x1b, 0x86, - 0x1c, 0x27, 0x90, 0x22, 0xb7, 0x2c, 0xba, 0x99, 0x46, 0x09, 0x57, 0xce, 0x66, 0xa8, 0x74, 0xab, - 0x4f, 0xeb, 0xd7, 0x1c, 0xe5, 0x00, 0x85, 0xe5, 0xd0, 0x3a, 0xc6, 0x22, 0xe5, 0x19, 0x3a, 0xa4, - 0x59, 0x69, 0x9b, 0x61, 0xd9, 0x76, 0x8f, 0x5f, 0x3f, 0x8e, 0x8c, 0xfc, 0x81, 0x92, 0xbc, 0xad, - 0x66, 0xfe, 0x76, 0x71, 0x66, 0xf1, 0x7b, 0x67, 0x40, 0x2b, 0xb9, 0xcb, 0x39, 0x35, 0xff, 0x4e, - 0xb1, 0xcb, 0xed, 0xd7, 0xf7, 0x71, 0x0f, 0xfe, 0xa3, 0xe5, 0x96, 0x6e, 0xf5, 0x79, 0x35, 0xf3, - 0xc9, 0x45, 0xff, 0x73, 0xe1, 0x91, 0xf9, 0xc2, 0x23, 0xdf, 0x0b, 0x8f, 0xbc, 0x2f, 0x3d, 0x63, - 0xbe, 0xf4, 0x8c, 0xaf, 0xa5, 0x67, 0xdc, 0x04, 0x22, 0x96, 0xb7, 0xd3, 0x61, 0x30, 0x82, 0x84, - 0x15, 0x99, 0xea, 0x72, 0x82, 0xe3, 0x3b, 0x95, 0xfa, 0x54, 0xc6, 0xf7, 0xbf, 0xf1, 0x0f, 0x6b, - 0x2a, 0xe6, 0xb3, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x89, 0xf1, 0xc8, 0x3c, 0xda, 0x01, 0x00, - 0x00, + // 339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, + 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, + 0x09, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x94, 0x94, 0x48, 0x7a, 0x7e, 0x7a, + 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x45, 0x45, 0x61, 0x26, 0xa4, 0x16, 0x97, 0xa4, 0x24, 0x96, + 0x24, 0x42, 0x85, 0xc5, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x73, 0x8b, 0xd3, 0xf5, 0xcb, + 0x0c, 0x41, 0x14, 0x44, 0x42, 0xc9, 0x9f, 0x8b, 0xc7, 0xb7, 0x38, 0xdd, 0xb9, 0x28, 0x35, 0xb1, + 0x24, 0xd5, 0x25, 0x3f, 0x5d, 0x48, 0x96, 0x8b, 0x39, 0x25, 0x3f, 0x5d, 0x82, 0x51, 0x81, 0x51, + 0x83, 0xdb, 0x88, 0x5b, 0x0f, 0x62, 0x9a, 0x9e, 0x4b, 0x7e, 0x7a, 0x10, 0x48, 0x5c, 0x48, 0x84, + 0x8b, 0x35, 0xbf, 0x3c, 0x2f, 0xb5, 0x48, 0x82, 0x49, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc2, 0xb1, + 0xe2, 0x6a, 0x7a, 0xbe, 0x41, 0x0b, 0xc2, 0x56, 0xd2, 0xe2, 0x12, 0x41, 0x36, 0x30, 0x28, 0xb5, + 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x88, 0x8b, 0x25, 0x2f, 0x31, 0x37, 0x15, 0x6c, 0x32, + 0x67, 0x10, 0x98, 0xad, 0x14, 0xc2, 0xc5, 0x1e, 0x92, 0x5a, 0x5c, 0xe2, 0x5b, 0x9c, 0x2e, 0x24, + 0xc1, 0xc5, 0x5e, 0x9c, 0x99, 0x9e, 0x97, 0x5a, 0x54, 0x2c, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0x19, + 0x04, 0xe3, 0x5a, 0xe9, 0x77, 0x2c, 0x90, 0x67, 0x00, 0x59, 0x00, 0x13, 0x41, 0x66, 0x77, 0x3d, + 0xdf, 0xa0, 0xc5, 0x07, 0xf5, 0x32, 0xd4, 0x28, 0x23, 0x5f, 0x2e, 0x66, 0x90, 0x89, 0xf6, 0x5c, + 0x9c, 0x08, 0x6f, 0x89, 0xc0, 0x7c, 0x82, 0xec, 0x36, 0x29, 0x19, 0x6c, 0xa2, 0x30, 0x17, 0x4b, + 0xb1, 0x36, 0x3c, 0xdf, 0xa0, 0xc5, 0xe8, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, + 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, + 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xd0, + 0xf0, 0x85, 0x50, 0xba, 0xc5, 0x29, 0xd9, 0xe0, 0x18, 0x28, 0x2d, 0xc9, 0xcc, 0x81, 0x47, 0x45, + 0x12, 0x1b, 0x38, 0xc8, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd5, 0xbe, 0xa2, 0x89, 0xe6, + 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index bc9e66335a7e..9256f825d135 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -119,7 +119,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { require.NoError(t, err) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 - expectedSigners := []string{addr0.String(), addr1.String(), addr2.String()} + expectedSigners := []sdk.AccAddress{addr0, addr1, addr2} require.Equal(t, expectedSigners, tx.GetSigners()) return TestCaseArgs{ diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index 019897a95135..55fa204c59d1 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -409,7 +409,7 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal(s.val.String(), txBuilder.GetTx().GetSigners()[0]) + s.Require().Equal(s.val.String(), sdk.AccAddress(txBuilder.GetTx().GetSigners()[0]).String()) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -917,7 +917,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - s.Require().Equal([]string{val0.String(), val1.String()}, txBuilder.GetTx().GetSigners()) + s.Require().Equal([]sdk.AccAddress{val0, val1}, txBuilder.GetTx().GetSigners()) // Write the unsigned tx into a file. txJSON, err := s.clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) diff --git a/x/gov/types/v1/gov.pb.go b/x/gov/types/v1/gov.pb.go index 91f414b76851..8384b8f1df8d 100644 --- a/x/gov/types/v1/gov.pb.go +++ b/x/gov/types/v1/gov.pb.go @@ -2929,7 +2929,7 @@ func (m *Vote) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InterfaceRegistryOptions", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Options", wireType) } var msglen int for shift := uint(0); ; shift += 7 { diff --git a/x/gov/types/v1/tx.pb.go b/x/gov/types/v1/tx.pb.go index 02471136d838..3ab042b1787c 100644 --- a/x/gov/types/v1/tx.pb.go +++ b/x/gov/types/v1/tx.pb.go @@ -2814,7 +2814,7 @@ func (m *MsgVoteWeighted) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InterfaceRegistryOptions", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Options", wireType) } var msglen int for shift := uint(0); ; shift += 7 { diff --git a/x/gov/types/v1beta1/gov.pb.go b/x/gov/types/v1beta1/gov.pb.go index 993fa5a83600..1acd514b717a 100644 --- a/x/gov/types/v1beta1/gov.pb.go +++ b/x/gov/types/v1beta1/gov.pb.go @@ -2373,7 +2373,7 @@ func (m *Vote) Unmarshal(dAtA []byte) error { } case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InterfaceRegistryOptions", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Options", wireType) } var msglen int for shift := uint(0); ; shift += 7 { diff --git a/x/gov/types/v1beta1/tx.pb.go b/x/gov/types/v1beta1/tx.pb.go index d44670d92572..80d6fe1f1f4e 100644 --- a/x/gov/types/v1beta1/tx.pb.go +++ b/x/gov/types/v1beta1/tx.pb.go @@ -1538,7 +1538,7 @@ func (m *MsgVoteWeighted) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InterfaceRegistryOptions", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Options", wireType) } var msglen int for shift := uint(0); ; shift += 7 { From 24152357ffa648e3023e8cd39b113bf5af8dcb58 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 12:28:46 -0400 Subject: [PATCH 42/83] add codec testutil --- api/go.mod | 2 +- api/go.sum | 2 ++ baseapp/baseapp_test.go | 13 +--------- client/v2/go.mod | 2 +- client/v2/go.sum | 2 ++ codec/types/interface_registry.go | 3 +-- core/go.mod | 2 +- core/go.sum | 2 ++ go.mod | 2 +- go.sum | 2 ++ orm/go.mod | 2 +- orm/go.sum | 2 ++ server/mock/app.go | 5 ++-- simapp/go.mod | 2 +- simapp/go.sum | 2 ++ store/go.mod | 2 +- store/go.sum | 2 ++ tests/go.mod | 2 +- tests/go.sum | 2 ++ testutil/codec.go | 43 +++++++++++++++++++++++++++++++ tools/confix/go.mod | 2 +- tools/confix/go.sum | 2 ++ tools/cosmovisor/go.mod | 2 +- tools/cosmovisor/go.sum | 2 ++ tools/hubl/go.mod | 2 +- tools/hubl/go.sum | 2 ++ tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 2 ++ x/auth/tx/builder_test.go | 2 +- x/circuit/go.mod | 2 +- x/circuit/go.sum | 2 ++ x/evidence/go.mod | 2 +- x/evidence/go.sum | 2 ++ x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 2 ++ x/nft/go.mod | 2 +- x/nft/go.sum | 2 ++ x/tx/go.mod | 2 +- x/tx/go.sum | 2 ++ x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 2 ++ 41 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 testutil/codec.go diff --git a/api/go.mod b/api/go.mod index f79837ed6d4e..79478d259c6d 100644 --- a/api/go.mod +++ b/api/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 google.golang.org/genproto v0.0.0-20230320184635-7606e756e683 google.golang.org/grpc v1.54.0 google.golang.org/protobuf v1.30.0 diff --git a/api/go.sum b/api/go.sum index 692d403f799c..c3132ca7773f 100644 --- a/api/go.sum +++ b/api/go.sum @@ -2,6 +2,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQ github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 346ed312aafb..9712a85338a7 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -11,7 +11,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" "cosmossdk.io/store/metrics" @@ -57,17 +56,7 @@ type ( ) func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { - protoRegistry, err := proto.MergedRegistry() - require.NoError(t, err) - interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions( - codectypes.InterfaceRegistryOptions{ - ProtoFiles: protoRegistry, - AddressCodec: testAddressCodec{}, - ValidatorAddressCodec: testAddressCodec{}, - }, - ) - require.NoError(t, err) - cdc := codec.NewProtoCodec(interfaceRegistry) + cdc := testutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) diff --git a/client/v2/go.mod b/client/v2/go.mod index 0a84f400063d..e3c7c21b0b3e 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -43,7 +43,7 @@ require ( github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.0-rc.1 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cosmos/iavl v0.21.0-beta.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect github.com/danieljoos/wincred v1.1.2 // indirect diff --git a/client/v2/go.sum b/client/v2/go.sum index 3cfd8a34bdd4..6d9eccf3d4ca 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -146,6 +146,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index c2a2ae57db08..f182c011f1f7 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" "cosmossdk.io/core/address" @@ -115,7 +114,7 @@ type interfaceMap = map[string]reflect.Type // NewInterfaceRegistry returns a new InterfaceRegistry func NewInterfaceRegistry() InterfaceRegistry { registry, err := NewInterfaceRegistryWithOptions(InterfaceRegistryOptions{ - ProtoFiles: protoregistry.GlobalFiles, + ProtoFiles: proto.HybridResolver, AddressCodec: failingAddressCodec{}, ValidatorAddressCodec: failingAddressCodec{}, }) diff --git a/core/go.mod b/core/go.mod index 023a12db95d2..6d783c154959 100644 --- a/core/go.mod +++ b/core/go.mod @@ -23,7 +23,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/pebble v0.0.0-20230226194802-02d779ffbc46 // indirect github.com/cockroachdb/redact v1.1.3 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/core/go.sum b/core/go.sum index 1263f59c77cc..10eb4566bb76 100644 --- a/core/go.sum +++ b/core/go.sum @@ -49,6 +49,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQ github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0= diff --git a/go.mod b/go.mod index 7ee046ff473e..930217238fce 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/cosmos/cosmos-sdk/db v1.0.0-beta.1.0.20220726092710-f848e4300a8a github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogogateway v1.2.0 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/cosmos/ledger-cosmos-go v0.13.0 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 github.com/golang/mock v1.6.0 diff --git a/go.sum b/go.sum index 2265464421a0..20b5a591f3ee 100644 --- a/go.sum +++ b/go.sum @@ -190,6 +190,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/orm/go.mod b/orm/go.mod index ffb7953dbb82..16efc4001c11 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -31,7 +31,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/pebble v0.0.0-20230412222916-60cfeb46143b // indirect github.com/cockroachdb/redact v1.1.3 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cucumber/common/gherkin/go/v22 v22.0.0 // indirect github.com/cucumber/common/messages/go/v17 v17.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/orm/go.sum b/orm/go.sum index 0b5c92f9c217..b4b5e4382c0d 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -55,6 +55,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQ github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0= diff --git a/server/mock/app.go b/server/mock/app.go index 078bf2adf69e..2c7bd89060aa 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -12,11 +12,12 @@ import ( "google.golang.org/grpc" "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/testutil" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -36,7 +37,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { baseApp.MountStores(capKeyMainStore) baseApp.SetInitChainer(InitChainer(capKeyMainStore)) - interfaceRegistry := codectypes.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &KVStoreTx{}) router := bam.NewMsgServiceRouter() diff --git a/simapp/go.mod b/simapp/go.mod index 5efe530ca9fa..16bca95da609 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -20,7 +20,7 @@ require ( github.com/cosmos/cosmos-db v1.0.0-rc.1 // this version is not used as it is always replaced by the latest Cosmos SDK version github.com/cosmos/cosmos-sdk v0.48.0 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/mock v1.6.0 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.7.0 diff --git a/simapp/go.sum b/simapp/go.sum index 3491bcc8ae92..9e7d9900e084 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -347,6 +347,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/store/go.mod b/store/go.mod index f83c0907c9ad..62ecc026b262 100644 --- a/store/go.mod +++ b/store/go.mod @@ -9,7 +9,7 @@ require ( github.com/armon/go-metrics v0.4.1 github.com/cometbft/cometbft v0.37.1 github.com/cosmos/cosmos-db v1.0.0-rc.1 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/cosmos/iavl v0.21.0 github.com/cosmos/ics23/go v0.10.0 github.com/golang/mock v1.6.0 diff --git a/store/go.sum b/store/go.sum index 92a2ade11bc4..045407a18ac1 100644 --- a/store/go.sum +++ b/store/go.sum @@ -65,6 +65,8 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/tests/go.mod b/tests/go.mod index 0454ff6ff35b..b9b2f7f790ad 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -21,7 +21,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 // this version is not used as it is always replaced by the latest Cosmos SDK version github.com/cosmos/cosmos-sdk v0.48.0 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 // indirect github.com/spf13/cobra v1.7.0 diff --git a/tests/go.sum b/tests/go.sum index 28873dcc964d..8d0b3281fd75 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -347,6 +347,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/testutil/codec.go b/testutil/codec.go new file mode 100644 index 000000000000..5330966de7cf --- /dev/null +++ b/testutil/codec.go @@ -0,0 +1,43 @@ +package testutil + +import ( + "github.com/cosmos/gogoproto/proto" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +// CodecOptions are options for creating a test codec. +type CodecOptions struct { + AccAddressPrefix string + ValAddressPrefix string +} + +// NewInterfaceRegistry returns a new InterfaceRegistry with the given options. +func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { + accAddressPrefix := o.AccAddressPrefix + if accAddressPrefix == "" { + accAddressPrefix = "sim" + } + + valAddressPrefix := o.ValAddressPrefix + if valAddressPrefix == "" { + valAddressPrefix = "simvaloper" + } + + ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + AddressCodec: address.NewBech32Codec(accAddressPrefix), + ValidatorAddressCodec: address.NewBech32Codec(valAddressPrefix), + }) + if err != nil { + panic(err) + } + return ir +} + +// NewCodec returns a new codec with the given options. +func (o CodecOptions) NewCodec() *codec.ProtoCodec { + return codec.NewProtoCodec(o.NewInterfaceRegistry()) +} diff --git a/tools/confix/go.mod b/tools/confix/go.mod index 843c3456e289..455022a6738d 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -46,7 +46,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cosmos/iavl v0.21.0-beta.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect github.com/creachadair/taskgroup v0.4.2 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index 69b1553a25a5..96b0d539364f 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -192,6 +192,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/tools/cosmovisor/go.mod b/tools/cosmovisor/go.mod index 297f5dd6b48f..ce91bda035f1 100644 --- a/tools/cosmovisor/go.mod +++ b/tools/cosmovisor/go.mod @@ -50,7 +50,7 @@ require ( github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230424095137-b73c17cb9cc8 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cosmos/iavl v0.21.0-beta.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect github.com/danieljoos/wincred v1.1.2 // indirect diff --git a/tools/cosmovisor/go.sum b/tools/cosmovisor/go.sum index 39d1020ceda5..a82f3b407802 100644 --- a/tools/cosmovisor/go.sum +++ b/tools/cosmovisor/go.sum @@ -345,6 +345,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/tools/hubl/go.mod b/tools/hubl/go.mod index 050ad9e4cbaf..fd2907daab19 100644 --- a/tools/hubl/go.mod +++ b/tools/hubl/go.mod @@ -44,7 +44,7 @@ require ( github.com/cosmos/cosmos-db v1.0.0-rc.1 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cosmos/iavl v0.21.0-beta.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect github.com/danieljoos/wincred v1.1.2 // indirect diff --git a/tools/hubl/go.sum b/tools/hubl/go.sum index 68c75240c037..f211f4ef71b2 100644 --- a/tools/hubl/go.sum +++ b/tools/hubl/go.sum @@ -154,6 +154,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index b0540668f1aa..8fdfcc02ffa7 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -44,7 +44,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/cosmos/iavl v0.21.0 // indirect github.com/cosmos/ics23/go v0.10.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 636e219aac05..4b24ab115158 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -172,6 +172,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 549be2a6373c..832a9e28320a 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -139,7 +139,7 @@ func TestBuilderValidateBasic(t *testing.T) { // require to fail validation upon invalid fee badFeeAmount := testdata.NewTestFeeAmount() badFeeAmount[0].Amount = sdkmath.NewInt(-5) - txBuilder := newBuilder(nil) + txBuilder := newBuilder(codec.NewProtoCodec(codectypes.NewInterfaceRegistry())) var sig1, sig2 signing.SignatureV2 sig1 = signing.SignatureV2{ diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 81b3b0b40c6f..5d7f96578538 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230424095137-b73c17cb9cc8 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/regen-network/gocuke v0.6.2 diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 6b2df1374696..9a233840742d 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -103,6 +103,8 @@ github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index b624234bd3a6..ffe9e35a2a20 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -13,7 +13,7 @@ require ( github.com/cometbft/cometbft v0.37.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419074131-aa683247d515 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 4c9e42ba410c..3bfc644eba41 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -183,6 +183,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0 h1:E39qwHl45PaQUe/mRA8lY4kOqaunOorVQufpv5JPgXk= github.com/cosmos/iavl v0.21.0/go.mod h1:ejCWRfxvfmQTcligmeRcoQeB8VgHGxkVlIqKSKG7YaI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 218e5af8830a..efc5a61a2576 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -13,7 +13,7 @@ require ( github.com/cometbft/cometbft v0.37.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230426101247-6dfe7351a5c2 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 96b743766b1a..39973ff168d5 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -197,6 +197,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/x/nft/go.mod b/x/nft/go.mod index 315a9b995eac..ef20bc305382 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -13,7 +13,7 @@ require ( github.com/cometbft/cometbft v0.37.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230426101247-6dfe7351a5c2 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 diff --git a/x/nft/go.sum b/x/nft/go.sum index 699cf2175f04..03484d530832 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -192,6 +192,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= diff --git a/x/tx/go.mod b/x/tx/go.mod index fdbc59ca0fe3..e569af2e6d3f 100644 --- a/x/tx/go.mod +++ b/x/tx/go.mod @@ -19,7 +19,7 @@ require ( ) require ( - github.com/cosmos/gogoproto v1.4.8 // indirect + github.com/cosmos/gogoproto v1.4.9 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/x/tx/go.sum b/x/tx/go.sum index 571e96b15087..24235ac09345 100644 --- a/x/tx/go.sum +++ b/x/tx/go.sum @@ -10,6 +10,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQ github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 65f257bbc233..28396883fb32 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -14,7 +14,7 @@ require ( github.com/cosmos/cosmos-db v1.0.0-rc.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419074131-aa683247d515 - github.com/cosmos/gogoproto v1.4.8 + github.com/cosmos/gogoproto v1.4.9 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/hashicorp/go-getter v1.7.1 diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 83c2fe1fc966..c90708440675 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -357,6 +357,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4= github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY= +github.com/cosmos/gogoproto v1.4.9 h1:MjVmV6F1yk1rJLWtKeYdGQcTbE880t+VlRcayEBqUKQ= +github.com/cosmos/gogoproto v1.4.9/go.mod h1:c0ysUnwvnlR+RmCUvqqii7pp8kHBB/DBcp/5VLA/nQk= github.com/cosmos/iavl v0.21.0-beta.1 h1:fBQeBc8HLZ14plJNcmGfaOXSSMLVEHvEQXiTXSD76m0= github.com/cosmos/iavl v0.21.0-beta.1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U= github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s= From b8e7e96bf7b5fc7669a7362b8444de99fde79b14 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 12:38:44 -0400 Subject: [PATCH 43/83] test fixes --- baseapp/baseapp_test.go | 3 ++- {testutil => codec/testutil}/codec.go | 4 ++-- server/mock/app.go | 3 +-- types/module/testutil/codec.go | 3 ++- x/auth/tx/builder_test.go | 3 ++- 5 files changed, 9 insertions(+), 7 deletions(-) rename {testutil => codec/testutil}/codec.go (94%) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 9712a85338a7..68ba2bc04a9f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -19,6 +19,7 @@ import ( "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" + testutil2 "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" @@ -56,7 +57,7 @@ type ( ) func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { - cdc := testutil.CodecOptions{}.NewCodec() + cdc := testutil2.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) diff --git a/testutil/codec.go b/codec/testutil/codec.go similarity index 94% rename from testutil/codec.go rename to codec/testutil/codec.go index 5330966de7cf..2f08a4ad3b4c 100644 --- a/testutil/codec.go +++ b/codec/testutil/codec.go @@ -18,12 +18,12 @@ type CodecOptions struct { func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { accAddressPrefix := o.AccAddressPrefix if accAddressPrefix == "" { - accAddressPrefix = "sim" + accAddressPrefix = "cosmos" } valAddressPrefix := o.ValAddressPrefix if valAddressPrefix == "" { - valAddressPrefix = "simvaloper" + valAddressPrefix = "cosmosvaloper" } ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ diff --git a/server/mock/app.go b/server/mock/app.go index 2c7bd89060aa..9cef19f4c4a3 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -14,10 +14,9 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/testutil" - bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 2a6959f02dad..5972c002d3ae 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -3,6 +3,7 @@ package testutil import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" @@ -22,7 +23,7 @@ type TestEncodingConfig struct { func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() codec := codec.NewProtoCodec(interfaceRegistry) encCfg := TestEncodingConfig{ diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 832a9e28320a..2bba067a832f 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -139,7 +140,7 @@ func TestBuilderValidateBasic(t *testing.T) { // require to fail validation upon invalid fee badFeeAmount := testdata.NewTestFeeAmount() badFeeAmount[0].Amount = sdkmath.NewInt(-5) - txBuilder := newBuilder(codec.NewProtoCodec(codectypes.NewInterfaceRegistry())) + txBuilder := newBuilder(testutil.CodecOptions{}.NewCodec()) var sig1, sig2 signing.SignatureV2 sig1 = signing.SignatureV2{ From 6452dc05c39210e9311dab5c540645547e56101c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 14:13:53 -0400 Subject: [PATCH 44/83] fix test --- server/mock/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/mock/app.go b/server/mock/app.go index 9cef19f4c4a3..8a4548c8f8a1 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -38,6 +38,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &KVStoreTx{}) + baseApp.SetInterfaceRegistry(interfaceRegistry) router := bam.NewMsgServiceRouter() router.SetInterfaceRegistry(interfaceRegistry) From b17adc241d8b4292f4cca96a3b6f8d83730e9d8b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 15:20:16 -0400 Subject: [PATCH 45/83] test fixes --- baseapp/baseapp_test.go | 4 +++- baseapp/utils_test.go | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 68ba2bc04a9f..946fa6b25deb 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -20,6 +20,7 @@ import ( snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" testutil2 "github.com/cosmos/cosmos-sdk/codec/testutil" + "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" @@ -109,6 +110,7 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun for height := int64(1); height <= int64(cfg.blocks); height++ { suite.baseApp.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: height}}) + _, _, addr := testdata.KeyTestPubAddr() for txNum := 0; txNum < cfg.blockTxs; txNum++ { msgs := []sdk.Msg{} for msgNum := 0; msgNum < 100; msgNum++ { @@ -118,7 +120,7 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun _, err := r.Read(value) require.NoError(t, err) - msgs = append(msgs, &baseapptestutil.MsgKeyValue{Key: key, Value: value}) + msgs = append(msgs, &baseapptestutil.MsgKeyValue{Key: key, Value: value, Signer: addr.String()}) keyCounter++ } diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index cbdee8a0c347..362d1aa00e1f 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -15,16 +15,18 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" - "cosmossdk.io/core/appconfig" "cosmossdk.io/depinject" errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" - storetypes "cosmossdk.io/store/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" + "cosmossdk.io/core/appconfig" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" @@ -322,9 +324,10 @@ func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) { } func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters ...int64) signing.Tx { + _, _, addr := testdata.KeyTestPubAddr() msgs := make([]sdk.Msg, 0, len(msgCounters)) for _, c := range msgCounters { - msg := &baseapptestutil.MsgCounter{Counter: c, FailOnHandler: false} + msg := &baseapptestutil.MsgCounter{Counter: c, FailOnHandler: false, Signer: addr.String()} msgs = append(msgs, msg) } From 5e45f37ea9fa8895b8aa91b53aaceb869219adda Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 17:13:17 -0400 Subject: [PATCH 46/83] test fixes --- baseapp/abci_test.go | 6 ++++-- server/mock/tx.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 674a209b3a08..83d4fc4a7c2f 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -16,6 +16,7 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" + pruningtypes "cosmossdk.io/store/pruning/types" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" @@ -781,8 +782,9 @@ func TestABCI_DeliverTx_MultiMsg(t *testing.T) { builder := suite.txConfig.NewTxBuilder() msgs := tx.GetMsgs() - msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 0}) - msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 1}) + _, _, addr := testdata.KeyTestPubAddr() + msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 0, Signer: addr.String()}) + msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 1, Signer: addr.String()}) builder.SetMsgs(msgs...) builder.SetMemo(tx.GetMemo()) diff --git a/server/mock/tx.go b/server/mock/tx.go index 15479a227d2e..a2e7a5b2a9a7 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -86,7 +86,7 @@ var ( ) func NewTx(key, value string, accAddress sdk.AccAddress) *KVStoreTx { - bytes := fmt.Sprintf("%s=%s", key, value) + bytes := fmt.Sprintf("%s=%s=%s", key, value, accAddress) return &KVStoreTx{ key: []byte(key), value: []byte(value), @@ -104,7 +104,7 @@ func (msg *KVStoreTx) GetMsgs() []sdk.Msg { } func (msg *KVStoreTx) GetMsgsV2() []protov2.Message { - return []protov2.Message{&bankv1beta1.MsgSend{FromAddress: "test"}} // this is a hack for tests + return []protov2.Message{&bankv1beta1.MsgSend{FromAddress: msg.address.String()}} // this is a hack for tests } func (msg *KVStoreTx) GetSignBytes() []byte { @@ -135,6 +135,9 @@ func decodeTx(txBytes []byte) (sdk.Tx, error) { case 2: k, v := split[0], split[1] tx = &KVStoreTx{k, v, txBytes, nil} + case 3: + k, v, addr := split[0], split[1], split[2] + tx = &KVStoreTx{k, v, txBytes, addr} default: return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "too many '='") } From 2c038a9dfc4ca4e1d79c7abbf90b75cba2b14b9f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 3 May 2023 17:22:34 -0400 Subject: [PATCH 47/83] test fixes --- x/auth/client/cli/suite_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index 55fa204c59d1..11d37128761e 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -7,12 +7,13 @@ import ( "strings" "testing" - "cosmossdk.io/core/address" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/address" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" @@ -409,7 +410,7 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal(s.val.String(), sdk.AccAddress(txBuilder.GetTx().GetSigners()[0]).String()) + s.Require().Equal([]byte(s.val), txBuilder.GetTx().GetSigners()[0]) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -917,7 +918,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - s.Require().Equal([]sdk.AccAddress{val0, val1}, txBuilder.GetTx().GetSigners()) + s.Require().Equal([][]byte{val0, val1}, txBuilder.GetTx().GetSigners()) // Write the unsigned tx into a file. txJSON, err := s.clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) From 3bb3a14d5392e30ed0882ff0a80faf5c88287620 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 12:24:03 -0400 Subject: [PATCH 48/83] fixes --- CHANGELOG.md | 5 ++++- client/tx_config.go | 1 + simapp/app.go | 4 +++- types/module/testutil/codec.go | 2 +- x/auth/ante/ante.go | 3 ++- x/auth/ante/ante_test.go | 3 ++- x/auth/ante/sigverify.go | 16 ++++++++++++---- x/auth/ante/sigverify_test.go | 6 +++--- x/auth/ante/testutil_test.go | 1 + x/auth/tx/builder_test.go | 14 +++++++------- x/auth/tx/config.go | 18 ++++++++++++------ x/auth/tx/config/config.go | 4 +++- x/auth/tx/config_test.go | 4 ++-- x/auth/tx/direct_aux_test.go | 5 +++-- x/auth/tx/testutil/suite.go | 9 +++++---- x/tx/CHANGELOG.md | 2 +- 16 files changed, 62 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 353c95302ee5..1672d0fc1916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -182,11 +182,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ * The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`. * The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments. * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. -* (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHanlder` interface instead of deliverTx. The interface is implemented on baseapp +* (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHandler` interface instead of deliverTx. The interface is implemented on baseapp * [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) * `sdk.Msg.GetSigners` was deprecated and no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. * `types/tx.Tx` no longer implements `sdk.Tx`. * `sdk.Tx` now requires a new methods `GetMsgsV2()`. + * `ante.HandlerOptions` has a new required field `SigningContext *signing.Context` + * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` + * `TxConfig` has a new method `SigningContext() *signing.Context` * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. * (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. diff --git a/client/tx_config.go b/client/tx_config.go index 5b74c0d175cb..655e19cbeba7 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -30,6 +30,7 @@ type ( NewTxBuilder() TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error) SignModeHandler() *txsigning.HandlerMap + SigningContext() *txsigning.Context } // TxBuilder defines an interface which an application-defined concrete transaction diff --git a/simapp/app.go b/simapp/app.go index 29da63e5dcab..17a24890a0b7 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -9,11 +9,12 @@ import ( "os" "path/filepath" + "cosmossdk.io/log" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" - "cosmossdk.io/log" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" abci "github.com/cometbft/cometbft/abci/types" @@ -529,6 +530,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: app.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + SigningContext: txConfig.SigningContext(), }, ) if err != nil { diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 5972c002d3ae..42efba87de1d 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -44,7 +44,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig } func MakeTestTxConfig() client.TxConfig { - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) return tx.NewTxConfig(cdc, tx.DefaultSignModes) } diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 05c5eb102657..250b01f54153 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -21,6 +21,7 @@ type HandlerOptions struct { SignModeHandler *txsigning.HandlerMap SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker + SigningContext *txsigning.Context } // NewAnteHandler returns an AnteHandler that checks and increments sequence @@ -47,7 +48,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), - NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators + NewSetPubKeyDecorator(options.AccountKeeper, options.SigningContext), // SetPubKeyDecorator must be called before all signature verification decorators NewValidateSigCountDecorator(options.AccountKeeper), NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 9256f825d135..4bb791362ab4 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -119,7 +119,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { require.NoError(t, err) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 - expectedSigners := []sdk.AccAddress{addr0, addr1, addr2} + expectedSigners := [][]byte{addr0, addr1, addr2} require.Equal(t, expectedSigners, tx.GetSigners()) return TestCaseArgs{ @@ -1328,6 +1328,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { return errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized public key type: %T", pubkey) } }, + SigningContext: suite.clientCtx.TxConfig.SigningContext(), }, ) require.NoError(t, err) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 248878377b9b..5d22e71ec2b7 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -9,6 +9,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" errorsmod "cosmossdk.io/errors" + storetypes "cosmossdk.io/store/types" txsigning "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -49,12 +50,14 @@ type SignatureVerificationGasConsumer = func(meter storetypes.GasMeter, sig sign // PubKeys must be set in context for all signers before any other sigverify decorators run // CONTRACT: Tx must implement SigVerifiableTx interface type SetPubKeyDecorator struct { - ak AccountKeeper + ak AccountKeeper + signingCtx *txsigning.Context } -func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { +func NewSetPubKeyDecorator(ak AccountKeeper, signingCtx *txsigning.Context) SetPubKeyDecorator { return SetPubKeyDecorator{ - ak: ak, + ak: ak, + signingCtx: signingCtx, } } @@ -80,8 +83,13 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b } // Only make check if simulate=false if !simulate && !bytes.Equal(pk.Address(), signers[i]) { + signerStr, err := spkd.signingCtx.AddressCodec().BytesToString(signers[i]) + if err != nil { + return sdk.Context{}, err + } + return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, - "pubKey does not match signer address %s with signer index: %d", signers[i], i) + "pubKey does not match signer address %s with signer index: %d", signerStr, i) } acc, err := GetSignerAcc(ctx, spkd.ak, signers[i]) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index e5538ee03e18..0667fcdff43b 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -56,7 +56,7 @@ func TestSetPubKey(t *testing.T) { tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.encCfg.TxConfig.SigningContext()) antehandler := sdk.ChainAnteDecorators(spkd) ctx, err := antehandler(suite.ctx, tx, false) @@ -164,7 +164,7 @@ func TestSigVerification(t *testing.T) { feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SigningContext()) txConfigOpts = authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(suite.txBankKeeper), EnabledSignModes: enabledSignModes, @@ -291,7 +291,7 @@ func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...crypto tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.encCfg.TxConfig.SigningContext()) svgc := ante.NewSigGasConsumeDecorator(suite.accountKeeper, ante.DefaultSigVerificationGasConsumer) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svgc, svd) diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 5056e85b7fa1..5008dd41d454 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -100,6 +100,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { FeegrantKeeper: suite.feeGrantKeeper, SignModeHandler: suite.encCfg.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + SigningContext: suite.encCfg.TxConfig.SigningContext(), }, ) diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 2bba067a832f..6ddf6325329c 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -259,21 +259,21 @@ func TestBuilderFeePayer(t *testing.T) { cases := map[string]struct { txFeePayer sdk.AccAddress - expectedSigners []sdk.AccAddress - expectedPayer sdk.AccAddress + expectedSigners [][]byte + expectedPayer []byte }{ "no fee payer specified": { - expectedSigners: []sdk.AccAddress{addr1, addr2}, + expectedSigners: [][]byte{addr1, addr2}, expectedPayer: addr1, }, "secondary signer set as fee payer": { txFeePayer: addr2, - expectedSigners: []sdk.AccAddress{addr1, addr2}, + expectedSigners: [][]byte{addr1, addr2}, expectedPayer: addr2, }, "outside signer set as fee payer": { txFeePayer: addr3, - expectedSigners: []sdk.AccAddress{addr1, addr2, addr3}, + expectedSigners: [][]byte{addr1, addr2, addr3}, expectedPayer: addr3, }, } @@ -281,7 +281,7 @@ func TestBuilderFeePayer(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { // setup basic tx - txBuilder := newBuilder(nil) + txBuilder := newBuilder(testutil.CodecOptions{}.NewCodec()) err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) @@ -315,5 +315,5 @@ func TestBuilderFeeGranter(t *testing.T) { // set fee granter txBuilder.SetFeeGranter(addr1) - require.Equal(t, addr1, txBuilder.GetTx().FeeGranter()) + require.Equal(t, addr1.String(), txBuilder.GetTx().FeeGranter()) } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 448c9ebb0232..7af96216bf76 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -18,12 +18,13 @@ import ( ) type config struct { - handler *txsigning.HandlerMap - decoder sdk.TxDecoder - encoder sdk.TxEncoder - jsonDecoder sdk.TxDecoder - jsonEncoder sdk.TxEncoder - protoCodec codec.ProtoCodecMarshaler + handler *txsigning.HandlerMap + decoder sdk.TxDecoder + encoder sdk.TxEncoder + jsonDecoder sdk.TxDecoder + jsonEncoder sdk.TxEncoder + protoCodec codec.ProtoCodecMarshaler + signingContext *txsigning.Context } // ConfigOptions define the configuration of a TxConfig when calling NewTxConfigWithOptions. @@ -125,6 +126,7 @@ func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, configOptions panic(err) } } + txConfig.signingContext = opts.SigningContext lenSignModes := len(configOptions.EnabledSignModes) handlers := make([]txsigning.SignModeHandler, lenSignModes+len(opts.CustomSignModes)) @@ -203,3 +205,7 @@ func (g config) TxJSONEncoder() sdk.TxEncoder { func (g config) TxJSONDecoder() sdk.TxDecoder { return g.jsonDecoder } + +func (g config) SigningContext() *txsigning.Context { + return g.signingContext +} diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 69629e14cd51..6d04cce46067 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -10,8 +10,9 @@ import ( bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" - "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + + "cosmossdk.io/core/appmodule" txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/textual" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" @@ -133,6 +134,7 @@ func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + SigningContext: txConfig.SigningContext(), }, ) if err != nil { diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index 0e1e44970f0c..ebfb3d628977 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,7 +14,7 @@ import ( ) func TestGenerator(t *testing.T) { - interfaceRegistry := codectypes.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) diff --git a/x/auth/tx/direct_aux_test.go b/x/auth/tx/direct_aux_test.go index 27a5764dbefc..32f76b17fbb8 100644 --- a/x/auth/tx/direct_aux_test.go +++ b/x/auth/tx/direct_aux_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +19,7 @@ import ( func TestDirectAuxHandler(t *testing.T) { privKey, pubkey, addr := testdata.KeyTestPubAddr() _, feePayerPubKey, feePayerAddr := testdata.KeyTestPubAddr() - interfaceRegistry := codectypes.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) marshaler := codec.NewProtoCodec(interfaceRegistry) @@ -81,7 +82,7 @@ func TestDirectAuxHandler(t *testing.T) { t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX") _, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, feePayerSigningData, txBuilder.GetTx()) - require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", feePayerAddr.String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)) + require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", []byte(feePayerAddr), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)) t.Log("verify GetSignBytes with generating sign bytes by marshaling signDocDirectAux") signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx()) diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 249a8c8bb140..2fe0f1943170 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "github.com/cosmos/cosmos-sdk/client" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -74,8 +75,8 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { s.Require().NoError(err) tx := txBuilder.GetTx() s.Require().Equal(msgs, tx.GetMsgs()) - s.Require().Equal([]sdk.AccAddress{addr1, addr2}, tx.GetSigners()) - s.Require().Equal(addr1.String(), tx.FeePayer()) + s.Require().Equal([][]byte{addr1, addr2}, tx.GetSigners()) + s.Require().Equal([]byte(addr1), tx.FeePayer()) s.Require().Error(tx.ValidateBasic()) // should fail because of no signatures } @@ -127,7 +128,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Len(sigsV2, 2) s.Require().True(sigEquals(sig1, sigsV2[0])) s.Require().True(sigEquals(msig, sigsV2[1])) - s.Require().Equal([]sdk.AccAddress{addr, msigAddr}, sigTx.GetSigners()) + s.Require().Equal([][]byte{addr, msigAddr}, sigTx.GetSigners()) s.Require().NoError(sigTx.ValidateBasic()) // sign transaction @@ -178,7 +179,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Len(sigsV2, 2) s.Require().True(sigEquals(sig1, sigsV2[0])) s.Require().True(sigEquals(msig, sigsV2[1])) - s.Require().Equal([]sdk.AccAddress{addr, msigAddr}, sigTx.GetSigners()) + s.Require().Equal([][]byte{addr, msigAddr}, sigTx.GetSigners()) s.Require().NoError(sigTx.ValidateBasic()) } diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 7796b0952f6d..124c53b9c8d4 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -29,7 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog -## v0.6.0 +## Unreleased ## v0.6.2 From 641457c9c99bace5cf5b4e1b09609d697e74bfac Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 13:03:13 -0400 Subject: [PATCH 49/83] fixes --- baseapp/baseapp_test.go | 10 ----- types/tx/types.go | 62 +++++++++++++++++++++++++++++ types/tx_msg.go | 1 - x/auth/ante/basic.go | 6 ++- x/auth/client/cli/suite_test.go | 2 +- x/auth/client/cli/validate_sigs.go | 7 +++- x/auth/signing/sig_verifiable_tx.go | 1 + 7 files changed, 74 insertions(+), 15 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 946fa6b25deb..275eb28eaefd 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -661,13 +661,3 @@ func TestLoadVersionPruning(t *testing.T) { require.Nil(t, err) testLoadVersionHelper(t, app, int64(7), lastCommitID) } - -type testAddressCodec struct{} - -func (t testAddressCodec) StringToBytes(text string) ([]byte, error) { - return []byte(text), nil -} - -func (t testAddressCodec) BytesToString(bz []byte) (string, error) { - return string(bz), nil -} diff --git a/types/tx/types.go b/types/tx/types.go index 838f3e198129..48a5caa26ed2 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -1,12 +1,16 @@ package tx import ( + "fmt" + + errorsmod "cosmossdk.io/errors" protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // MaxGasWanted defines the max gas allowed. @@ -31,6 +35,64 @@ func (t *Tx) GetMsgs() []sdk.Msg { return res } +// ValidateBasic implements the ValidateBasic method on sdk.Tx. +func (t *Tx) ValidateBasic() error { + if t == nil { + return fmt.Errorf("bad Tx") + } + + body := t.Body + if body == nil { + return fmt.Errorf("missing TxBody") + } + + authInfo := t.AuthInfo + if authInfo == nil { + return fmt.Errorf("missing AuthInfo") + } + + fee := authInfo.Fee + if fee == nil { + return fmt.Errorf("missing fee") + } + + if fee.GasLimit > MaxGasWanted { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "invalid gas supplied; %d > %d", fee.GasLimit, MaxGasWanted, + ) + } + + if fee.Amount.IsAnyNil() { + return errorsmod.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: null", + ) + } + + if fee.Amount.IsAnyNegative() { + return errorsmod.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: %s", fee.Amount, + ) + } + + if fee.Payer != "" { + _, err := sdk.AccAddressFromBech32(fee.Payer) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid fee payer address (%s)", err) + } + } + + sigs := t.Signatures + + if len(sigs) == 0 { + return sdkerrors.ErrNoSignatures + } + + return nil +} + // GetSigners retrieves all the signers of a tx. // This includes all unique signers of the messages (in order), // as well as the FeePayer (if specified and not already included). diff --git a/types/tx_msg.go b/types/tx_msg.go index ec1e6646d22a..2f7f2a487f7b 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -43,7 +43,6 @@ type ( // HasMsgs defines an interface a transaction must fulfill. HasMsgs interface { - HasValidateBasic // GetMsgs gets the all the transaction's messages. GetMsgs() []Msg } diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 8d335fc32b01..23c83436468e 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -31,8 +31,10 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat return next(ctx, tx, simulate) } - if err := tx.ValidateBasic(); err != nil { - return ctx, err + if validateBasic, ok := tx.(sdk.HasValidateBasic); ok { + if err := validateBasic.ValidateBasic(); err != nil { + return ctx, err + } } return next(ctx, tx, simulate) diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index 11d37128761e..d34e080e9250 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -386,7 +386,7 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { // Test validate-signatures res, err := authtestutil.TxValidateSignaturesExec(s.clientCtx, unsignedTxFile.Name()) s.Require().EqualError(err, "signatures validation failed") - s.Require().True(strings.Contains(res.String(), fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", s.val.String()))) + s.Require().Contains(res.String(), fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", s.val.String())) // Test sign diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 4b9856bff427..66b5c58010ee 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -66,11 +66,16 @@ func printAndValidateSigs( ) bool { sigTx := tx.(authsigning.SigVerifiableTx) signModeHandler := clientCtx.TxConfig.SignModeHandler() + addrCdc := clientCtx.TxConfig.SigningContext().AddressCodec() cmd.Println("Signers:") signers := sigTx.GetSigners() for i, signer := range signers { - cmd.Printf(" %v: %v\n", i, signer) + signerStr, err := addrCdc.BytesToString(signer) + if err != nil { + panic(err) + } + cmd.Printf(" %v: %v\n", i, signerStr) } success := true diff --git a/x/auth/signing/sig_verifiable_tx.go b/x/auth/signing/sig_verifiable_tx.go index bfb736833f3b..6404d7856ac0 100644 --- a/x/auth/signing/sig_verifiable_tx.go +++ b/x/auth/signing/sig_verifiable_tx.go @@ -25,4 +25,5 @@ type Tx interface { types.FeeTx tx.TipTx types.TxWithTimeoutHeight + types.HasValidateBasic } From 50a6ec16d114876a21522ad19047dba359a23f30 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 13:50:38 -0400 Subject: [PATCH 50/83] fixes --- baseapp/abci_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 83d4fc4a7c2f..6ce54cd17be6 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -935,7 +935,8 @@ func TestABCI_InvalidTransaction(t *testing.T) { // transaction with no known route { txBuilder := suite.txConfig.NewTxBuilder() - txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{}) + _, _, addr := testdata.KeyTestPubAddr() + txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{Signer: addr.String()}) setTxSignature(t, txBuilder, 0) unknownRouteTx := txBuilder.GetTx() @@ -948,7 +949,10 @@ func TestABCI_InvalidTransaction(t *testing.T) { require.EqualValues(t, sdkerrors.ErrUnknownRequest.ABCICode(), code, err) txBuilder = suite.txConfig.NewTxBuilder() - txBuilder.SetMsgs(&baseapptestutil.MsgCounter{}, &baseapptestutil.MsgCounter2{}) + txBuilder.SetMsgs( + &baseapptestutil.MsgCounter{Signer: addr.String()}, + &baseapptestutil.MsgCounter2{Signer: addr.String()}, + ) setTxSignature(t, txBuilder, 0) unknownRouteTx = txBuilder.GetTx() From 00205a59bcdd9d8b72feb6b4eb8790e798f00d37 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 14:10:04 -0400 Subject: [PATCH 51/83] fixes --- testutil/testdata/testpb/tx.proto | 3 +- testutil/testdata/testpb/tx.pulsar.go | 37 +++++++++++---------- testutil/testdata/tx.pb.go | 46 +++++++++++++-------------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/testutil/testdata/testpb/tx.proto b/testutil/testdata/testpb/tx.proto index 11e5b47cff56..13e48c7702a7 100644 --- a/testutil/testdata/testpb/tx.proto +++ b/testutil/testdata/testpb/tx.proto @@ -31,9 +31,8 @@ message MsgCreateDogResponse { // https://github.com/cosmos/cosmos-sdk/issues/6213. message TestMsg { option (cosmos.msg.v1.signer) = "signers"; - option (gogoproto.goproto_getters) = false; - option (cosmos.msg.v1.signer) = "signers"; option (amino.name) = "testpb/TestMsg"; + repeated string signers = 1; } diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index b8ecd5e33e56..5e4213c4802a 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -1560,26 +1560,25 @@ var file_testpb_tx_proto_rawDesc = []byte{ 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, - 0x54, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, + 0x48, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x2f, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, - 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, - 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x54, 0x65, - 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x1a, - 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, - 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x65, 0x73, - 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, - 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, - 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, - 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x23, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2f, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, + 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, + 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, + 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, + 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, + 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, + 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index 192354be6122..e2d416faa41e 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -174,29 +174,29 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 339 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, - 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, - 0x09, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x94, 0x94, 0x48, 0x7a, 0x7e, 0x7a, - 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x45, 0x45, 0x61, 0x26, 0xa4, 0x16, 0x97, 0xa4, 0x24, 0x96, - 0x24, 0x42, 0x85, 0xc5, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x73, 0x8b, 0xd3, 0xf5, 0xcb, - 0x0c, 0x41, 0x14, 0x44, 0x42, 0xc9, 0x9f, 0x8b, 0xc7, 0xb7, 0x38, 0xdd, 0xb9, 0x28, 0x35, 0xb1, - 0x24, 0xd5, 0x25, 0x3f, 0x5d, 0x48, 0x96, 0x8b, 0x39, 0x25, 0x3f, 0x5d, 0x82, 0x51, 0x81, 0x51, - 0x83, 0xdb, 0x88, 0x5b, 0x0f, 0x62, 0x9a, 0x9e, 0x4b, 0x7e, 0x7a, 0x10, 0x48, 0x5c, 0x48, 0x84, - 0x8b, 0x35, 0xbf, 0x3c, 0x2f, 0xb5, 0x48, 0x82, 0x49, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc2, 0xb1, - 0xe2, 0x6a, 0x7a, 0xbe, 0x41, 0x0b, 0xc2, 0x56, 0xd2, 0xe2, 0x12, 0x41, 0x36, 0x30, 0x28, 0xb5, - 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x88, 0x8b, 0x25, 0x2f, 0x31, 0x37, 0x15, 0x6c, 0x32, - 0x67, 0x10, 0x98, 0xad, 0x14, 0xc2, 0xc5, 0x1e, 0x92, 0x5a, 0x5c, 0xe2, 0x5b, 0x9c, 0x2e, 0x24, - 0xc1, 0xc5, 0x5e, 0x9c, 0x99, 0x9e, 0x97, 0x5a, 0x54, 0x2c, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0x19, - 0x04, 0xe3, 0x5a, 0xe9, 0x77, 0x2c, 0x90, 0x67, 0x00, 0x59, 0x00, 0x13, 0x41, 0x66, 0x77, 0x3d, - 0xdf, 0xa0, 0xc5, 0x07, 0xf5, 0x32, 0xd4, 0x28, 0x23, 0x5f, 0x2e, 0x66, 0x90, 0x89, 0xf6, 0x5c, - 0x9c, 0x08, 0x6f, 0x89, 0xc0, 0x7c, 0x82, 0xec, 0x36, 0x29, 0x19, 0x6c, 0xa2, 0x30, 0x17, 0x4b, - 0xb1, 0x36, 0x3c, 0xdf, 0xa0, 0xc5, 0xe8, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, - 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, - 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xd0, - 0xf0, 0x85, 0x50, 0xba, 0xc5, 0x29, 0xd9, 0xe0, 0x18, 0x28, 0x2d, 0xc9, 0xcc, 0x81, 0x47, 0x45, - 0x12, 0x1b, 0x38, 0xc8, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd5, 0xbe, 0xa2, 0x89, 0xe6, - 0x01, 0x00, 0x00, + // 337 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0xc7, 0x73, 0xd6, 0xb6, 0xe4, 0x2a, 0x8a, 0x21, 0x62, 0x08, 0x1a, 0x4b, 0x5d, 0x4a, 0xc0, + 0x1c, 0xd6, 0xad, 0x8b, 0xa0, 0x1d, 0xba, 0x14, 0x21, 0x38, 0xb9, 0xa5, 0xed, 0x71, 0x06, 0x4d, + 0x5e, 0xc9, 0xbb, 0xaa, 0xa3, 0x38, 0x89, 0x93, 0x1f, 0xc1, 0x8f, 0xd0, 0x8f, 0xe1, 0xd8, 0xd1, + 0x51, 0xda, 0xa1, 0x5f, 0x43, 0x72, 0x97, 0x68, 0x07, 0x97, 0xbc, 0xff, 0xfb, 0x3d, 0xf2, 0xbf, + 0xf7, 0xfe, 0x74, 0x47, 0x72, 0x94, 0x93, 0x21, 0x93, 0x4f, 0xc1, 0x24, 0x03, 0x09, 0x56, 0x4d, + 0x03, 0x77, 0x37, 0x4a, 0xe2, 0x14, 0x98, 0xfa, 0xea, 0x91, 0x6b, 0x0b, 0x10, 0xa0, 0x24, 0xcb, + 0x55, 0x41, 0xf7, 0x4a, 0x07, 0x8e, 0x72, 0x1c, 0xc9, 0xa8, 0xc0, 0xfb, 0x23, 0xc0, 0x04, 0x90, + 0x25, 0x28, 0xd8, 0xc3, 0x69, 0x5e, 0xf4, 0xa0, 0x75, 0x45, 0xb7, 0x06, 0x28, 0x2e, 0x33, 0x1e, + 0x49, 0xde, 0x03, 0x61, 0x1d, 0xd2, 0xca, 0x18, 0x84, 0x43, 0x9a, 0xa4, 0xdd, 0xe8, 0x34, 0x02, + 0xed, 0x16, 0xf4, 0x40, 0x84, 0x39, 0xb7, 0x6c, 0x5a, 0x85, 0xc7, 0x94, 0x67, 0xce, 0x46, 0x93, + 0xb4, 0xcd, 0x50, 0x37, 0x5d, 0xfa, 0xb2, 0x9a, 0xf9, 0x5a, 0xb7, 0x7c, 0x6a, 0xaf, 0x1b, 0x86, + 0x1c, 0x27, 0x90, 0x22, 0xb7, 0x2c, 0xba, 0x99, 0x46, 0x09, 0x57, 0xce, 0x66, 0xa8, 0x74, 0xab, + 0x4f, 0xeb, 0xd7, 0x1c, 0xe5, 0x00, 0x85, 0xe5, 0xd0, 0x3a, 0xc6, 0x22, 0xe5, 0x19, 0x3a, 0xa4, + 0x59, 0x69, 0x9b, 0x61, 0xd9, 0x76, 0x8f, 0x5f, 0x3f, 0x8e, 0x8c, 0xfc, 0x81, 0x92, 0xbc, 0xad, + 0x66, 0xfe, 0x76, 0x71, 0x66, 0xf1, 0x7b, 0x67, 0x40, 0x2b, 0xb9, 0xcb, 0x39, 0x35, 0xff, 0x4e, + 0xb1, 0xcb, 0xed, 0xd7, 0xf7, 0x71, 0x0f, 0xfe, 0xa3, 0xe5, 0x96, 0x6e, 0xf5, 0x79, 0x35, 0xf3, + 0xc9, 0x45, 0xff, 0x73, 0xe1, 0x91, 0xf9, 0xc2, 0x23, 0xdf, 0x0b, 0x8f, 0xbc, 0x2f, 0x3d, 0x63, + 0xbe, 0xf4, 0x8c, 0xaf, 0xa5, 0x67, 0xdc, 0x04, 0x22, 0x96, 0xb7, 0xd3, 0x61, 0x30, 0x82, 0x84, + 0x15, 0x99, 0xea, 0x72, 0x82, 0xe3, 0x3b, 0x95, 0xfa, 0x54, 0xc6, 0xf7, 0xbf, 0xf1, 0x0f, 0x6b, + 0x2a, 0xe6, 0xb3, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x89, 0xf1, 0xc8, 0x3c, 0xda, 0x01, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. From 15ff7e94291150d83c0b3392103074790111656b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 14:29:25 -0400 Subject: [PATCH 52/83] fix rosetta --- tools/rosetta/client_offline.go | 6 ++++- tools/rosetta/converter.go | 44 ++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tools/rosetta/client_offline.go b/tools/rosetta/client_offline.go index adbf734ab538..85ef6d2945de 100644 --- a/tools/rosetta/client_offline.go +++ b/tools/rosetta/client_offline.go @@ -84,7 +84,11 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con accountIdentifiers := make([]*types.AccountIdentifier, len(signers)) for i, sig := range signers { - addr := sig.String() + addr, err := c.config.InterfaceRegistry.SigningContext().AddressCodec().BytesToString(sig) + if err != nil { + return nil, err + } + signersStr[i] = addr accountIdentifiers[i] = &types.AccountIdentifier{ Address: addr, diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index 3bbdbe9fb42e..bf55bf6e3b9f 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -15,6 +15,7 @@ import ( secp "github.com/decred/dcrd/dcrec/secp256k1/v4" sdkmath "cosmossdk.io/math" + crgerrs "cosmossdk.io/tools/rosetta/lib/errors" crgtypes "cosmossdk.io/tools/rosetta/lib/types" @@ -171,7 +172,11 @@ func (c converter) UnsignedTx(ops []*rosettatypes.Operation) (tx authsigning.Tx, } } - signers := msg.GetSigners() + signers, _, err := c.cdc.GetMsgV1Signers(msg) + if err != nil { + return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, err.Error()) + } + // check if there are enough signers if len(signers) == 0 { return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, fmt.Sprintf("operation at index %d got no signers", op.OperationIdentifier.Index)) @@ -249,12 +254,22 @@ func (c converter) Ops(status string, msg sdk.Msg) ([]*rosettatypes.Operation, e return nil, err } - ops := make([]*rosettatypes.Operation, len(msg.GetSigners())) - for i, signer := range msg.GetSigners() { + signers, _, err := c.cdc.GetMsgV1Signers(msg) + if err != nil { + return nil, err + } + + ops := make([]*rosettatypes.Operation, len(signers)) + for i, signer := range signers { + signerStr, err := c.ir.SigningContext().AddressCodec().BytesToString(signer) + if err != nil { + return nil, err + } + op := &rosettatypes.Operation{ Type: opName, Status: &status, - Account: &rosettatypes.AccountIdentifier{Address: signer.String()}, + Account: &rosettatypes.AccountIdentifier{Address: signerStr}, Metadata: meta, } @@ -595,8 +610,14 @@ func (c converter) OpsAndSigners(txBytes []byte) (ops []*rosettatypes.Operation, } for _, signer := range txBuilder.GetTx().GetSigners() { + var signerStr string + signerStr, err = c.ir.SigningContext().AddressCodec().BytesToString(signer) + if err != nil { + return + } + signers = append(signers, &rosettatypes.AccountIdentifier{ - Address: signer.String(), + Address: signerStr, }) } @@ -704,16 +725,21 @@ func (c converter) SigningComponents(tx authsigning.Tx, metadata *ConstructionMe if err != nil { return nil, nil, err } - if !bytes.Equal(pubKey.Address().Bytes(), signer.Bytes()) { + if !bytes.Equal(pubKey.Address().Bytes(), signer) { return nil, nil, crgerrs.WrapError( crgerrs.ErrBadArgument, - fmt.Sprintf("public key at index %d does not match the expected transaction signer: %X <-> %X", i, rosPubKeys[i].Bytes, signer.Bytes()), + fmt.Sprintf("public key at index %d does not match the expected transaction signer: %X <-> %X", i, rosPubKeys[i].Bytes, signer), ) } + signerStr, err := c.ir.SigningContext().AddressCodec().BytesToString(signer) + if err != nil { + return nil, nil, crgerrs.WrapError(crgerrs.ErrBadArgument, err.Error()) + } + // set the signer data signerData := authsigning.SignerData{ - Address: signer.String(), + Address: signerStr, ChainID: metadata.ChainID, AccountNumber: metadata.SignersData[i].AccountNumber, Sequence: metadata.SignersData[i].Sequence, @@ -728,7 +754,7 @@ func (c converter) SigningComponents(tx authsigning.Tx, metadata *ConstructionMe // set payload payloadsToSign[i] = &rosettatypes.SigningPayload{ - AccountIdentifier: &rosettatypes.AccountIdentifier{Address: signer.String()}, + AccountIdentifier: &rosettatypes.AccountIdentifier{Address: signerStr}, Bytes: signBytes, SignatureType: rosettatypes.Ecdsa, } From f2bbf36f66786c160bf12c212bb86280bade028a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 14:51:52 -0400 Subject: [PATCH 53/83] fixes --- x/auth/tx/aux_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 777c9e0b17d8..c0249eaa86d2 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -162,7 +162,7 @@ func TestBuilderWithAux(t *testing.T) { require.NoError(t, err) tx, err := txConfig.TxDecoder()(txBz) require.NoError(t, err) - require.Equal(t, tx.(sdk.FeeTx).FeePayer(), feepayerAddr.String()) + require.Equal(t, tx.(sdk.FeeTx).FeePayer(), []byte(feepayerAddr)) require.Equal(t, tx.(sdk.FeeTx).GetFee(), fee) require.Equal(t, tx.(sdk.FeeTx).GetGas(), gas) require.Equal(t, tip, tx.(txtypes.TipTx).GetTip()) From 227a0a63d92f37f28daa3e514209074ef513d3dd Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:22:47 -0400 Subject: [PATCH 54/83] test fixes --- tests/integration/aminojson/aminojson_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/aminojson/aminojson_test.go b/tests/integration/aminojson/aminojson_test.go index 25b714b6a736..01539bba8a8c 100644 --- a/tests/integration/aminojson/aminojson_test.go +++ b/tests/integration/aminojson/aminojson_test.go @@ -48,6 +48,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module/testutil" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -129,7 +130,7 @@ func TestAminoJSON_Equivalence(t *testing.T) { require.Equal(t, string(legacyAminoJSON), string(aminoJSON)) // test amino json signer handler equivalence - gogoMsg, ok := gogo.(types.Msg) + gogoMsg, ok := gogo.(legacytx.LegacyMsg) if !ok { // not signable return @@ -430,7 +431,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) { require.Equal(t, string(gogoBytes), string(newGogoBytes)) // test amino json signer handler equivalence - msg, ok := tc.gogo.(types.Msg) + msg, ok := tc.gogo.(legacytx.LegacyMsg) if !ok { // not signable return From 0a216cc50d135c2fe0f31023c0a057b4cc8a3ec8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:25:30 -0400 Subject: [PATCH 55/83] make ante.HandlerOptions.SigningContext optional --- CHANGELOG.md | 1 - x/auth/ante/sigverify.go | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1672d0fc1916..c7d5ba134e49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -187,7 +187,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `sdk.Msg.GetSigners` was deprecated and no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. * `types/tx.Tx` no longer implements `sdk.Tx`. * `sdk.Tx` now requires a new methods `GetMsgsV2()`. - * `ante.HandlerOptions` has a new required field `SigningContext *signing.Context` * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` * `TxConfig` has a new method `SigningContext() *signing.Context` * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 5d22e71ec2b7..d0599e4462ef 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -83,9 +83,15 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b } // Only make check if simulate=false if !simulate && !bytes.Equal(pk.Address(), signers[i]) { - signerStr, err := spkd.signingCtx.AddressCodec().BytesToString(signers[i]) - if err != nil { - return sdk.Context{}, err + var signerStr string + if spkd.signingCtx != nil { + var err error + signerStr, err = spkd.signingCtx.AddressCodec().BytesToString(signers[i]) + if err != nil { + return sdk.Context{}, err + } + } else { + signerStr = sdk.AccAddress(signers[i]).String() } return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, From 5822abc976e02865675ea3297e5fd23eb65392f5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:28:14 -0400 Subject: [PATCH 56/83] update CHANGELOG.md --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d5ba134e49..92e8d5d6c1b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,11 +184,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. * (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHandler` interface instead of deliverTx. The interface is implemented on baseapp * [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) - * `sdk.Msg.GetSigners` was deprecated and no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. - * `types/tx.Tx` no longer implements `sdk.Tx`. + * `sdk.Msg.GetSigners` was deprecated and is no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. * `sdk.Tx` now requires a new methods `GetMsgsV2()`. - * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` + * `types/tx.Tx` no longer implements `sdk.Tx`. * `TxConfig` has a new method `SigningContext() *signing.Context` + * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. * (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. From 53d93e82c03f4522398132b76ed0129e58f2b6fc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:38:20 -0400 Subject: [PATCH 57/83] return errors --- tools/rosetta/converter.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index bf55bf6e3b9f..a9f931079dad 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -609,7 +609,12 @@ func (c converter) OpsAndSigners(txBytes []byte) (ops []*rosettatypes.Operation, return nil, nil, crgerrs.WrapError(crgerrs.ErrCodec, err.Error()) } - for _, signer := range txBuilder.GetTx().GetSigners() { + signerAddrs, err := txBuilder.GetTx().GetSigners() + if err != nil { + return nil, nil, crgerrs.WrapError(crgerrs.ErrBadArgument, err.Error()) + } + + for _, signer := range signerAddrs { var signerStr string signerStr, err = c.ir.SigningContext().AddressCodec().BytesToString(signer) if err != nil { @@ -697,7 +702,11 @@ func (c converter) SigningComponents(tx authsigning.Tx, metadata *ConstructionMe return nil, nil, crgerrs.WrapError(crgerrs.ErrBadArgument, err.Error()) } - signers := tx.GetSigners() + signers, err := tx.GetSigners() + if err != nil { + return nil, nil, crgerrs.WrapError(crgerrs.ErrBadArgument, err.Error()) + } + // assert the signers data provided in options are the same as the expected signing accounts // and that the number of rosetta provided public keys equals the one of the signers if len(metadata.SignersData) != len(signers) || len(signers) != len(rosPubKeys) { From 9d69fa5cfc34e041adea2babe1255d3923682fde Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:40:04 -0400 Subject: [PATCH 58/83] don't panic --- CHANGELOG.md | 3 +- server/mock/tx.go | 8 ++--- tools/rosetta/client_offline.go | 6 +++- types/mempool/mempool_test.go | 8 ++--- types/tx_msg.go | 2 +- x/auth/ante/sigverify.go | 17 ++++++++--- x/auth/client/cli/validate_sigs.go | 6 +++- x/auth/signing/sig_verifiable_tx.go | 2 +- x/auth/tx/builder.go | 47 ++++++++++++++++++++--------- x/auth/tx/direct_test.go | 6 ++-- 10 files changed, 71 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e8d5d6c1b8..3d507397760c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -185,10 +185,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHandler` interface instead of deliverTx. The interface is implemented on baseapp * [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) * `sdk.Msg.GetSigners` was deprecated and is no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. - * `sdk.Tx` now requires a new methods `GetMsgsV2()`. + * `sdk.Tx` now requires a new method `GetMsgsV2()`. * `types/tx.Tx` no longer implements `sdk.Tx`. * `TxConfig` has a new method `SigningContext() *signing.Context` * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` + * `SigVerifiableTx.GetSigners()` now returns `([][]byte, error)` instead of `[]sdk.AccAddress` * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. * (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. diff --git a/server/mock/tx.go b/server/mock/tx.go index a2e7a5b2a9a7..941c002e0036 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -103,8 +103,8 @@ func (msg *KVStoreTx) GetMsgs() []sdk.Msg { return []sdk.Msg{msg} } -func (msg *KVStoreTx) GetMsgsV2() []protov2.Message { - return []protov2.Message{&bankv1beta1.MsgSend{FromAddress: msg.address.String()}} // this is a hack for tests +func (msg *KVStoreTx) GetMsgsV2() ([]protov2.Message, error) { + return []protov2.Message{&bankv1beta1.MsgSend{FromAddress: msg.address.String()}}, nil // this is a hack for tests } func (msg *KVStoreTx) GetSignBytes() []byte { @@ -116,8 +116,8 @@ func (msg *KVStoreTx) ValidateBasic() error { return nil } -func (msg *KVStoreTx) GetSigners() [][]byte { - return nil +func (msg *KVStoreTx) GetSigners() ([][]byte, error) { + return nil, nil } func (msg *KVStoreTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } diff --git a/tools/rosetta/client_offline.go b/tools/rosetta/client_offline.go index 85ef6d2945de..ef01d69a113f 100644 --- a/tools/rosetta/client_offline.go +++ b/tools/rosetta/client_offline.go @@ -79,7 +79,11 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con } // get the signers - signers := tx.GetSigners() + signers, err := tx.GetSigners() + if err != nil { + return nil, err + } + signersStr := make([]string, len(signers)) accountIdentifiers := make([]*types.AccountIdentifier, len(signers)) diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index e154d714c4ef..9ed3b4d596a9 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -54,7 +54,7 @@ type testTx struct { strAddress string } -func (tx testTx) GetSigners() [][]byte { panic("not implemented") } +func (tx testTx) GetSigners() ([][]byte, error) { panic("not implemented") } func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("not implemented") } @@ -76,7 +76,7 @@ var ( func (tx testTx) GetMsgs() []sdk.Msg { return nil } -func (tx testTx) GetMsgsV2() []protov2.Message { return nil } +func (tx testTx) GetMsgsV2() ([]protov2.Message, error) { return nil, nil } func (tx testTx) ValidateBasic() error { return nil } @@ -92,11 +92,11 @@ func (sigErrTx) Size() int64 { return 0 } func (sigErrTx) GetMsgs() []sdk.Msg { return nil } -func (sigErrTx) GetMsgsV2() []protov2.Message { return nil } +func (sigErrTx) GetMsgsV2() ([]protov2.Message, error) { return nil, nil } func (sigErrTx) ValidateBasic() error { return nil } -func (sigErrTx) GetSigners() [][]byte { return nil } +func (sigErrTx) GetSigners() ([][]byte, error) { return nil, nil } func (sigErrTx) GetPubKeys() ([]cryptotypes.PubKey, error) { return nil, nil } diff --git a/types/tx_msg.go b/types/tx_msg.go index 2f7f2a487f7b..75d0541133a7 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -52,7 +52,7 @@ type ( HasMsgs // GetMsgsV2 gets the transaction's messages as google.golang.org/protobuf/proto.Message's. - GetMsgsV2() []protov2.Message + GetMsgsV2() ([]protov2.Message, error) } // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index d0599e4462ef..a08e3e43dea1 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -71,7 +71,11 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b if err != nil { return ctx, err } - signers := sigTx.GetSigners() + + signers, err := sigTx.GetSigners() + if err != nil { + return sdk.Context{}, err + } for i, pk := range pubkeys { // PublicKey was omitted from slice since it has already been set in context @@ -178,7 +182,7 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. - signers := sigTx.GetSigners() + signers, _ := sigTx.GetSigners() for i, sig := range sigs { signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signers[i]) @@ -263,7 +267,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul return ctx, err } - signers := sigTx.GetSigners() + signers, _ := sigTx.GetSigners() // check that signer length and signature length are the same if len(sigs) != len(signers) { @@ -362,7 +366,12 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } // increment sequence of all signers - for _, signer := range sigTx.GetSigners() { + signers, err := sigTx.GetSigners() + if err != nil { + return sdk.Context{}, err + } + + for _, signer := range signers { acc := isd.ak.GetAccount(ctx, signer) if err := acc.SetSequence(acc.GetSequence() + 1); err != nil { panic(err) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 66b5c58010ee..4d599218d378 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -69,7 +69,11 @@ func printAndValidateSigs( addrCdc := clientCtx.TxConfig.SigningContext().AddressCodec() cmd.Println("Signers:") - signers := sigTx.GetSigners() + signers, err := sigTx.GetSigners() + if err != nil { + panic(err) + } + for i, signer := range signers { signerStr, err := addrCdc.BytesToString(signer) if err != nil { diff --git a/x/auth/signing/sig_verifiable_tx.go b/x/auth/signing/sig_verifiable_tx.go index 6404d7856ac0..7aa05219f1cd 100644 --- a/x/auth/signing/sig_verifiable_tx.go +++ b/x/auth/signing/sig_verifiable_tx.go @@ -11,7 +11,7 @@ import ( // handlers. type SigVerifiableTx interface { types.Tx - GetSigners() [][]byte + GetSigners() ([][]byte, error) GetPubKeys() ([]cryptotypes.PubKey, error) // If signer already has pubkey in context, this list will have nil in its place GetSignaturesV2() ([]signing.SignatureV2, error) } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 34f5e877ac82..fc8d7acd635c 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -8,6 +8,7 @@ import ( protov2 "google.golang.org/protobuf/proto" errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -39,6 +40,7 @@ type wrapper struct { signers [][]byte msgsV2 []protov2.Message + err error } var ( @@ -75,12 +77,12 @@ func (w *wrapper) GetMsgs() []sdk.Msg { return w.tx.GetMsgs() } -func (w *wrapper) GetMsgsV2() []protov2.Message { +func (w *wrapper) GetMsgsV2() ([]protov2.Message, error) { if w.msgsV2 == nil { w.initSignersAndMsgsV2() } - return w.msgsV2 + return w.msgsV2, w.err } func (w *wrapper) ValidateBasic() error { @@ -137,7 +139,7 @@ func (w *wrapper) ValidateBasic() error { return sdkerrors.ErrNoSignatures } - signers := w.GetSigners() + signers, _ := w.GetSigners() if len(sigs) != len(signers) { return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, @@ -181,18 +183,14 @@ func (w *wrapper) getAuthInfoBytes() []byte { } func (w *wrapper) initSignersAndMsgsV2() { - var err error - w.signers, w.msgsV2, err = w.tx.GetSigners(w.cdc) - if err != nil { - panic(err) - } + w.signers, w.msgsV2, w.err = w.tx.GetSigners(w.cdc) } -func (w *wrapper) GetSigners() [][]byte { +func (w *wrapper) GetSigners() ([][]byte, error) { if w.signers == nil { w.initSignersAndMsgsV2() } - return w.signers + return w.signers, w.err } func (w *wrapper) GetPubKeys() ([]cryptotypes.PubKey, error) { @@ -235,8 +233,14 @@ func (w *wrapper) FeePayer() []byte { } return feePayerAddr } + // use first signer as default if no payer specified - return w.GetSigners()[0] + signers, err := w.GetSigners() + if err != nil { + return nil + } + + return signers[0] } func (w *wrapper) FeeGranter() string { @@ -412,8 +416,13 @@ func (w *wrapper) setSignerInfos(infos []*tx.SignerInfo) { } func (w *wrapper) setSignerInfoAtIndex(index int, info *tx.SignerInfo) { + signers, err := w.GetSigners() + if err != nil { + panic(err) + } + if w.tx.AuthInfo.SignerInfos == nil { - w.tx.AuthInfo.SignerInfos = make([]*tx.SignerInfo, len(w.GetSigners())) + w.tx.AuthInfo.SignerInfos = make([]*tx.SignerInfo, len(signers)) } w.tx.AuthInfo.SignerInfos[index] = info @@ -426,8 +435,13 @@ func (w *wrapper) setSignatures(sigs [][]byte) { } func (w *wrapper) setSignatureAtIndex(index int, sig []byte) { + signers, err := w.GetSigners() + if err != nil { + panic(err) + } + if w.tx.Signatures == nil { - w.tx.Signatures = make([][]byte, len(w.GetSigners())) + w.tx.Signatures = make([][]byte, len(signers)) } w.tx.Signatures[index] = sig @@ -547,7 +561,12 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error { // Get the aux signer's index in GetSigners. signerIndex := -1 - for i, signer := range w.GetSigners() { + signers, err := w.GetSigners() + if err != nil { + return err + } + + for i, signer := range signers { addrBz, err := w.cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(data.Address) if err != nil { return err diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 20ebdcb650d5..296f82008f88 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -157,9 +157,9 @@ func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) { type nonProtoTx int -func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } -func (npt *nonProtoTx) GetMsgsV2() []protov2.Message { return nil } -func (npt *nonProtoTx) ValidateBasic() error { return nil } +func (npt *nonProtoTx) GetMsgs() []sdk.Msg { return nil } +func (npt *nonProtoTx) GetMsgsV2() ([]protov2.Message, error) { return nil, nil } +func (npt *nonProtoTx) ValidateBasic() error { return nil } var _ sdk.Tx = (*nonProtoTx)(nil) From 0459d107af3dc4159d720cea470a25143e073a21 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 15:52:14 -0400 Subject: [PATCH 59/83] fixes --- CHANGELOG.md | 6 +++--- baseapp/baseapp.go | 16 ++++++++++------ tests/e2e/auth/suite.go | 8 ++++++-- tests/e2e/tx/service_test.go | 6 ++++-- x/auth/ante/basic.go | 7 ++++++- x/auth/client/tx.go | 13 +++++++++++-- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d507397760c..62b5b2ec0656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -187,9 +187,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `sdk.Msg.GetSigners` was deprecated and is no longer supported. Use the `cosmos.msg.v1.signer` protobuf annotation instead. * `sdk.Tx` now requires a new method `GetMsgsV2()`. * `types/tx.Tx` no longer implements `sdk.Tx`. - * `TxConfig` has a new method `SigningContext() *signing.Context` - * `ante.NewSetPubKeyDecorator` now requires `*signing.Context` - * `SigVerifiableTx.GetSigners()` now returns `([][]byte, error)` instead of `[]sdk.AccAddress` + * `TxConfig` has a new method `SigningContext() *signing.Context`. + * `ante.NewSetPubKeyDecorator` now requires `*signing.Context`. + * `SigVerifiableTx.GetSigners()` now returns `([][]byte, error)` instead of `[]sdk.AccAddress`. * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. * (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index ccb7ee1fd94b..da7a144de9fd 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -7,10 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" - "cosmossdk.io/store" - storemetrics "cosmossdk.io/store/metrics" - "cosmossdk.io/store/snapshots" - storetypes "cosmossdk.io/store/types" "github.com/cockroachdb/errors" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/tmhash" @@ -20,6 +16,11 @@ import ( "golang.org/x/exp/maps" protov2 "google.golang.org/protobuf/proto" + "cosmossdk.io/store" + storemetrics "cosmossdk.io/store/metrics" + "cosmossdk.io/store/snapshots" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -578,7 +579,7 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context } ctx := modeState.ctx. WithTxBytes(txBytes) - // WithVoteInfos(app.voteInfos) // TODO: identify if this is needed + // WithVoteInfos(app.voteInfos) // TODO: identify if this is needed ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx)) @@ -738,7 +739,10 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re // Attempt to execute all messages and only update state if all messages pass // and we're in DeliverTx. Note, runMsgs will never return a reference to a // Result if any single message fails or does not have a registered Handler. - result, err = app.runMsgs(runMsgCtx, msgs, tx.GetMsgsV2(), mode) + msgsV2, err := tx.GetMsgsV2() + if err == nil { + result, err = app.runMsgs(runMsgCtx, msgs, msgsV2, mode) + } if err == nil { // Run optional postHandlers. // diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 347fa83cf84f..8cb1e0de6f92 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -743,7 +743,9 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal(val1.Address.String(), txBuilder.GetTx().GetSigners()[0]) + signers, err := txBuilder.GetTx().GetSigners() + s.Require().NoError(err) + s.Require().Equal([]byte(val1.Address), signers[0]) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -1574,7 +1576,9 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - require.Equal([]string{val0.Address.String(), val1.Address.String()}, txBuilder.GetTx().GetSigners()) + signers, err := txBuilder.GetTx().GetSigners() + require.NoError(err) + require.Equal([][]byte{val0.Address, val1.Address}, signers) // Write the unsigned tx into a file. txJSON, err := val0.ClientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index ab650e8ea7c6..cf962fc1b205 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -1097,7 +1097,9 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo("foobar") - s.Require().Equal([]sdk.AccAddress{val.Address}, txBuilder.GetTx().GetSigners()) + signers, err := txBuilder.GetTx().GetSigners() + s.Require().NoError(err) + s.Require().Equal([][]byte{val.Address}, signers) // setup txFactory txFactory := clienttx.Factory{}. @@ -1107,7 +1109,7 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder { WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) // Sign Tx. - err := authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true) + err = authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true) s.Require().NoError(err) return txBuilder diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 23c83436468e..750824570ac4 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -110,7 +110,12 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } n := len(sigs) - for i, signer := range sigTx.GetSigners() { + signers, err := sigTx.GetSigners() + if err != nil { + return sdk.Context{}, err + } + + for i, signer := range signers { // if signature is already filled in, no need to simulate gas cost if i < n && !isIncompleteSignature(sigs[i].Data) { continue diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 032e2b7c1d23..a2e829641f1f 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -48,7 +48,11 @@ func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuild return err } addr := sdk.AccAddress(pubKey.Address()) - if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { + signers, err := txBuilder.GetTx().GetSigners() + if err != nil { + return err + } + if !isTxSigner(addr, signers) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } if !offline { @@ -75,7 +79,12 @@ func SignTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, add } // check whether the address is a signer - if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { + signers, err := txBuilder.GetTx().GetSigners() + if err != nil { + return err + } + + if !isTxSigner(addr, signers) { return fmt.Errorf("%s: %s", errors.ErrorInvalidSigner, name) } From 0b9432c0f8425c5a2b206399c3c4a54d5de4855b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 16:04:13 -0400 Subject: [PATCH 60/83] lint --- tests/integration/tx/decode_test.go | 3 ++- tools/rosetta/converter_test.go | 6 ++++-- types/tx_msg.go | 6 ++---- x/auth/ante/ante_test.go | 4 +++- x/auth/client/cli/suite_test.go | 8 ++++++-- x/auth/tx/builder_test.go | 4 +++- x/auth/tx/testutil/suite.go | 12 +++++++++--- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/integration/tx/decode_test.go b/tests/integration/tx/decode_test.go index 43094b017085..9efc85c64745 100644 --- a/tests/integration/tx/decode_test.go +++ b/tests/integration/tx/decode_test.go @@ -23,6 +23,7 @@ import ( txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/vesting" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/bank" @@ -101,7 +102,7 @@ func TestDecode(t *testing.T) { Sequence: accSeq, } - gogoMsg, ok := gogo.(sdk.Msg) + gogoMsg, ok := gogo.(legacytx.LegacyMsg) require.True(t, ok) err = txBuilder.SetMsgs(gogoMsg) diff --git a/tools/rosetta/converter_test.go b/tools/rosetta/converter_test.go index 4a30d9b793c4..7eba1fde67b1 100644 --- a/tools/rosetta/converter_test.go +++ b/tools/rosetta/converter_test.go @@ -172,9 +172,11 @@ func (s *ConverterTestSuite) TestOpsAndSigners() { ops, signers, err := s.c.ToRosetta().OpsAndSigners(txBytes) s.Require().NoError(err) - s.Require().Equal(len(ops), len(sdkTx.GetMsgs())*len(sdkTx.GetSigners()), "operation number mismatch") + signerAddrs, err := sdkTx.GetSigners() + s.Require().NoError(err) + s.Require().Equal(len(ops), len(sdkTx.GetMsgs())*len(signerAddrs), "operation number mismatch") - s.Require().Equal(len(signers), len(sdkTx.GetSigners()), "signers number mismatch") + s.Require().Equal(len(signers), len(signerAddrs), "signers number mismatch") }) } diff --git a/types/tx_msg.go b/types/tx_msg.go index 75d0541133a7..898a8f6ea6d3 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -98,11 +98,9 @@ type TxEncoder func(tx Tx) ([]byte, error) func MsgTypeURL(msg proto.Message) string { if m, ok := msg.(protov2.Message); ok { return "/" + string(m.ProtoReflect().Descriptor().FullName()) - } else if m, ok := msg.(proto.Message); ok { - return "/" + proto.MessageName(m) - } else { - panic(fmt.Errorf("%T is not a proto message", m)) } + + return "/" + proto.MessageName(msg) } // GetMsgFromTypeURL returns a `sdk.Msg` message type from a type URL diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 4bb791362ab4..c32f0122ca6f 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -120,7 +120,9 @@ func TestAnteHandlerSigErrors(t *testing.T) { // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 expectedSigners := [][]byte{addr0, addr1, addr2} - require.Equal(t, expectedSigners, tx.GetSigners()) + signers, err := tx.GetSigners() + require.NoError(t, err) + require.Equal(t, expectedSigners, signers) return TestCaseArgs{ accNums: accNums, diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index d34e080e9250..bc05f7f1f7cf 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -410,7 +410,9 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { sigs, err = txBuilder.GetTx().GetSignaturesV2() s.Require().NoError(err) s.Require().Equal(1, len(sigs)) - s.Require().Equal([]byte(s.val), txBuilder.GetTx().GetSigners()[0]) + signers, err := txBuilder.GetTx().GetSigners() + s.Require().NoError(err) + s.Require().Equal([]byte(s.val), signers[0]) // Write the output to disk signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) @@ -918,7 +920,9 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { ) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2) - s.Require().Equal([][]byte{val0, val1}, txBuilder.GetTx().GetSigners()) + signers, err := txBuilder.GetTx().GetSigners() + s.Require().NoError(err) + s.Require().Equal([][]byte{val0, val1}, signers) // Write the unsigned tx into a file. txJSON, err := s.clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 6ddf6325329c..c817b1718d80 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -290,7 +290,9 @@ func TestBuilderFeePayer(t *testing.T) { // set fee payer txBuilder.SetFeePayer(tc.txFeePayer) // and check it updates fields properly - require.Equal(t, tc.expectedSigners, txBuilder.GetSigners()) + signers, err := txBuilder.GetSigners() + require.NoError(t, err) + require.Equal(t, tc.expectedSigners, signers) require.Equal(t, tc.expectedPayer, txBuilder.FeePayer()) }) } diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 2fe0f1943170..2d95ba6dcffa 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -75,7 +75,9 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { s.Require().NoError(err) tx := txBuilder.GetTx() s.Require().Equal(msgs, tx.GetMsgs()) - s.Require().Equal([][]byte{addr1, addr2}, tx.GetSigners()) + signers, err := tx.GetSigners() + s.Require().NoError(err) + s.Require().Equal([][]byte{addr1, addr2}, signers) s.Require().Equal([]byte(addr1), tx.FeePayer()) s.Require().Error(tx.ValidateBasic()) // should fail because of no signatures } @@ -128,7 +130,9 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Len(sigsV2, 2) s.Require().True(sigEquals(sig1, sigsV2[0])) s.Require().True(sigEquals(msig, sigsV2[1])) - s.Require().Equal([][]byte{addr, msigAddr}, sigTx.GetSigners()) + signers, err := sigTx.GetSigners() + s.Require().NoError(err) + s.Require().Equal([][]byte{addr, msigAddr}, signers) s.Require().NoError(sigTx.ValidateBasic()) // sign transaction @@ -179,7 +183,9 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Len(sigsV2, 2) s.Require().True(sigEquals(sig1, sigsV2[0])) s.Require().True(sigEquals(msig, sigsV2[1])) - s.Require().Equal([][]byte{addr, msigAddr}, sigTx.GetSigners()) + signers, err = sigTx.GetSigners() + s.Require().NoError(err) + s.Require().Equal([][]byte{addr, msigAddr}, signers) s.Require().NoError(sigTx.ValidateBasic()) } From 9fe79846a096ce57a5cd98cf1c9a41c3b553c63b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 16:05:23 -0400 Subject: [PATCH 61/83] lint --- x/authz/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 3b80da613a89..8c1a11ec4851 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -1,8 +1,8 @@ package keeper import ( - "context" "bytes" + "context" "fmt" "strconv" "time" From 3ad191bfd36227c8a745a2e4a3e0596ed094f635 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 4 May 2023 18:11:24 -0400 Subject: [PATCH 62/83] lint --- tools/rosetta/client_online.go | 7 +++---- tools/rosetta/converter.go | 9 ++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tools/rosetta/client_online.go b/tools/rosetta/client_online.go index c89f6c2cfc47..04aa3121da47 100644 --- a/tools/rosetta/client_online.go +++ b/tools/rosetta/client_online.go @@ -32,6 +32,7 @@ import ( bank "github.com/cosmos/cosmos-sdk/x/bank/types" tmrpc "github.com/cometbft/cometbft/rpc/client" + "github.com/cosmos/cosmos-sdk/types/query" ) @@ -71,14 +72,12 @@ func NewClient(cfg *Config) (*Client, error) { var supportedOperations []string for _, ii := range cfg.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) { - resolvedMsg, err := cfg.InterfaceRegistry.Resolve(ii) + _, err := cfg.InterfaceRegistry.Resolve(ii) if err != nil { continue } - if _, ok := resolvedMsg.(sdk.Msg); ok { - supportedOperations = append(supportedOperations, ii) - } + supportedOperations = append(supportedOperations, ii) } supportedOperations = append( diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index a9f931079dad..e21bb9025a7e 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -147,16 +147,11 @@ func (c converter) UnsignedTx(ops []*rosettatypes.Operation) (tx authsigning.Tx, for i := 0; i < len(ops); i++ { op := ops[i] - protoMessage, err := c.ir.Resolve(op.Type) + msg, err := c.ir.Resolve(op.Type) if err != nil { return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, "operation not found: "+op.Type) } - msg, ok := protoMessage.(sdk.Msg) - if !ok { - return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, "operation is not a valid supported sdk.Msg: "+op.Type) - } - err = c.Msg(op.Metadata, msg) if err != nil { return nil, crgerrs.WrapError(crgerrs.ErrCodec, err.Error()) @@ -626,7 +621,7 @@ func (c converter) OpsAndSigners(txBytes []byte) (ops []*rosettatypes.Operation, }) } - return + return ops, signers, nil } func (c converter) SignedTx(txBytes []byte, signatures []*rosettatypes.Signature) (signedTxBytes []byte, err error) { From 195349e8f1da36f988bc533d6d767d489c63e269 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 9 May 2023 13:12:54 -0400 Subject: [PATCH 63/83] Update baseapp/baseapp.go Co-authored-by: Matt Kocubinski --- baseapp/baseapp.go | 1 + 1 file changed, 1 insertion(+) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index da7a144de9fd..730b0a4f30e8 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -196,6 +196,7 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() // initialize with an empty interface registry to avoid nil pointer dereference + // note: unless SetInterfaceRegistry is called with an interface registry with proper address codecs base app will panic. app.cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) return app From cdc0d9cc6c025570d87b7480e93ee8b0689745cf Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 9 May 2023 13:37:41 -0400 Subject: [PATCH 64/83] address review comments --- x/auth/tx/builder.go | 71 ++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index fc8d7acd635c..f13363884666 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -40,7 +40,6 @@ type wrapper struct { signers [][]byte msgsV2 []protov2.Message - err error } var ( @@ -79,10 +78,13 @@ func (w *wrapper) GetMsgs() []sdk.Msg { func (w *wrapper) GetMsgsV2() ([]protov2.Message, error) { if w.msgsV2 == nil { - w.initSignersAndMsgsV2() + err := w.initSignersAndMsgsV2() + if err != nil { + return nil, err + } } - return w.msgsV2, w.err + return w.msgsV2, nil } func (w *wrapper) ValidateBasic() error { @@ -90,56 +92,16 @@ func (w *wrapper) ValidateBasic() error { return fmt.Errorf("bad Tx") } - body := w.tx.Body - if body == nil { - return fmt.Errorf("missing TxBody") - } - - authInfo := w.tx.AuthInfo - if authInfo == nil { - return fmt.Errorf("missing AuthInfo") - } - - fee := authInfo.Fee - if fee == nil { - return fmt.Errorf("missing fee") - } - - if fee.GasLimit > tx.MaxGasWanted { - return errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", fee.GasLimit, tx.MaxGasWanted, - ) - } - - if fee.Amount.IsAnyNil() { - return errorsmod.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: null", - ) - } - - if fee.Amount.IsAnyNegative() { - return errorsmod.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: %s", fee.Amount, - ) - } - - if fee.Payer != "" { - _, err := sdk.AccAddressFromBech32(fee.Payer) - if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid fee payer address (%s)", err) - } + if err := w.tx.ValidateBasic(); err != nil { + return err } sigs := w.tx.Signatures - - if len(sigs) == 0 { - return sdkerrors.ErrNoSignatures + signers, err := w.GetSigners() + if err != nil { + return err } - signers, _ := w.GetSigners() if len(sigs) != len(signers) { return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, @@ -182,15 +144,20 @@ func (w *wrapper) getAuthInfoBytes() []byte { return w.authInfoBz } -func (w *wrapper) initSignersAndMsgsV2() { - w.signers, w.msgsV2, w.err = w.tx.GetSigners(w.cdc) +func (w *wrapper) initSignersAndMsgsV2() error { + var err error + w.signers, w.msgsV2, err = w.tx.GetSigners(w.cdc) + return err } func (w *wrapper) GetSigners() ([][]byte, error) { if w.signers == nil { - w.initSignersAndMsgsV2() + err := w.initSignersAndMsgsV2() + if err != nil { + return nil, err + } } - return w.signers, w.err + return w.signers, nil } func (w *wrapper) GetPubKeys() ([]cryptotypes.PubKey, error) { From 81faf2bcffaa767edc4cbb20bc97afc49f7f04a7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 9 May 2023 13:42:18 -0400 Subject: [PATCH 65/83] address review comments --- baseapp/baseapp_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 275eb28eaefd..c7b98430a7c7 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -19,15 +19,14 @@ import ( "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" - testutil2 "github.com/cosmos/cosmos-sdk/codec/testutil" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) @@ -58,7 +57,7 @@ type ( ) func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { - cdc := testutil2.CodecOptions{}.NewCodec() + cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) From 136811ab0dfca8067a8cbd626d59d46009b004bc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 11 May 2023 11:50:52 -0400 Subject: [PATCH 66/83] add `AccountKeeper.AddressCodec()` method --- CHANGELOG.md | 2 +- simapp/app.go | 1 - x/auth/ante/ante.go | 3 +-- x/auth/ante/ante_test.go | 1 - x/auth/ante/expected_keepers.go | 2 ++ x/auth/ante/sigverify.go | 20 +++++++------------- x/auth/ante/testutil_test.go | 1 - x/auth/keeper/keeper.go | 11 +++++++++-- x/auth/tx/config/config.go | 1 - 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f1637876046..f9295176c625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,7 +196,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `sdk.Tx` now requires a new method `GetMsgsV2()`. * `types/tx.Tx` no longer implements `sdk.Tx`. * `TxConfig` has a new method `SigningContext() *signing.Context`. - * `ante.NewSetPubKeyDecorator` now requires `*signing.Context`. + * `AccountKeeper` now has an `AddressCodec() address.Codec` method and the expected `AccountKeeper` for `x/auth/ante` expects this method. * `SigVerifiableTx.GetSigners()` now returns `([][]byte, error)` instead of `[]sdk.AccAddress`. * (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. * (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`. diff --git a/simapp/app.go b/simapp/app.go index c39446dac739..b1cebe5e6bda 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -530,7 +530,6 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: app.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - SigningContext: txConfig.SigningContext(), }, ) if err != nil { diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 250b01f54153..05c5eb102657 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -21,7 +21,6 @@ type HandlerOptions struct { SignModeHandler *txsigning.HandlerMap SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker - SigningContext *txsigning.Context } // NewAnteHandler returns an AnteHandler that checks and increments sequence @@ -48,7 +47,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), - NewSetPubKeyDecorator(options.AccountKeeper, options.SigningContext), // SetPubKeyDecorator must be called before all signature verification decorators + NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators NewValidateSigCountDecorator(options.AccountKeeper), NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index c32f0122ca6f..f5b33fe6e4e8 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -1330,7 +1330,6 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { return errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized public key type: %T", pubkey) } }, - SigningContext: suite.clientCtx.TxConfig.SigningContext(), }, ) require.NoError(t, err) diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index 99f2dd8dc6ae..1fec5fdf1712 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -3,6 +3,7 @@ package ante import ( "context" + "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -14,6 +15,7 @@ type AccountKeeper interface { GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI SetAccount(ctx context.Context, acc sdk.AccountI) GetModuleAddress(moduleName string) sdk.AccAddress + AddressCodec() address.Codec } // FeegrantKeeper defines the expected feegrant keeper. diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index a08e3e43dea1..732e6b392cc3 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -50,14 +50,12 @@ type SignatureVerificationGasConsumer = func(meter storetypes.GasMeter, sig sign // PubKeys must be set in context for all signers before any other sigverify decorators run // CONTRACT: Tx must implement SigVerifiableTx interface type SetPubKeyDecorator struct { - ak AccountKeeper - signingCtx *txsigning.Context + ak AccountKeeper } -func NewSetPubKeyDecorator(ak AccountKeeper, signingCtx *txsigning.Context) SetPubKeyDecorator { +func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { return SetPubKeyDecorator{ - ak: ak, - signingCtx: signingCtx, + ak: ak, } } @@ -88,14 +86,10 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b // Only make check if simulate=false if !simulate && !bytes.Equal(pk.Address(), signers[i]) { var signerStr string - if spkd.signingCtx != nil { - var err error - signerStr, err = spkd.signingCtx.AddressCodec().BytesToString(signers[i]) - if err != nil { - return sdk.Context{}, err - } - } else { - signerStr = sdk.AccAddress(signers[i]).String() + var err error + signerStr, err = spkd.ak.AddressCodec().BytesToString(signers[i]) + if err != nil { + return sdk.Context{}, err } return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 5008dd41d454..5056e85b7fa1 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -100,7 +100,6 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { FeegrantKeeper: suite.feeGrantKeeper, SignModeHandler: suite.encCfg.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - SigningContext: suite.encCfg.TxConfig.SigningContext(), }, ) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index a5e626f1ddcc..14aba6df3287 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -7,11 +7,12 @@ import ( "cosmossdk.io/collections" - "cosmossdk.io/core/address" - "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" + "cosmossdk.io/core/address" + "cosmossdk.io/core/store" + "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -56,6 +57,8 @@ type AccountKeeperI interface { // GetModulePermissions fetches per-module account permissions GetModulePermissions() map[string]types.PermissionsForAddress + + AddressCodec() address.Codec } // AccountKeeper encodes/decodes accounts using the go-amino (binary) @@ -276,3 +279,7 @@ func (ak AccountKeeper) GetParams(ctx context.Context) (params types.Params) { } return params } + +func (ak AccountKeeper) AddressCodec() address.Codec { + return ak.Codec +} diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 6d04cce46067..5d6ab319474b 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -134,7 +134,6 @@ func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - SigningContext: txConfig.SigningContext(), }, ) if err != nil { From e2d668a4c4c57dd14dbc874087ca9ba1cf7fe361 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 11 May 2023 11:55:44 -0400 Subject: [PATCH 67/83] fix tests --- x/auth/ante/sigverify_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 0667fcdff43b..e5538ee03e18 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -56,7 +56,7 @@ func TestSetPubKey(t *testing.T) { tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.encCfg.TxConfig.SigningContext()) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) antehandler := sdk.ChainAnteDecorators(spkd) ctx, err := antehandler(suite.ctx, tx, false) @@ -164,7 +164,7 @@ func TestSigVerification(t *testing.T) { feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SigningContext()) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) txConfigOpts = authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(suite.txBankKeeper), EnabledSignModes: enabledSignModes, @@ -291,7 +291,7 @@ func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...crypto tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper, suite.encCfg.TxConfig.SigningContext()) + spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) svgc := ante.NewSigGasConsumeDecorator(suite.accountKeeper, ante.DefaultSigVerificationGasConsumer) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svgc, svd) From 8c22d9aa0f17a1cda40e4aeb58e25a32f3cf132e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 16 May 2023 10:11:13 -0400 Subject: [PATCH 68/83] add benchmark --- codec/bench_test.go | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 codec/bench_test.go diff --git a/codec/bench_test.go b/codec/bench_test.go new file mode 100644 index 000000000000..187843b4ce65 --- /dev/null +++ b/codec/bench_test.go @@ -0,0 +1,68 @@ +package codec_test + +import ( + "testing" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + "github.com/stretchr/testify/require" + + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +func BenchmarkLegacyGetSigners(b *testing.B) { + _, _, addr := testdata.KeyTestPubAddr() + msg := &banktypes.MsgSend{ + FromAddress: addr.String(), + ToAddress: "", + Amount: nil, + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = msg.GetSigners() + } +} + +func BenchmarkProtoreflectGetSigners(b *testing.B) { + cdc := codectestutil.CodecOptions{}.NewCodec() + signingCtx := cdc.InterfaceRegistry().SigningContext() + _, _, addr := testdata.KeyTestPubAddr() + msg := &bankv1beta1.MsgSend{ + FromAddress: addr.String(), + ToAddress: "", + Amount: nil, + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := signingCtx.GetSigners(msg) + if err != nil { + panic(err) + } + } +} + +func BenchmarkProtoreflectGetSignersWithUnmarshal(b *testing.B) { + cdc := codectestutil.CodecOptions{}.NewCodec() + _, _, addr := testdata.KeyTestPubAddr() + // start with a protoreflect message + msg := &banktypes.MsgSend{ + FromAddress: addr.String(), + ToAddress: "", + Amount: nil, + } + // marshal to an any first because this is what we get from the wire + a, err := codectypes.NewAnyWithValue(msg) + require.NoError(b, err) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, _, err := cdc.GetMsgAnySigners(a) + if err != nil { + panic(err) + } + } +} From 9d16ef253ba5529be21548b03a44c43c808f5285 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 16 May 2023 10:23:30 -0400 Subject: [PATCH 69/83] add dynamicpb bench --- codec/bench_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/codec/bench_test.go b/codec/bench_test.go index 187843b4ce65..cb3c821213e1 100644 --- a/codec/bench_test.go +++ b/codec/bench_test.go @@ -5,6 +5,8 @@ import ( bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" "github.com/stretchr/testify/require" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/dynamicpb" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -30,6 +32,7 @@ func BenchmarkProtoreflectGetSigners(b *testing.B) { cdc := codectestutil.CodecOptions{}.NewCodec() signingCtx := cdc.InterfaceRegistry().SigningContext() _, _, addr := testdata.KeyTestPubAddr() + // use a pulsar message msg := &bankv1beta1.MsgSend{ FromAddress: addr.String(), ToAddress: "", @@ -66,3 +69,28 @@ func BenchmarkProtoreflectGetSignersWithUnmarshal(b *testing.B) { } } } + +func BenchmarkProtoreflectGetSignersDynamicpb(b *testing.B) { + cdc := codectestutil.CodecOptions{}.NewCodec() + signingCtx := cdc.InterfaceRegistry().SigningContext() + _, _, addr := testdata.KeyTestPubAddr() + msg := &bankv1beta1.MsgSend{ + FromAddress: addr.String(), + ToAddress: "", + Amount: nil, + } + bz, err := protov2.Marshal(msg) + require.NoError(b, err) + + dynamicmsg := dynamicpb.NewMessage(msg.ProtoReflect().Descriptor()) + err = protov2.Unmarshal(bz, dynamicmsg) + require.NoError(b, err) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := signingCtx.GetSigners(dynamicmsg) + if err != nil { + panic(err) + } + } +} From e033c045cd2bace2c908b7fcdf0bffbc4c0d50fb Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 16 May 2023 11:48:05 -0500 Subject: [PATCH 70/83] fix simapp tests (#16185) --- simapp/app.go | 56 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 0155fe917810..93b0c1a96e8f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -15,14 +15,15 @@ import ( reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + "github.com/cosmos/cosmos-sdk/x/auth/tx" abci "github.com/cometbft/cometbft/abci/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cast" - simappparams "cosmossdk.io/simapp/params" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/evidence" evidencekeeper "cosmossdk.io/x/evidence/keeper" @@ -40,6 +41,7 @@ import ( "cosmossdk.io/x/circuit" circuitkeeper "cosmossdk.io/x/circuit/keeper" circuittypes "cosmossdk.io/x/circuit/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -132,6 +134,36 @@ var ( _ servertypes.Application = (*SimApp)(nil) ) +// stdAccAddressCodec is a temporary address codec that we will use until we +// can populate it with the correct bech32 prefixes without depending on the global. +type stdAccAddressCodec struct{} + +func (g stdAccAddressCodec) StringToBytes(text string) ([]byte, error) { + if text == "" { + return nil, nil + } + return sdk.AccAddressFromBech32(text) +} + +func (g stdAccAddressCodec) BytesToString(bz []byte) (string, error) { + if bz == nil { + return "", nil + } + return sdk.AccAddress(bz).String(), nil +} + +// stdValAddressCodec is a temporary address codec that we will use until we +// can populate it with the correct bech32 prefixes without depending on the global. +type stdValAddressCodec struct{} + +func (g stdValAddressCodec) StringToBytes(text string) ([]byte, error) { + return sdk.ValAddressFromBech32(text) +} + +func (g stdValAddressCodec) BytesToString(bz []byte) (string, error) { + return sdk.ValAddress(bz).String(), nil +} + // SimApp extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. @@ -194,12 +226,14 @@ func NewSimApp( appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - encodingConfig := simappparams.MakeTestEncodingConfig() - - appCodec := encodingConfig.Codec - legacyAmino := encodingConfig.Amino - interfaceRegistry := encodingConfig.InterfaceRegistry - txConfig := encodingConfig.TxConfig + interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + AddressCodec: stdAccAddressCodec{}, + ValidatorAddressCodec: stdValAddressCodec{}, + }) + appCodec := codec.NewProtoCodec(interfaceRegistry) + legacyAmino := codec.NewLegacyAmino() + txConfig := tx.NewTxConfig(appCodec, tx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -367,7 +401,7 @@ func NewSimApp( app.ModuleManager = module.NewManager( genutil.NewAppModule( app.AccountKeeper, app.StakingKeeper, app, - encodingConfig.TxConfig, + txConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), @@ -403,8 +437,8 @@ func NewSimApp( }, ), }) - app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino) - app.BasicModuleManager.RegisterInterfaces(encodingConfig.InterfaceRegistry) + app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) + app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the @@ -486,7 +520,7 @@ func NewSimApp( app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) - app.setAnteHandler(encodingConfig.TxConfig) + app.setAnteHandler(txConfig) // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like // antehandlers, but are run _after_ the `runMsgs` execution. They are also From 077e20293e076e475f0a4878dbd4e811e9e51a36 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 16 May 2023 12:52:28 -0400 Subject: [PATCH 71/83] address review comments --- x/auth/ante/sigverify.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 732e6b392cc3..657a7c3bdbc4 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -176,7 +176,10 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. - signers, _ := sigTx.GetSigners() + signers, err := sigTx.GetSigners() + if err != nil { + return ctx, err + } for i, sig := range sigs { signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signers[i]) @@ -261,7 +264,10 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul return ctx, err } - signers, _ := sigTx.GetSigners() + signers, err := sigTx.GetSigners() + if err != nil { + return ctx, err + } // check that signer length and signature length are the same if len(sigs) != len(signers) { From 20028439b835d6e49fd43f74f9edf95b832b3bd9 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 17 May 2023 09:18:04 -0500 Subject: [PATCH 72/83] fix comment in linter --- baseapp/baseapp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 4728150acd83..c59bdae6003d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -195,8 +195,8 @@ func NewBaseApp( app.runTxRecoveryMiddleware = newDefaultRecoveryMiddleware() - // initialize with an empty interface registry to avoid nil pointer dereference - // note: unless SetInterfaceRegistry is called with an interface registry with proper address codecs base app will panic. + // Initialize with an empty interface registry to avoid nil pointer dereference. + // Unless SetInterfaceRegistry is called with an interface registry with proper address codecs base app will panic. app.cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) return app From a13f25314397bb31312e5f6ba911b54a0b4eb2ff Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 17 May 2023 13:23:26 -0500 Subject: [PATCH 73/83] Register Tx with HasMsg interface --- runtime/module.go | 2 +- types/tx/types.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/module.go b/runtime/module.go index c4ca32e8009f..e4b961c8fb43 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -100,7 +100,7 @@ func ProvideApp() ( } interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ - ProtoFiles: protoFiles, + ProtoFiles: proto.HybridResolver, AddressCodec: globalAccAddressCodec{}, ValidatorAddressCodec: globalValAddressCodec{}, }) diff --git a/types/tx/types.go b/types/tx/types.go index 0f3d22575678..c83b248b9d5e 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -224,6 +224,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil)) + registry.RegisterImplementations((*sdk.HasMsgs)(nil), &Tx{}) registry.RegisterInterface("cosmos.tx.v1beta1.TxExtensionOptionI", (*TxExtensionOptionI)(nil)) } From 04f8c5226446294d15312c7e3c05fab05be6f12a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 17 May 2023 13:32:21 -0500 Subject: [PATCH 74/83] Fix some e2e tests --- types/result.go | 2 +- types/tx/types.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/result.go b/types/result.go index 31d3784799a9..16382a422777 100644 --- a/types/result.go +++ b/types/result.go @@ -183,7 +183,7 @@ func (s SearchTxsResult) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (r TxResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { if r.Tx != nil { - var tx Tx + var tx HasMsgs return unpacker.UnpackAny(r.Tx, &tx) } return nil diff --git a/types/tx/types.go b/types/tx/types.go index c83b248b9d5e..4df21dea7fc5 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -223,7 +223,7 @@ func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) - registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil)) + registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.HasMsgs)(nil)) registry.RegisterImplementations((*sdk.HasMsgs)(nil), &Tx{}) registry.RegisterInterface("cosmos.tx.v1beta1.TxExtensionOptionI", (*TxExtensionOptionI)(nil)) From 8538e0ec2f89d7d36cd021f286830ee3eb3fdec1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 12:00:42 -0400 Subject: [PATCH 75/83] fix --- x/auth/keeper/keeper.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 3b1f878c186d..8e4766db7a90 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -277,7 +277,3 @@ func (ak AccountKeeper) GetParams(ctx context.Context) (params types.Params) { } return params } - -func (ak AccountKeeper) AddressCodec() address.Codec { - return ak.Codec -} From 5040e7e0dfc1a1190510141c66106f8f4d42e697 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 14:27:39 -0400 Subject: [PATCH 76/83] fix test --- baseapp/abci_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 9c5f6e7e5d5f..9d12ed1ac121 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -11,16 +11,17 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" - pruningtypes "cosmossdk.io/store/pruning/types" - "cosmossdk.io/store/snapshots" - snapshottypes "cosmossdk.io/store/snapshots/types" - storetypes "cosmossdk.io/store/types" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/jsonpb" "github.com/stretchr/testify/require" + pruningtypes "cosmossdk.io/store/pruning/types" + "cosmossdk.io/store/snapshots" + snapshottypes "cosmossdk.io/store/snapshots/types" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/testutil" @@ -1253,7 +1254,7 @@ func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) { } resPrepareProposal, err := suite.baseApp.PrepareProposal(&reqPrepareProposal) require.NoError(t, err) - require.Equal(t, 11, len(resPrepareProposal.Txs)) + require.Equal(t, 8, len(resPrepareProposal.Txs)) } func TestABCI_PrepareProposal_BadEncoding(t *testing.T) { From d37b395a186f1a61fa9c89cb9291fb287f18ab55 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 15:10:27 -0400 Subject: [PATCH 77/83] fix rosetta, simplify runtime --- runtime/module.go | 43 ++++++++++-------------------------------- tools/rosetta/codec.go | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index 7f58f579b821..a84019036f1a 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -19,6 +19,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/core/store" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -98,9 +99,15 @@ func ProvideApp() ( } interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - AddressCodec: globalAccAddressCodec{}, - ValidatorAddressCodec: globalValAddressCodec{}, + ProtoFiles: proto.HybridResolver, + // using the global prefixes is a temporary solution until we refactor this + // to get the address.Codec's from the container + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, }) if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, err @@ -243,33 +250,3 @@ func ProvideHeaderInfoService(app *AppBuilder) header.Service { func ProvideBasicManager(app *AppBuilder) module.BasicManager { return app.app.basicManager } - -// globalAccAddressCodec is a temporary address codec that we will use until we -// can populate it with the correct bech32 prefixes without depending on the global. -type globalAccAddressCodec struct{} - -func (g globalAccAddressCodec) StringToBytes(text string) ([]byte, error) { - if text == "" { - return nil, nil - } - return sdk.AccAddressFromBech32(text) -} - -func (g globalAccAddressCodec) BytesToString(bz []byte) (string, error) { - if bz == nil { - return "", nil - } - return sdk.AccAddress(bz).String(), nil -} - -// globalValAddressCodec is a temporary address codec that we will use until we -// can populate it with the correct bech32 prefixes without depending on the global. -type globalValAddressCodec struct{} - -func (g globalValAddressCodec) StringToBytes(text string) ([]byte, error) { - return sdk.ValAddressFromBech32(text) -} - -func (g globalValAddressCodec) BytesToString(bz []byte) (string, error) { - return sdk.ValAddress(bz).String(), nil -} diff --git a/tools/rosetta/codec.go b/tools/rosetta/codec.go index 96242a9e044a..ff0668378890 100644 --- a/tools/rosetta/codec.go +++ b/tools/rosetta/codec.go @@ -1,9 +1,13 @@ package rosetta import ( + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" authcodec "github.com/cosmos/cosmos-sdk/x/auth/types" bankcodec "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -11,7 +15,20 @@ import ( // MakeCodec generates the codec required to interact // with the cosmos APIs used by the rosetta gateway func MakeCodec() (*codec.ProtoCodec, codectypes.InterfaceRegistry) { - ir := codectypes.NewInterfaceRegistry() + ir, err := codectypes.NewInterfaceRegistryWithOptions( + codectypes.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + ) + if err != nil { + panic(err) + } cdc := codec.NewProtoCodec(ir) authcodec.RegisterInterfaces(ir) From 9b6be9f6529b2fa4b99705c5a1eef1f8367f21c6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 16:07:51 -0400 Subject: [PATCH 78/83] fix amino --- x/auth/types/codec.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index f5c6b5b4f036..554e5dc73f5a 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -7,6 +7,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" @@ -24,6 +25,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&ModuleCredential{}, "cosmos-sdk/GroupAccountCredential", nil) legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/auth/MsgUpdateParams") + + legacytx.RegisterLegacyAminoCodec(cdc) } // RegisterInterfaces associates protoName with AccountI interface From 9b1be48a9f44728da8df11f89d76ae387ab08379 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 16:13:32 -0400 Subject: [PATCH 79/83] fix test --- baseapp/msg_service_router_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index eeee401a7d82..23acbe99409b 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -115,9 +115,14 @@ func TestMsgService(t *testing.T) { app.MsgServiceRouter(), testdata.MsgServerImpl{}, ) - app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) + _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) + require.NoError(t, err) - msg := testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}} + _, _, addr := testdata.KeyTestPubAddr() + msg := testdata.MsgCreateDog{ + Dog: &testdata.Dog{Name: "Spot"}, + Owner: addr.String(), + } txBuilder := txConfig.NewTxBuilder() txBuilder.SetFeeAmount(testdata.NewTestFeeAmount()) From 7c2b7cc6b009737086b1fc45933b90c261a866a9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 16:51:46 -0400 Subject: [PATCH 80/83] check error --- tests/e2e/auth/suite.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 476748cf98fe..7b81085ba106 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -561,6 +561,7 @@ func (s *E2ETestSuite) TestCLIQueryTxCmdByEvents() { s.Require().Contains(err.Error(), tc.expectErrStr) } else { var result sdk.TxResponse + s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) s.Require().NotNil(result.Height) } From bd63b848e79deb61871a173652d4cf2742b4bb48 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 May 2023 17:12:35 -0400 Subject: [PATCH 81/83] fix acc_seq event --- x/auth/ante/sigverify.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 29bbabc779ed..7cd4e5cf2dce 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -76,7 +76,14 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b return sdk.Context{}, err } + signerStrs := make([]string, len(signers)) for i, pk := range pubkeys { + var err error + signerStrs[i], err = spkd.ak.AddressCodec().BytesToString(signers[i]) + if err != nil { + return sdk.Context{}, err + } + // PublicKey was omitted from slice since it has already been set in context if pk == nil { if !simulate { @@ -86,15 +93,8 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b } // Only make check if simulate=false if !simulate && !bytes.Equal(pk.Address(), signers[i]) { - var signerStr string - var err error - signerStr, err = spkd.ak.AddressCodec().BytesToString(signers[i]) - if err != nil { - return sdk.Context{}, err - } - return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, - "pubKey does not match signer address %s with signer index: %d", signerStr, i) + "pubKey does not match signer address %s with signer index: %d", signerStrs[i], i) } acc, err := GetSignerAcc(ctx, spkd.ak, signers[i]) @@ -124,7 +124,7 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b var events sdk.Events for i, sig := range sigs { events = append(events, sdk.NewEvent(sdk.EventTypeTx, - sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)), + sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signerStrs[i], sig.Sequence)), )) sigBzs, err := signatureDataToBz(sig.Data) @@ -539,10 +539,10 @@ func signatureDataToBz(data signing.SignatureData) ([][]byte, error) { sigs = append(sigs, nestedSigs...) } - multisig := cryptotypes.MultiSignature{ + multiSignature := cryptotypes.MultiSignature{ Signatures: sigs, } - aggregatedSig, err := multisig.Marshal() + aggregatedSig, err := multiSignature.Marshal() if err != nil { return nil, err } From b41ab3ff952463ea75048d51a46cf50d3b2eac4a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 25 May 2023 14:17:13 -0400 Subject: [PATCH 82/83] use address.Bech32Codec in simapp --- simapp/app.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 00202794a03f..904a0e0818bd 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -15,6 +15,7 @@ import ( reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/codec/address" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -227,9 +228,13 @@ func NewSimApp( baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - AddressCodec: stdAccAddressCodec{}, - ValidatorAddressCodec: stdValAddressCodec{}, + ProtoFiles: proto.HybridResolver, + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() From 85129fd715d2146e281da57611a05c81fad5a3d1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 25 May 2023 14:18:17 -0400 Subject: [PATCH 83/83] address review comment --- x/auth/tx/builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index f13363884666..7cd594235873 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -359,12 +359,12 @@ func (w *wrapper) SetSignatures(signatures ...signing.SignatureV2) error { for i, sig := range signatures { var modeInfo *tx.ModeInfo modeInfo, rawSigs[i] = SignatureDataToModeInfoAndSig(sig.Data) - a, err := codectypes.NewAnyWithValue(sig.PubKey) + pubKey, err := codectypes.NewAnyWithValue(sig.PubKey) if err != nil { return err } signerInfos[i] = &tx.SignerInfo{ - PublicKey: a, + PublicKey: pubKey, ModeInfo: modeInfo, Sequence: sig.Sequence, }