From aa99314bc7728de83cfe26a3f14c8bbf3d414e78 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 12 Nov 2021 13:21:31 +0530 Subject: [PATCH 01/43] WIP: middleware refactor --- types/tx/middleware.go | 15 +++- x/auth/middleware/basic.go | 92 ++++++++++++------------ x/auth/middleware/ext.go | 22 +++--- x/auth/middleware/fee.go | 46 ++++++------ x/auth/middleware/gas.go | 36 +++++----- x/auth/middleware/gas_test.go | 12 ++-- x/auth/middleware/index_events.go | 12 ++-- x/auth/middleware/recovery.go | 10 +-- x/auth/middleware/run_msgs.go | 18 ++--- x/auth/middleware/sigverify.go | 114 +++++++++++++++--------------- 10 files changed, 192 insertions(+), 185 deletions(-) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index c99df63d95c6..d8501f86cade 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -3,6 +3,7 @@ package tx import ( context "context" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,12 +22,20 @@ type ResponseSimulateTx struct { Result *sdk.Result } +type Response struct { + GasWanted uint64 + GasUsed uint64 + MsgResponses []codectypes.Any // Represents each Msg service handler's response type. Will get proto-serialized into the `Data` field in ABCI, see note #2 + Log string + Events []abci.Event +} + // TxHandler defines the baseapp's CheckTx, DeliverTx and Simulate respective // handlers. It is designed as a middleware stack. type Handler interface { - CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) - DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) - SimulateTx(ctx context.Context, tx sdk.Tx, req RequestSimulateTx) (ResponseSimulateTx, error) + CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (Response, error) + DeliverTx(ctx context.Context, tx sdk.Tx) (Response, error) + SimulateTx(ctx context.Context, tx sdk.Tx) (Response, error) } // TxMiddleware defines one layer of the TxHandler middleware stack. diff --git a/x/auth/middleware/basic.go b/x/auth/middleware/basic.go index 58d05bdd7610..83b0c3c396c7 100644 --- a/x/auth/middleware/basic.go +++ b/x/auth/middleware/basic.go @@ -49,47 +49,47 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh validateBasicTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { +func (txh validateBasicTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { // no need to validate basic on recheck tx, call next middleware if req.Type == abci.CheckTxType_Recheck { - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, sdkTx, req) } - if err := validateBasicTxMsgs(tx.GetMsgs()); err != nil { - return abci.ResponseCheckTx{}, err + if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { + return tx.Response{}, err } - if err := tx.ValidateBasic(); err != nil { - return abci.ResponseCheckTx{}, err + if err := sdkTx.ValidateBasic(); err != nil { + return tx.Response{}, err } - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh validateBasicTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := tx.ValidateBasic(); err != nil { - return abci.ResponseDeliverTx{}, err +func (txh validateBasicTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := sdkTx.ValidateBasic(); err != nil { + return tx.Response{}, err } - if err := validateBasicTxMsgs(tx.GetMsgs()); err != nil { - return abci.ResponseDeliverTx{}, err + if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { + return tx.Response{}, err } - return txh.next.DeliverTx(ctx, tx, req) + return txh.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh validateBasicTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh validateBasicTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := sdkTx.ValidateBasic(); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx, req) + return txh.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = txTimeoutHeightTxHandler{} @@ -124,30 +124,30 @@ func checkTimeout(ctx context.Context, tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := checkTimeout(ctx, tx); err != nil { - return abci.ResponseCheckTx{}, err +func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := checkTimeout(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh txTimeoutHeightTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := checkTimeout(ctx, tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (txh txTimeoutHeightTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := checkTimeout(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return txh.next.DeliverTx(ctx, tx, req) + return txh.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh txTimeoutHeightTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh txTimeoutHeightTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := checkTimeout(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx, req) + return txh.next.SimulateTx(ctx, sdkTx) } type validateMemoTxHandler struct { @@ -190,30 +190,30 @@ func (vmm validateMemoTxHandler) checkForValidMemo(ctx context.Context, tx sdk.T } // CheckTx implements tx.Handler.CheckTx method. -func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := vmm.checkForValidMemo(ctx, tx); err != nil { - return abci.ResponseCheckTx{}, err +func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return vmm.next.CheckTx(ctx, tx, req) + return vmm.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx method. -func (vmm validateMemoTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := vmm.checkForValidMemo(ctx, tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (vmm validateMemoTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return vmm.next.DeliverTx(ctx, tx, req) + return vmm.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx method. -func (vmm validateMemoTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (vmm validateMemoTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return vmm.next.SimulateTx(ctx, sdkTx, req) + return vmm.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = consumeTxSizeGasTxHandler{} @@ -304,21 +304,21 @@ func (cgts consumeTxSizeGasTxHandler) consumeTxSizeGas(ctx context.Context, _ sd } // CheckTx implements tx.Handler.CheckTx. -func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := cgts.consumeTxSizeGas(ctx, tx, req.GetTx()); err != nil { - return abci.ResponseCheckTx{}, err +func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := cgts.consumeTxSizeGas(ctx, sdkTx, req.GetTx()); err != nil { + return tx.Response{}, err } - return cgts.next.CheckTx(ctx, tx, req) + return cgts.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (cgts consumeTxSizeGasTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := cgts.consumeTxSizeGas(ctx, tx, req.GetTx()); err != nil { +func (cgts consumeTxSizeGasTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestDeliverTx) (tx.Response, error) { + if err := cgts.consumeTxSizeGas(ctx, sdkTx, req.GetTx()); err != nil { return abci.ResponseDeliverTx{}, err } - return cgts.next.DeliverTx(ctx, tx, req) + return cgts.next.DeliverTx(ctx, sdkTx, req) } // SimulateTx implements tx.Handler.SimulateTx. diff --git a/x/auth/middleware/ext.go b/x/auth/middleware/ext.go index 3fec1f674a47..db271fb5e3df 100644 --- a/x/auth/middleware/ext.go +++ b/x/auth/middleware/ext.go @@ -44,28 +44,28 @@ func checkExtOpts(tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := checkExtOpts(tx); err != nil { - return abci.ResponseCheckTx{}, err +func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := checkExtOpts(sdkTx); err != nil { + return tx.Response{}, err } - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh rejectExtensionOptionsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := checkExtOpts(tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (txh rejectExtensionOptionsTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := checkExtOpts(sdkTx); err != nil { + return tx.Response{}, err } - return txh.next.DeliverTx(ctx, tx, req) + return txh.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh rejectExtensionOptionsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh rejectExtensionOptionsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := checkExtOpts(sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx, req) + return txh.next.SimulateTx(ctx, sdkTx) } diff --git a/x/auth/middleware/fee.go b/x/auth/middleware/fee.go index 7285d530cfb2..d95bc8a89bc9 100644 --- a/x/auth/middleware/fee.go +++ b/x/auth/middleware/fee.go @@ -31,12 +31,12 @@ func MempoolFeeMiddleware(txh tx.Handler) tx.Handler { } // CheckTx implements tx.Handler.CheckTx. -func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { +func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - feeTx, ok := tx.(sdk.FeeTx) + feeTx, ok := sdkTx.(sdk.FeeTx) if !ok { - return abci.ResponseCheckTx{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return tx.Response{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } feeCoins := feeTx.GetFee() @@ -58,21 +58,21 @@ func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci. } if !feeCoins.IsAnyGTE(requiredFees) { - return abci.ResponseCheckTx{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) + return tx.Response{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) } } - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh mempoolFeeTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - return txh.next.DeliverTx(ctx, tx, req) +func (txh mempoolFeeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + return txh.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh mempoolFeeTxHandler) SimulateTx(ctx context.Context, tx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - return txh.next.SimulateTx(ctx, tx, req) +func (txh mempoolFeeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + return txh.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = deductFeeTxHandler{} @@ -99,9 +99,9 @@ func DeductFeeMiddleware(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKeepe } } -func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, tx sdk.Tx) error { +func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, sdkTx sdk.Tx) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - feeTx, ok := tx.(sdk.FeeTx) + feeTx, ok := sdkTx.(sdk.FeeTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } @@ -122,7 +122,7 @@ func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, tx sdk.Tx) err if dfd.feegrantKeeper == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled") } else if !feeGranter.Equals(feePayer) { - err := dfd.feegrantKeeper.UseGrantedFees(sdkCtx, feeGranter, feePayer, fee, tx.GetMsgs()) + err := dfd.feegrantKeeper.UseGrantedFees(sdkCtx, feeGranter, feePayer, fee, sdkTx.GetMsgs()) if err != nil { return sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer) @@ -154,29 +154,29 @@ func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, tx sdk.Tx) err } // CheckTx implements tx.Handler.CheckTx. -func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := dfd.checkDeductFee(ctx, tx); err != nil { - return abci.ResponseCheckTx{}, err +func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return dfd.next.CheckTx(ctx, tx, req) + return dfd.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (dfd deductFeeTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := dfd.checkDeductFee(ctx, tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (dfd deductFeeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return dfd.next.DeliverTx(ctx, tx, req) + return dfd.next.DeliverTx(ctx, sdkTx) } -func (dfd deductFeeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (dfd deductFeeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return dfd.next.SimulateTx(ctx, sdkTx, req) + return dfd.next.SimulateTx(ctx, sdkTx) } // DeductFees deducts fees from the given account. diff --git a/x/auth/middleware/gas.go b/x/auth/middleware/gas.go index b49ce43702cc..16944ca524de 100644 --- a/x/auth/middleware/gas.go +++ b/x/auth/middleware/gas.go @@ -30,45 +30,43 @@ func GasTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = gasTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (txh gasTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), tx, false) +func (txh gasTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, false) if err != nil { - return abci.ResponseCheckTx{}, err + return tx.Response{}, err } - res, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), tx, req) - res.GasUsed = int64(sdkCtx.GasMeter().GasConsumed()) - res.GasWanted = int64(sdkCtx.GasMeter().Limit()) + res, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), sdkTx, req) + res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) + res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) return res, err } // DeliverTx implements tx.Handler.DeliverTx. -func (txh gasTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), tx, false) +func (txh gasTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, false) if err != nil { - return abci.ResponseDeliverTx{}, err + return tx.Response{}, err } - res, err := txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), tx, req) - res.GasUsed = int64(sdkCtx.GasMeter().GasConsumed()) - res.GasWanted = int64(sdkCtx.GasMeter().Limit()) + res, err := txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), sdkTx) + res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) + res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) return res, err } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh gasTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh gasTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, true) if err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - res, err := txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), sdkTx, req) - res.GasInfo = sdk.GasInfo{ - GasWanted: sdkCtx.GasMeter().Limit(), - GasUsed: sdkCtx.GasMeter().GasConsumed(), - } + res, err := txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), sdkTx) + res.GasWanted = sdkCtx.GasMeter().Limit() + res.GasUsed = sdkCtx.GasMeter().GasConsumed() return res, err } diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index 30534ad7e8ad..47c1d43553df 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -127,12 +127,12 @@ type noopTxHandler struct{} var _ tx.Handler = noopTxHandler{} -func (txh noopTxHandler) CheckTx(_ context.Context, _ sdk.Tx, _ abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - return abci.ResponseCheckTx{}, nil +func (txh noopTxHandler) CheckTx(_ context.Context, _ sdk.Tx, _ abci.RequestCheckTx) (tx.Response, error) { + return tx.Response{}, nil } -func (txh noopTxHandler) SimulateTx(_ context.Context, _ sdk.Tx, _ tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - return tx.ResponseSimulateTx{}, nil +func (txh noopTxHandler) SimulateTx(_ context.Context, _ sdk.Tx) (tx.Response, error) { + return tx.Response{}, nil } -func (txh noopTxHandler) DeliverTx(ctx context.Context, _ sdk.Tx, _ abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - return abci.ResponseDeliverTx{}, nil +func (txh noopTxHandler) DeliverTx(ctx context.Context, _ sdk.Tx) (tx.Response, error) { + return tx.Response{}, nil } diff --git a/x/auth/middleware/index_events.go b/x/auth/middleware/index_events.go index 30c7aea40158..e8f5911c6d0d 100644 --- a/x/auth/middleware/index_events.go +++ b/x/auth/middleware/index_events.go @@ -30,7 +30,7 @@ func NewIndexEventsTxMiddleware(indexEvents map[string]struct{}) tx.Middleware { var _ tx.Handler = indexEventsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh indexEventsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { +func (txh indexEventsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { res, err := txh.inner.CheckTx(ctx, tx, req) if err != nil { return res, err @@ -41,8 +41,8 @@ func (txh indexEventsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - res, err := txh.inner.DeliverTx(ctx, tx, req) +func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (tx.Response, error) { + res, err := txh.inner.DeliverTx(ctx, tx) if err != nil { return res, err } @@ -52,12 +52,12 @@ func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req ab } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh indexEventsTxHandler) SimulateTx(ctx context.Context, tx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - res, err := txh.inner.SimulateTx(ctx, tx, req) +func (txh indexEventsTxHandler) SimulateTx(ctx context.Context, tx sdk.Tx) (tx.Response, error) { + res, err := txh.inner.SimulateTx(ctx, tx) if err != nil { return res, err } - res.Result.Events = sdk.MarkEventsToIndex(res.Result.Events, txh.indexEvents) + res.Events = sdk.MarkEventsToIndex(res.Events, txh.indexEvents) return res, nil } diff --git a/x/auth/middleware/recovery.go b/x/auth/middleware/recovery.go index 42091c354171..df4c8762cfa6 100644 --- a/x/auth/middleware/recovery.go +++ b/x/auth/middleware/recovery.go @@ -26,7 +26,7 @@ func RecoveryTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = recoveryTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh recoveryTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (res abci.ResponseCheckTx, err error) { +func (txh recoveryTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // Panic recovery. defer func() { @@ -39,7 +39,7 @@ func (txh recoveryTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.Re } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh recoveryTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (res abci.ResponseDeliverTx, err error) { +func (txh recoveryTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // only run the tx if there is block gas remaining if sdkCtx.BlockGasMeter().IsOutOfGas() { @@ -71,11 +71,11 @@ func (txh recoveryTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci. } }() - return txh.next.DeliverTx(ctx, tx, req) + return txh.next.DeliverTx(ctx, tx) } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh recoveryTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (res tx.ResponseSimulateTx, err error) { +func (txh recoveryTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // Panic recovery. defer func() { @@ -84,7 +84,7 @@ func (txh recoveryTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req t } }() - return txh.next.SimulateTx(ctx, sdkTx, req) + return txh.next.SimulateTx(ctx, sdkTx) } func handleRecovery(r interface{}, sdkCtx sdk.Context) error { diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index e9073b59a9af..72257b7769f4 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -30,19 +30,19 @@ func NewRunMsgsTxHandler(msr *MsgServiceRouter, legacyRouter sdk.Router) tx.Hand var _ tx.Handler = runMsgsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh runMsgsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { +func (txh runMsgsTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { // Don't run Msgs during CheckTx. - return abci.ResponseCheckTx{}, nil + return tx.Response{}, nil } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), tx.GetMsgs(), req.Tx) +func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestDeliverTx) (tx.Response, error) { + res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), sdkTx.GetMsgs(), req.Tx) if err != nil { - return abci.ResponseDeliverTx{}, err + return tx.Response{}, err } - return abci.ResponseDeliverTx{ + return tx.Response{ // GasInfo will be populated by the Gas middleware. Log: res.Log, Data: res.Data, @@ -51,13 +51,13 @@ func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.R } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.Response, error) { res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), sdkTx.GetMsgs(), req.TxBytes) if err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return tx.ResponseSimulateTx{ + return tx.Response{ // GasInfo will be populated by the Gas middleware. Result: res, }, nil diff --git a/x/auth/middleware/sigverify.go b/x/auth/middleware/sigverify.go index 504b7a27de46..98e5ba8df3f2 100644 --- a/x/auth/middleware/sigverify.go +++ b/x/auth/middleware/sigverify.go @@ -126,28 +126,28 @@ func (spkm setPubKeyTxHandler) setPubKey(ctx context.Context, tx sdk.Tx, simulat } // CheckTx implements tx.Handler.CheckTx. -func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := spkm.setPubKey(ctx, tx, false); err != nil { - return abci.ResponseCheckTx{}, err +func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := spkm.setPubKey(ctx, sdkTx, false); err != nil { + return tx.Response{}, err } - return spkm.next.CheckTx(ctx, tx, req) + return spkm.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (spkm setPubKeyTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := spkm.setPubKey(ctx, tx, false); err != nil { - return abci.ResponseDeliverTx{}, err +func (spkm setPubKeyTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := spkm.setPubKey(ctx, sdkTx, false); err != nil { + return tx.Response{}, err } - return spkm.next.DeliverTx(ctx, tx, req) + return spkm.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (spkm setPubKeyTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (spkm setPubKeyTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := spkm.setPubKey(ctx, sdkTx, true); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return spkm.next.SimulateTx(ctx, sdkTx, req) + return spkm.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = validateSigCountTxHandler{} @@ -170,10 +170,10 @@ func ValidateSigCountMiddleware(ak AccountKeeper) tx.Middleware { } } -func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, tx sdk.Tx) error { +func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, sdkTx sdk.Tx) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - sigTx, ok := tx.(authsigning.SigVerifiableTx) + sigTx, ok := sdkTx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") } @@ -196,30 +196,30 @@ func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, tx sdk. } // CheckTx implements tx.Handler.CheckTx. -func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := vscd.checkSigCount(ctx, tx); err != nil { - return abci.ResponseCheckTx{}, err +func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := vscd.checkSigCount(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return vscd.next.CheckTx(ctx, tx, req) + return vscd.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (vscd validateSigCountTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (vscd validateSigCountTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := vscd.checkSigCount(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return vscd.next.SimulateTx(ctx, sdkTx, req) + return vscd.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (vscd validateSigCountTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := vscd.checkSigCount(ctx, tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (vscd validateSigCountTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := vscd.checkSigCount(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return vscd.next.DeliverTx(ctx, tx, req) + return vscd.next.SimulateTx(ctx, sdkTx) } // DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas @@ -359,30 +359,30 @@ func (sgcm sigGasConsumeTxHandler) sigGasConsume(ctx context.Context, tx sdk.Tx, } // CheckTx implements tx.Handler.CheckTx. -func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := sgcm.sigGasConsume(ctx, tx, false); err != nil { - return abci.ResponseCheckTx{}, err +func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := sgcm.sigGasConsume(ctx, sdkTx, false); err != nil { + return tx.Response{}, err } - return sgcm.next.CheckTx(ctx, tx, req) + return sgcm.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (sgcm sigGasConsumeTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := sgcm.sigGasConsume(ctx, tx, false); err != nil { - return abci.ResponseDeliverTx{}, err +func (sgcm sigGasConsumeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := sgcm.sigGasConsume(ctx, sdkTx, false); err != nil { + return tx.Response{}, err } - return sgcm.next.DeliverTx(ctx, tx, req) + return sgcm.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (sgcm sigGasConsumeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (sgcm sigGasConsumeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := sgcm.sigGasConsume(ctx, sdkTx, true); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return sgcm.next.SimulateTx(ctx, sdkTx, req) + return sgcm.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = sigVerificationTxHandler{} @@ -511,30 +511,30 @@ func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, tx sdk.Tx, is } // CheckTx implements tx.Handler.CheckTx. -func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := svd.sigVerify(ctx, tx, req.Type == abci.CheckTxType_Recheck, false); err != nil { - return abci.ResponseCheckTx{}, err +func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := svd.sigVerify(ctx, sdkTx, req.Type == abci.CheckTxType_Recheck, false); err != nil { + return tx.Response{}, err } - return svd.next.CheckTx(ctx, tx, req) + return svd.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (svd sigVerificationTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := svd.sigVerify(ctx, tx, false, false); err != nil { - return abci.ResponseDeliverTx{}, err +func (svd sigVerificationTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := svd.sigVerify(ctx, sdkTx, false, false); err != nil { + return tx.Response{}, err } - return svd.next.DeliverTx(ctx, tx, req) + return svd.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (svd sigVerificationTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (svd sigVerificationTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := svd.sigVerify(ctx, sdkTx, false, true); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return svd.next.SimulateTx(ctx, sdkTx, req) + return svd.next.SimulateTx(ctx, sdkTx) } var _ tx.Handler = incrementSequenceTxHandler{} @@ -583,30 +583,30 @@ func (isd incrementSequenceTxHandler) incrementSeq(ctx context.Context, tx sdk.T } // CheckTx implements tx.Handler.CheckTx. -func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - if err := isd.incrementSeq(ctx, tx); err != nil { - return abci.ResponseCheckTx{}, err +func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { + if err := isd.incrementSeq(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return isd.next.CheckTx(ctx, tx, req) + return isd.next.CheckTx(ctx, sdkTx, req) } // DeliverTx implements tx.Handler.DeliverTx. -func (isd incrementSequenceTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - if err := isd.incrementSeq(ctx, tx); err != nil { - return abci.ResponseDeliverTx{}, err +func (isd incrementSequenceTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { + if err := isd.incrementSeq(ctx, sdkTx); err != nil { + return tx.Response{}, err } - return isd.next.DeliverTx(ctx, tx, req) + return isd.next.DeliverTx(ctx, sdkTx) } // SimulateTx implements tx.Handler.SimulateTx. -func (isd incrementSequenceTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (isd incrementSequenceTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { if err := isd.incrementSeq(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return isd.next.SimulateTx(ctx, sdkTx, req) + return isd.next.SimulateTx(ctx, sdkTx) } // GetSignerAcc returns an account for a given address that is expected to sign From 58c09f24aefb0f3c5513a9a3a3c75fd4316b1f1f Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 15 Nov 2021 17:54:57 +0530 Subject: [PATCH 02/43] refactor `tx.Request` --- types/tx/middleware.go | 11 ++- x/auth/middleware/basic.go | 90 ++++++++++----------- x/auth/middleware/basic_test.go | 17 ++-- x/auth/middleware/ext.go | 18 ++--- x/auth/middleware/ext_test.go | 5 +- x/auth/middleware/fee.go | 32 ++++---- x/auth/middleware/fee_test.go | 15 ++-- x/auth/middleware/feegrant_test.go | 8 +- x/auth/middleware/gas.go | 18 ++--- x/auth/middleware/gas_test.go | 26 ++++--- x/auth/middleware/index_events.go | 12 +-- x/auth/middleware/middleware_test.go | 27 +++---- x/auth/middleware/recovery.go | 12 +-- x/auth/middleware/run_msgs.go | 17 ++-- x/auth/middleware/run_msgs_test.go | 9 +-- x/auth/middleware/sigverify.go | 112 +++++++++++++-------------- x/auth/middleware/sigverify_test.go | 16 ++-- x/auth/middleware/testutil_test.go | 5 +- 18 files changed, 229 insertions(+), 221 deletions(-) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index d8501f86cade..fd6088e1fe3a 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -30,12 +30,17 @@ type Response struct { Events []abci.Event } +type Request struct { + Tx sdk.Tx + TxBytes []byte +} + // TxHandler defines the baseapp's CheckTx, DeliverTx and Simulate respective // handlers. It is designed as a middleware stack. type Handler interface { - CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (Response, error) - DeliverTx(ctx context.Context, tx sdk.Tx) (Response, error) - SimulateTx(ctx context.Context, tx sdk.Tx) (Response, error) + CheckTx(ctx context.Context, req Request, checkReq abci.RequestCheckTx) (Response, error) + DeliverTx(ctx context.Context, req Request) (Response, error) + SimulateTx(ctx context.Context, req Request) (Response, error) } // TxMiddleware defines one layer of the TxHandler middleware stack. diff --git a/x/auth/middleware/basic.go b/x/auth/middleware/basic.go index 83b0c3c396c7..e44fd191bda6 100644 --- a/x/auth/middleware/basic.go +++ b/x/auth/middleware/basic.go @@ -49,47 +49,47 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh validateBasicTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { +func (txh validateBasicTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { // no need to validate basic on recheck tx, call next middleware - if req.Type == abci.CheckTxType_Recheck { - return txh.next.CheckTx(ctx, sdkTx, req) + if checkReq.Type == abci.CheckTxType_Recheck { + return txh.next.CheckTx(ctx, req, checkReq) } - if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { + if err := validateBasicTxMsgs(req.Tx.GetMsgs()); err != nil { return tx.Response{}, err } - if err := sdkTx.ValidateBasic(); err != nil { + if err := req.Tx.ValidateBasic(); err != nil { return tx.Response{}, err } - return txh.next.CheckTx(ctx, sdkTx, req) + return txh.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh validateBasicTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := sdkTx.ValidateBasic(); err != nil { +func (txh validateBasicTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := req.Tx.ValidateBasic(); err != nil { return tx.Response{}, err } - if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { + if err := validateBasicTxMsgs(req.Tx.GetMsgs()); err != nil { return tx.Response{}, err } - return txh.next.DeliverTx(ctx, sdkTx) + return txh.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh validateBasicTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := sdkTx.ValidateBasic(); err != nil { +func (txh validateBasicTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := req.Tx.ValidateBasic(); err != nil { return tx.Response{}, err } - if err := validateBasicTxMsgs(sdkTx.GetMsgs()); err != nil { + if err := validateBasicTxMsgs(req.Tx.GetMsgs()); err != nil { return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx) + return txh.next.SimulateTx(ctx, req) } var _ tx.Handler = txTimeoutHeightTxHandler{} @@ -124,30 +124,30 @@ func checkTimeout(ctx context.Context, tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := checkTimeout(ctx, sdkTx); err != nil { +func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := checkTimeout(ctx, req.Tx); err != nil { return tx.Response{}, err } - return txh.next.CheckTx(ctx, sdkTx, req) + return txh.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh txTimeoutHeightTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := checkTimeout(ctx, sdkTx); err != nil { +func (txh txTimeoutHeightTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := checkTimeout(ctx, req.Tx); err != nil { return tx.Response{}, err } - return txh.next.DeliverTx(ctx, sdkTx) + return txh.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh txTimeoutHeightTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := checkTimeout(ctx, sdkTx); err != nil { +func (txh txTimeoutHeightTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := checkTimeout(ctx, req.Tx); err != nil { return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx) + return txh.next.SimulateTx(ctx, req) } type validateMemoTxHandler struct { @@ -190,30 +190,30 @@ func (vmm validateMemoTxHandler) checkForValidMemo(ctx context.Context, tx sdk.T } // CheckTx implements tx.Handler.CheckTx method. -func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { +func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := vmm.checkForValidMemo(ctx, req.Tx); err != nil { return tx.Response{}, err } - return vmm.next.CheckTx(ctx, sdkTx, req) + return vmm.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx method. -func (vmm validateMemoTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { +func (vmm validateMemoTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := vmm.checkForValidMemo(ctx, req.Tx); err != nil { return tx.Response{}, err } - return vmm.next.DeliverTx(ctx, sdkTx) + return vmm.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx method. -func (vmm validateMemoTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := vmm.checkForValidMemo(ctx, sdkTx); err != nil { +func (vmm validateMemoTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := vmm.checkForValidMemo(ctx, req.Tx); err != nil { return tx.Response{}, err } - return vmm.next.SimulateTx(ctx, sdkTx) + return vmm.next.SimulateTx(ctx, req) } var _ tx.Handler = consumeTxSizeGasTxHandler{} @@ -304,34 +304,34 @@ func (cgts consumeTxSizeGasTxHandler) consumeTxSizeGas(ctx context.Context, _ sd } // CheckTx implements tx.Handler.CheckTx. -func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := cgts.consumeTxSizeGas(ctx, sdkTx, req.GetTx()); err != nil { +func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := cgts.consumeTxSizeGas(ctx, req.Tx, req.TxBytes); err != nil { return tx.Response{}, err } - return cgts.next.CheckTx(ctx, sdkTx, req) + return cgts.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (cgts consumeTxSizeGasTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestDeliverTx) (tx.Response, error) { - if err := cgts.consumeTxSizeGas(ctx, sdkTx, req.GetTx()); err != nil { - return abci.ResponseDeliverTx{}, err +func (cgts consumeTxSizeGasTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := cgts.consumeTxSizeGas(ctx, req.Tx, req.TxBytes); err != nil { + return tx.Response{}, err } - return cgts.next.DeliverTx(ctx, sdkTx, req) + return cgts.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (cgts consumeTxSizeGasTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - if err := cgts.consumeTxSizeGas(ctx, sdkTx, req.TxBytes); err != nil { - return tx.ResponseSimulateTx{}, err +func (cgts consumeTxSizeGasTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := cgts.consumeTxSizeGas(ctx, req.Tx, req.TxBytes); err != nil { + return tx.Response{}, err } - if err := cgts.simulateSigGasCost(ctx, sdkTx); err != nil { - return tx.ResponseSimulateTx{}, err + if err := cgts.simulateSigGasCost(ctx, req.Tx); err != nil { + return tx.Response{}, err } - return cgts.next.SimulateTx(ctx, sdkTx, req) + return cgts.next.SimulateTx(ctx, req) } // isIncompleteSignature tests whether SignatureData is fully filled in for simulation purposes diff --git a/x/auth/middleware/basic_test.go b/x/auth/middleware/basic_test.go index 8e1ad1db6a30..6e067306691a 100644 --- a/x/auth/middleware/basic_test.go +++ b/x/auth/middleware/basic_test.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/middleware" - "github.com/tendermint/tendermint/abci/types" ) func (s *MWTestSuite) TestValidateBasic() { @@ -34,21 +33,21 @@ func (s *MWTestSuite) TestValidateBasic() { invalidTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), invalidTx, types.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().NotNil(err, "Did not error on invalid tx") privs, accNums, accSeqs = []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} validTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), validTx, types.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) // test middleware skips on recheck ctx = ctx.WithIsReCheckTx(true) // middleware should skip processing invalidTx on recheck and thus return nil-error - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), invalidTx, types.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().Nil(err, "ValidateBasicMiddleware ran on ReCheck") } @@ -74,7 +73,7 @@ func (s *MWTestSuite) TestValidateMemo() { s.Require().NoError(err) // require that long memos get rejected - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), invalidTx, types.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().NotNil(err, "Did not error on tx with high memo") @@ -83,7 +82,7 @@ func (s *MWTestSuite) TestValidateMemo() { s.Require().NoError(err) // require small memos pass ValidateMemo middleware - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), validTx, types.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) } @@ -137,7 +136,7 @@ func (s *MWTestSuite) TestConsumeGasForTxSize() { expectedGas += afterGas - beforeGas beforeGas = ctx.GasMeter().GasConsumed() - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), testTx, types.RequestDeliverTx{Tx: txBytes}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().Nil(err, "ConsumeTxSizeGasMiddleware returned error: %v", err) @@ -162,7 +161,7 @@ func (s *MWTestSuite) TestConsumeGasForTxSize() { beforeSimGas := ctx.GasMeter().GasConsumed() // run txhandler in simulate mode - _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), testTx, tx.RequestSimulateTx{TxBytes: simTxBytes}) + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: simTxBytes}) consumedSimGas := ctx.GasMeter().GasConsumed() - beforeSimGas // require that txhandler passes and does not underestimate middleware cost @@ -215,7 +214,7 @@ func (s *MWTestSuite) TestTxHeightTimeoutMiddleware() { s.Require().NoError(err) ctx := ctx.WithBlockHeight(tc.height) - _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), testTx, tx.RequestSimulateTx{}) + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) s.Require().Equal(tc.expectErr, err != nil, err) }) } diff --git a/x/auth/middleware/ext.go b/x/auth/middleware/ext.go index db271fb5e3df..616e6b364b17 100644 --- a/x/auth/middleware/ext.go +++ b/x/auth/middleware/ext.go @@ -44,28 +44,28 @@ func checkExtOpts(tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := checkExtOpts(sdkTx); err != nil { +func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := checkExtOpts(req.Tx); err != nil { return tx.Response{}, err } - return txh.next.CheckTx(ctx, sdkTx, req) + return txh.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh rejectExtensionOptionsTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := checkExtOpts(sdkTx); err != nil { +func (txh rejectExtensionOptionsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := checkExtOpts(req.Tx); err != nil { return tx.Response{}, err } - return txh.next.DeliverTx(ctx, sdkTx) + return txh.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh rejectExtensionOptionsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := checkExtOpts(sdkTx); err != nil { +func (txh rejectExtensionOptionsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := checkExtOpts(req.Tx); err != nil { return tx.Response{}, err } - return txh.next.SimulateTx(ctx, sdkTx) + return txh.next.SimulateTx(ctx, req) } diff --git a/x/auth/middleware/ext_test.go b/x/auth/middleware/ext_test.go index a2fd323e3bb8..cac7003fcecd 100644 --- a/x/auth/middleware/ext_test.go +++ b/x/auth/middleware/ext_test.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + typestx "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/auth/tx" abci "github.com/tendermint/tendermint/abci/types" @@ -17,7 +18,7 @@ func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { // no extension options should not trigger an error theTx := txBuilder.GetTx() - _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), theTx, abci.RequestCheckTx{}) + _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, abci.RequestCheckTx{}) s.Require().NoError(err) extOptsTxBldr, ok := txBuilder.(tx.ExtensionOptionsTxBuilder) @@ -31,6 +32,6 @@ func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { s.Require().NoError(err) extOptsTxBldr.SetExtensionOptions(any) theTx = txBuilder.GetTx() - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), theTx, abci.RequestCheckTx{}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, abci.RequestCheckTx{}) s.Require().EqualError(err, "unknown extension options") } diff --git a/x/auth/middleware/fee.go b/x/auth/middleware/fee.go index d95bc8a89bc9..f4d0edcf7e9a 100644 --- a/x/auth/middleware/fee.go +++ b/x/auth/middleware/fee.go @@ -31,10 +31,10 @@ func MempoolFeeMiddleware(txh tx.Handler) tx.Handler { } // CheckTx implements tx.Handler.CheckTx. -func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { +func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - feeTx, ok := sdkTx.(sdk.FeeTx) + feeTx, ok := req.Tx.(sdk.FeeTx) if !ok { return tx.Response{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } @@ -62,17 +62,17 @@ func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req ab } } - return txh.next.CheckTx(ctx, sdkTx, req) + return txh.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (txh mempoolFeeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - return txh.next.DeliverTx(ctx, sdkTx) +func (txh mempoolFeeTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return txh.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (txh mempoolFeeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - return txh.next.SimulateTx(ctx, sdkTx) +func (txh mempoolFeeTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return txh.next.SimulateTx(ctx, req) } var _ tx.Handler = deductFeeTxHandler{} @@ -154,29 +154,29 @@ func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, sdkTx sdk.Tx) } // CheckTx implements tx.Handler.CheckTx. -func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { +func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := dfd.checkDeductFee(ctx, req.Tx); err != nil { return tx.Response{}, err } - return dfd.next.CheckTx(ctx, sdkTx, req) + return dfd.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (dfd deductFeeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { +func (dfd deductFeeTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := dfd.checkDeductFee(ctx, req.Tx); err != nil { return tx.Response{}, err } - return dfd.next.DeliverTx(ctx, sdkTx) + return dfd.next.DeliverTx(ctx, req) } -func (dfd deductFeeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := dfd.checkDeductFee(ctx, sdkTx); err != nil { +func (dfd deductFeeTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := dfd.checkDeductFee(ctx, req.Tx); err != nil { return tx.Response{}, err } - return dfd.next.SimulateTx(ctx, sdkTx) + return dfd.next.SimulateTx(ctx, req) } // DeductFees deducts fees from the given account. diff --git a/x/auth/middleware/fee_test.go b/x/auth/middleware/fee_test.go index 219d790d0d61..12ea74b01ff1 100644 --- a/x/auth/middleware/fee_test.go +++ b/x/auth/middleware/fee_test.go @@ -4,6 +4,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/bank/testutil" abci "github.com/tendermint/tendermint/abci/types" @@ -27,7 +28,7 @@ func (s *MWTestSuite) TestEnsureMempoolFees() { txBuilder.SetGasLimit(gasLimit) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) // Set high gas price so standard test fee fails @@ -36,18 +37,18 @@ func (s *MWTestSuite) TestEnsureMempoolFees() { ctx = ctx.WithMinGasPrices(highGasPrice) // txHandler errors with insufficient fees - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) s.Require().NotNil(err, "Middleware should have errored on too low fee for local gasPrice") // txHandler should not error since we do not check minGasPrice in DeliverTx - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) s.Require().Nil(err, "MempoolFeeMiddleware returned error in DeliverTx") atomPrice = sdk.NewDecCoinFromDec("atom", sdk.NewDec(0).Quo(sdk.NewDec(100000))) lowGasPrice := []sdk.DecCoin{atomPrice} ctx = ctx.WithMinGasPrices(lowGasPrice) - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) s.Require().Nil(err, "Middleware should not have errored on fee higher than local gasPrice") } @@ -75,7 +76,7 @@ func (s *MWTestSuite) TestDeductFees() { txBuilder.SetGasLimit(gasLimit) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) // Set account with insufficient funds @@ -85,7 +86,7 @@ func (s *MWTestSuite) TestDeductFees() { err = testutil.FundAccount(s.app.BankKeeper, ctx, addr1, coins) s.Require().NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) s.Require().NotNil(err, "Tx did not error when fee payer had insufficient funds") // Set account with sufficient funds @@ -93,7 +94,7 @@ func (s *MWTestSuite) TestDeductFees() { err = testutil.FundAccount(s.app.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(200)))) s.Require().NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) s.Require().Nil(err, "Tx errored after account has been set with sufficient funds") } diff --git a/x/auth/middleware/feegrant_test.go b/x/auth/middleware/feegrant_test.go index c76b3ec825e4..e9e1db2ced29 100644 --- a/x/auth/middleware/feegrant_test.go +++ b/x/auth/middleware/feegrant_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/client" @@ -15,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/middleware" authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -145,11 +145,11 @@ func (s *MWTestSuite) TestDeductFeesNoDelegation() { accNums, seqs = []uint64{acc.GetAccountNumber()}, []uint64{acc.GetSequence()} } - tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, helpers.DefaultGenTxGas, ctx.ChainID(), accNums, seqs, tc.feeAccount, privs...) + testTx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, helpers.DefaultGenTxGas, ctx.ChainID(), accNums, seqs, tc.feeAccount, privs...) s.Require().NoError(err) // tests only feegrant middleware - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), txtypes.Request{Tx: testTx}) if tc.valid { s.Require().NoError(err) } else { @@ -157,7 +157,7 @@ func (s *MWTestSuite) TestDeductFeesNoDelegation() { } // tests while stack - _, err = s.txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{}) + _, err = s.txHandler.DeliverTx(sdk.WrapSDKContext(ctx), txtypes.Request{Tx: testTx}) if tc.valid { s.Require().NoError(err) } else { diff --git a/x/auth/middleware/gas.go b/x/auth/middleware/gas.go index 16944ca524de..867c1eb954e8 100644 --- a/x/auth/middleware/gas.go +++ b/x/auth/middleware/gas.go @@ -30,13 +30,13 @@ func GasTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = gasTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (txh gasTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, false) +func (txh gasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), req.Tx, false) if err != nil { return tx.Response{}, err } - res, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), sdkTx, req) + res, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) @@ -44,13 +44,13 @@ func (txh gasTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.Requ } // DeliverTx implements tx.Handler.DeliverTx. -func (txh gasTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, false) +func (txh gasTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), req.Tx, false) if err != nil { return tx.Response{}, err } - res, err := txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), sdkTx) + res, err := txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), req) res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) @@ -58,13 +58,13 @@ func (txh gasTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Respons } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh gasTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), sdkTx, true) +func (txh gasTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), req.Tx, true) if err != nil { return tx.Response{}, err } - res, err := txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), sdkTx) + res, err := txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), req) res.GasWanted = sdkCtx.GasMeter().Limit() res.GasUsed = sdkCtx.GasMeter().GasConsumed() diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index 47c1d43553df..dde359928e8a 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -51,7 +51,7 @@ func (s *MWTestSuite) setupGasTx() (signing.Tx, []byte, sdk.Context, uint64) { } func (s *MWTestSuite) TestSetup() { - tx, _, ctx, gasLimit := s.setupGasTx() + testTx, _, ctx, gasLimit := s.setupGasTx() txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.GasTxMiddleware) testcases := []struct { @@ -62,11 +62,11 @@ func (s *MWTestSuite) TestSetup() { errorStr string }{ {"not a gas tx", txTest{}, 0, true, "Tx must be GasTx: tx parse error"}, - {"tx with its own gas limit", tx, gasLimit, false, ""}, + {"tx with its own gas limit", testTx, gasLimit, false, ""}, } for _, tc := range testcases { s.Run(tc.name, func() { - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tc.tx, abci.RequestCheckTx{}) + res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) if tc.expErr { s.Require().EqualError(err, tc.errorStr) } else { @@ -78,15 +78,17 @@ func (s *MWTestSuite) TestSetup() { } func (s *MWTestSuite) TestRecoverPanic() { - tx, txBytes, ctx, gasLimit := s.setupGasTx() + testTx, txBytes, ctx, gasLimit := s.setupGasTx() txHandler := middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware) - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{Tx: txBytes}) + res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes}) s.Require().Error(err, "Did not return error on OutOfGas panic") s.Require().True(errors.Is(sdkerrors.ErrOutOfGas, err), "Returned error is not an out of gas error") s.Require().Equal(gasLimit, uint64(res.GasWanted)) txHandler = middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware) - s.Require().Panics(func() { txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{Tx: txBytes}) }, "Recovered from non-Out-of-Gas panic") + s.Require().Panics(func() { + txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes}) + }, "Recovered from non-Out-of-Gas panic") } // outOfGasTxHandler is a test middleware that will throw OutOfGas panic. @@ -94,7 +96,7 @@ type outOfGasTxHandler struct{} var _ tx.Handler = outOfGasTxHandler{} -func (txh outOfGasTxHandler) DeliverTx(ctx context.Context, _ sdk.Tx, _ abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { +func (txh outOfGasTxHandler) DeliverTx(ctx context.Context, _ tx.Request) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) overLimit := sdkCtx.GasMeter().Limit() + 1 @@ -103,7 +105,7 @@ func (txh outOfGasTxHandler) DeliverTx(ctx context.Context, _ sdk.Tx, _ abci.Req panic("not reached") } -func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ sdk.Tx, _ abci.RequestCheckTx) (abci.ResponseCheckTx, error) { +func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ tx.Request, _ abci.RequestCheckTx) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) overLimit := sdkCtx.GasMeter().Limit() + 1 @@ -112,7 +114,7 @@ func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ sdk.Tx, _ abci.Reque panic("not reached") } -func (txh outOfGasTxHandler) SimulateTx(ctx context.Context, _ sdk.Tx, _ tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { +func (txh outOfGasTxHandler) SimulateTx(ctx context.Context, _ tx.Request) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) overLimit := sdkCtx.GasMeter().Limit() + 1 @@ -127,12 +129,12 @@ type noopTxHandler struct{} var _ tx.Handler = noopTxHandler{} -func (txh noopTxHandler) CheckTx(_ context.Context, _ sdk.Tx, _ abci.RequestCheckTx) (tx.Response, error) { +func (txh noopTxHandler) CheckTx(_ context.Context, _ tx.Request, _ abci.RequestCheckTx) (tx.Response, error) { return tx.Response{}, nil } -func (txh noopTxHandler) SimulateTx(_ context.Context, _ sdk.Tx) (tx.Response, error) { +func (txh noopTxHandler) SimulateTx(_ context.Context, _ tx.Request) (tx.Response, error) { return tx.Response{}, nil } -func (txh noopTxHandler) DeliverTx(ctx context.Context, _ sdk.Tx) (tx.Response, error) { +func (txh noopTxHandler) DeliverTx(ctx context.Context, _ tx.Request) (tx.Response, error) { return tx.Response{}, nil } diff --git a/x/auth/middleware/index_events.go b/x/auth/middleware/index_events.go index e8f5911c6d0d..ca4e20720357 100644 --- a/x/auth/middleware/index_events.go +++ b/x/auth/middleware/index_events.go @@ -30,8 +30,8 @@ func NewIndexEventsTxMiddleware(indexEvents map[string]struct{}) tx.Middleware { var _ tx.Handler = indexEventsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh indexEventsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - res, err := txh.inner.CheckTx(ctx, tx, req) +func (txh indexEventsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + res, err := txh.inner.CheckTx(ctx, req, checkReq) if err != nil { return res, err } @@ -41,8 +41,8 @@ func (txh indexEventsTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (tx.Response, error) { - res, err := txh.inner.DeliverTx(ctx, tx) +func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.inner.DeliverTx(ctx, req) if err != nil { return res, err } @@ -52,8 +52,8 @@ func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (tx.Re } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh indexEventsTxHandler) SimulateTx(ctx context.Context, tx sdk.Tx) (tx.Response, error) { - res, err := txh.inner.SimulateTx(ctx, tx) +func (txh indexEventsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.inner.SimulateTx(ctx, req) if err != nil { return res, err } diff --git a/x/auth/middleware/middleware_test.go b/x/auth/middleware/middleware_test.go index e3b04983b6f5..69872c20baf4 100644 --- a/x/auth/middleware/middleware_test.go +++ b/x/auth/middleware/middleware_test.go @@ -14,6 +14,7 @@ import ( "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" "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -851,14 +852,14 @@ func (s *MWTestSuite) TestTxHandlerSetPubKey() { txBuilder.SetGasLimit(gasLimit) // Manually create tx, and remove signature. - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - txBuilder, err := s.clientCtx.TxConfig.WrapTxBuilder(tx) + txBuilder, err := s.clientCtx.TxConfig.WrapTxBuilder(testTx) s.Require().NoError(err) s.Require().NoError(txBuilder.SetSignatures()) // Run txHandler manually, expect ErrNoSignatures. - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), txBuilder.GetTx(), abci.RequestCheckTx{}) + _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, abci.RequestCheckTx{}) s.Require().Error(err) s.Require().True(errors.Is(err, sdkerrors.ErrNoSignatures)) @@ -1057,9 +1058,9 @@ func (s *MWTestSuite) TestCustomSignatureVerificationGasConsumer() { s.Run(fmt.Sprintf("Case %s", tc.desc), func() { tc.malleate() - tx, txBytes, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, txBytes, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, abci.RequestDeliverTx{Tx: txBytes}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().Error(err) s.Require().True(errors.Is(err, tc.expErr)) }) @@ -1088,21 +1089,21 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { // test that operations skipped on recheck do not run privs, accNums, accSeqs := []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) // make signature array empty which would normally cause ValidateBasicMiddleware and SigVerificationMiddleware fail // since these middlewares don't run on recheck, the tx should pass the middleware - txBuilder, err = s.clientCtx.TxConfig.WrapTxBuilder(tx) + txBuilder, err = s.clientCtx.TxConfig.WrapTxBuilder(testTx) s.Require().NoError(err) s.Require().NoError(txBuilder.SetSignatures()) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), txBuilder.GetTx(), abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) s.Require().Nil(err, "TxHandler errored on recheck unexpectedly: %v", err) - tx, _, err = s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err = s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - txBytes, err := json.Marshal(tx) + txBytes, err := json.Marshal(testTx) s.Require().Nil(err, "Error marshalling tx: %v", err) ctx = ctx.WithTxBytes(txBytes) @@ -1120,7 +1121,7 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { // set testcase parameters s.app.AccountKeeper.SetParams(ctx, tc.params) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{Tx: txBytes, Type: abci.CheckTxType_Recheck}) + _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes, Type: abci.CheckTxType_Recheck}) s.Require().NotNil(err, "tx does not fail on recheck with updated params in test case: %s", tc.name) @@ -1134,7 +1135,7 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { Denom: "dnecoin", // fee does not have this denom Amount: sdk.NewDec(5), }}) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) s.Require().NotNil(err, "txhandler on recheck did not fail when mingasPrice was changed") // reset min gasprice @@ -1146,6 +1147,6 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { err = s.app.BankKeeper.SendCoinsFromAccountToModule(ctx, accounts[0].acc.GetAddress(), minttypes.ModuleName, balances) s.Require().NoError(err) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) s.Require().NotNil(err, "txhandler on recheck did not fail once feePayer no longer has sufficient funds") } diff --git a/x/auth/middleware/recovery.go b/x/auth/middleware/recovery.go index df4c8762cfa6..0a0f89c7a890 100644 --- a/x/auth/middleware/recovery.go +++ b/x/auth/middleware/recovery.go @@ -26,7 +26,7 @@ func RecoveryTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = recoveryTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh recoveryTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (res tx.Response, err error) { +func (txh recoveryTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // Panic recovery. defer func() { @@ -35,11 +35,11 @@ func (txh recoveryTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.Re } }() - return txh.next.CheckTx(ctx, tx, req) + return txh.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh recoveryTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (res tx.Response, err error) { +func (txh recoveryTxHandler) DeliverTx(ctx context.Context, req tx.Request) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // only run the tx if there is block gas remaining if sdkCtx.BlockGasMeter().IsOutOfGas() { @@ -71,11 +71,11 @@ func (txh recoveryTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx) (res tx.R } }() - return txh.next.DeliverTx(ctx, tx) + return txh.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh recoveryTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (res tx.Response, err error) { +func (txh recoveryTxHandler) SimulateTx(ctx context.Context, req tx.Request) (res tx.Response, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // Panic recovery. defer func() { @@ -84,7 +84,7 @@ func (txh recoveryTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (res } }() - return txh.next.SimulateTx(ctx, sdkTx) + return txh.next.SimulateTx(ctx, req) } func handleRecovery(r interface{}, sdkCtx sdk.Context) error { diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 72257b7769f4..770c89d44654 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -30,36 +30,37 @@ func NewRunMsgsTxHandler(msr *MsgServiceRouter, legacyRouter sdk.Router) tx.Hand var _ tx.Handler = runMsgsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh runMsgsTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { +func (txh runMsgsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { // Don't run Msgs during CheckTx. return tx.Response{}, nil } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestDeliverTx) (tx.Response, error) { - res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), sdkTx.GetMsgs(), req.Tx) +func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) if err != nil { return tx.Response{}, err } return tx.Response{ // GasInfo will be populated by the Gas middleware. - Log: res.Log, - Data: res.Data, + Log: res.Log, + MsgResponses: res.Data, + // Data: res.Data, Events: res.Events, }, nil } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.Response, error) { - res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), sdkTx.GetMsgs(), req.TxBytes) +func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) if err != nil { return tx.Response{}, err } return tx.Response{ // GasInfo will be populated by the Gas middleware. - Result: res, + MsgResponses: res, }, nil } diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 909de101d46d..0179fe96e2be 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -1,11 +1,10 @@ package middleware_test import ( - "github.com/tendermint/tendermint/abci/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" ) @@ -20,12 +19,12 @@ func (s *MWTestSuite) TestRunMsgs() { txBuilder := s.clientCtx.TxConfig.NewTxBuilder() txBuilder.SetMsgs(&testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}}) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) - txBytes, err := s.clientCtx.TxConfig.TxEncoder()(tx) + txBytes, err := s.clientCtx.TxConfig.TxEncoder()(testTx) s.Require().NoError(err) - res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, types.RequestDeliverTx{Tx: txBytes}) + res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) s.Require().NotEmpty(res.Data) var txMsgData sdk.TxMsgData diff --git a/x/auth/middleware/sigverify.go b/x/auth/middleware/sigverify.go index 98e5ba8df3f2..f74a6006dddd 100644 --- a/x/auth/middleware/sigverify.go +++ b/x/auth/middleware/sigverify.go @@ -52,9 +52,9 @@ func SetPubKeyMiddleware(ak AccountKeeper) tx.Middleware { } } -func (spkm setPubKeyTxHandler) setPubKey(ctx context.Context, tx sdk.Tx, simulate bool) error { +func (spkm setPubKeyTxHandler) setPubKey(ctx context.Context, req tx.Request, simulate bool) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - sigTx, ok := tx.(authsigning.SigVerifiableTx) + sigTx, ok := req.Tx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } @@ -126,28 +126,28 @@ func (spkm setPubKeyTxHandler) setPubKey(ctx context.Context, tx sdk.Tx, simulat } // CheckTx implements tx.Handler.CheckTx. -func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := spkm.setPubKey(ctx, sdkTx, false); err != nil { +func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := spkm.setPubKey(ctx, req, false); err != nil { return tx.Response{}, err } - return spkm.next.CheckTx(ctx, sdkTx, req) + return spkm.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (spkm setPubKeyTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := spkm.setPubKey(ctx, sdkTx, false); err != nil { +func (spkm setPubKeyTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := spkm.setPubKey(ctx, req, false); err != nil { return tx.Response{}, err } - return spkm.next.DeliverTx(ctx, sdkTx) + return spkm.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (spkm setPubKeyTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := spkm.setPubKey(ctx, sdkTx, true); err != nil { +func (spkm setPubKeyTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := spkm.setPubKey(ctx, req, true); err != nil { return tx.Response{}, err } - return spkm.next.SimulateTx(ctx, sdkTx) + return spkm.next.SimulateTx(ctx, req) } var _ tx.Handler = validateSigCountTxHandler{} @@ -170,10 +170,10 @@ func ValidateSigCountMiddleware(ak AccountKeeper) tx.Middleware { } } -func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, sdkTx sdk.Tx) error { +func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, req tx.Request) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - sigTx, ok := sdkTx.(authsigning.SigVerifiableTx) + sigTx, ok := req.Tx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") } @@ -196,30 +196,30 @@ func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, sdkTx s } // CheckTx implements tx.Handler.CheckTx. -func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := vscd.checkSigCount(ctx, sdkTx); err != nil { +func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := vscd.checkSigCount(ctx, req); err != nil { return tx.Response{}, err } - return vscd.next.CheckTx(ctx, sdkTx, req) + return vscd.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (vscd validateSigCountTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := vscd.checkSigCount(ctx, sdkTx); err != nil { +func (vscd validateSigCountTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := vscd.checkSigCount(ctx, req); err != nil { return tx.Response{}, err } - return vscd.next.DeliverTx(ctx, sdkTx) + return vscd.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (vscd validateSigCountTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := vscd.checkSigCount(ctx, sdkTx); err != nil { +func (vscd validateSigCountTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := vscd.checkSigCount(ctx, req); err != nil { return tx.Response{}, err } - return vscd.next.SimulateTx(ctx, sdkTx) + return vscd.next.SimulateTx(ctx, req) } // DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas @@ -308,10 +308,10 @@ func SigGasConsumeMiddleware(ak AccountKeeper, sigGasConsumer SignatureVerificat } } -func (sgcm sigGasConsumeTxHandler) sigGasConsume(ctx context.Context, tx sdk.Tx, simulate bool) error { +func (sgcm sigGasConsumeTxHandler) sigGasConsume(ctx context.Context, req tx.Request, simulate bool) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - sigTx, ok := tx.(authsigning.SigVerifiableTx) + sigTx, ok := req.Tx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -359,30 +359,30 @@ func (sgcm sigGasConsumeTxHandler) sigGasConsume(ctx context.Context, tx sdk.Tx, } // CheckTx implements tx.Handler.CheckTx. -func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := sgcm.sigGasConsume(ctx, sdkTx, false); err != nil { +func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := sgcm.sigGasConsume(ctx, req, false); err != nil { return tx.Response{}, err } - return sgcm.next.CheckTx(ctx, sdkTx, req) + return sgcm.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (sgcm sigGasConsumeTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := sgcm.sigGasConsume(ctx, sdkTx, false); err != nil { +func (sgcm sigGasConsumeTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := sgcm.sigGasConsume(ctx, req, false); err != nil { return tx.Response{}, err } - return sgcm.next.DeliverTx(ctx, sdkTx) + return sgcm.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (sgcm sigGasConsumeTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := sgcm.sigGasConsume(ctx, sdkTx, true); err != nil { +func (sgcm sigGasConsumeTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := sgcm.sigGasConsume(ctx, req, true); err != nil { return tx.Response{}, err } - return sgcm.next.SimulateTx(ctx, sdkTx) + return sgcm.next.SimulateTx(ctx, req) } var _ tx.Handler = sigVerificationTxHandler{} @@ -429,13 +429,13 @@ func OnlyLegacyAminoSigners(sigData signing.SignatureData) bool { } } -func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, tx sdk.Tx, isReCheckTx, simulate bool) error { +func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, req tx.Request, isReCheckTx, simulate bool) error { sdkCtx := sdk.UnwrapSDKContext(ctx) // no need to verify signatures on recheck tx if isReCheckTx { return nil } - sigTx, ok := tx.(authsigning.SigVerifiableTx) + sigTx, ok := req.Tx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -491,7 +491,7 @@ func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, tx sdk.Tx, is } if !simulate { - err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, tx) + err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, req.Tx) if err != nil { var errMsg string if OnlyLegacyAminoSigners(sig.Data) { @@ -511,30 +511,30 @@ func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, tx sdk.Tx, is } // CheckTx implements tx.Handler.CheckTx. -func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := svd.sigVerify(ctx, sdkTx, req.Type == abci.CheckTxType_Recheck, false); err != nil { +func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := svd.sigVerify(ctx, req, checkReq.Type == abci.CheckTxType_Recheck, false); err != nil { return tx.Response{}, err } - return svd.next.CheckTx(ctx, sdkTx, req) + return svd.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (svd sigVerificationTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := svd.sigVerify(ctx, sdkTx, false, false); err != nil { +func (svd sigVerificationTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := svd.sigVerify(ctx, req, false, false); err != nil { return tx.Response{}, err } - return svd.next.DeliverTx(ctx, sdkTx) + return svd.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (svd sigVerificationTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := svd.sigVerify(ctx, sdkTx, false, true); err != nil { +func (svd sigVerificationTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := svd.sigVerify(ctx, req, false, true); err != nil { return tx.Response{}, err } - return svd.next.SimulateTx(ctx, sdkTx) + return svd.next.SimulateTx(ctx, req) } var _ tx.Handler = incrementSequenceTxHandler{} @@ -562,9 +562,9 @@ func IncrementSequenceMiddleware(ak AccountKeeper) tx.Middleware { } } -func (isd incrementSequenceTxHandler) incrementSeq(ctx context.Context, tx sdk.Tx) error { +func (isd incrementSequenceTxHandler) incrementSeq(ctx context.Context, req tx.Request) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - sigTx, ok := tx.(authsigning.SigVerifiableTx) + sigTx, ok := req.Tx.(authsigning.SigVerifiableTx) if !ok { return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -583,30 +583,30 @@ func (isd incrementSequenceTxHandler) incrementSeq(ctx context.Context, tx sdk.T } // CheckTx implements tx.Handler.CheckTx. -func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (tx.Response, error) { - if err := isd.incrementSeq(ctx, sdkTx); err != nil { +func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + if err := isd.incrementSeq(ctx, req); err != nil { return tx.Response{}, err } - return isd.next.CheckTx(ctx, sdkTx, req) + return isd.next.CheckTx(ctx, req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx. -func (isd incrementSequenceTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := isd.incrementSeq(ctx, sdkTx); err != nil { +func (isd incrementSequenceTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := isd.incrementSeq(ctx, req); err != nil { return tx.Response{}, err } - return isd.next.DeliverTx(ctx, sdkTx) + return isd.next.DeliverTx(ctx, req) } // SimulateTx implements tx.Handler.SimulateTx. -func (isd incrementSequenceTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx) (tx.Response, error) { - if err := isd.incrementSeq(ctx, sdkTx); err != nil { +func (isd incrementSequenceTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + if err := isd.incrementSeq(ctx, req); err != nil { return tx.Response{}, err } - return isd.next.SimulateTx(ctx, sdkTx) + return isd.next.SimulateTx(ctx, req) } // GetSignerAcc returns an account for a given address that is expected to sign diff --git a/x/auth/middleware/sigverify_test.go b/x/auth/middleware/sigverify_test.go index 59c46938f619..69e19919d685 100644 --- a/x/auth/middleware/sigverify_test.go +++ b/x/auth/middleware/sigverify_test.go @@ -55,7 +55,7 @@ func (s *MWTestSuite) TestSetPubKey() { testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) require.NoError(err) - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) require.NoError(err) // Require that all accounts have pubkey set after middleware runs @@ -183,9 +183,9 @@ func (s *MWTestSuite) TestSigVerification() { s.Require().NoError(err) if tc.recheck { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) } else { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestCheckTx{}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) } if tc.shouldErr { s.Require().NotNil(err, "TestCase %d: %s did not error as expected", i, tc.name) @@ -278,9 +278,9 @@ func (s *MWTestSuite) TestSigVerification_ExplicitAmino() { s.Require().NoError(err) if tc.recheck { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) } else { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestCheckTx{}) + _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) } if tc.shouldErr { s.Require().NotNil(err, "TestCase %d: %s did not error as expected", i, tc.name) @@ -353,7 +353,7 @@ func (s *MWTestSuite) runSigMiddlewares(params types.Params, _ bool, privs ...cr // Determine gas consumption of txhandler with default params before := ctx.GasMeter().GasConsumed() - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), testTx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) after := ctx.GasMeter().GasConsumed() return after - before, err @@ -401,9 +401,9 @@ func (s *MWTestSuite) TestIncrementSequenceMiddleware() { for i, tc := range testCases { var err error if tc.simulate { - _, err = txHandler.SimulateTx(sdk.WrapSDKContext(tc.ctx), testTx, tx.RequestSimulateTx{}) + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(tc.ctx), tx.Request{Tx: testTx}) } else { - _, err = txHandler.DeliverTx(sdk.WrapSDKContext(tc.ctx), testTx, abci.RequestDeliverTx{}) + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(tc.ctx), tx.Request{Tx: testTx}) } s.Require().NoError(err, "unexpected error; tc #%d, %v", i, tc) diff --git a/x/auth/middleware/testutil_test.go b/x/auth/middleware/testutil_test.go index 4f174f6e69f2..64415d4a0fc7 100644 --- a/x/auth/middleware/testutil_test.go +++ b/x/auth/middleware/testutil_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/client" @@ -176,8 +175,8 @@ func (s *MWTestSuite) runTestCase(ctx sdk.Context, txBuilder client.TxBuilder, p // Theoretically speaking, middleware unit tests should only test // middlewares, but here we sometimes also test the tx creation // process. - tx, _, txErr := s.createTestTx(txBuilder, privs, accNums, accSeqs, chainID) - newCtx, txHandlerErr := s.txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx, types.RequestDeliverTx{}) + testTx, _, txErr := s.createTestTx(txBuilder, privs, accNums, accSeqs, chainID) + newCtx, txHandlerErr := s.txHandler.DeliverTx(sdk.WrapSDKContext(ctx), txtypes.Request{Tx: testTx}) if tc.expPass { s.Require().NoError(txErr) From f766aef056bc0a5751aaee709946243a638ad453 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:56:47 +0100 Subject: [PATCH 03/43] Add MsgResponses any in sdk.Result --- docs/core/proto-docs.md | 10 +- proto/cosmos/base/abci/v1beta1/abci.proto | 18 +- types/abci.pb.go | 253 +++++++++++++++++----- types/result.go | 14 +- x/auth/middleware/run_msgs.go | 24 +- 5 files changed, 244 insertions(+), 75 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index d38a3d306a54..c0a635797f7f 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1453,9 +1453,12 @@ Result is the union of ResponseFormat and ResponseCheckTx. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `data` | [bytes](#bytes) | | Data is any data returned from message or handler execution. It MUST be length prefixed in order to separate data from multiple message executions. | +| `data` | [bytes](#bytes) | | **Deprecated.** Data is any data returned from message or handler execution. It MUST be length prefixed in order to separate data from multiple message executions. Deprecated. This field is still populated, but prefer msg_response instead because it also contains the Msg response typeURL. | | `log` | [string](#string) | | Log contains the log information from message or handler execution. | | `events` | [tendermint.abci.Event](#tendermint.abci.Event) | repeated | Events contains a slice of Event objects that were emitted during message or handler execution. | +| `msg_responses` | [google.protobuf.Any](#google.protobuf.Any) | repeated | msg_responses contains the Msg handler responses type packed in Anys. + +Since: cosmos-sdk 0.45 | @@ -1525,7 +1528,10 @@ for each message. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `data` | [MsgData](#cosmos.base.abci.v1beta1.MsgData) | repeated | | +| `data` | [MsgData](#cosmos.base.abci.v1beta1.MsgData) | repeated | **Deprecated.** | +| `msg_responses` | [google.protobuf.Any](#google.protobuf.Any) | repeated | msg_responses contains the Msg handler responses type packed in Anys. + +Since: cosmos-sdk 0.45 | diff --git a/proto/cosmos/base/abci/v1beta1/abci.proto b/proto/cosmos/base/abci/v1beta1/abci.proto index 8bfeaf8e1dcb..10c0b2a1d74b 100644 --- a/proto/cosmos/base/abci/v1beta1/abci.proto +++ b/proto/cosmos/base/abci/v1beta1/abci.proto @@ -84,7 +84,9 @@ message Result { // Data is any data returned from message or handler execution. It MUST be // length prefixed in order to separate data from multiple message executions. - bytes data = 1; + // Deprecated. This field is still populated, but prefer msg_response instead + // because it also contains the Msg response typeURL. + bytes data = 1 [deprecated = true]; // Log contains the log information from message or handler execution. string log = 2; @@ -92,6 +94,11 @@ message Result { // Events contains a slice of Event objects that were emitted during message // or handler execution. repeated tendermint.abci.Event events = 3 [(gogoproto.nullable) = false]; + + // msg_responses contains the Msg handler responses type packed in Anys. + // + // Since: cosmos-sdk 0.45 + repeated google.protobuf.Any msg_responses = 4; } // SimulationResponse defines the response generated when a transaction is @@ -104,6 +111,7 @@ message SimulationResponse { // MsgData defines the data returned in a Result object during message // execution. message MsgData { + option deprecated = true; option (gogoproto.stringer) = true; string msg_type = 1; @@ -115,7 +123,13 @@ message MsgData { message TxMsgData { option (gogoproto.stringer) = true; - repeated MsgData data = 1; + // data field is deprecated and not populated. + repeated MsgData data = 1 [deprecated = true]; + + // msg_responses contains the Msg handler responses type packed in Anys. + // + // Since: cosmos-sdk 0.45 + repeated google.protobuf.Any msg_responses = 2; } // SearchTxsResult defines a structure for querying txs pageable diff --git a/types/abci.pb.go b/types/abci.pb.go index 04174b97e412..083d66a509c6 100644 --- a/types/abci.pb.go +++ b/types/abci.pb.go @@ -317,12 +317,18 @@ func (m *GasInfo) GetGasUsed() uint64 { type Result struct { // Data is any data returned from message or handler execution. It MUST be // length prefixed in order to separate data from multiple message executions. - Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + // Deprecated. This field is still populated, but prefer msg_response instead + // because it also contains the Msg response typeURL. + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // Deprecated: Do not use. // Log contains the log information from message or handler execution. Log string `protobuf:"bytes,2,opt,name=log,proto3" json:"log,omitempty"` // Events contains a slice of Event objects that were emitted during message // or handler execution. Events []types1.Event `protobuf:"bytes,3,rep,name=events,proto3" json:"events"` + // msg_responses contains the Msg handler responses type packed in Anys. + // + // Since: cosmos-sdk 0.45 + MsgResponses []*types.Any `protobuf:"bytes,4,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` } func (m *Result) Reset() { *m = Result{} } @@ -405,6 +411,8 @@ func (m *SimulationResponse) GetResult() *Result { // MsgData defines the data returned in a Result object during message // execution. +// +// Deprecated: Do not use. type MsgData struct { MsgType string `protobuf:"bytes,1,opt,name=msg_type,json=msgType,proto3" json:"msg_type,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` @@ -459,7 +467,11 @@ func (m *MsgData) GetData() []byte { // TxMsgData defines a list of MsgData. A transaction will have a MsgData object // for each message. type TxMsgData struct { - Data []*MsgData `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` + Data []*MsgData `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` // Deprecated: Do not use. + // msg_responses contains the Msg handler responses type packed in Anys. + // + // Since: cosmos-sdk 0.45 + MsgResponses []*types.Any `protobuf:"bytes,2,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` } func (m *TxMsgData) Reset() { *m = TxMsgData{} } @@ -494,6 +506,7 @@ func (m *TxMsgData) XXX_DiscardUnknown() { var xxx_messageInfo_TxMsgData proto.InternalMessageInfo +// Deprecated: Do not use. func (m *TxMsgData) GetData() []*MsgData { if m != nil { return m.Data @@ -501,6 +514,13 @@ func (m *TxMsgData) GetData() []*MsgData { return nil } +func (m *TxMsgData) GetMsgResponses() []*types.Any { + if m != nil { + return m.MsgResponses + } + return nil +} + // SearchTxsResult defines a structure for querying txs pageable type SearchTxsResult struct { // Count of all txs @@ -609,62 +629,65 @@ func init() { } var fileDescriptor_4e37629bc7eb0df8 = []byte{ - // 874 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x95, 0xbd, 0x6f, 0xdb, 0x46, - 0x14, 0xc0, 0x45, 0x89, 0xa1, 0xcc, 0x27, 0x27, 0x2e, 0x0e, 0x46, 0x42, 0x27, 0xad, 0xa4, 0x2a, - 0x29, 0xa0, 0x25, 0x54, 0xe3, 0xb4, 0x45, 0x91, 0xa1, 0x68, 0xe8, 0x7e, 0xc4, 0x40, 0xd2, 0xe1, - 0xac, 0xa0, 0x40, 0x17, 0xe1, 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a7, 0x71, 0x12, 0x6b, 0x7c, 0xf3, - 0x5c, 0x6a, 0x15, 0xf2, 0x05, 0xd4, 0x74, 0xa1, 0x02, 0x0f, 0x71, 0xdc, 0xdb, 0x8c, 0x63, 0xf5, - 0x52, 0x53, 0x73, 0xc0, 0x02, 0x89, 0xbe, 0x7e, 0xf3, 0x5f, 0xb3, 0xf2, 0xfa, 0xbc, 0xe9, 0x9c, - 0x9d, 0x37, 0x9d, 0x7f, 0xcf, 0x9b, 0xce, 0xef, 0x17, 0xcd, 0xca, 0xd9, 0x45, 0xb3, 0xf2, 0xe6, - 0xa2, 0x59, 0xf9, 0xa9, 0x23, 0x62, 0x3d, 0xc9, 0x87, 0xe1, 0x48, 0x26, 0xbd, 0xf2, 0xcb, 0x63, - 0x7f, 0xee, 0xab, 0xf1, 0x4b, 0xfb, 0x99, 0x18, 0x7a, 0xf8, 0x44, 0x3d, 0xfc, 0x3f, 0x00, 0x00, - 0xff, 0xff, 0x84, 0x62, 0x26, 0x5f, 0x9b, 0x06, 0x00, 0x00, + // 917 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x95, 0xbf, 0x6f, 0x1b, 0x37, + 0x14, 0xc7, 0x75, 0xd2, 0xe5, 0x64, 0x3d, 0x29, 0x71, 0x41, 0x18, 0x0e, 0x9d, 0xb4, 0x92, 0x7a, + 0x49, 0x01, 0x2d, 0x39, 0x35, 0x4e, 0x51, 0x34, 0x9e, 0x92, 0x73, 0x7f, 0x19, 0x48, 0x3a, 0xd0, + 0x0a, 0x0a, 0x74, 0x11, 0x28, 0x89, 0xa1, 0x0e, 0xd1, 0x1d, 0x85, 0x23, 0xcf, 0x3e, 0x6f, 0xdd, + 0xda, 0xa9, 0xe8, 0x94, 0xa1, 0x53, 0xd7, 0xf6, 0x2f, 0xc9, 0xe8, 0x31, 0x43, 0xa1, 0xb6, 0xf6, + 0x96, 0xbf, 0xa2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xe3, 0x1b, 0x6f, 0x16, 0x9d, 0x95, 0x28, 0x69, + 0x68, 0x7b, 0xa0, 0x4d, 0xbd, 0xec, 0x2c, 0x49, 0x13, 0x65, 0x5e, 0x5d, 0x9f, 0x58, 0x07, 0x7d, + 0x0a, 0x35, 0x55, 0x4a, 0x1c, 0x18, 0x12, 0x77, 0xd7, 0xd3, 0xbc, 0xfc, 0x57, 0x10, 0x3d, 0xc1, + 0x02, 0x89, 0x1f, 0xbd, 0xfe, 0xbb, 0x5d, 0x79, 0x75, 0xd6, 0xf6, 0x4e, 0xcf, 0xda, 0xde, 0x5f, + 0x67, 0x6d, 0xef, 0xe7, 0xf3, 0x76, 0xe5, 0xf4, 0xbc, 0x5d, 0x79, 0x7d, 0xde, 0xae, 0x7c, 0x17, + 0xf2, 0x44, 0x4d, 0x8b, 0x51, 0x34, 0x16, 0x69, 0xdf, 0xfd, 0xfb, 0xec, 0xe7, 0x9e, 0x9c, 0xbc, + 0xb0, 0x3f, 0xaa, 0x51, 0x60, 0xa0, 0x3f, 0xf8, 0x27, 0x00, 0x00, 0xff, 0xff, 0x04, 0xb9, 0x0f, + 0x96, 0x1d, 0x07, 0x00, 0x00, } func (m *TxResponse) Marshal() (dAtA []byte, err error) { @@ -961,6 +984,20 @@ func (m *Result) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MsgResponses) > 0 { + for iNdEx := len(m.MsgResponses) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MsgResponses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAbci(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } if len(m.Events) > 0 { for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { { @@ -1094,6 +1131,20 @@ func (m *TxMsgData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MsgResponses) > 0 { + for iNdEx := len(m.MsgResponses) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MsgResponses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAbci(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } if len(m.Data) > 0 { for iNdEx := len(m.Data) - 1; iNdEx >= 0; iNdEx-- { { @@ -1332,6 +1383,12 @@ func (m *Result) Size() (n int) { n += 1 + l + sovAbci(uint64(l)) } } + if len(m.MsgResponses) > 0 { + for _, e := range m.MsgResponses { + l = e.Size() + n += 1 + l + sovAbci(uint64(l)) + } + } return n } @@ -1379,6 +1436,12 @@ func (m *TxMsgData) Size() (n int) { n += 1 + l + sovAbci(uint64(l)) } } + if len(m.MsgResponses) > 0 { + for _, e := range m.MsgResponses { + l = e.Size() + n += 1 + l + sovAbci(uint64(l)) + } + } return n } @@ -1471,8 +1534,14 @@ func (this *TxMsgData) String() string { repeatedStringForData += strings.Replace(f.String(), "MsgData", "MsgData", 1) + "," } repeatedStringForData += "}" + repeatedStringForMsgResponses := "[]*Any{" + for _, f := range this.MsgResponses { + repeatedStringForMsgResponses += strings.Replace(fmt.Sprintf("%v", f), "Any", "types.Any", 1) + "," + } + repeatedStringForMsgResponses += "}" s := strings.Join([]string{`&TxMsgData{`, `Data:` + repeatedStringForData + `,`, + `MsgResponses:` + repeatedStringForMsgResponses + `,`, `}`, }, "") return s @@ -2475,6 +2544,40 @@ func (m *Result) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgResponses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAbci + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAbci + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAbci + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgResponses = append(m.MsgResponses, &types.Any{}) + if err := m.MsgResponses[len(m.MsgResponses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAbci(dAtA[iNdEx:]) @@ -2794,6 +2897,40 @@ func (m *TxMsgData) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgResponses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAbci + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAbci + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAbci + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgResponses = append(m.MsgResponses, &types.Any{}) + if err := m.MsgResponses[len(m.MsgResponses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAbci(dAtA[iNdEx:]) diff --git a/types/result.go b/types/result.go index 42ed79c534e6..aa0752026e95 100644 --- a/types/result.go +++ b/types/result.go @@ -8,11 +8,9 @@ import ( "strings" "github.com/gogo/protobuf/proto" - - "sigs.k8s.io/yaml" - abci "github.com/tendermint/tendermint/abci/types" ctypes "github.com/tendermint/tendermint/rpc/core/types" + "sigs.k8s.io/yaml" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -275,6 +273,11 @@ func WrapServiceResult(ctx Context, res proto.Message, err error) (*Result, erro return nil, err } + any, err := codectypes.NewAnyWithValue(res) + if err != nil { + return nil, err + } + var data []byte if res != nil { data, err = proto.Marshal(res) @@ -289,7 +292,8 @@ func WrapServiceResult(ctx Context, res proto.Message, err error) (*Result, erro } return &Result{ - Data: data, - Events: events, + Data: data, + Events: events, + MsgResponses: []*codectypes.Any{any}, }, nil } diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 770c89d44654..4a6bd9115c0a 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -9,6 +9,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" @@ -80,9 +81,7 @@ func (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes // Result if any single message fails or does not have a registered Handler. msgLogs := make(sdk.ABCIMessageLogs, 0, len(msgs)) events := sdkCtx.EventManager().Events() - txMsgData := &sdk.TxMsgData{ - Data: make([]*sdk.MsgData, 0, len(msgs)), - } + msgResponses := make([]*codectypes.Any, len(msgs)) // NOTE: GasWanted is determined by the Gas TxHandler and GasUsed by the GasMeter. for i, msg := range msgs { @@ -129,20 +128,29 @@ func (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes // separate each result. events = events.AppendEvents(msgEvents) - txMsgData.Data = append(txMsgData.Data, &sdk.MsgData{MsgType: sdk.MsgTypeURL(msg), Data: msgResult.Data}) + // Each individual sdk.Result has exactly one Msg response. We aggregate here. + msgResponse := msgResult.MsgResponses[0] + if msgResponse == nil { + return nil, sdkerrors.ErrLogic.Wrapf("got nil Msg response at index %d", i) + } + msgResponses[i] = msgResponse msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint32(i), msgResult.Log, msgEvents)) } msCache.Write() - data, err := proto.Marshal(txMsgData) + // The data we send back to tendermint is the proto-marshalled bytes of TxMsgData. + data, err := proto.Marshal(&sdk.TxMsgData{ + MsgResponses: msgResponses, + }) if err != nil { return nil, sdkerrors.Wrap(err, "failed to marshal tx data") } return &sdk.Result{ - Data: data, - Log: strings.TrimSpace(msgLogs.String()), - Events: events.ToABCIEvents(), + Data: data, + Log: strings.TrimSpace(msgLogs.String()), + Events: events.ToABCIEvents(), + MsgResponses: msgResponses, }, nil } From c5e516b139c5d2fbbaca40184767e1274c68603e Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 17 Nov 2021 17:18:28 +0530 Subject: [PATCH 04/43] add helper functions in abci --- baseapp/abci.go | 44 ++++++++++++++++++++++++++----- baseapp/custom_txhandler_test.go | 24 ++++++++--------- baseapp/test_helpers.go | 45 ++++++++++++++++++++++++-------- types/tx/middleware.go | 2 +- x/auth/middleware/run_msgs.go | 7 +++-- 5 files changed, 87 insertions(+), 35 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index a5b142b51571..27628031a4d9 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" ) // InitChain implements the ABCI interface. It runs the initialization logic @@ -255,17 +256,18 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type)) } - tx, err := app.txDecoder(req.Tx) + reqTx, err := app.txDecoder(req.Tx) if err != nil { return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace) } ctx := app.getContextForTx(mode, req.Tx) - res, err := app.txHandler.CheckTx(ctx, tx, req) + checkTxRes, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx}, req) if err != nil { - return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + return sdkerrors.ResponseCheckTx(err, uint64(checkTxRes.GasUsed), uint64(checkTxRes.GasWanted), app.trace) } + res := convertTxResponseToCheckTx(checkTxRes) return res } @@ -285,20 +287,20 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx } } }() - tx, err := app.txDecoder(req.Tx) + reqTx, err := app.txDecoder(req.Tx) if err != nil { res = sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace) return res } ctx := app.getContextForTx(runTxModeDeliver, req.Tx) - res, err = app.txHandler.DeliverTx(ctx, tx, req) + delTxRes, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}) if err != nil { - res = sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + res = sdkerrors.ResponseDeliverTx(err, uint64(delTxRes.GasUsed), uint64(delTxRes.GasWanted), app.trace) return res } - return res + return convertTxResponseToDeliverTx(delTxRes) } // Commit implements the ABCI interface. It will commit all state that exists in @@ -900,3 +902,31 @@ func splitPath(requestPath string) (path []string) { return path } + +func convertTxResponseToCheckTx(txRes tx.Response) abci.ResponseCheckTx { + txMsgData := &sdk.TxMsgData{MsgResponses: txRes.MsgResponses} + data, err := proto.Marshal(txMsgData) + if err != nil { + panic(fmt.Sprintf("error while converting tx response to check tx: %s", err.Error())) + } + res := abci.ResponseCheckTx{ + Data: data, + Log: txRes.Log, + Events: txRes.Events, + } + return res +} + +func convertTxResponseToDeliverTx(txRes tx.Response) abci.ResponseDeliverTx { + txMsgData := &sdk.TxMsgData{MsgResponses: txRes.MsgResponses} + data, err := proto.Marshal(txMsgData) + if err != nil { + panic(fmt.Sprintf("error while converting tx response to deliver tx: %s", err.Error())) + } + res := abci.ResponseDeliverTx{ + Data: data, + Log: txRes.Log, + Events: txRes.Events, + } + return res +} diff --git a/baseapp/custom_txhandler_test.go b/baseapp/custom_txhandler_test.go index 6582dda66184..55b664533a4f 100644 --- a/baseapp/custom_txhandler_test.go +++ b/baseapp/custom_txhandler_test.go @@ -31,33 +31,33 @@ func CustomTxHandlerMiddleware(handler handlerFun) tx.Middleware { } // CheckTx implements tx.Handler.CheckTx method. -func (txh customTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - sdkCtx, err := txh.runHandler(ctx, tx, req.Tx, false) +func (txh customTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { + sdkCtx, err := txh.runHandler(ctx, req.Tx, req.TxBytes, false) if err != nil { - return abci.ResponseCheckTx{}, err + return tx.Response{}, err } - return txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), tx, req) + return txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) } // DeliverTx implements tx.Handler.DeliverTx method. -func (txh customTxHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - sdkCtx, err := txh.runHandler(ctx, tx, req.Tx, false) +func (txh customTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + sdkCtx, err := txh.runHandler(ctx, req.Tx, req.TxBytes, false) if err != nil { - return abci.ResponseDeliverTx{}, err + return tx.Response{}, err } - return txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), tx, req) + return txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), req) } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh customTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - sdkCtx, err := txh.runHandler(ctx, sdkTx, req.TxBytes, true) +func (txh customTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + sdkCtx, err := txh.runHandler(ctx, req.Tx, req.TxBytes, true) if err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - return txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), sdkTx, req) + return txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), req) } func (txh customTxHandler) runHandler(ctx context.Context, tx sdk.Tx, txBytes []byte, isSimulate bool) (sdk.Context, error) { diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 64924523493e..e0b863eb0e5a 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -1,6 +1,7 @@ package baseapp import ( + "github.com/golang/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -10,23 +11,29 @@ import ( ) // SimCheck defines a CheckTx helper function that used in tests and simulations. -func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { // CheckTx expects tx bytes as argument, so we encode the tx argument into // bytes. Note that CheckTx will actually decode those bytes again. But since // this helper is only used in tests/simulation, it's fine. - bz, err := txEncoder(tx) + bz, err := txEncoder(sdkTx) if err != nil { return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } ctx := app.getContextForTx(runTxModeDeliver, bz) - res, err := app.txHandler.CheckTx(ctx, tx, abci.RequestCheckTx{Tx: bz, Type: abci.CheckTxType_New}) + res, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: sdkTx}, abci.RequestCheckTx{Tx: bz, Type: abci.CheckTxType_New}) gInfo := sdk.GasInfo{GasWanted: uint64(res.GasWanted), GasUsed: uint64(res.GasUsed)} if err != nil { return gInfo, nil, err } - return gInfo, &sdk.Result{Data: res.Data, Log: res.Log, Events: res.Events}, nil + txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} + data, err := proto.Marshal(txMsgData) + if err != nil { + return gInfo, nil, err + } + + return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil } // Simulate executes a tx in simulate mode to get result and gas info. @@ -37,31 +44,47 @@ func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { } ctx := app.getContextForTx(runTxModeSimulate, txBytes) - res, err := app.txHandler.SimulateTx(ctx, sdkTx, tx.RequestSimulateTx{TxBytes: txBytes}) + res, err := app.txHandler.SimulateTx(ctx, tx.Request{Tx: sdkTx, TxBytes: txBytes}) + gasInfo := sdk.GasInfo{ + GasWanted: res.GasWanted, + GasUsed: res.GasUsed, + } + if err != nil { + return gasInfo, nil, err + } + + txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} + data, err := proto.Marshal(txMsgData) if err != nil { - return res.GasInfo, nil, err + return gasInfo, nil, err } - return res.GasInfo, res.Result, nil + return gasInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil } // SimDeliver defines a DeliverTx helper function that used in tests and // simulations. -func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { // See comment for Check(). - bz, err := txEncoder(tx) + bz, err := txEncoder(sdkTx) if err != nil { return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } ctx := app.getContextForTx(runTxModeDeliver, bz) - res, err := app.txHandler.DeliverTx(ctx, tx, abci.RequestDeliverTx{Tx: bz}) + res, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: sdkTx, TxBytes: bz}) gInfo := sdk.GasInfo{GasWanted: uint64(res.GasWanted), GasUsed: uint64(res.GasUsed)} if err != nil { return gInfo, nil, err } - return gInfo, &sdk.Result{Data: res.Data, Log: res.Log, Events: res.Events}, nil + txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} + data, err := proto.Marshal(txMsgData) + if err != nil { + return gInfo, nil, err + } + + return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil } // Context with current {check, deliver}State of the app used by tests. diff --git a/types/tx/middleware.go b/types/tx/middleware.go index fd6088e1fe3a..6f7de28dc023 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -25,7 +25,7 @@ type ResponseSimulateTx struct { type Response struct { GasWanted uint64 GasUsed uint64 - MsgResponses []codectypes.Any // Represents each Msg service handler's response type. Will get proto-serialized into the `Data` field in ABCI, see note #2 + MsgResponses []*codectypes.Any // Represents each Msg service handler's response type. Will get proto-serialized into the `Data` field in ABCI, see note #2 Log string Events []abci.Event } diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 4a6bd9115c0a..61c6b9eb72c5 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -46,9 +46,8 @@ func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.R return tx.Response{ // GasInfo will be populated by the Gas middleware. Log: res.Log, - MsgResponses: res.Data, - // Data: res.Data, - Events: res.Events, + MsgResponses: res.MsgResponses, + Events: res.Events, }, nil } @@ -61,7 +60,7 @@ func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx. return tx.Response{ // GasInfo will be populated by the Gas middleware. - MsgResponses: res, + MsgResponses: res.MsgResponses, }, nil } From 306c1fcb8295b54ec4f2ab26e3c79fb4ccd7e45c Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 18 Nov 2021 15:58:32 +0530 Subject: [PATCH 05/43] refactor tips --- x/auth/middleware/tips.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/x/auth/middleware/tips.go b/x/auth/middleware/tips.go index bcef9e62e0cd..dfc912ba61ec 100644 --- a/x/auth/middleware/tips.go +++ b/x/auth/middleware/tips.go @@ -26,57 +26,57 @@ func NewTipMiddleware(bankKeeper types.BankKeeper) tx.Middleware { var _ tx.Handler = tipsTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (txh tipsTxHandler) CheckTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - res, err := txh.next.CheckTx(ctx, sdkTx, req) +func (txh tipsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkTx abci.RequestCheckTx) (tx.Response, error) { + res, err := txh.next.CheckTx(ctx, req, checkTx) if err != nil { - return abci.ResponseCheckTx{}, err + return tx.Response{}, err } - tipTx, ok := sdkTx.(tx.TipTx) + tipTx, ok := req.Tx.(tx.TipTx) if !ok || tipTx.GetTip() == nil { return res, err } if err := txh.transferTip(ctx, tipTx); err != nil { - return abci.ResponseCheckTx{}, err + return tx.Response{}, err } return res, err } // DeliverTx implements tx.Handler.DeliverTx. -func (txh tipsTxHandler) DeliverTx(ctx context.Context, sdkTx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - res, err := txh.next.DeliverTx(ctx, sdkTx, req) +func (txh tipsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.next.DeliverTx(ctx, req) if err != nil { - return abci.ResponseDeliverTx{}, err + return tx.Response{}, err } - tipTx, ok := sdkTx.(tx.TipTx) + tipTx, ok := req.Tx.(tx.TipTx) if !ok || tipTx.GetTip() == nil { return res, err } if err := txh.transferTip(ctx, tipTx); err != nil { - return abci.ResponseDeliverTx{}, err + return tx.Response{}, err } return res, err } // SimulateTx implements tx.Handler.SimulateTx method. -func (txh tipsTxHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - res, err := txh.next.SimulateTx(ctx, sdkTx, req) +func (txh tipsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + res, err := txh.next.SimulateTx(ctx, req) if err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } - tipTx, ok := sdkTx.(tx.TipTx) + tipTx, ok := req.Tx.(tx.TipTx) if !ok || tipTx.GetTip() == nil { return res, err } if err := txh.transferTip(ctx, tipTx); err != nil { - return tx.ResponseSimulateTx{}, err + return tx.Response{}, err } return res, err From caf2e398dbec74b7fcabe212d4653f06f7939377 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 23 Nov 2021 12:58:10 +0530 Subject: [PATCH 06/43] review changes --- baseapp/abci.go | 8 +++----- baseapp/test_helpers.go | 2 +- types/tx/middleware.go | 10 +++++++++- x/auth/middleware/basic.go | 18 +++++++++--------- x/auth/middleware/ext.go | 6 ++---- x/auth/middleware/ext_test.go | 5 ++--- x/auth/middleware/fee.go | 11 +++++------ x/auth/middleware/fee_test.go | 5 ++--- x/auth/middleware/gas.go | 10 ++++------ x/auth/middleware/gas_test.go | 14 ++++++-------- x/auth/middleware/index_events.go | 10 ++++------ x/auth/middleware/middleware_test.go | 10 +++++----- x/auth/middleware/recovery.go | 4 +--- x/auth/middleware/run_msgs.go | 5 ++--- x/auth/middleware/run_msgs_test.go | 2 +- x/auth/middleware/sigverify.go | 20 ++++++++++---------- x/auth/middleware/sigverify_test.go | 8 ++++---- x/auth/middleware/tips.go | 14 ++++++-------- 18 files changed, 76 insertions(+), 86 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index ef09ca4d17bf..e0b5fd49822d 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -256,13 +256,11 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { } ctx := app.getContextForTx(mode, req.Tx) - checkTxRes, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx}, req) + res, _, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx}, tx.RequestCheckTx{Type: req.Type}) if err != nil { - return sdkerrors.ResponseCheckTx(err, uint64(checkTxRes.GasUsed), uint64(checkTxRes.GasWanted), app.trace) + return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) } - - res := convertTxResponseToCheckTx(checkTxRes) - return res + return convertTxResponseToCheckTx(res) } // DeliverTx implements the ABCI interface and executes a tx in DeliverTx mode. diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index e0b863eb0e5a..72272975983e 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -21,7 +21,7 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasInfo } ctx := app.getContextForTx(runTxModeDeliver, bz) - res, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: sdkTx}, abci.RequestCheckTx{Tx: bz, Type: abci.CheckTxType_New}) + res, _, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: sdkTx, TxBytes: bz}, tx.RequestCheckTx{Type: abci.CheckTxType_New}) gInfo := sdk.GasInfo{GasWanted: uint64(res.GasWanted), GasUsed: uint64(res.GasUsed)} if err != nil { return gInfo, nil, err diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 6f7de28dc023..ccc1a67cec6c 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -35,10 +35,18 @@ type Request struct { TxBytes []byte } +type ResponseCheckTx struct { + priority uint64 +} + +type RequestCheckTx struct { + Type abci.CheckTxType +} + // TxHandler defines the baseapp's CheckTx, DeliverTx and Simulate respective // handlers. It is designed as a middleware stack. type Handler interface { - CheckTx(ctx context.Context, req Request, checkReq abci.RequestCheckTx) (Response, error) + CheckTx(ctx context.Context, req Request, checkReq RequestCheckTx) (Response, ResponseCheckTx, error) DeliverTx(ctx context.Context, req Request) (Response, error) SimulateTx(ctx context.Context, req Request) (Response, error) } diff --git a/x/auth/middleware/basic.go b/x/auth/middleware/basic.go index e8c9afdc535c..429c9a39537f 100644 --- a/x/auth/middleware/basic.go +++ b/x/auth/middleware/basic.go @@ -49,18 +49,18 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh validateBasicTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh validateBasicTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { // no need to validate basic on recheck tx, call next middleware if checkReq.Type == abci.CheckTxType_Recheck { return txh.next.CheckTx(ctx, req, checkReq) } if err := validateBasicTxMsgs(req.Tx.GetMsgs()); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } if err := req.Tx.ValidateBasic(); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return txh.next.CheckTx(ctx, req, checkReq) @@ -124,9 +124,9 @@ func checkTimeout(ctx context.Context, tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh txTimeoutHeightTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := checkTimeout(ctx, req.Tx); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return txh.next.CheckTx(ctx, req, checkReq) @@ -190,9 +190,9 @@ func (vmm validateMemoTxHandler) checkForValidMemo(ctx context.Context, tx sdk.T } // CheckTx implements tx.Handler.CheckTx method. -func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (vmm validateMemoTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := vmm.checkForValidMemo(ctx, req.Tx); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return vmm.next.CheckTx(ctx, req, checkReq) @@ -305,9 +305,9 @@ func (cgts consumeTxSizeGasTxHandler) consumeTxSizeGas(ctx context.Context, _ sd } // CheckTx implements tx.Handler.CheckTx. -func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (cgts consumeTxSizeGasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := cgts.consumeTxSizeGas(ctx, req.Tx, req.TxBytes); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return cgts.next.CheckTx(ctx, req, checkReq) diff --git a/x/auth/middleware/ext.go b/x/auth/middleware/ext.go index 616e6b364b17..783c3bbc476b 100644 --- a/x/auth/middleware/ext.go +++ b/x/auth/middleware/ext.go @@ -3,8 +3,6 @@ package middleware import ( "context" - abci "github.com/tendermint/tendermint/abci/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -44,9 +42,9 @@ func checkExtOpts(tx sdk.Tx) error { } // CheckTx implements tx.Handler.CheckTx. -func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh rejectExtensionOptionsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := checkExtOpts(req.Tx); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return txh.next.CheckTx(ctx, req, checkReq) diff --git a/x/auth/middleware/ext_test.go b/x/auth/middleware/ext_test.go index cac7003fcecd..db2714536463 100644 --- a/x/auth/middleware/ext_test.go +++ b/x/auth/middleware/ext_test.go @@ -7,7 +7,6 @@ import ( typestx "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/auth/tx" - abci "github.com/tendermint/tendermint/abci/types" ) func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { @@ -18,7 +17,7 @@ func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { // no extension options should not trigger an error theTx := txBuilder.GetTx() - _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, abci.RequestCheckTx{}) + _, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, typestx.RequestCheckTx{}) s.Require().NoError(err) extOptsTxBldr, ok := txBuilder.(tx.ExtensionOptionsTxBuilder) @@ -32,6 +31,6 @@ func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { s.Require().NoError(err) extOptsTxBldr.SetExtensionOptions(any) theTx = txBuilder.GetTx() - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, abci.RequestCheckTx{}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, typestx.RequestCheckTx{}) s.Require().EqualError(err, "unknown extension options") } diff --git a/x/auth/middleware/fee.go b/x/auth/middleware/fee.go index f4d0edcf7e9a..a5c4d153e48a 100644 --- a/x/auth/middleware/fee.go +++ b/x/auth/middleware/fee.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/types" - abci "github.com/tendermint/tendermint/abci/types" ) var _ tx.Handler = mempoolFeeTxHandler{} @@ -31,12 +30,12 @@ func MempoolFeeMiddleware(txh tx.Handler) tx.Handler { } // CheckTx implements tx.Handler.CheckTx. -func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) feeTx, ok := req.Tx.(sdk.FeeTx) if !ok { - return tx.Response{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } feeCoins := feeTx.GetFee() @@ -58,7 +57,7 @@ func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, chec } if !feeCoins.IsAnyGTE(requiredFees) { - return tx.Response{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) + return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) } } @@ -154,9 +153,9 @@ func (dfd deductFeeTxHandler) checkDeductFee(ctx context.Context, sdkTx sdk.Tx) } // CheckTx implements tx.Handler.CheckTx. -func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (dfd deductFeeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := dfd.checkDeductFee(ctx, req.Tx); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return dfd.next.CheckTx(ctx, req, checkReq) diff --git a/x/auth/middleware/fee_test.go b/x/auth/middleware/fee_test.go index 12ea74b01ff1..3a60558e0da0 100644 --- a/x/auth/middleware/fee_test.go +++ b/x/auth/middleware/fee_test.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/bank/testutil" - abci "github.com/tendermint/tendermint/abci/types" ) func (s *MWTestSuite) TestEnsureMempoolFees() { @@ -37,7 +36,7 @@ func (s *MWTestSuite) TestEnsureMempoolFees() { ctx = ctx.WithMinGasPrices(highGasPrice) // txHandler errors with insufficient fees - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) s.Require().NotNil(err, "Middleware should have errored on too low fee for local gasPrice") // txHandler should not error since we do not check minGasPrice in DeliverTx @@ -48,7 +47,7 @@ func (s *MWTestSuite) TestEnsureMempoolFees() { lowGasPrice := []sdk.DecCoin{atomPrice} ctx = ctx.WithMinGasPrices(lowGasPrice) - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) s.Require().Nil(err, "Middleware should not have errored on fee higher than local gasPrice") } diff --git a/x/auth/middleware/gas.go b/x/auth/middleware/gas.go index 867c1eb954e8..604aa612abfa 100644 --- a/x/auth/middleware/gas.go +++ b/x/auth/middleware/gas.go @@ -3,8 +3,6 @@ package middleware import ( "context" - abci "github.com/tendermint/tendermint/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" @@ -30,17 +28,17 @@ func GasTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = gasTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (txh gasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh gasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { sdkCtx, err := gasContext(sdk.UnwrapSDKContext(ctx), req.Tx, false) if err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } - res, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) + res, resCheckTx, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) - return res, err + return res, resCheckTx, err } // DeliverTx implements tx.Handler.DeliverTx. diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index dde359928e8a..121072552533 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -4,8 +4,6 @@ import ( "context" "errors" - abci "github.com/tendermint/tendermint/abci/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -66,7 +64,7 @@ func (s *MWTestSuite) TestSetup() { } for _, tc := range testcases { s.Run(tc.name, func() { - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) if tc.expErr { s.Require().EqualError(err, tc.errorStr) } else { @@ -80,14 +78,14 @@ func (s *MWTestSuite) TestSetup() { func (s *MWTestSuite) TestRecoverPanic() { testTx, txBytes, ctx, gasLimit := s.setupGasTx() txHandler := middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware) - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes}) + res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}, tx.RequestCheckTx{}) s.Require().Error(err, "Did not return error on OutOfGas panic") s.Require().True(errors.Is(sdkerrors.ErrOutOfGas, err), "Returned error is not an out of gas error") s.Require().Equal(gasLimit, uint64(res.GasWanted)) txHandler = middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware) s.Require().Panics(func() { - txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes}) + txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}, tx.RequestCheckTx{}) }, "Recovered from non-Out-of-Gas panic") } @@ -105,7 +103,7 @@ func (txh outOfGasTxHandler) DeliverTx(ctx context.Context, _ tx.Request) (tx.Re panic("not reached") } -func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ tx.Request, _ abci.RequestCheckTx) (tx.Response, error) { +func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ tx.Request, _ tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) overLimit := sdkCtx.GasMeter().Limit() + 1 @@ -129,8 +127,8 @@ type noopTxHandler struct{} var _ tx.Handler = noopTxHandler{} -func (txh noopTxHandler) CheckTx(_ context.Context, _ tx.Request, _ abci.RequestCheckTx) (tx.Response, error) { - return tx.Response{}, nil +func (txh noopTxHandler) CheckTx(_ context.Context, _ tx.Request, _ tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + return tx.Response{}, tx.ResponseCheckTx{}, nil } func (txh noopTxHandler) SimulateTx(_ context.Context, _ tx.Request) (tx.Response, error) { return tx.Response{}, nil diff --git a/x/auth/middleware/index_events.go b/x/auth/middleware/index_events.go index ca4e20720357..9a55db3947c4 100644 --- a/x/auth/middleware/index_events.go +++ b/x/auth/middleware/index_events.go @@ -3,8 +3,6 @@ package middleware import ( "context" - abci "github.com/tendermint/tendermint/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" ) @@ -30,14 +28,14 @@ func NewIndexEventsTxMiddleware(indexEvents map[string]struct{}) tx.Middleware { var _ tx.Handler = indexEventsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh indexEventsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { - res, err := txh.inner.CheckTx(ctx, req, checkReq) +func (txh indexEventsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + res, resCheckTx, err := txh.inner.CheckTx(ctx, req, checkReq) if err != nil { - return res, err + return res, tx.ResponseCheckTx{}, err } res.Events = sdk.MarkEventsToIndex(res.Events, txh.indexEvents) - return res, nil + return res, resCheckTx, nil } // DeliverTx implements tx.Handler.DeliverTx method. diff --git a/x/auth/middleware/middleware_test.go b/x/auth/middleware/middleware_test.go index acfd09a2b36e..417ac8e7fcaa 100644 --- a/x/auth/middleware/middleware_test.go +++ b/x/auth/middleware/middleware_test.go @@ -861,7 +861,7 @@ func (s *MWTestSuite) TestTxHandlerSetPubKey() { s.Require().NoError(txBuilder.SetSignatures()) // Run txHandler manually, expect ErrNoSignatures. - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, abci.RequestCheckTx{}) + _, _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, tx.RequestCheckTx{}) s.Require().Error(err) s.Require().True(errors.Is(err, sdkerrors.ErrNoSignatures)) @@ -1100,7 +1100,7 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { s.Require().NoError(err) s.Require().NoError(txBuilder.SetSignatures()) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: txBuilder.GetTx()}, tx.RequestCheckTx{Type: abci.CheckTxType_Recheck}) s.Require().Nil(err, "TxHandler errored on recheck unexpectedly: %v", err) testTx, _, err = s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) @@ -1123,7 +1123,7 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { // set testcase parameters s.app.AccountKeeper.SetParams(ctx, tc.params) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Tx: txBytes, Type: abci.CheckTxType_Recheck}) + _, _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}, tx.RequestCheckTx{Type: abci.CheckTxType_Recheck}) s.Require().NotNil(err, "tx does not fail on recheck with updated params in test case: %s", tc.name) @@ -1137,7 +1137,7 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { Denom: "dnecoin", // fee does not have this denom Amount: sdk.NewDec(5), }}) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) s.Require().NotNil(err, "txhandler on recheck did not fail when mingasPrice was changed") // reset min gasprice @@ -1149,6 +1149,6 @@ func (s *MWTestSuite) TestTxHandlerReCheck() { err = s.app.BankKeeper.SendCoinsFromAccountToModule(ctx, accounts[0].acc.GetAddress(), minttypes.ModuleName, balances) s.Require().NoError(err) - _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = s.txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) s.Require().NotNil(err, "txhandler on recheck did not fail once feePayer no longer has sufficient funds") } diff --git a/x/auth/middleware/recovery.go b/x/auth/middleware/recovery.go index 0a0f89c7a890..1d9cd4db7cdd 100644 --- a/x/auth/middleware/recovery.go +++ b/x/auth/middleware/recovery.go @@ -4,8 +4,6 @@ import ( "context" "runtime/debug" - abci "github.com/tendermint/tendermint/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" @@ -26,7 +24,7 @@ func RecoveryTxMiddleware(txh tx.Handler) tx.Handler { var _ tx.Handler = recoveryTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh recoveryTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (res tx.Response, err error) { +func (txh recoveryTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (res tx.Response, resCheckTx tx.ResponseCheckTx, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // Panic recovery. defer func() { diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 61c6b9eb72c5..3621c55887dd 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/gogo/protobuf/proto" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -31,9 +30,9 @@ func NewRunMsgsTxHandler(msr *MsgServiceRouter, legacyRouter sdk.Router) tx.Hand var _ tx.Handler = runMsgsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. -func (txh runMsgsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh runMsgsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { // Don't run Msgs during CheckTx. - return tx.Response{}, nil + return tx.Response{}, tx.ResponseCheckTx{}, nil } // DeliverTx implements tx.Handler.DeliverTx method. diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 0179fe96e2be..c0c11370d796 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -26,7 +26,7 @@ func (s *MWTestSuite) TestRunMsgs() { res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) - s.Require().NotEmpty(res.Data) + s.Require().NotEmpty(res.MsgResponses) var txMsgData sdk.TxMsgData err = s.clientCtx.Codec.Unmarshal(res.Data, &txMsgData) s.Require().NoError(err) diff --git a/x/auth/middleware/sigverify.go b/x/auth/middleware/sigverify.go index f74a6006dddd..0e31efa52877 100644 --- a/x/auth/middleware/sigverify.go +++ b/x/auth/middleware/sigverify.go @@ -126,9 +126,9 @@ func (spkm setPubKeyTxHandler) setPubKey(ctx context.Context, req tx.Request, si } // CheckTx implements tx.Handler.CheckTx. -func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (spkm setPubKeyTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := spkm.setPubKey(ctx, req, false); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return spkm.next.CheckTx(ctx, req, checkReq) @@ -196,9 +196,9 @@ func (vscd validateSigCountTxHandler) checkSigCount(ctx context.Context, req tx. } // CheckTx implements tx.Handler.CheckTx. -func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (vscd validateSigCountTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := vscd.checkSigCount(ctx, req); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return vscd.next.CheckTx(ctx, req, checkReq) @@ -359,9 +359,9 @@ func (sgcm sigGasConsumeTxHandler) sigGasConsume(ctx context.Context, req tx.Req } // CheckTx implements tx.Handler.CheckTx. -func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (sgcm sigGasConsumeTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := sgcm.sigGasConsume(ctx, req, false); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return sgcm.next.CheckTx(ctx, req, checkReq) @@ -511,9 +511,9 @@ func (svd sigVerificationTxHandler) sigVerify(ctx context.Context, req tx.Reques } // CheckTx implements tx.Handler.CheckTx. -func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (svd sigVerificationTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := svd.sigVerify(ctx, req, checkReq.Type == abci.CheckTxType_Recheck, false); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return svd.next.CheckTx(ctx, req, checkReq) @@ -583,9 +583,9 @@ func (isd incrementSequenceTxHandler) incrementSeq(ctx context.Context, req tx.R } // CheckTx implements tx.Handler.CheckTx. -func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (isd incrementSequenceTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { if err := isd.incrementSeq(ctx, req); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return isd.next.CheckTx(ctx, req, checkReq) diff --git a/x/auth/middleware/sigverify_test.go b/x/auth/middleware/sigverify_test.go index 69e19919d685..b5f4d9c15966 100644 --- a/x/auth/middleware/sigverify_test.go +++ b/x/auth/middleware/sigverify_test.go @@ -183,9 +183,9 @@ func (s *MWTestSuite) TestSigVerification() { s.Require().NoError(err) if tc.recheck { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{Type: abci.CheckTxType_Recheck}) } else { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) } if tc.shouldErr { s.Require().NotNil(err, "TestCase %d: %s did not error as expected", i, tc.name) @@ -278,9 +278,9 @@ func (s *MWTestSuite) TestSigVerification_ExplicitAmino() { s.Require().NoError(err) if tc.recheck { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{Type: abci.CheckTxType_Recheck}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{Type: abci.CheckTxType_Recheck}) } else { - _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, abci.RequestCheckTx{}) + _, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) } if tc.shouldErr { s.Require().NotNil(err, "TestCase %d: %s did not error as expected", i, tc.name) diff --git a/x/auth/middleware/tips.go b/x/auth/middleware/tips.go index dfc912ba61ec..95d2cc17c778 100644 --- a/x/auth/middleware/tips.go +++ b/x/auth/middleware/tips.go @@ -3,8 +3,6 @@ package middleware import ( "context" - abci "github.com/tendermint/tendermint/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -26,22 +24,22 @@ func NewTipMiddleware(bankKeeper types.BankKeeper) tx.Middleware { var _ tx.Handler = tipsTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (txh tipsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkTx abci.RequestCheckTx) (tx.Response, error) { - res, err := txh.next.CheckTx(ctx, req, checkTx) +func (txh tipsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkTx tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + res, resCheckTx, err := txh.next.CheckTx(ctx, req, checkTx) if err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } tipTx, ok := req.Tx.(tx.TipTx) if !ok || tipTx.GetTip() == nil { - return res, err + return res, tx.ResponseCheckTx{}, err } if err := txh.transferTip(ctx, tipTx); err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } - return res, err + return res, resCheckTx, err } // DeliverTx implements tx.Handler.DeliverTx. From 81f013a7447c2c8ff1ade82be8e5828b49d00291 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 12:32:34 +0100 Subject: [PATCH 07/43] Fix mock tests --- server/mock/app.go | 11 +++++++++-- server/mock/tx.go | 18 +++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/server/mock/app.go b/server/mock/app.go index 779b9c5c320c..ff4a58fa829c 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -12,6 +12,7 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -74,7 +75,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { // them to the db func KVStoreHandler(storeKey storetypes.StoreKey) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - dTx, ok := msg.(kvstoreTx) + dTx, ok := msg.(*kvstoreTx) if !ok { return nil, errors.New("KVStoreHandler should only receive kvstoreTx") } @@ -86,8 +87,14 @@ func KVStoreHandler(storeKey storetypes.StoreKey) sdk.Handler { store := ctx.KVStore(storeKey) store.Set(key, value) + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + return &sdk.Result{ - Log: fmt.Sprintf("set %s=%s", key, value), + Log: fmt.Sprintf("set %s=%s", key, value), + MsgResponses: []*codectypes.Any{any}, }, nil } } diff --git a/server/mock/tx.go b/server/mock/tx.go index afa3c266b7b2..bfa6e6ad6b4b 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -21,13 +21,13 @@ type kvstoreTx struct { } // dummy implementation of proto.Message -func (msg kvstoreTx) Reset() {} -func (msg kvstoreTx) String() string { return "TODO" } -func (msg kvstoreTx) ProtoMessage() {} +func (msg *kvstoreTx) Reset() {} +func (msg *kvstoreTx) String() string { return "TODO" } +func (msg *kvstoreTx) ProtoMessage() {} -var _ sdk.Tx = kvstoreTx{} -var _ sdk.Msg = kvstoreTx{} -var _ middleware.GasTx = kvstoreTx{} +var _ sdk.Tx = &kvstoreTx{} +var _ sdk.Msg = &kvstoreTx{} +var _ middleware.GasTx = &kvstoreTx{} func NewTx(key, value string) kvstoreTx { bytes := fmt.Sprintf("%s=%s", key, value) @@ -46,7 +46,7 @@ func (tx kvstoreTx) Type() string { return "kvstore_tx" } -func (tx kvstoreTx) GetMsgs() []sdk.Msg { +func (tx *kvstoreTx) GetMsgs() []sdk.Msg { return []sdk.Msg{tx} } @@ -79,10 +79,10 @@ func decodeTx(txBytes []byte) (sdk.Tx, error) { split := bytes.Split(txBytes, []byte("=")) if len(split) == 1 { k := split[0] - tx = kvstoreTx{k, k, txBytes} + tx = &kvstoreTx{k, k, txBytes} } else if len(split) == 2 { k, v := split[0], split[1] - tx = kvstoreTx{k, v, txBytes} + tx = &kvstoreTx{k, v, txBytes} } else { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='") } From b2dbf101912ae78f63e966b2fe301be7058b0aee Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:35:51 +0100 Subject: [PATCH 08/43] Update baseapp/abci.go --- baseapp/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index e0b5fd49822d..3e628ef3f331 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -256,7 +256,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { } ctx := app.getContextForTx(mode, req.Tx) - res, _, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx}, tx.RequestCheckTx{Type: req.Type}) + res, checkRes, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}, tx.RequestCheckTx{Type: req.Type}) if err != nil { return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) } From d6859635dd47ad733a6227b6c34a64e8028077f3 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:36:06 +0100 Subject: [PATCH 09/43] Update baseapp/abci.go --- baseapp/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 3e628ef3f331..a478ff57d7ae 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -895,7 +895,7 @@ func splitPath(requestPath string) (path []string) { return path } -func convertTxResponseToCheckTx(txRes tx.Response) abci.ResponseCheckTx { +func convertTxResponseToCheckTx(txRes tx.Response, checkRes tx.ResponseCheckTx) abci.ResponseCheckTx { txMsgData := &sdk.TxMsgData{MsgResponses: txRes.MsgResponses} data, err := proto.Marshal(txMsgData) if err != nil { From 043c3d48d684575027e1e72419aa6bf844fa281b Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:36:13 +0100 Subject: [PATCH 10/43] Update types/tx/middleware.go --- types/tx/middleware.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index ccc1a67cec6c..21a8a8968b78 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -22,6 +22,7 @@ type ResponseSimulateTx struct { Result *sdk.Result } +// Response is the tx response type used in middlewares. type Response struct { GasWanted uint64 GasUsed uint64 From 23ef03724e065855a249ec2fdd35597d9d957350 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:36:20 +0100 Subject: [PATCH 11/43] Update types/tx/middleware.go --- types/tx/middleware.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 21a8a8968b78..3c761d7301ca 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -26,7 +26,10 @@ type ResponseSimulateTx struct { type Response struct { GasWanted uint64 GasUsed uint64 - MsgResponses []*codectypes.Any // Represents each Msg service handler's response type. Will get proto-serialized into the `Data` field in ABCI, see note #2 + // MsgResponses is an array containing each Msg service handler's response + // type, packed in an Any. This will get proto-serialized into the `Data` field + // in the ABCI Check/DeliverTx responses. + MsgResponses []*codectypes.Any Log string Events []abci.Event } From fded41a59df22b0f397b796c0332db2bcdf06262 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:41:41 +0100 Subject: [PATCH 12/43] tx.Response to abci conversion --- baseapp/abci.go | 68 ++++++++++++++++++++++++++---------------- types/tx/middleware.go | 6 ++-- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index a478ff57d7ae..2f88cf3bd91a 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -260,7 +260,13 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { if err != nil { return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) } - return convertTxResponseToCheckTx(res) + + abciRes, err := convertTxResponseToCheckTx(res, checkRes) + if err != nil { + return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + } + + return abciRes } // DeliverTx implements the ABCI interface and executes a tx in DeliverTx mode. @@ -271,28 +277,34 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx") - var res abci.ResponseDeliverTx + var abciRes abci.ResponseDeliverTx defer func() { for _, streamingListener := range app.abciListeners { - if err := streamingListener.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil { + if err := streamingListener.ListenDeliverTx(app.deliverState.ctx, req, abciRes); err != nil { app.logger.Error("DeliverTx listening hook failed", "err", err) } } }() reqTx, err := app.txDecoder(req.Tx) if err != nil { - res = sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace) - return res + abciRes = sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace) + return abciRes } ctx := app.getContextForTx(runTxModeDeliver, req.Tx) - delTxRes, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}) + res, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}) if err != nil { - res = sdkerrors.ResponseDeliverTx(err, uint64(delTxRes.GasUsed), uint64(delTxRes.GasWanted), app.trace) - return res + abciRes = sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + return abciRes } - return convertTxResponseToDeliverTx(delTxRes) + abciRes, err = convertTxResponseToDeliverTx(res) + if err != nil { + return sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + } + + return abciRes + } // Commit implements the ABCI interface. It will commit all state that exists in @@ -895,30 +907,34 @@ func splitPath(requestPath string) (path []string) { return path } -func convertTxResponseToCheckTx(txRes tx.Response, checkRes tx.ResponseCheckTx) abci.ResponseCheckTx { - txMsgData := &sdk.TxMsgData{MsgResponses: txRes.MsgResponses} - data, err := proto.Marshal(txMsgData) +// makeABCIData generates the Data field to be sent to ABCI Check/DeliverTx. +func makeABCIData(txRes tx.Response) ([]byte, error) { + return proto.Marshal(&sdk.TxMsgData{MsgResponses: txRes.MsgResponses}) +} + +func convertTxResponseToCheckTx(txRes tx.Response, checkRes tx.ResponseCheckTx) (abci.ResponseCheckTx, error) { + data, err := makeABCIData(txRes) if err != nil { - panic(fmt.Sprintf("error while converting tx response to check tx: %s", err.Error())) - } - res := abci.ResponseCheckTx{ - Data: data, - Log: txRes.Log, - Events: txRes.Events, + return abci.ResponseCheckTx{}, nil } - return res + + return abci.ResponseCheckTx{ + Data: data, + Log: txRes.Log, + Events: txRes.Events, + Priority: checkRes.Priority, + }, nil } -func convertTxResponseToDeliverTx(txRes tx.Response) abci.ResponseDeliverTx { - txMsgData := &sdk.TxMsgData{MsgResponses: txRes.MsgResponses} - data, err := proto.Marshal(txMsgData) +func convertTxResponseToDeliverTx(txRes tx.Response) (abci.ResponseDeliverTx, error) { + data, err := makeABCIData(txRes) if err != nil { - panic(fmt.Sprintf("error while converting tx response to deliver tx: %s", err.Error())) + return abci.ResponseDeliverTx{}, nil } - res := abci.ResponseDeliverTx{ + + return abci.ResponseDeliverTx{ Data: data, Log: txRes.Log, Events: txRes.Events, - } - return res + }, nil } diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 3c761d7301ca..3400b4522ac0 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -24,8 +24,8 @@ type ResponseSimulateTx struct { // Response is the tx response type used in middlewares. type Response struct { - GasWanted uint64 - GasUsed uint64 + GasWanted uint64 + GasUsed uint64 // MsgResponses is an array containing each Msg service handler's response // type, packed in an Any. This will get proto-serialized into the `Data` field // in the ABCI Check/DeliverTx responses. @@ -40,7 +40,7 @@ type Request struct { } type ResponseCheckTx struct { - priority uint64 + Priority int64 } type RequestCheckTx struct { From dfeac86085ba93dcdb1c5b413c953c6066fd4cae Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:45:25 +0100 Subject: [PATCH 13/43] refactor makeABCIData --- baseapp/abci.go | 2 ++ baseapp/test_helpers.go | 14 +++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 2f88cf3bd91a..b3569ff8f53c 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -912,6 +912,7 @@ func makeABCIData(txRes tx.Response) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: txRes.MsgResponses}) } +// convertTxResponseToCheckTx converts a tx.Response into a abci.ResponseCheckTx. func convertTxResponseToCheckTx(txRes tx.Response, checkRes tx.ResponseCheckTx) (abci.ResponseCheckTx, error) { data, err := makeABCIData(txRes) if err != nil { @@ -926,6 +927,7 @@ func convertTxResponseToCheckTx(txRes tx.Response, checkRes tx.ResponseCheckTx) }, nil } +// convertTxResponseToDeliverTx converts a tx.Response into a abci.ResponseDeliverTx. func convertTxResponseToDeliverTx(txRes tx.Response) (abci.ResponseDeliverTx, error) { data, err := makeABCIData(txRes) if err != nil { diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 72272975983e..4e74b9982435 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -1,7 +1,6 @@ package baseapp import ( - "github.com/golang/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -27,13 +26,12 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasInfo return gInfo, nil, err } - txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} - data, err := proto.Marshal(txMsgData) + data, err := makeABCIData(res) if err != nil { return gInfo, nil, err } - return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil + return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events, MsgResponses: res.MsgResponses}, nil } // Simulate executes a tx in simulate mode to get result and gas info. @@ -53,8 +51,7 @@ func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { return gasInfo, nil, err } - txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} - data, err := proto.Marshal(txMsgData) + data, err := makeABCIData(res) if err != nil { return gasInfo, nil, err } @@ -78,13 +75,12 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasIn return gInfo, nil, err } - txMsgData := &sdk.TxMsgData{MsgResponses: res.MsgResponses} - data, err := proto.Marshal(txMsgData) + data, err := makeABCIData(res) if err != nil { return gInfo, nil, err } - return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil + return gInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events, MsgResponses: res.MsgResponses}, nil } // Context with current {check, deliver}State of the app used by tests. From b75795e522d9ab64de1c4ff3f5e5b637e4a9b63a Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:51:01 +0100 Subject: [PATCH 14/43] Add comments --- baseapp/test_helpers.go | 2 +- types/tx/middleware.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 4e74b9982435..bc837e3cc595 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -56,7 +56,7 @@ func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { return gasInfo, nil, err } - return gasInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events}, nil + return gasInfo, &sdk.Result{Data: data, Log: res.Log, Events: res.Events, MsgResponses: res.MsgResponses}, nil } // SimDeliver defines a DeliverTx helper function that used in tests and diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 3400b4522ac0..e67b783796d9 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -34,19 +34,24 @@ type Response struct { Events []abci.Event } +// Request is the tx request type used in middlewares. type Request struct { Tx sdk.Tx TxBytes []byte } -type ResponseCheckTx struct { - Priority int64 -} - +// RequestCheckTx is the additional request type used in middlewares CheckTx +// method. type RequestCheckTx struct { Type abci.CheckTxType } +// RequestCheckTx is the additional response type used in middlewares CheckTx +// method. +type ResponseCheckTx struct { + Priority int64 +} + // TxHandler defines the baseapp's CheckTx, DeliverTx and Simulate respective // handlers. It is designed as a middleware stack. type Handler interface { From fe7dbbc212d484e9f79b5b58d484470c07adae6a Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:57:56 +0100 Subject: [PATCH 15/43] Fix build --- x/auth/middleware/middleware.go | 6 +++--- x/auth/middleware/run_msgs_test.go | 10 +++++----- x/auth/middleware/tx_priority.go | 22 ++++++++++------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/x/auth/middleware/middleware.go b/x/auth/middleware/middleware.go index 365d7441ed02..e8610ee2971d 100644 --- a/x/auth/middleware/middleware.go +++ b/x/auth/middleware/middleware.go @@ -50,15 +50,15 @@ type TxHandlerOptions struct { // for most applications. func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for compose middlewares") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for middlewares") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for compose middlewares") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for middlewares") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for compose middlewares") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares") } var sigGasConsumer = options.SigGasConsumer diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index c0c11370d796..dbb77f94e1b7 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -1,6 +1,10 @@ package middleware_test import ( + "fmt" + + "github.com/gogo/protobuf/proto" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,9 +31,5 @@ func (s *MWTestSuite) TestRunMsgs() { res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) s.Require().NotEmpty(res.MsgResponses) - var txMsgData sdk.TxMsgData - err = s.clientCtx.Codec.Unmarshal(res.Data, &txMsgData) - s.Require().NoError(err) - s.Require().Len(txMsgData.Data, 1) - s.Require().Equal(sdk.MsgTypeURL(&testdata.MsgCreateDog{}), txMsgData.Data[0].MsgType) + s.Require().Equal(fmt.Sprintf("/%s", proto.MessageName(&testdata.MsgCreateDogResponse{})), res.MsgResponses[0].TypeUrl) } diff --git a/x/auth/middleware/tx_priority.go b/x/auth/middleware/tx_priority.go index 81d8d3124e7b..c2494b2f102e 100644 --- a/x/auth/middleware/tx_priority.go +++ b/x/auth/middleware/tx_priority.go @@ -3,8 +3,6 @@ package middleware import ( "context" - abci "github.com/tendermint/tendermint/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" @@ -28,26 +26,26 @@ func TxPriorityHandler(txh tx.Handler) tx.Handler { // fees included. Applications that need more sophisticated mempool ordering // should look to implement their own fee handling middleware instead of using // TxPriorityHandler. -func (h txPriorityHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { - feeTx, ok := tx.(sdk.FeeTx) +func (h txPriorityHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + feeTx, ok := req.Tx.(sdk.FeeTx) if !ok { - return abci.ResponseCheckTx{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } feeCoins := feeTx.GetFee() - res, err := h.next.CheckTx(ctx, tx, req) - res.Priority = GetTxPriority(feeCoins) + res, checkRes, err := h.next.CheckTx(ctx, req, checkReq) + checkRes.Priority = GetTxPriority(feeCoins) - return res, err + return res, checkRes, err } -func (h txPriorityHandler) DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { - return h.next.DeliverTx(ctx, tx, req) +func (h txPriorityHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return h.next.DeliverTx(ctx, req) } -func (h txPriorityHandler) SimulateTx(ctx context.Context, sdkTx sdk.Tx, req tx.RequestSimulateTx) (tx.ResponseSimulateTx, error) { - return h.next.SimulateTx(ctx, sdkTx, req) +func (h txPriorityHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return h.next.SimulateTx(ctx, req) } // GetTxPriority returns a naive tx priority based on the total sum of all fees From 51861fbf70fb685c7d1ddbd79059e225d25efa1b Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 26 Nov 2021 12:35:08 +0530 Subject: [PATCH 16/43] fix build error --- baseapp/custom_txhandler_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/baseapp/custom_txhandler_test.go b/baseapp/custom_txhandler_test.go index 55b664533a4f..27cec992ed10 100644 --- a/baseapp/custom_txhandler_test.go +++ b/baseapp/custom_txhandler_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" ) @@ -31,10 +30,10 @@ func CustomTxHandlerMiddleware(handler handlerFun) tx.Middleware { } // CheckTx implements tx.Handler.CheckTx method. -func (txh customTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq abci.RequestCheckTx) (tx.Response, error) { +func (txh customTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { sdkCtx, err := txh.runHandler(ctx, req.Tx, req.TxBytes, false) if err != nil { - return tx.Response{}, err + return tx.Response{}, tx.ResponseCheckTx{}, err } return txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) From 9783965271aeb9cb0211b7268d96792038effc36 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 26 Nov 2021 21:30:50 +0530 Subject: [PATCH 17/43] fix tests --- baseapp/baseapp_test.go | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 84fff39ab2f4..487e0ab0fad2 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" @@ -148,7 +149,14 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options legacyRouter.AddRoute(sdk.NewRoute(routeMsgKeyValue, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { kv := msg.(*msgKeyValue) bapp.CMS().GetCommitKVStore(capKey2).Set(kv.Key, kv.Value) - return &sdk.Result{}, nil + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil })) txHandler := testTxHandler( middleware.TxHandlerOptions{ @@ -903,6 +911,14 @@ func handlerMsgCounter(t *testing.T, capKey storetypes.StoreKey, deliverKey []by } res.Events = ctx.EventManager().Events().ToABCIEvents() + + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + res.MsgResponses = []*codectypes.Any{any} + return res, nil } } @@ -1153,7 +1169,13 @@ func TestSimulateTx(t *testing.T) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx.GasMeter().ConsumeGas(gasConsumed, "test") - return &sdk.Result{}, nil + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil }) legacyRouter.AddRoute(r) txHandler := testTxHandler( @@ -1651,7 +1673,14 @@ func TestQuery(t *testing.T) { r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { store := ctx.KVStore(capKey1) store.Set(key, value) - return &sdk.Result{}, nil + + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil }) legacyRouter.AddRoute(r) txHandler := testTxHandler( From 4c2320ad0c563445599da995cbad0cb8d37a4b81 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 26 Nov 2021 23:01:23 +0530 Subject: [PATCH 18/43] fix test --- baseapp/baseapp_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 487e0ab0fad2..ab6b45008a92 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -1360,7 +1360,14 @@ func TestTxGasLimits(t *testing.T) { r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { count := msg.(msgCounter).Counter ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") - return &sdk.Result{}, nil + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil }) legacyRouter.AddRoute(r) txHandler := testTxHandler( @@ -1439,7 +1446,15 @@ func TestMaxBlockGasLimits(t *testing.T) { r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { count := msg.(msgCounter).Counter ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") - return &sdk.Result{}, nil + + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil }) legacyRouter.AddRoute(r) txHandler := testTxHandler( From cde4010ea9c787c7c706caeb00f438cca5ccbfc2 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 29 Nov 2021 18:25:13 +0530 Subject: [PATCH 19/43] fix tests --- baseapp/baseapp_test.go | 46 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index ab6b45008a92..196738ec692d 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -724,7 +724,7 @@ func (tx *txTest) setFailOnAnte(fail bool) { func (tx *txTest) setFailOnHandler(fail bool) { for i, msg := range tx.Msgs { - tx.Msgs[i] = msgCounter{msg.(msgCounter).Counter, fail} + tx.Msgs[i] = &msgCounter{msg.(*msgCounter).Counter, fail} } } @@ -752,16 +752,16 @@ type msgCounter struct { } // dummy implementation of proto.Message -func (msg msgCounter) Reset() {} -func (msg msgCounter) String() string { return "TODO" } -func (msg msgCounter) ProtoMessage() {} +func (msg *msgCounter) Reset() {} +func (msg *msgCounter) String() string { return "TODO" } +func (msg *msgCounter) ProtoMessage() {} // Implements Msg -func (msg msgCounter) Route() string { return routeMsgCounter } -func (msg msgCounter) Type() string { return "counter1" } -func (msg msgCounter) GetSignBytes() []byte { return nil } -func (msg msgCounter) GetSigners() []sdk.AccAddress { return nil } -func (msg msgCounter) ValidateBasic() error { +func (msg *msgCounter) Route() string { return routeMsgCounter } +func (msg *msgCounter) Type() string { return "counter1" } +func (msg *msgCounter) GetSignBytes() []byte { return nil } +func (msg *msgCounter) GetSigners() []sdk.AccAddress { return nil } +func (msg *msgCounter) ValidateBasic() error { if msg.Counter >= 0 { return nil } @@ -771,7 +771,7 @@ func (msg msgCounter) ValidateBasic() error { func newTxCounter(counter int64, msgCounters ...int64) txTest { msgs := make([]sdk.Msg, 0, len(msgCounters)) for _, c := range msgCounters { - msgs = append(msgs, msgCounter{c, false}) + msgs = append(msgs, &msgCounter{c, false}) } return txTest{msgs, counter, false, math.MaxUint64} @@ -1173,6 +1173,7 @@ func TestSimulateTx(t *testing.T) { if err != nil { return nil, err } + return &sdk.Result{ MsgResponses: []*codectypes.Any{any}, }, nil @@ -1243,7 +1244,14 @@ func TestRunInvalidTransaction(t *testing.T) { txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - return &sdk.Result{}, nil + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil }) legacyRouter.AddRoute(r) txHandler := testTxHandler( @@ -1291,7 +1299,7 @@ func TestRunInvalidTransaction(t *testing.T) { for _, testCase := range testCases { tx := testCase.tx - _, result, err := app.SimDeliver(aminoTxEncoder(), tx) + _, _, err := app.SimDeliver(aminoTxEncoder(), tx) if testCase.fail { require.Error(t, err) @@ -1300,14 +1308,14 @@ func TestRunInvalidTransaction(t *testing.T) { require.EqualValues(t, sdkerrors.ErrInvalidSequence.Codespace(), space, err) require.EqualValues(t, sdkerrors.ErrInvalidSequence.ABCICode(), code, err) } else { - require.NotNil(t, result) + require.NoError(t, err) } } } // transaction with no known route { - unknownRouteTx := txTest{[]sdk.Msg{msgNoRoute{}}, 0, false, math.MaxUint64} + unknownRouteTx := txTest{[]sdk.Msg{&msgNoRoute{}}, 0, false, math.MaxUint64} _, result, err := app.SimDeliver(aminoTxEncoder(), unknownRouteTx) require.Error(t, err) require.Nil(t, result) @@ -1316,7 +1324,7 @@ func TestRunInvalidTransaction(t *testing.T) { require.EqualValues(t, sdkerrors.ErrUnknownRequest.Codespace(), space, err) require.EqualValues(t, sdkerrors.ErrUnknownRequest.ABCICode(), code, err) - unknownRouteTx = txTest{[]sdk.Msg{msgCounter{}, msgNoRoute{}}, 0, false, math.MaxUint64} + unknownRouteTx = txTest{[]sdk.Msg{&msgCounter{}, &msgNoRoute{}}, 0, false, math.MaxUint64} _, result, err = app.SimDeliver(aminoTxEncoder(), unknownRouteTx) require.Error(t, err) require.Nil(t, result) @@ -1329,7 +1337,7 @@ func TestRunInvalidTransaction(t *testing.T) { // Transaction with an unregistered message { tx := newTxCounter(0, 0) - tx.Msgs = append(tx.Msgs, msgNoDecode{}) + tx.Msgs = append(tx.Msgs, &msgNoDecode{}) // new codec so we can encode the tx, but we shouldn't be able to decode newCdc := codec.NewLegacyAmino() @@ -1358,7 +1366,7 @@ func TestTxGasLimits(t *testing.T) { txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - count := msg.(msgCounter).Counter + count := msg.(*msgCounter).Counter ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") any, err := codectypes.NewAnyWithValue(msg) if err != nil { @@ -1444,7 +1452,7 @@ func TestMaxBlockGasLimits(t *testing.T) { txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - count := msg.(msgCounter).Counter + count := msg.(*msgCounter).Counter ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") any, err := codectypes.NewAnyWithValue(msg) @@ -1632,7 +1640,7 @@ func TestGasConsumptionBadTx(t *testing.T) { txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - count := msg.(msgCounter).Counter + count := msg.(*msgCounter).Counter ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") return &sdk.Result{}, nil }) From 02e3f934d3d6445d119c47e32b446225f1279311 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Mon, 29 Nov 2021 15:15:56 +0100 Subject: [PATCH 20/43] Fix TestSimulateTx --- baseapp/baseapp_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 196738ec692d..46051b38237b 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -1169,7 +1169,8 @@ func TestSimulateTx(t *testing.T) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx.GasMeter().ConsumeGas(gasConsumed, "test") - any, err := codectypes.NewAnyWithValue(msg) + // Return dummy MsgResponse for msgCounter. + any, err := codectypes.NewAnyWithValue(&testdata.Dog{}) if err != nil { return nil, err } From e795b2e72401e097e44e306b7b12fe83d05c3794 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 30 Nov 2021 10:14:33 +0530 Subject: [PATCH 21/43] fix tests --- x/auth/middleware/gas_test.go | 2 +- x/auth/middleware/priority_test.go | 8 ++++---- x/auth/middleware/testutil_test.go | 12 +++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index 121072552533..f89492f16f6c 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -64,7 +64,7 @@ func (s *MWTestSuite) TestSetup() { } for _, tc := range testcases { s.Run(tc.name, func() { - res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) + res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: tc.tx}, tx.RequestCheckTx{}) if tc.expErr { s.Require().EqualError(err, tc.errorStr) } else { diff --git a/x/auth/middleware/priority_test.go b/x/auth/middleware/priority_test.go index a06233f7e12b..76df644e448f 100644 --- a/x/auth/middleware/priority_test.go +++ b/x/auth/middleware/priority_test.go @@ -4,8 +4,8 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" - abci "github.com/tendermint/tendermint/abci/types" ) func (s *MWTestSuite) TestPriority() { @@ -28,11 +28,11 @@ func (s *MWTestSuite) TestPriority() { txBuilder.SetGasLimit(gasLimit) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) // txHandler errors with insufficient fees - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, checkTxRes, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}, tx.RequestCheckTx{}) s.Require().NoError(err, "Middleware should not have errored on too low fee for local gasPrice") - s.Require().Equal(atomCoin.Amount.Int64(), res.Priority, "priority should be atom amount") + s.Require().Equal(atomCoin.Amount.Int64(), checkTxRes.Priority, "priority should be atom amount") } diff --git a/x/auth/middleware/testutil_test.go b/x/auth/middleware/testutil_test.go index 4739e83addd6..9d804fa17ae2 100644 --- a/x/auth/middleware/testutil_test.go +++ b/x/auth/middleware/testutil_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -69,7 +70,16 @@ func (s *MWTestSuite) SetupTest(isCheckTx bool) sdk.Context { msr := middleware.NewMsgServiceRouter(encodingConfig.InterfaceRegistry) testdata.RegisterMsgServer(msr, testdata.MsgServerImpl{}) legacyRouter := middleware.NewLegacyRouter() - legacyRouter.AddRoute(sdk.NewRoute((&testdata.TestMsg{}).Route(), func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { return &sdk.Result{}, nil })) + legacyRouter.AddRoute(sdk.NewRoute((&testdata.TestMsg{}).Route(), func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + any, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return &sdk.Result{ + MsgResponses: []*codectypes.Any{any}, + }, nil + })) txHandler, err := middleware.NewDefaultTxHandler(middleware.TxHandlerOptions{ Debug: s.app.Trace(), MsgServiceRouter: msr, From c6c387c34affdc33529e87dcda000093a970337a Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 30 Nov 2021 11:05:48 +0530 Subject: [PATCH 22/43] fix test --- types/result_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/result_test.go b/types/result_test.go index 04b75a2f2597..2fe01fef4121 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -193,14 +193,14 @@ func TestWrapServiceResult(t *testing.T) { require.Nil(t, res) require.NotNil(t, err) - res, err = sdk.WrapServiceResult(ctx, nil, nil) + res, err = sdk.WrapServiceResult(ctx, &testdata.Dog{}, nil) require.NotNil(t, res) require.Nil(t, err) require.Empty(t, res.Events) ctx = ctx.WithEventManager(sdk.NewEventManager()) ctx.EventManager().EmitEvent(sdk.NewEvent("test")) - res, err = sdk.WrapServiceResult(ctx, nil, nil) + res, err = sdk.WrapServiceResult(ctx, &testdata.Dog{}, nil) require.NotNil(t, res) require.Nil(t, err) require.Len(t, res.Events, 1) From 141d214ddf304c74343accc779138d91373c1a3d Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 12:52:01 +0100 Subject: [PATCH 23/43] Fix build --- x/auth/middleware/priority_test.go | 8 ++++---- x/auth/middleware/run_msgs.go | 2 ++ x/auth/tx/service_test.go | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/x/auth/middleware/priority_test.go b/x/auth/middleware/priority_test.go index a06233f7e12b..c98f4b2012d6 100644 --- a/x/auth/middleware/priority_test.go +++ b/x/auth/middleware/priority_test.go @@ -4,8 +4,8 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" - abci "github.com/tendermint/tendermint/abci/types" ) func (s *MWTestSuite) TestPriority() { @@ -28,11 +28,11 @@ func (s *MWTestSuite) TestPriority() { txBuilder.SetGasLimit(gasLimit) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - tx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) + sdkTx, txBz, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) // txHandler errors with insufficient fees - res, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx, abci.RequestCheckTx{}) + _, checkRes, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: sdkTx, TxBytes: txBz}, tx.RequestCheckTx{}) s.Require().NoError(err, "Middleware should not have errored on too low fee for local gasPrice") - s.Require().Equal(atomCoin.Amount.Int64(), res.Priority, "priority should be atom amount") + s.Require().Equal(atomCoin.Amount.Int64(), checkRes.Priority, "priority should be atom amount") } diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 3621c55887dd..0dc0f1c53786 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -59,7 +59,9 @@ func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx. return tx.Response{ // GasInfo will be populated by the Gas middleware. + Log: res.Log, MsgResponses: res.MsgResponses, + Events: res.Events, }, nil } diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 0424afba82e4..fe1a6150bc4a 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -137,6 +137,10 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPC() { } func (s IntegrationTestSuite) TestSimulateTx_GRPCGateway() { + // Skipping this test, pending on how to decode MsgResponses with interface registry. + // TODO https://github.com/cosmos/cosmos-sdk/issues/10496#issuecomment-982561928 + s.T().Skip() + val := s.network.Validators[0] txBuilder := s.mkTxBuilder() // Convert the txBuilder to a tx.Tx. From fa5df344f2abbb30ea1532f7212958ae3b475ba2 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 13:20:08 +0100 Subject: [PATCH 24/43] Simplify code --- types/abci.pb.go | 1 + x/auth/middleware/gas.go | 16 +++++---- x/auth/middleware/index_events.go | 14 ++++---- x/auth/middleware/middleware.go | 4 +-- x/auth/middleware/priority.go | 4 +-- x/auth/middleware/priority_test.go | 2 +- x/auth/middleware/run_msgs.go | 46 +++++--------------------- x/auth/middleware/tips.go | 53 +++++++++--------------------- 8 files changed, 46 insertions(+), 94 deletions(-) diff --git a/types/abci.pb.go b/types/abci.pb.go index 083d66a509c6..ed6e1967fc8d 100644 --- a/types/abci.pb.go +++ b/types/abci.pb.go @@ -467,6 +467,7 @@ func (m *MsgData) GetData() []byte { // TxMsgData defines a list of MsgData. A transaction will have a MsgData object // for each message. type TxMsgData struct { + // data field is deprecated and not populated. Data []*MsgData `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` // Deprecated: Do not use. // msg_responses contains the Msg handler responses type packed in Anys. // diff --git a/x/auth/middleware/gas.go b/x/auth/middleware/gas.go index 604aa612abfa..ee31fc1bff89 100644 --- a/x/auth/middleware/gas.go +++ b/x/auth/middleware/gas.go @@ -35,10 +35,8 @@ func (txh gasTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx } res, resCheckTx, err := txh.next.CheckTx(sdk.WrapSDKContext(sdkCtx), req, checkReq) - res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) - res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) - return res, resCheckTx, err + return populateGas(res, sdkCtx), resCheckTx, err } // DeliverTx implements tx.Handler.DeliverTx. @@ -49,10 +47,8 @@ func (txh gasTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Respo } res, err := txh.next.DeliverTx(sdk.WrapSDKContext(sdkCtx), req) - res.GasUsed = uint64(sdkCtx.GasMeter().GasConsumed()) - res.GasWanted = uint64(sdkCtx.GasMeter().Limit()) - return res, err + return populateGas(res, sdkCtx), err } // SimulateTx implements tx.Handler.SimulateTx method. @@ -63,10 +59,16 @@ func (txh gasTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Resp } res, err := txh.next.SimulateTx(sdk.WrapSDKContext(sdkCtx), req) + + return populateGas(res, sdkCtx), err +} + +// populateGas returns a new tx.Response with gas fields populated. +func populateGas(res tx.Response, sdkCtx sdk.Context) tx.Response { res.GasWanted = sdkCtx.GasMeter().Limit() res.GasUsed = sdkCtx.GasMeter().GasConsumed() - return res, err + return res } // gasContext returns a new context with a gas meter set from a given context. diff --git a/x/auth/middleware/index_events.go b/x/auth/middleware/index_events.go index 9a55db3947c4..4a5ad009daa2 100644 --- a/x/auth/middleware/index_events.go +++ b/x/auth/middleware/index_events.go @@ -11,16 +11,16 @@ type indexEventsTxHandler struct { // indexEvents defines the set of events in the form {eventType}.{attributeKey}, // which informs Tendermint what to index. If empty, all events will be indexed. indexEvents map[string]struct{} - inner tx.Handler + next tx.Handler } -// NewIndexEventsTxMiddleware defines a middleware to optionally only index a +// NewIndexEventsMiddleware defines a middleware to optionally only index a // subset of the emitted events inside the Tendermint events indexer. -func NewIndexEventsTxMiddleware(indexEvents map[string]struct{}) tx.Middleware { +func NewIndexEventsMiddleware(indexEvents map[string]struct{}) tx.Middleware { return func(txHandler tx.Handler) tx.Handler { return indexEventsTxHandler{ indexEvents: indexEvents, - inner: txHandler, + next: txHandler, } } } @@ -29,7 +29,7 @@ var _ tx.Handler = indexEventsTxHandler{} // CheckTx implements tx.Handler.CheckTx method. func (txh indexEventsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { - res, resCheckTx, err := txh.inner.CheckTx(ctx, req, checkReq) + res, resCheckTx, err := txh.next.CheckTx(ctx, req, checkReq) if err != nil { return res, tx.ResponseCheckTx{}, err } @@ -40,7 +40,7 @@ func (txh indexEventsTxHandler) CheckTx(ctx context.Context, req tx.Request, che // DeliverTx implements tx.Handler.DeliverTx method. func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { - res, err := txh.inner.DeliverTx(ctx, req) + res, err := txh.next.DeliverTx(ctx, req) if err != nil { return res, err } @@ -51,7 +51,7 @@ func (txh indexEventsTxHandler) DeliverTx(ctx context.Context, req tx.Request) ( // SimulateTx implements tx.Handler.SimulateTx method. func (txh indexEventsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { - res, err := txh.inner.SimulateTx(ctx, req) + res, err := txh.next.SimulateTx(ctx, req) if err != nil { return res, err } diff --git a/x/auth/middleware/middleware.go b/x/auth/middleware/middleware.go index e8610ee2971d..6db421d7a0bd 100644 --- a/x/auth/middleware/middleware.go +++ b/x/auth/middleware/middleware.go @@ -79,7 +79,7 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { RecoveryTxMiddleware, // Choose which events to index in Tendermint. Make sure no events are // emitted outside of this middleware. - NewIndexEventsTxMiddleware(options.IndexEvents), + NewIndexEventsMiddleware(options.IndexEvents), // Reject all extension options which can optionally be included in the // tx. RejectExtensionOptionsMiddleware, @@ -89,7 +89,7 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { ValidateMemoMiddleware(options.AccountKeeper), ConsumeTxSizeGasMiddleware(options.AccountKeeper), DeductFeeMiddleware(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), - TxPriorityHandler, + TxPriorityMiddleware, SetPubKeyMiddleware(options.AccountKeeper), ValidateSigCountMiddleware(options.AccountKeeper), SigGasConsumeMiddleware(options.AccountKeeper, sigGasConsumer), diff --git a/x/auth/middleware/priority.go b/x/auth/middleware/priority.go index 79c5d3953d80..a464fddd1e7d 100644 --- a/x/auth/middleware/priority.go +++ b/x/auth/middleware/priority.go @@ -14,10 +14,10 @@ type txPriorityHandler struct { next tx.Handler } -// TxPriorityHandler implements tx handling middleware that determines a +// TxPriorityMiddleware implements tx handling middleware that determines a // transaction's priority via a naive mechanism -- the total sum of fees provided. // It sets the Priority in ResponseCheckTx only. -func TxPriorityHandler(txh tx.Handler) tx.Handler { +func TxPriorityMiddleware(txh tx.Handler) tx.Handler { return txPriorityHandler{next: txh} } diff --git a/x/auth/middleware/priority_test.go b/x/auth/middleware/priority_test.go index 76df644e448f..a04e2065d971 100644 --- a/x/auth/middleware/priority_test.go +++ b/x/auth/middleware/priority_test.go @@ -12,7 +12,7 @@ func (s *MWTestSuite) TestPriority() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.TxPriorityHandler) + txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.TxPriorityMiddleware) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/auth/middleware/run_msgs.go b/x/auth/middleware/run_msgs.go index 0dc0f1c53786..c90d222a907b 100644 --- a/x/auth/middleware/run_msgs.go +++ b/x/auth/middleware/run_msgs.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/gogo/protobuf/proto" "github.com/tendermint/tendermint/crypto/tmhash" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -37,32 +36,12 @@ func (txh runMsgsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkRe // DeliverTx implements tx.Handler.DeliverTx method. func (txh runMsgsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { - res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) - if err != nil { - return tx.Response{}, err - } - - return tx.Response{ - // GasInfo will be populated by the Gas middleware. - Log: res.Log, - MsgResponses: res.MsgResponses, - Events: res.Events, - }, nil + return txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) } // SimulateTx implements tx.Handler.SimulateTx method. func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { - res, err := txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) - if err != nil { - return tx.Response{}, err - } - - return tx.Response{ - // GasInfo will be populated by the Gas middleware. - Log: res.Log, - MsgResponses: res.MsgResponses, - Events: res.Events, - }, nil + return txh.runMsgs(sdk.UnwrapSDKContext(ctx), req.Tx.GetMsgs(), req.TxBytes) } // runMsgs iterates through a list of messages and executes them with the provided @@ -70,7 +49,7 @@ func (txh runMsgsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx. // 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 (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes []byte) (*sdk.Result, error) { +func (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes []byte) (tx.Response, error) { // Create a new Context based off of the existing Context with a MultiStore branch // in case message processing fails. At this point, the MultiStore // is a branch of a branch. @@ -105,16 +84,16 @@ func (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes eventMsgName = legacyMsg.Type() handler := txh.legacyRouter.Route(sdkCtx, msgRoute) if handler == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i) + return tx.Response{}, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i) } msgResult, err = handler(sdkCtx, msg) } else { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg) + return tx.Response{}, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg) } if err != nil { - return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i) + return tx.Response{}, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i) } msgEvents := sdk.Events{ @@ -131,23 +110,16 @@ func (txh runMsgsTxHandler) runMsgs(sdkCtx sdk.Context, msgs []sdk.Msg, txBytes // Each individual sdk.Result has exactly one Msg response. We aggregate here. msgResponse := msgResult.MsgResponses[0] if msgResponse == nil { - return nil, sdkerrors.ErrLogic.Wrapf("got nil Msg response at index %d", i) + return tx.Response{}, sdkerrors.ErrLogic.Wrapf("got nil Msg response at index %d for msg %s", i, sdk.MsgTypeURL(msg)) } msgResponses[i] = msgResponse msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint32(i), msgResult.Log, msgEvents)) } msCache.Write() - // The data we send back to tendermint is the proto-marshalled bytes of TxMsgData. - data, err := proto.Marshal(&sdk.TxMsgData{ - MsgResponses: msgResponses, - }) - if err != nil { - return nil, sdkerrors.Wrap(err, "failed to marshal tx data") - } - return &sdk.Result{ - Data: data, + return tx.Response{ + // GasInfo will be populated by the Gas middleware. Log: strings.TrimSpace(msgLogs.String()), Events: events.ToABCIEvents(), MsgResponses: msgResponses, diff --git a/x/auth/middleware/tips.go b/x/auth/middleware/tips.go index 95d2cc17c778..68749b020647 100644 --- a/x/auth/middleware/tips.go +++ b/x/auth/middleware/tips.go @@ -26,18 +26,7 @@ var _ tx.Handler = tipsTxHandler{} // CheckTx implements tx.Handler.CheckTx. func (txh tipsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkTx tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { res, resCheckTx, err := txh.next.CheckTx(ctx, req, checkTx) - if err != nil { - return tx.Response{}, tx.ResponseCheckTx{}, err - } - - tipTx, ok := req.Tx.(tx.TipTx) - if !ok || tipTx.GetTip() == nil { - return res, tx.ResponseCheckTx{}, err - } - - if err := txh.transferTip(ctx, tipTx); err != nil { - return tx.Response{}, tx.ResponseCheckTx{}, err - } + res, err = txh.transferTip(ctx, req, res, err) return res, resCheckTx, err } @@ -45,48 +34,36 @@ func (txh tipsTxHandler) CheckTx(ctx context.Context, req tx.Request, checkTx tx // DeliverTx implements tx.Handler.DeliverTx. func (txh tipsTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { res, err := txh.next.DeliverTx(ctx, req) - if err != nil { - return tx.Response{}, err - } - tipTx, ok := req.Tx.(tx.TipTx) - if !ok || tipTx.GetTip() == nil { - return res, err - } - - if err := txh.transferTip(ctx, tipTx); err != nil { - return tx.Response{}, err - } - - return res, err + return txh.transferTip(ctx, req, res, err) } // SimulateTx implements tx.Handler.SimulateTx method. func (txh tipsTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { res, err := txh.next.SimulateTx(ctx, req) - if err != nil { - return tx.Response{}, err - } + return txh.transferTip(ctx, req, res, err) +} + +// transferTip transfers the tip from the tipper to the fee payer. +func (txh tipsTxHandler) transferTip(ctx context.Context, req tx.Request, res tx.Response, err error) (tx.Response, error) { tipTx, ok := req.Tx.(tx.TipTx) + + // No-op if the tx doesn't have tips. if !ok || tipTx.GetTip() == nil { return res, err } - if err := txh.transferTip(ctx, tipTx); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) + tipper, err := sdk.AccAddressFromBech32(tipTx.GetTip().Tipper) + if err != nil { return tx.Response{}, err } - return res, err -} - -// transferTip transfers the tip from the tipper to the fee payer. -func (txh tipsTxHandler) transferTip(ctx context.Context, tipTx tx.TipTx) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) - tipper, err := sdk.AccAddressFromBech32(tipTx.GetTip().Tipper) + err = txh.bankKeeper.SendCoins(sdkCtx, tipper, tipTx.FeePayer(), tipTx.GetTip().Amount) if err != nil { - return err + return tx.Response{}, err } - return txh.bankKeeper.SendCoins(sdkCtx, tipper, tipTx.FeePayer(), tipTx.GetTip().Amount) + return res, nil } From 1608e1837c3cd9fc5123d1f80b90e787cc86a2d9 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 13:35:36 +0100 Subject: [PATCH 25/43] fix test build --- baseapp/baseapp_test.go | 2 +- server/mock/app.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 46051b38237b..fc2961a695b1 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -134,7 +134,7 @@ func testTxHandler(options middleware.TxHandlerOptions, customTxHandlerMiddlewar middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, - middleware.NewIndexEventsTxMiddleware(options.IndexEvents), + middleware.NewIndexEventsMiddleware(options.IndexEvents), middleware.ValidateBasicMiddleware, CustomTxHandlerMiddleware(customTxHandlerMiddleware), ) diff --git a/server/mock/app.go b/server/mock/app.go index ff4a58fa829c..7dce197f6fac 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -25,7 +25,7 @@ func testTxHandler(options middleware.TxHandlerOptions) tx.Handler { middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, - middleware.NewIndexEventsTxMiddleware(options.IndexEvents), + middleware.NewIndexEventsMiddleware(options.IndexEvents), ) } From 4e9071f386320e0fab096867d15d123d34c1f0d1 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:34:21 +0100 Subject: [PATCH 26/43] Use repeated bytes in txMsgData --- baseapp/abci.go | 7 +- docs/core/proto-docs.md | 2 +- proto/cosmos/base/abci/v1beta1/abci.proto | 7 +- types/abci.pb.go | 163 ++++++++++------------ x/auth/tx/service_test.go | 4 - 5 files changed, 89 insertions(+), 94 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index b3569ff8f53c..5c3fca2c45ef 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -909,7 +909,12 @@ func splitPath(requestPath string) (path []string) { // makeABCIData generates the Data field to be sent to ABCI Check/DeliverTx. func makeABCIData(txRes tx.Response) ([]byte, error) { - return proto.Marshal(&sdk.TxMsgData{MsgResponses: txRes.MsgResponses}) + msgResBz := make([][]byte, len(txRes.MsgResponses)) + for i, any := range txRes.MsgResponses { + msgResBz[i] = any.Value + } + + return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResBz}) } // convertTxResponseToCheckTx converts a tx.Response into a abci.ResponseCheckTx. diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 6d5d354158da..c3cdc2129300 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2394,7 +2394,7 @@ for each message. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `data` | [MsgData](#cosmos.base.abci.v1beta1.MsgData) | repeated | **Deprecated.** data field is deprecated and not populated. | -| `msg_responses` | [google.protobuf.Any](#google.protobuf.Any) | repeated | msg_responses contains the Msg handler responses type packed in Anys. +| `msg_responses` | [bytes](#bytes) | repeated | msg_responses contains the Msg handler responses, serialized using Protobuf. The bytes at index i correspond to the Protobuf serialization of the i-th Msg's response type in the tx. It can be decoded into the corresponding `Msg{...}Response` type. Since: cosmos-sdk 0.45 | diff --git a/proto/cosmos/base/abci/v1beta1/abci.proto b/proto/cosmos/base/abci/v1beta1/abci.proto index 10c0b2a1d74b..3837c25d9b45 100644 --- a/proto/cosmos/base/abci/v1beta1/abci.proto +++ b/proto/cosmos/base/abci/v1beta1/abci.proto @@ -126,10 +126,13 @@ message TxMsgData { // data field is deprecated and not populated. repeated MsgData data = 1 [deprecated = true]; - // msg_responses contains the Msg handler responses type packed in Anys. + // msg_responses contains the Msg handler responses, serialized using + // Protobuf. The bytes at index i correspond to the Protobuf serialization + // of the i-th Msg's response type in the tx. It can be decoded into the + // corresponding `Msg{...}Response` type. // // Since: cosmos-sdk 0.45 - repeated google.protobuf.Any msg_responses = 2; + repeated bytes msg_responses = 2; } // SearchTxsResult defines a structure for querying txs pageable diff --git a/types/abci.pb.go b/types/abci.pb.go index ed6e1967fc8d..14a3994a061f 100644 --- a/types/abci.pb.go +++ b/types/abci.pb.go @@ -469,10 +469,13 @@ func (m *MsgData) GetData() []byte { type TxMsgData struct { // data field is deprecated and not populated. Data []*MsgData `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` // Deprecated: Do not use. - // msg_responses contains the Msg handler responses type packed in Anys. + // msg_responses contains the Msg handler responses, serialized using + // Protobuf. The bytes at index i correspond to the Protobuf serialization + // of the i-th Msg's response type in the tx. It can be decoded into the + // corresponding `Msg{...}Response` type. // // Since: cosmos-sdk 0.45 - MsgResponses []*types.Any `protobuf:"bytes,2,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` + MsgResponses [][]byte `protobuf:"bytes,2,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` } func (m *TxMsgData) Reset() { *m = TxMsgData{} } @@ -515,7 +518,7 @@ func (m *TxMsgData) GetData() []*MsgData { return nil } -func (m *TxMsgData) GetMsgResponses() []*types.Any { +func (m *TxMsgData) GetMsgResponses() [][]byte { if m != nil { return m.MsgResponses } @@ -630,65 +633,65 @@ func init() { } var fileDescriptor_4e37629bc7eb0df8 = []byte{ - // 917 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x95, 0xbf, 0x6f, 0x1b, 0x37, - 0x14, 0xc7, 0x75, 0xd2, 0xe5, 0x64, 0x3d, 0x29, 0x71, 0x41, 0x18, 0x0e, 0x9d, 0xb4, 0x92, 0x7a, - 0x49, 0x01, 0x2d, 0x39, 0x35, 0x4e, 0x51, 0x34, 0x9e, 0x92, 0x73, 0x7f, 0x19, 0x48, 0x3a, 0xd0, - 0x0a, 0x0a, 0x74, 0x11, 0x28, 0x89, 0xa1, 0x0e, 0xd1, 0x1d, 0x85, 0x23, 0xcf, 0x3e, 0x6f, 0xdd, - 0xda, 0xa9, 0xe8, 0x94, 0xa1, 0x53, 0xd7, 0xf6, 0x2f, 0xc9, 0xe8, 0x31, 0x43, 0xa1, 0xb6, 0xf6, - 0x96, 0xbf, 0xa2, 0xe0, 0x0f, 0xd9, 0x4a, 0x5d, 0x05, 0x9d, 0xee, 0xbd, 0xc7, 0xc7, 0x47, 0xf2, - 0xf3, 0xbe, 0xe4, 0xc1, 0x9d, 0xb1, 0x90, 0xa9, 0x90, 0xfd, 0x11, 0x95, 0xac, 0x4f, 0x47, 0xe3, - 0xa4, 0x7f, 0x74, 0x7f, 0xc4, 0x14, 0xbd, 0x6f, 0x9c, 0x68, 0x9e, 0x0b, 0x25, 0x10, 0xb6, 0x49, - 0x91, 0x4e, 0x8a, 0x4c, 0xdc, 0x25, 0xdd, 0xda, 0xe2, 0x82, 0x0b, 0x93, 0xd4, 0xd7, 0x96, 0xcd, - 0xbf, 0x75, 0x5b, 0xb1, 0x6c, 0xc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0xde, 0xae, 0x7c, 0x17, - 0xf2, 0x44, 0x4d, 0x8b, 0x51, 0x34, 0x16, 0x69, 0xdf, 0xfd, 0xfb, 0xec, 0xe7, 0x9e, 0x9c, 0xbc, - 0xb0, 0x3f, 0xaa, 0x51, 0x60, 0xa0, 0x3f, 0xf8, 0x27, 0x00, 0x00, 0xff, 0xff, 0x04, 0xb9, 0x0f, - 0x96, 0x1d, 0x07, 0x00, 0x00, + // 918 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x95, 0xbf, 0x6f, 0x1b, 0x37, + 0x14, 0xc7, 0x75, 0xd2, 0xe5, 0x64, 0x3d, 0xc9, 0x71, 0x41, 0x18, 0x0e, 0x9d, 0xb4, 0x92, 0x7a, + 0x4e, 0x01, 0x2d, 0x39, 0x35, 0x4e, 0x51, 0x34, 0x9e, 0x92, 0x73, 0x7f, 0x19, 0x48, 0x3a, 0xd0, + 0x0a, 0x0a, 0x74, 0x11, 0x28, 0x89, 0xa1, 0x0e, 0xd1, 0x1d, 0xd5, 0x23, 0xcf, 0x3e, 0x6f, 0x1d, + 0x3b, 0x15, 0x9d, 0x32, 0x74, 0xea, 0xda, 0xfe, 0x25, 0x19, 0x3d, 0x66, 0x28, 0xdc, 0xd6, 0xde, + 0xf2, 0x57, 0x14, 0xfc, 0x21, 0x5b, 0x71, 0xaa, 0x4c, 0xf7, 0xde, 0xe3, 0xe3, 0x23, 0xf9, 0x79, + 0x5f, 0xf2, 0x60, 0x67, 0x2c, 0x64, 0x2a, 0x64, 0x7f, 0x44, 0x25, 0xeb, 0xd3, 0xd1, 0x38, 0xe9, + 0x1f, 0xdd, 0x1f, 0x31, 0x45, 0xef, 0x1b, 0x27, 0x9a, 0xe7, 0x42, 0x09, 0x84, 0x6d, 0x52, 0xa4, + 0x93, 0x22, 0x13, 0x77, 0x49, 0xb7, 0x37, 0xb9, 0xe0, 0xc2, 0x24, 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, + 0xe7, 0xbc, 0xed, 0xfd, 0x7a, 0xd1, 0xae, 0x9c, 0x5e, 0xb4, 0x2b, 0xaf, 0x2f, 0xda, 0x95, 0x1f, + 0x42, 0x9e, 0xa8, 0x69, 0x31, 0x8a, 0xc6, 0x22, 0xed, 0xbb, 0x9f, 0x9c, 0xfd, 0xdc, 0x93, 0x93, + 0x17, 0xf6, 0x8f, 0x34, 0x0a, 0x8c, 0x84, 0x1f, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0xc3, 0x97, + 0x3c, 0x6d, 0x06, 0x07, 0x00, 0x00, } func (m *TxResponse) Marshal() (dAtA []byte, err error) { @@ -1134,14 +1137,9 @@ func (m *TxMsgData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = l if len(m.MsgResponses) > 0 { for iNdEx := len(m.MsgResponses) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.MsgResponses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAbci(dAtA, i, uint64(size)) - } + i -= len(m.MsgResponses[iNdEx]) + copy(dAtA[i:], m.MsgResponses[iNdEx]) + i = encodeVarintAbci(dAtA, i, uint64(len(m.MsgResponses[iNdEx]))) i-- dAtA[i] = 0x12 } @@ -1438,8 +1436,8 @@ func (m *TxMsgData) Size() (n int) { } } if len(m.MsgResponses) > 0 { - for _, e := range m.MsgResponses { - l = e.Size() + for _, b := range m.MsgResponses { + l = len(b) n += 1 + l + sovAbci(uint64(l)) } } @@ -1535,14 +1533,9 @@ func (this *TxMsgData) String() string { repeatedStringForData += strings.Replace(f.String(), "MsgData", "MsgData", 1) + "," } repeatedStringForData += "}" - repeatedStringForMsgResponses := "[]*Any{" - for _, f := range this.MsgResponses { - repeatedStringForMsgResponses += strings.Replace(fmt.Sprintf("%v", f), "Any", "types.Any", 1) + "," - } - repeatedStringForMsgResponses += "}" s := strings.Join([]string{`&TxMsgData{`, `Data:` + repeatedStringForData + `,`, - `MsgResponses:` + repeatedStringForMsgResponses + `,`, + `MsgResponses:` + fmt.Sprintf("%v", this.MsgResponses) + `,`, `}`, }, "") return s @@ -2902,7 +2895,7 @@ func (m *TxMsgData) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MsgResponses", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAbci @@ -2912,25 +2905,23 @@ func (m *TxMsgData) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthAbci } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthAbci } if postIndex > l { return io.ErrUnexpectedEOF } - m.MsgResponses = append(m.MsgResponses, &types.Any{}) - if err := m.MsgResponses[len(m.MsgResponses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.MsgResponses = append(m.MsgResponses, make([]byte, postIndex-iNdEx)) + copy(m.MsgResponses[len(m.MsgResponses)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index fe1a6150bc4a..0424afba82e4 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -137,10 +137,6 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPC() { } func (s IntegrationTestSuite) TestSimulateTx_GRPCGateway() { - // Skipping this test, pending on how to decode MsgResponses with interface registry. - // TODO https://github.com/cosmos/cosmos-sdk/issues/10496#issuecomment-982561928 - s.T().Skip() - val := s.network.Validators[0] txBuilder := s.mkTxBuilder() // Convert the txBuilder to a tx.Tx. From 310fee5e19ea66f1753721ebbccb65fc6f1ff27e Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:58:49 +0100 Subject: [PATCH 27/43] Fix grpc-gateway test --- x/auth/tx/service.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index a0deedae6aa2..3a85eb04f050 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -119,6 +119,14 @@ func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (* return nil, err } + // Don't show the MsgResponses explicity, since they are already in + // result.Data. + // Moreover, `result.MsgResponses` are Anys, which means that we need to + // register all `Msg{...}Response` concrete types in the interface registry + // to make it work. + // This is doable, but not necessary for a first version. + result.MsgResponses = nil + return &txtypes.SimulateResponse{ GasInfo: &gasInfo, Result: result, From 39bee75f03afc98743ee5eb13c1d7874bb7a4b4b Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:11:10 +0100 Subject: [PATCH 28/43] Make proto-gen --- docs/core/proto-docs.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index c3cdc2129300..8e29ecd923e1 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2424,6 +2424,9 @@ tags are stringified and the log is JSON decoded. | `gas_used` | [int64](#int64) | | Amount of gas consumed by transaction. | | `tx` | [google.protobuf.Any](#google.protobuf.Any) | | The request transaction bytes. | | `timestamp` | [string](#string) | | Time of the previous block. For heights > 1, it's the weighted median of the timestamps of the valid votes in the block.LastCommit. For height == 1, it's genesis time. | +| `events` | [tendermint.abci.Event](#tendermint.abci.Event) | repeated | Events defines all the events emitted by processing a transaction. Note, these events include those emitted by processing all the messages and those emitted from the ante handler. Whereas Logs contains the events, with additional metadata, emitted only by processing the messages. + +Since: cosmos-sdk 0.42.11, 0.44.5, 0.45 | From 39f0bccf8012acab90e3053367534a403f6be148 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:26:53 +0100 Subject: [PATCH 29/43] Automagically register MsgResponse --- server/grpc/reflection/v2alpha1/reflection.go | 2 +- server/rosetta/client_online.go | 3 ++- std/codec.go | 8 +++---- types/codec.go | 22 ------------------- types/msgservice/msg_service.go | 5 ++++- types/result.go | 1 - types/tx/msgs.go | 11 ++++++++++ types/tx/types.go | 12 +++++++++- x/auth/tx/service.go | 8 ------- x/auth/tx/service_test.go | 4 +++- 10 files changed, 35 insertions(+), 41 deletions(-) delete mode 100644 types/codec.go diff --git a/server/grpc/reflection/v2alpha1/reflection.go b/server/grpc/reflection/v2alpha1/reflection.go index 789f9e35ff86..5e33b4ab2bc9 100644 --- a/server/grpc/reflection/v2alpha1/reflection.go +++ b/server/grpc/reflection/v2alpha1/reflection.go @@ -169,7 +169,7 @@ func newTxDescriptor(ir codectypes.InterfaceRegistry) (*TxDescriptor, error) { return nil, fmt.Errorf("unable to get *tx.Tx protobuf name") } // get msgs - sdkMsgImplementers := ir.ListImplementations(sdk.MsgInterfaceProtoName) + sdkMsgImplementers := ir.ListImplementations(tx.MsgInterfaceProtoName) msgsDesc := make([]*MsgDescriptor, 0, len(sdkMsgImplementers)) diff --git a/server/rosetta/client_online.go b/server/rosetta/client_online.go index dc46e187e8cc..4f21485715b4 100644 --- a/server/rosetta/client_online.go +++ b/server/rosetta/client_online.go @@ -22,6 +22,7 @@ import ( crgtypes "github.com/cosmos/cosmos-sdk/server/rosetta/lib/types" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/version" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" auth "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -60,7 +61,7 @@ func NewClient(cfg *Config) (*Client, error) { txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes) var supportedOperations []string - for _, ii := range cfg.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) { + for _, ii := range cfg.InterfaceRegistry.ListImplementations(tx.MsgInterfaceProtoName) { resolvedMsg, err := cfg.InterfaceRegistry.Resolve(ii) if err != nil { continue diff --git a/std/codec.go b/std/codec.go index 7310d75a25fd..5a88b2a042f3 100644 --- a/std/codec.go +++ b/std/codec.go @@ -4,19 +4,17 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - txtypes "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx" ) // RegisterLegacyAminoCodec registers types with the Amino codec. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - sdk.RegisterLegacyAminoCodec(cdc) + tx.RegisterLegacyAminoCodec(cdc) cryptocodec.RegisterCrypto(cdc) } // RegisterInterfaces registers Interfaces from sdk/types, vesting, crypto, tx. func RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) { - sdk.RegisterInterfaces(interfaceRegistry) - txtypes.RegisterInterfaces(interfaceRegistry) + tx.RegisterInterfaces(interfaceRegistry) cryptocodec.RegisterInterfaces(interfaceRegistry) } diff --git a/types/codec.go b/types/codec.go deleted file mode 100644 index 69202d488fc6..000000000000 --- a/types/codec.go +++ /dev/null @@ -1,22 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" -) - -const ( - // MsgInterfaceProtoName defines the protobuf name of the cosmos Msg interface - MsgInterfaceProtoName = "cosmos.base.v1beta1.Msg" -) - -// RegisterLegacyAminoCodec registers the sdk message type. -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterInterface((*Msg)(nil), nil) - cdc.RegisterInterface((*Tx)(nil), nil) -} - -// RegisterInterfaces registers the sdk message type. -func RegisterInterfaces(registry types.InterfaceRegistry) { - registry.RegisterInterface(MsgInterfaceProtoName, (*Msg)(nil)) -} diff --git a/types/msgservice/msg_service.go b/types/msgservice/msg_service.go index 382913590cad..08140154c131 100644 --- a/types/msgservice/msg_service.go +++ b/types/msgservice/msg_service.go @@ -8,6 +8,8 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/gogo/protobuf/proto" ) // RegisterMsgServiceDesc registers all type_urls from Msg services described @@ -21,7 +23,7 @@ func RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.Serv // NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry. // This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself. // We use a no-op interceptor to avoid actually calling into the handler itself. - _, _ = methodHandler(nil, context.Background(), func(i interface{}) error { + r, _ := methodHandler(nil, context.Background(), func(i interface{}) error { msg, ok := i.(sdk.Msg) if !ok { // We panic here because there is no other alternative and the app cannot be initialized correctly @@ -35,6 +37,7 @@ func RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.Serv return nil }, noopInterceptor) + registry.RegisterImplementations((*tx.MsgResponse)(nil), r.(proto.Message)) } } diff --git a/types/result.go b/types/result.go index b6d91b8cfaaf..38787e8eb5eb 100644 --- a/types/result.go +++ b/types/result.go @@ -9,7 +9,6 @@ import ( "github.com/gogo/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/rpc/coretypes" - "sigs.k8s.io/yaml" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/types/tx/msgs.go b/types/tx/msgs.go index 4c4ad9dcd04a..f2d6980d6182 100644 --- a/types/tx/msgs.go +++ b/types/tx/msgs.go @@ -7,6 +7,17 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +const ( + // MsgInterfaceProtoName defines the protobuf name of the cosmos Msg interface + MsgInterfaceProtoName = "cosmos.base.v1beta1.Msg" + msgResponseInterfaceProtoName = "cosmos.tx.v1beta1.MsgResponse" +) + +// MsgResponse is the interface all Msg server handlers' response types need to +// implement. It's the interface that's representing all Msg responses packin +// in Anys. +type MsgResponse interface{} + // SetMsgs takes a slice of sdk.Msg's and turn them into Any's. func SetMsgs(msgs []sdk.Msg) ([]*types.Any, error) { anys := make([]*types.Any, len(msgs)) diff --git a/types/tx/types.go b/types/tx/types.go index 43982731f1c4..681e09cd0f58 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -3,6 +3,7 @@ package tx import ( "fmt" + "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" @@ -192,8 +193,17 @@ func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { return unpacker.UnpackAny(m.PublicKey, new(cryptotypes.PubKey)) } -// RegisterInterfaces registers the sdk.Tx interface. +// RegisterLegacyAminoCodec registers the sdk Tx and Msg types. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterInterface((*sdk.Msg)(nil), nil) + cdc.RegisterInterface((*sdk.Tx)(nil), nil) +} + +// RegisterInterfaces registers the sdk.Tx and Msg interfaces. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterInterface(MsgInterfaceProtoName, (*sdk.Msg)(nil)) + registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) + registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil)) registry.RegisterImplementations((*sdk.Tx)(nil), &Tx{}) } diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 3a85eb04f050..a0deedae6aa2 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -119,14 +119,6 @@ func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (* return nil, err } - // Don't show the MsgResponses explicity, since they are already in - // result.Data. - // Moreover, `result.MsgResponses` are Anys, which means that we need to - // register all `Msg{...}Response` concrete types in the interface registry - // to make it work. - // This is doable, but not necessary for a first version. - result.MsgResponses = nil - return &txtypes.SimulateResponse{ GasInfo: &gasInfo, Result: result, diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 0424afba82e4..06242bd50eaa 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -129,6 +129,7 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPC() { // - Sending Amount to recipient: coin_spent, coin_received, transfer and message.sender= // - Msg events: message.module=bank and message.action=/cosmos.bank.v1beta1.MsgSend s.Require().Equal(len(res.GetResult().GetEvents()), 13) + s.Require().Len(res.GetResult().MsgResponses, 1) // Check the result and gas used are correct. s.Require().True(res.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty. } @@ -171,7 +172,8 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPCGateway() { s.Require().NoError(err) // Check the result and gas used are correct. s.Require().Equal(len(result.GetResult().GetEvents()), 13) // See TestSimulateTx_GRPC for the 13 events. - s.Require().True(result.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty. + s.Require().Len(result.GetResult().MsgResponses, 1) + s.Require().True(result.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty. } }) } From 72b0c303500d34723a3f707770300254f32e07fa Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 1 Dec 2021 13:09:26 +0530 Subject: [PATCH 30/43] review changes --- x/auth/middleware/run_msgs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index dbb77f94e1b7..6278d5c023d2 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -30,6 +30,6 @@ func (s *MWTestSuite) TestRunMsgs() { res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) - s.Require().NotEmpty(res.MsgResponses) + s.Require().Len(res.MsgResponses, 1) s.Require().Equal(fmt.Sprintf("/%s", proto.MessageName(&testdata.MsgCreateDogResponse{})), res.MsgResponses[0].TypeUrl) } From cf51edff0c43064b8d72257909eef50a9ee8d9bd Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 09:46:44 +0100 Subject: [PATCH 31/43] Use froydi's trick --- types/msgservice/msg_service.go | 82 ++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/types/msgservice/msg_service.go b/types/msgservice/msg_service.go index 08140154c131..f8dc5aff5029 100644 --- a/types/msgservice/msg_service.go +++ b/types/msgservice/msg_service.go @@ -1,47 +1,73 @@ package msgservice import ( - "context" + "bytes" + "compress/gzip" "fmt" + "io/ioutil" + "reflect" + "github.com/gogo/protobuf/proto" "google.golang.org/grpc" + proto2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/descriptorpb" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/gogo/protobuf/proto" ) // RegisterMsgServiceDesc registers all type_urls from Msg services described // in `sd` into the registry. func RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.ServiceDesc) { - // Adds a top-level type_url based on the Msg service name. - for _, method := range sd.Methods { - fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName) - methodHandler := method.Handler - - // NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry. - // This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself. - // We use a no-op interceptor to avoid actually calling into the handler itself. - r, _ := methodHandler(nil, context.Background(), func(i interface{}) error { - msg, ok := i.(sdk.Msg) - if !ok { - // We panic here because there is no other alternative and the app cannot be initialized correctly - // this should only happen if there is a problem with code generation in which case the app won't - // work correctly anyway. - panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod)) - } - - registry.RegisterImplementations((*sdk.Msg)(nil), msg) - - return nil - }, noopInterceptor) - - registry.RegisterImplementations((*tx.MsgResponse)(nil), r.(proto.Message)) + fdBytesUnzipped := unzip(proto.FileDescriptor(sd.Metadata.(string))) + if fdBytesUnzipped == nil { + panic(fmt.Errorf("error unzipping file description for MsgService %s", sd.ServiceName)) + } + + fdRaw := &descriptorpb.FileDescriptorProto{} + err := proto2.Unmarshal(fdBytesUnzipped, fdRaw) + if err != nil { + panic(err) + } + + fd, err := protodesc.FileOptions{ + AllowUnresolvable: true, + }.New(fdRaw, nil) + if err != nil { + panic(err) + } + + prefSd := fd.Services().ByName(protoreflect.FullName(sd.ServiceName).Name()) + for i := 0; i < prefSd.Methods().Len(); i++ { + md := prefSd.Methods().Get(i) + requestDesc := md.Input() + responseDesc := md.Output() + + reqTyp := proto.MessageType(string(requestDesc.FullName())) + respTyp := proto.MessageType(string(responseDesc.FullName())) + + // Register sdk.Msg and sdk.MsgResponse to the registry. + registry.RegisterImplementations((*sdk.Msg)(nil), reflect.New(reqTyp).Elem().Interface().(proto.Message)) + registry.RegisterImplementations((*tx.MsgResponse)(nil), reflect.New(respTyp).Elem().Interface().(proto.Message)) } } -// gRPC NOOP interceptor -func noopInterceptor(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) { - return nil, nil +func unzip(b []byte) []byte { + if b == nil { + return nil + } + r, err := gzip.NewReader(bytes.NewReader(b)) + if err != nil { + panic(err) + } + + unzipped, err := ioutil.ReadAll(r) + if err != nil { + panic(err) + } + + return unzipped } From 5c935171fdef852122f644dd9f621add1248fdee Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 09:46:50 +0100 Subject: [PATCH 32/43] Use Any in TxMsgData --- baseapp/abci.go | 7 +- docs/core/proto-docs.md | 2 +- proto/cosmos/base/abci/v1beta1/abci.proto | 7 +- types/abci.pb.go | 159 ++++++++++++---------- 4 files changed, 88 insertions(+), 87 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 5c3fca2c45ef..b3569ff8f53c 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -909,12 +909,7 @@ func splitPath(requestPath string) (path []string) { // makeABCIData generates the Data field to be sent to ABCI Check/DeliverTx. func makeABCIData(txRes tx.Response) ([]byte, error) { - msgResBz := make([][]byte, len(txRes.MsgResponses)) - for i, any := range txRes.MsgResponses { - msgResBz[i] = any.Value - } - - return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResBz}) + return proto.Marshal(&sdk.TxMsgData{MsgResponses: txRes.MsgResponses}) } // convertTxResponseToCheckTx converts a tx.Response into a abci.ResponseCheckTx. diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 8e29ecd923e1..7dd29cfbd7d2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2394,7 +2394,7 @@ for each message. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `data` | [MsgData](#cosmos.base.abci.v1beta1.MsgData) | repeated | **Deprecated.** data field is deprecated and not populated. | -| `msg_responses` | [bytes](#bytes) | repeated | msg_responses contains the Msg handler responses, serialized using Protobuf. The bytes at index i correspond to the Protobuf serialization of the i-th Msg's response type in the tx. It can be decoded into the corresponding `Msg{...}Response` type. +| `msg_responses` | [google.protobuf.Any](#google.protobuf.Any) | repeated | msg_responses contains the Msg handler responses packed into Anys. Since: cosmos-sdk 0.45 | diff --git a/proto/cosmos/base/abci/v1beta1/abci.proto b/proto/cosmos/base/abci/v1beta1/abci.proto index 64330a163172..b9a5ae1a83bc 100644 --- a/proto/cosmos/base/abci/v1beta1/abci.proto +++ b/proto/cosmos/base/abci/v1beta1/abci.proto @@ -133,13 +133,10 @@ message TxMsgData { // data field is deprecated and not populated. repeated MsgData data = 1 [deprecated = true]; - // msg_responses contains the Msg handler responses, serialized using - // Protobuf. The bytes at index i correspond to the Protobuf serialization - // of the i-th Msg's response type in the tx. It can be decoded into the - // corresponding `Msg{...}Response` type. + // msg_responses contains the Msg handler responses packed into Anys. // // Since: cosmos-sdk 0.45 - repeated bytes msg_responses = 2; + repeated google.protobuf.Any msg_responses = 2; } // SearchTxsResult defines a structure for querying txs pageable diff --git a/types/abci.pb.go b/types/abci.pb.go index b1c08776cdf3..834b221c9006 100644 --- a/types/abci.pb.go +++ b/types/abci.pb.go @@ -476,13 +476,10 @@ func (m *MsgData) GetData() []byte { type TxMsgData struct { // data field is deprecated and not populated. Data []*MsgData `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` // Deprecated: Do not use. - // msg_responses contains the Msg handler responses, serialized using - // Protobuf. The bytes at index i correspond to the Protobuf serialization - // of the i-th Msg's response type in the tx. It can be decoded into the - // corresponding `Msg{...}Response` type. + // msg_responses contains the Msg handler responses packed into Anys. // // Since: cosmos-sdk 0.45 - MsgResponses [][]byte `protobuf:"bytes,2,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` + MsgResponses []*types.Any `protobuf:"bytes,2,rep,name=msg_responses,json=msgResponses,proto3" json:"msg_responses,omitempty"` } func (m *TxMsgData) Reset() { *m = TxMsgData{} } @@ -525,7 +522,7 @@ func (m *TxMsgData) GetData() []*MsgData { return nil } -func (m *TxMsgData) GetMsgResponses() [][]byte { +func (m *TxMsgData) GetMsgResponses() []*types.Any { if m != nil { return m.MsgResponses } @@ -640,65 +637,65 @@ func init() { } var fileDescriptor_4e37629bc7eb0df8 = []byte{ - // 926 bytes of a gzipped FileDescriptorProto + // 924 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x3f, 0x6f, 0x1b, 0x37, - 0x14, 0xd7, 0x49, 0x97, 0x93, 0xf5, 0x24, 0xc7, 0x05, 0x61, 0x38, 0x74, 0xd2, 0x4a, 0xaa, 0x9c, + 0x14, 0xd7, 0x49, 0x97, 0x93, 0xf5, 0x24, 0xc7, 0x05, 0x61, 0x38, 0x74, 0xd2, 0x4a, 0xaa, 0x92, 0x02, 0x5a, 0x72, 0x6a, 0x9c, 0xa0, 0x68, 0x32, 0x25, 0x72, 0xff, 0x19, 0x48, 0x3a, 0x9c, 0x15, - 0x14, 0xe8, 0x22, 0x50, 0x12, 0x43, 0x1d, 0xa2, 0x3b, 0xaa, 0x47, 0xca, 0x3e, 0x6f, 0x1d, 0x3b, - 0x15, 0x9d, 0x3a, 0x74, 0xea, 0xda, 0x7e, 0x92, 0x0c, 0x1d, 0x3c, 0x66, 0x28, 0xd4, 0xd6, 0xde, - 0xf2, 0x29, 0x0a, 0x3e, 0x52, 0xb2, 0xe2, 0x54, 0x41, 0xa7, 0x7b, 0xff, 0xf8, 0xf8, 0xde, 0xef, - 0xfd, 0xee, 0x11, 0xf6, 0x86, 0x52, 0x25, 0x52, 0x75, 0x06, 0x4c, 0xf1, 0x0e, 0x1b, 0x0c, 0xe3, - 0xce, 0xf1, 0xdd, 0x01, 0xd7, 0xec, 0x2e, 0x2a, 0xe1, 0x34, 0x93, 0x5a, 0x12, 0x6a, 0x83, 0x42, - 0x13, 0x14, 0xa2, 0xdd, 0x05, 0xdd, 0xdc, 0x16, 0x52, 0x48, 0x0c, 0xea, 0x18, 0xc9, 0xc6, 0xdf, - 0xbc, 0xa5, 0x79, 0x3a, 0xe2, 0x59, 0x12, 0xa7, 0xda, 0xe6, 0xd4, 0xa7, 0x53, 0xae, 0x9c, 0x73, - 0x57, 0x48, 0x29, 0x26, 0xbc, 0x83, 0xda, 0x60, 0xf6, 0xbc, 0xc3, 0xd2, 0x53, 0xeb, 0x6a, 0xfd, - 0x51, 0x02, 0xe8, 0xe5, 0x11, 0x57, 0x53, 0x99, 0x2a, 0x4e,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xab, 0xe6, 0x08, 0x50, 0xd9, 0x37, 0xb2, 0x61, 0xac, 0x8d, 0xb5, 0x74, 0xb3, + 0x8a, 0xc9, 0x33, 0x65, 0x82, 0xf7, 0xd3, 0x59, 0x32, 0xe0, 0x19, 0x6e, 0x5f, 0x97, 0x67, 0xc5, + 0x1c, 0x81, 0x51, 0xbe, 0x46, 0x99, 0xdc, 0x05, 0xd4, 0xfa, 0x98, 0x1a, 0xb7, 0xb2, 0xdf, 0xbd, + 0xfe, 0x66, 0xde, 0x58, 0xb1, 0x46, 0x15, 0x23, 0xf7, 0x8c, 0x68, 0xae, 0x9d, 0xc4, 0x49, 0xac, + 0x71, 0x57, 0xfb, 0x91, 0x55, 0xc8, 0x27, 0x50, 0xd2, 0xb9, 0xa2, 0x01, 0x22, 0x71, 0x67, 0x3d, + 0x9a, 0x17, 0x2f, 0x4c, 0x64, 0x0e, 0x58, 0x40, 0xba, 0x8f, 0x5f, 0xff, 0x53, 0x2f, 0xbc, 0x3a, + 0xab, 0x7b, 0xa7, 0x67, 0x75, 0xef, 0xef, 0xb3, 0xba, 0xf7, 0xd3, 0x79, 0xbd, 0x70, 0x7a, 0x5e, + 0x2f, 0xbc, 0x3e, 0xaf, 0x17, 0xbe, 0x6d, 0x89, 0x58, 0x8f, 0x67, 0x83, 0x70, 0x28, 0x93, 0x8e, + 0x7b, 0x31, 0xed, 0xe7, 0xae, 0x1a, 0xbd, 0xb4, 0xcf, 0xdb, 0x20, 0x40, 0xd0, 0xef, 0xff, 0x1b, + 0x00, 0x00, 0xff, 0xff, 0x41, 0x3c, 0xca, 0x00, 0x53, 0x07, 0x00, 0x00, } func (m *TxResponse) Marshal() (dAtA []byte, err error) { @@ -1158,9 +1155,14 @@ func (m *TxMsgData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = l if len(m.MsgResponses) > 0 { for iNdEx := len(m.MsgResponses) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.MsgResponses[iNdEx]) - copy(dAtA[i:], m.MsgResponses[iNdEx]) - i = encodeVarintAbci(dAtA, i, uint64(len(m.MsgResponses[iNdEx]))) + { + size, err := m.MsgResponses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAbci(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x12 } @@ -1463,8 +1465,8 @@ func (m *TxMsgData) Size() (n int) { } } if len(m.MsgResponses) > 0 { - for _, b := range m.MsgResponses { - l = len(b) + for _, e := range m.MsgResponses { + l = e.Size() n += 1 + l + sovAbci(uint64(l)) } } @@ -1560,9 +1562,14 @@ func (this *TxMsgData) String() string { repeatedStringForData += strings.Replace(f.String(), "MsgData", "MsgData", 1) + "," } repeatedStringForData += "}" + repeatedStringForMsgResponses := "[]*Any{" + for _, f := range this.MsgResponses { + repeatedStringForMsgResponses += strings.Replace(fmt.Sprintf("%v", f), "Any", "types.Any", 1) + "," + } + repeatedStringForMsgResponses += "}" s := strings.Join([]string{`&TxMsgData{`, `Data:` + repeatedStringForData + `,`, - `MsgResponses:` + fmt.Sprintf("%v", this.MsgResponses) + `,`, + `MsgResponses:` + repeatedStringForMsgResponses + `,`, `}`, }, "") return s @@ -2956,7 +2963,7 @@ func (m *TxMsgData) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MsgResponses", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAbci @@ -2966,23 +2973,25 @@ func (m *TxMsgData) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthAbci } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthAbci } if postIndex > l { return io.ErrUnexpectedEOF } - m.MsgResponses = append(m.MsgResponses, make([]byte, postIndex-iNdEx)) - copy(m.MsgResponses[len(m.MsgResponses)-1], dAtA[iNdEx:postIndex]) + m.MsgResponses = append(m.MsgResponses, &types.Any{}) + if err := m.MsgResponses[len(m.MsgResponses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex From 19b718900e2a89ef99b5f0cee8368d000a9634ea Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 09:59:51 +0100 Subject: [PATCH 33/43] Finally remove API breaking change --- server/grpc/reflection/v2alpha1/reflection.go | 2 +- server/rosetta/client_online.go | 3 +-- std/codec.go | 8 ++++--- types/codec.go | 22 +++++++++++++++++++ types/tx/msgs.go | 4 +--- types/tx/types.go | 1 - 6 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 types/codec.go diff --git a/server/grpc/reflection/v2alpha1/reflection.go b/server/grpc/reflection/v2alpha1/reflection.go index 5e33b4ab2bc9..789f9e35ff86 100644 --- a/server/grpc/reflection/v2alpha1/reflection.go +++ b/server/grpc/reflection/v2alpha1/reflection.go @@ -169,7 +169,7 @@ func newTxDescriptor(ir codectypes.InterfaceRegistry) (*TxDescriptor, error) { return nil, fmt.Errorf("unable to get *tx.Tx protobuf name") } // get msgs - sdkMsgImplementers := ir.ListImplementations(tx.MsgInterfaceProtoName) + sdkMsgImplementers := ir.ListImplementations(sdk.MsgInterfaceProtoName) msgsDesc := make([]*MsgDescriptor, 0, len(sdkMsgImplementers)) diff --git a/server/rosetta/client_online.go b/server/rosetta/client_online.go index 4f21485715b4..dc46e187e8cc 100644 --- a/server/rosetta/client_online.go +++ b/server/rosetta/client_online.go @@ -22,7 +22,6 @@ import ( crgtypes "github.com/cosmos/cosmos-sdk/server/rosetta/lib/types" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" - "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/version" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" auth "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -61,7 +60,7 @@ func NewClient(cfg *Config) (*Client, error) { txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes) var supportedOperations []string - for _, ii := range cfg.InterfaceRegistry.ListImplementations(tx.MsgInterfaceProtoName) { + for _, ii := range cfg.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) { resolvedMsg, err := cfg.InterfaceRegistry.Resolve(ii) if err != nil { continue diff --git a/std/codec.go b/std/codec.go index 5a88b2a042f3..7310d75a25fd 100644 --- a/std/codec.go +++ b/std/codec.go @@ -4,17 +4,19 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/types/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) // RegisterLegacyAminoCodec registers types with the Amino codec. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - tx.RegisterLegacyAminoCodec(cdc) + sdk.RegisterLegacyAminoCodec(cdc) cryptocodec.RegisterCrypto(cdc) } // RegisterInterfaces registers Interfaces from sdk/types, vesting, crypto, tx. func RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) { - tx.RegisterInterfaces(interfaceRegistry) + sdk.RegisterInterfaces(interfaceRegistry) + txtypes.RegisterInterfaces(interfaceRegistry) cryptocodec.RegisterInterfaces(interfaceRegistry) } diff --git a/types/codec.go b/types/codec.go new file mode 100644 index 000000000000..69202d488fc6 --- /dev/null +++ b/types/codec.go @@ -0,0 +1,22 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" +) + +const ( + // MsgInterfaceProtoName defines the protobuf name of the cosmos Msg interface + MsgInterfaceProtoName = "cosmos.base.v1beta1.Msg" +) + +// RegisterLegacyAminoCodec registers the sdk message type. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterInterface((*Msg)(nil), nil) + cdc.RegisterInterface((*Tx)(nil), nil) +} + +// RegisterInterfaces registers the sdk message type. +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterInterface(MsgInterfaceProtoName, (*Msg)(nil)) +} diff --git a/types/tx/msgs.go b/types/tx/msgs.go index f2d6980d6182..25e79c4457f8 100644 --- a/types/tx/msgs.go +++ b/types/tx/msgs.go @@ -8,13 +8,11 @@ import ( ) const ( - // MsgInterfaceProtoName defines the protobuf name of the cosmos Msg interface - MsgInterfaceProtoName = "cosmos.base.v1beta1.Msg" msgResponseInterfaceProtoName = "cosmos.tx.v1beta1.MsgResponse" ) // MsgResponse is the interface all Msg server handlers' response types need to -// implement. It's the interface that's representing all Msg responses packin +// implement. It's the interface that's representing all Msg responses packed // in Anys. type MsgResponse interface{} diff --git a/types/tx/types.go b/types/tx/types.go index 681e09cd0f58..f38dd421d499 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -201,7 +201,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // RegisterInterfaces registers the sdk.Tx and Msg interfaces. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterInterface(MsgInterfaceProtoName, (*sdk.Msg)(nil)) registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil)) From ceb97a47dab8978287d911e31a01c5535f5510cc Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 10:03:13 +0100 Subject: [PATCH 34/43] Revert unnecessary stuff --- baseapp/baseapp_test.go | 2 +- server/mock/app.go | 2 +- types/tx/types.go | 11 +++-------- x/auth/middleware/index_events.go | 4 ++-- x/auth/middleware/middleware.go | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index fc2961a695b1..46051b38237b 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -134,7 +134,7 @@ func testTxHandler(options middleware.TxHandlerOptions, customTxHandlerMiddlewar middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, - middleware.NewIndexEventsMiddleware(options.IndexEvents), + middleware.NewIndexEventsTxMiddleware(options.IndexEvents), middleware.ValidateBasicMiddleware, CustomTxHandlerMiddleware(customTxHandlerMiddleware), ) diff --git a/server/mock/app.go b/server/mock/app.go index 7dce197f6fac..ff4a58fa829c 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -25,7 +25,7 @@ func testTxHandler(options middleware.TxHandlerOptions) tx.Handler { middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, - middleware.NewIndexEventsMiddleware(options.IndexEvents), + middleware.NewIndexEventsTxMiddleware(options.IndexEvents), ) } diff --git a/types/tx/types.go b/types/tx/types.go index f38dd421d499..006941b35f17 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -3,7 +3,6 @@ package tx import ( "fmt" - "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" @@ -193,13 +192,9 @@ func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { return unpacker.UnpackAny(m.PublicKey, new(cryptotypes.PubKey)) } -// RegisterLegacyAminoCodec registers the sdk Tx and Msg types. -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterInterface((*sdk.Msg)(nil), nil) - cdc.RegisterInterface((*sdk.Tx)(nil), nil) -} - -// RegisterInterfaces registers the sdk.Tx and Msg interfaces. +// RegisterInterfaces registers the sdk.Tx and MsgResponse interfaces. +// Note: the registration of sdk.Msg is done in sdk.RegisterInterfaces, but it +// could be moved inside this function. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterInterface(msgResponseInterfaceProtoName, (*MsgResponse)(nil)) diff --git a/x/auth/middleware/index_events.go b/x/auth/middleware/index_events.go index 4a5ad009daa2..2dd831417c2e 100644 --- a/x/auth/middleware/index_events.go +++ b/x/auth/middleware/index_events.go @@ -14,9 +14,9 @@ type indexEventsTxHandler struct { next tx.Handler } -// NewIndexEventsMiddleware defines a middleware to optionally only index a +// NewIndexEventsTxMiddleware defines a middleware to optionally only index a // subset of the emitted events inside the Tendermint events indexer. -func NewIndexEventsMiddleware(indexEvents map[string]struct{}) tx.Middleware { +func NewIndexEventsTxMiddleware(indexEvents map[string]struct{}) tx.Middleware { return func(txHandler tx.Handler) tx.Handler { return indexEventsTxHandler{ indexEvents: indexEvents, diff --git a/x/auth/middleware/middleware.go b/x/auth/middleware/middleware.go index 6db421d7a0bd..a17cdd291ed7 100644 --- a/x/auth/middleware/middleware.go +++ b/x/auth/middleware/middleware.go @@ -79,7 +79,7 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { RecoveryTxMiddleware, // Choose which events to index in Tendermint. Make sure no events are // emitted outside of this middleware. - NewIndexEventsMiddleware(options.IndexEvents), + NewIndexEventsTxMiddleware(options.IndexEvents), // Reject all extension options which can optionally be included in the // tx. RejectExtensionOptionsMiddleware, From 963e5b6f6a341e70e3cb8e2c91fb0fa110044bb1 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 16:03:39 +0100 Subject: [PATCH 35/43] refactor: Move TxDecoder into its own middleware --- baseapp/abci.go | 14 +----- baseapp/abci_test.go | 18 ++++---- baseapp/baseapp.go | 4 +- baseapp/baseapp_test.go | 49 +++++++------------- baseapp/grpcrouter_test.go | 2 +- baseapp/test_helpers.go | 7 +-- baseapp/util_test.go | 7 --- server/mock/app.go | 2 +- server/mock/tx.go | 21 --------- simapp/app.go | 3 +- simapp/app_test.go | 2 +- x/auth/middleware/middleware.go | 9 ++++ x/auth/middleware/run_msgs_test.go | 6 +-- x/auth/middleware/tx.go | 72 +++++++++++++++++++++++++++++ x/upgrade/types/storeloader_test.go | 4 +- 15 files changed, 118 insertions(+), 102 deletions(-) create mode 100644 x/auth/middleware/tx.go diff --git a/baseapp/abci.go b/baseapp/abci.go index b3569ff8f53c..398673bd1662 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -250,13 +250,8 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type)) } - reqTx, err := app.txDecoder(req.Tx) - if err != nil { - return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace) - } - ctx := app.getContextForTx(mode, req.Tx) - res, checkRes, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}, tx.RequestCheckTx{Type: req.Type}) + res, checkRes, err := app.txHandler.CheckTx(ctx, tx.Request{TxBytes: req.Tx}, tx.RequestCheckTx{Type: req.Type}) if err != nil { return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) } @@ -285,14 +280,9 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx } } }() - reqTx, err := app.txDecoder(req.Tx) - if err != nil { - abciRes = sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace) - return abciRes - } ctx := app.getContextForTx(runTxModeDeliver, req.Tx) - res, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}) + res, err := app.txHandler.DeliverTx(ctx, tx.Request{TxBytes: req.Tx}) if err != nil { abciRes = sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) return abciRes diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 2dee74b67e82..338c7c4d0cb3 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -25,20 +25,20 @@ func TestGetBlockRentionHeight(t *testing.T) { expected int64 }{ "defaults": { - bapp: baseapp.NewBaseApp(name, logger, db, nil), + bapp: baseapp.NewBaseApp(name, logger, db), maxAgeBlocks: 0, commitHeight: 499000, expected: 0, }, "pruning unbonding time only": { - bapp: baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetMinRetainBlocks(1)), + bapp: baseapp.NewBaseApp(name, logger, db, baseapp.SetMinRetainBlocks(1)), maxAgeBlocks: 362880, commitHeight: 499000, expected: 136120, }, "pruning iavl snapshot only": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}), baseapp.SetMinRetainBlocks(1), ), @@ -48,7 +48,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning state sync snapshot only": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3), baseapp.SetMinRetainBlocks(1), @@ -59,7 +59,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning min retention only": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetMinRetainBlocks(400000), ), maxAgeBlocks: 0, @@ -68,7 +68,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning all conditions": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}), baseapp.SetMinRetainBlocks(400000), baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3), @@ -79,7 +79,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "no pruning due to no persisted state": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}), baseapp.SetMinRetainBlocks(400000), baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3), @@ -90,7 +90,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "disable pruning": { bapp: baseapp.NewBaseApp( - name, logger, db, nil, + name, logger, db, baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}), baseapp.SetMinRetainBlocks(0), baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3), @@ -127,7 +127,7 @@ func TestBaseAppCreateQueryContextRejectsNegativeHeights(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db) proves := []bool{ false, true, diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 07713ef4fe24..0f1a1263f5c2 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -52,7 +52,6 @@ type BaseApp struct { // nolint: maligned queryRouter sdk.QueryRouter // router for redirecting query calls grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls interfaceRegistry types.InterfaceRegistry - txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx txHandler tx.Handler // txHandler for {Deliver,Check}Tx and simulations initChainer sdk.InitChainer // initialize state with validators and state blob @@ -137,7 +136,7 @@ type BaseApp struct { // nolint: maligned // // NOTE: The db is used to store the version number for now. func NewBaseApp( - name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp), + name string, logger log.Logger, db dbm.DB, options ...func(*BaseApp), ) *BaseApp { app := &BaseApp{ logger: logger, @@ -147,7 +146,6 @@ func NewBaseApp( storeLoader: DefaultStoreLoader, queryRouter: NewQueryRouter(), grpcQueryRouter: NewGRPCQueryRouter(), - txDecoder: txDecoder, fauxMerkleMode: false, } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 46051b38237b..285f09df6a4b 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -90,7 +90,7 @@ func newBaseApp(name string, options ...func(*baseapp.BaseApp)) *baseapp.BaseApp db := dbm.NewMemDB() codec := codec.NewLegacyAmino() registerTestCodec(codec) - return baseapp.NewBaseApp(name, logger, db, testTxDecoder(codec), options...) + return baseapp.NewBaseApp(name, logger, db, options...) } func registerTestCodec(cdc *codec.LegacyAmino) { @@ -245,7 +245,7 @@ func TestLoadVersion(t *testing.T) { pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, logger, db, pruningOpt) // make a cap key and mount the store err := app.LoadLatestVersion() // needed to make stores non-nil @@ -272,7 +272,7 @@ func TestLoadVersion(t *testing.T) { commitID2 := storetypes.CommitID{Version: 2, Hash: res.Data} // reload with LoadLatestVersion - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, logger, db, pruningOpt) app.MountStores() err = app.LoadLatestVersion() require.Nil(t, err) @@ -280,7 +280,7 @@ func TestLoadVersion(t *testing.T) { // reload with LoadVersion, see if you can commit the same block and get // the same result - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, logger, db, pruningOpt) err = app.LoadVersion(1) require.Nil(t, err) testLoadVersionHelper(t, app, int64(1), commitID1) @@ -359,7 +359,7 @@ func TestSetLoader(t *testing.T) { if tc.setLoader != nil { opts = append(opts, tc.setLoader) } - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -381,7 +381,7 @@ func TestVersionSetterGetter(t *testing.T) { pruningOpt := baseapp.SetPruning(storetypes.PruneDefault) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, logger, db, pruningOpt) require.Equal(t, "", app.Version()) res := app.Query(abci.RequestQuery{Path: "app/version"}) @@ -401,7 +401,7 @@ func TestLoadVersionInvalid(t *testing.T) { pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, logger, db, pruningOpt) err := app.LoadLatestVersion() require.Nil(t, err) @@ -416,7 +416,7 @@ func TestLoadVersionInvalid(t *testing.T) { commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data} // create a new app with the stores mounted under the same cap key - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, logger, db, pruningOpt) // require we can load the latest version err = app.LoadVersion(1) @@ -438,7 +438,7 @@ func TestLoadVersionPruning(t *testing.T) { pruningOpt := baseapp.SetPruning(pruningOptions) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, logger, db, pruningOpt) // make a cap key and mount the store capKey := sdk.NewKVStoreKey("key1") @@ -476,7 +476,7 @@ func TestLoadVersionPruning(t *testing.T) { } // reload with LoadLatestVersion, check it loads last version - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, logger, db, pruningOpt) app.MountStores(capKey) err = app.LoadLatestVersion() @@ -494,7 +494,7 @@ func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight in func TestOptionFunction(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() - bap := baseapp.NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name")) + bap := baseapp.NewBaseApp("starting name", logger, db, testChangeNameHelper("new name")) require.Equal(t, bap.GetName(), "new name", "BaseApp should have had name changed via option function") } @@ -504,23 +504,6 @@ func testChangeNameHelper(name string) func(*baseapp.BaseApp) { } } -// Test that txs can be unmarshalled and read and that -// correct error codes are returned when not -func TestTxDecoder(t *testing.T) { - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - - app := newBaseApp(t.Name()) - tx := newTxCounter(1, 0) - txBytes := codec.MustMarshal(tx) - - dTx, err := app.TxDecoder(txBytes) - require.NoError(t, err) - - cTx := dTx.(txTest) - require.Equal(t, tx.Counter, cTx.Counter) -} - // Test that Info returns the latest committed state. func TestInfo(t *testing.T) { app := newBaseApp(t.Name()) @@ -589,7 +572,7 @@ func TestInitChainer(t *testing.T) { // we can reload the same app later db := dbm.NewMemDB() logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") app.MountStores(capKey, capKey2) @@ -644,7 +627,7 @@ func TestInitChainer(t *testing.T) { require.Equal(t, value, res.Value) // reload app - app = baseapp.NewBaseApp(name, logger, db, nil) + app = baseapp.NewBaseApp(name, logger, db) app.SetInitChainer(initChainer) app.MountStores(capKey, capKey2) err = app.LoadLatestVersion() // needed to make stores non-nil @@ -668,7 +651,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db) app.InitChain( abci.RequestInitChain{ @@ -684,7 +667,7 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db) app.InitChain( abci.RequestInitChain{ @@ -2074,7 +2057,7 @@ func TestBaseApp_EndBlock(t *testing.T) { }, } - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db) app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) app.InitChain(abci.RequestInitChain{ ConsensusParams: cp, diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index e22e77a61de0..ca7a6e9b5486 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -55,7 +55,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) { db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := baseapp.NewBaseApp("test", logger, db, encCfg.TxConfig.TxDecoder()) + app := baseapp.NewBaseApp("test", logger, db) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) testdata.RegisterInterfaces(encCfg.InterfaceRegistry) diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index bc837e3cc595..6b770499c70b 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -36,13 +36,8 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, sdkTx sdk.Tx) (sdk.GasInfo // Simulate executes a tx in simulate mode to get result and gas info. func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { - sdkTx, err := app.txDecoder(txBytes) - if err != nil { - return sdk.GasInfo{}, nil, err - } - ctx := app.getContextForTx(runTxModeSimulate, txBytes) - res, err := app.txHandler.SimulateTx(ctx, tx.Request{Tx: sdkTx, TxBytes: txBytes}) + res, err := app.txHandler.SimulateTx(ctx, tx.Request{TxBytes: txBytes}) gasInfo := sdk.GasInfo{ GasWanted: res.GasWanted, GasUsed: res.GasUsed, diff --git a/baseapp/util_test.go b/baseapp/util_test.go index 5f7504af85ec..7244aff8307a 100644 --- a/baseapp/util_test.go +++ b/baseapp/util_test.go @@ -45,13 +45,6 @@ func (app *BaseApp) GetName() string { return app.name } -// GetName return name. -// -// This method is only accessible in baseapp tests. -func (app *BaseApp) TxDecoder(txBytes []byte) (sdk.Tx, error) { - return app.txDecoder(txBytes) -} - // CreateQueryContext calls app's createQueryContext. // // This method is only accessible in baseapp tests. diff --git a/server/mock/app.go b/server/mock/app.go index ff4a58fa829c..9de4420531f0 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -42,7 +42,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { capKeyMainStore := sdk.NewKVStoreKey("main") // Create BaseApp. - baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx) + baseApp := bam.NewBaseApp("kvstore", logger, db) // Set mounts for BaseApp's MultiStore. baseApp.MountStores(capKeyMainStore) diff --git a/server/mock/tx.go b/server/mock/tx.go index bfa6e6ad6b4b..0bd381443a45 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -2,12 +2,10 @@ package mock import ( - "bytes" "fmt" "math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/middleware" ) @@ -70,22 +68,3 @@ func (tx kvstoreTx) GetSigners() []sdk.AccAddress { func (tx kvstoreTx) GetGas() uint64 { return math.MaxUint64 } - -// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has -// all the signatures and can be used to authenticate. -func decodeTx(txBytes []byte) (sdk.Tx, error) { - var tx sdk.Tx - - split := bytes.Split(txBytes, []byte("=")) - if len(split) == 1 { - k := split[0] - tx = &kvstoreTx{k, k, txBytes} - } else if len(split) == 2 { - k, v := split[0], split[1] - tx = &kvstoreTx{k, v, txBytes} - } else { - return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='") - } - - return tx, nil -} diff --git a/simapp/app.go b/simapp/app.go index 3598f9de1f52..51306e498bd4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -205,7 +205,7 @@ func NewSimApp( legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) @@ -431,6 +431,7 @@ func (app *SimApp) setTxHandler(txConfig client.TxConfig, indexEventsStr []strin FeegrantKeeper: app.FeeGrantKeeper, SignModeHandler: txConfig.SignModeHandler(), SigGasConsumer: authmiddleware.DefaultSigVerificationGasConsumer, + TxDecoder: txConfig.TxDecoder(), }) if err != nil { panic(err) diff --git a/simapp/app_test.go b/simapp/app_test.go index 7b51b0d835bd..fa8881f93d29 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -78,7 +78,7 @@ func TestRunMigrations(t *testing.T) { app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) // Create a new baseapp and configurator for the purpose of this test. - bApp := baseapp.NewBaseApp(appName, logger, db, encCfg.TxConfig.TxDecoder()) + bApp := baseapp.NewBaseApp(appName, logger, db) bApp.SetCommitMultiStoreTracer(nil) bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) msr := authmiddleware.NewMsgServiceRouter(encCfg.InterfaceRegistry) diff --git a/x/auth/middleware/middleware.go b/x/auth/middleware/middleware.go index a17cdd291ed7..53d16938e219 100644 --- a/x/auth/middleware/middleware.go +++ b/x/auth/middleware/middleware.go @@ -32,6 +32,10 @@ func ComposeMiddlewares(txHandler tx.Handler, middlewares ...tx.Middleware) tx.H type TxHandlerOptions struct { Debug bool + + // TxDecoder is used to decode the raw tx bytes into a sdk.Tx. + TxDecoder sdk.TxDecoder + // IndexEvents defines the set of events in the form {eventType}.{attributeKey}, // which informs Tendermint what to index. If empty, all events will be indexed. IndexEvents map[string]struct{} @@ -49,6 +53,10 @@ type TxHandlerOptions struct { // NewDefaultTxHandler defines a TxHandler middleware stacks that should work // for most applications. func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { + if options.TxDecoder == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "txDecoder is required for middlewares") + } + if options.AccountKeeper == nil { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for middlewares") } @@ -68,6 +76,7 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { return ComposeMiddlewares( NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), + NewTxDecoderMiddleware(options.TxDecoder), // Set a new GasMeter on sdk.Context. // // Make sure the Gas middleware is outside of all other middlewares diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 6278d5c023d2..8d3fe1e6845b 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -1,10 +1,6 @@ package middleware_test import ( - "fmt" - - "github.com/gogo/protobuf/proto" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,5 +27,5 @@ func (s *MWTestSuite) TestRunMsgs() { res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) s.Require().Len(res.MsgResponses, 1) - s.Require().Equal(fmt.Sprintf("/%s", proto.MessageName(&testdata.MsgCreateDogResponse{})), res.MsgResponses[0].TypeUrl) + s.Require().Equal(sdk.MsgTypeURL(&testdata.MsgCreateDog{}), res.MsgResponses[0].TypeUrl) } diff --git a/x/auth/middleware/tx.go b/x/auth/middleware/tx.go new file mode 100644 index 000000000000..e198cff713f4 --- /dev/null +++ b/x/auth/middleware/tx.go @@ -0,0 +1,72 @@ +package middleware + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" +) + +type txDecoderTxHandler struct { + next tx.Handler + txDecoder sdk.TxDecoder +} + +// TxDecoderMiddleware +func NewTxDecoderMiddleware(txDecoder sdk.TxDecoder) tx.Middleware { + return func(txh tx.Handler) tx.Handler { + return txDecoderTxHandler{next: txh, txDecoder: txDecoder} + } +} + +var _ tx.Handler = gasTxHandler{} + +// CheckTx implements tx.Handler.CheckTx. +func (h txDecoderTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + newReq, err := h.populateReq(req) + if err != nil { + return tx.Response{}, tx.ResponseCheckTx{}, err + } + + return h.next.CheckTx(ctx, newReq, checkReq) +} + +// DeliverTx implements tx.Handler.DeliverTx. +func (h txDecoderTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + newReq, err := h.populateReq(req) + if err != nil { + return tx.Response{}, err + } + + return h.next.DeliverTx(ctx, newReq) +} + +// SimulateTx implements tx.Handler.SimulateTx method. +func (h txDecoderTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + newReq, err := h.populateReq(req) + if err != nil { + return tx.Response{}, err + } + + return h.next.SimulateTx(ctx, newReq) +} + +// populateReq takes a tx.Request, and if its Tx field is not set, then +// decodes the TxBytes and populates the decoded Tx field. +func (h txDecoderTxHandler) populateReq(req tx.Request) (tx.Request, error) { + if req.Tx != nil && req.TxBytes != nil { + return req, nil + } + + if len(req.TxBytes) == 0 { + return tx.Request{}, sdkerrors.ErrInvalidRequest.Wrap("got empty tx bytes") + } + + sdkTx, err := h.txDecoder(req.TxBytes) + if err != nil { + return tx.Request{}, err + } + + return tx.Request{Tx: sdkTx, TxBytes: req.TxBytes}, nil +} diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 4389f3da7838..341a2ffe30da 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -124,7 +124,7 @@ func TestSetLoader(t *testing.T) { // load the app with the existing db opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)} - origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, opts...) origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey)) err := origapp.LoadLatestVersion() require.Nil(t, err) @@ -140,7 +140,7 @@ func TestSetLoader(t *testing.T) { } // load the new app with the original app db - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err = app.LoadLatestVersion() require.Nil(t, err) From 51cbf7641081b2e668ea5ecefb075080dcd43330 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 16:42:27 +0100 Subject: [PATCH 36/43] Add test for txDecoderMiddleware --- baseapp/baseapp_test.go | 1 + server/mock/app.go | 1 + x/auth/middleware/basic_test.go | 8 ++-- x/auth/middleware/ext_test.go | 2 +- x/auth/middleware/fee_test.go | 4 +- x/auth/middleware/feegrant_test.go | 2 +- x/auth/middleware/gas_test.go | 62 ++++++++++--------------- x/auth/middleware/middleware_test.go | 1 + x/auth/middleware/sigverify_test.go | 10 ++--- x/auth/middleware/testutil_test.go | 1 + x/auth/middleware/tx_test.go | 67 ++++++++++++++++++++++++++++ 11 files changed, 108 insertions(+), 51 deletions(-) create mode 100644 x/auth/middleware/tx_test.go diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 285f09df6a4b..030b76135673 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -132,6 +132,7 @@ func setupBaseApp(t *testing.T, options ...func(*baseapp.BaseApp)) *baseapp.Base func testTxHandler(options middleware.TxHandlerOptions, customTxHandlerMiddleware handlerFun) tx.Handler { return middleware.ComposeMiddlewares( middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), + middleware.NewTxDecoderMiddleware(options.TxDecoder), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, middleware.NewIndexEventsTxMiddleware(options.IndexEvents), diff --git a/server/mock/app.go b/server/mock/app.go index 9de4420531f0..80102d6afda6 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -59,6 +59,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, ) baseApp.SetTxHandler(txHandler) diff --git a/x/auth/middleware/basic_test.go b/x/auth/middleware/basic_test.go index 6e067306691a..1c44e292eb93 100644 --- a/x/auth/middleware/basic_test.go +++ b/x/auth/middleware/basic_test.go @@ -16,7 +16,7 @@ func (s *MWTestSuite) TestValidateBasic() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.ValidateBasicMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.ValidateBasicMiddleware) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() @@ -54,7 +54,7 @@ func (s *MWTestSuite) TestValidateBasic() { func (s *MWTestSuite) TestValidateMemo() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.ValidateMemoMiddleware(s.app.AccountKeeper)) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.ValidateMemoMiddleware(s.app.AccountKeeper)) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() @@ -90,7 +90,7 @@ func (s *MWTestSuite) TestConsumeGasForTxSize() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.ConsumeTxSizeGasMiddleware(s.app.AccountKeeper)) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.ConsumeTxSizeGasMiddleware(s.app.AccountKeeper)) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() @@ -174,7 +174,7 @@ func (s *MWTestSuite) TestConsumeGasForTxSize() { func (s *MWTestSuite) TestTxHeightTimeoutMiddleware() { ctx := s.SetupTest(true) - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.TxTimeoutHeightMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.TxTimeoutHeightMiddleware) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/auth/middleware/ext_test.go b/x/auth/middleware/ext_test.go index db2714536463..ec57f722c893 100644 --- a/x/auth/middleware/ext_test.go +++ b/x/auth/middleware/ext_test.go @@ -13,7 +13,7 @@ func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.RejectExtensionOptionsMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.RejectExtensionOptionsMiddleware) // no extension options should not trigger an error theTx := txBuilder.GetTx() diff --git a/x/auth/middleware/fee_test.go b/x/auth/middleware/fee_test.go index 3a60558e0da0..e4673f3f8dd5 100644 --- a/x/auth/middleware/fee_test.go +++ b/x/auth/middleware/fee_test.go @@ -13,7 +13,7 @@ func (s *MWTestSuite) TestEnsureMempoolFees() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.MempoolFeeMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.MempoolFeeMiddleware) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() @@ -55,7 +55,7 @@ func (s *MWTestSuite) TestDeductFees() { ctx := s.SetupTest(false) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.DeductFeeMiddleware( s.app.AccountKeeper, s.app.BankKeeper, diff --git a/x/auth/middleware/feegrant_test.go b/x/auth/middleware/feegrant_test.go index e9e1db2ced29..c4c429f32f5b 100644 --- a/x/auth/middleware/feegrant_test.go +++ b/x/auth/middleware/feegrant_test.go @@ -31,7 +31,7 @@ func (s *MWTestSuite) TestDeductFeesNoDelegation() { protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(app.InterfaceRegistry()), tx.DefaultSignModes) txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.DeductFeeMiddleware( s.app.AccountKeeper, s.app.BankKeeper, diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index f89492f16f6c..78685fa6c766 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -50,7 +50,7 @@ func (s *MWTestSuite) setupGasTx() (signing.Tx, []byte, sdk.Context, uint64) { func (s *MWTestSuite) TestSetup() { testTx, _, ctx, gasLimit := s.setupGasTx() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.GasTxMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.GasTxMiddleware) testcases := []struct { name string @@ -77,42 +77,43 @@ func (s *MWTestSuite) TestSetup() { func (s *MWTestSuite) TestRecoverPanic() { testTx, txBytes, ctx, gasLimit := s.setupGasTx() - txHandler := middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware) + txHandler := middleware.ComposeMiddlewares(outOfGasTxHandler, middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware) res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}, tx.RequestCheckTx{}) s.Require().Error(err, "Did not return error on OutOfGas panic") s.Require().True(errors.Is(sdkerrors.ErrOutOfGas, err), "Returned error is not an out of gas error") s.Require().Equal(gasLimit, uint64(res.GasWanted)) - txHandler = middleware.ComposeMiddlewares(outOfGasTxHandler{}, middleware.GasTxMiddleware) + txHandler = middleware.ComposeMiddlewares(outOfGasTxHandler, middleware.GasTxMiddleware) s.Require().Panics(func() { txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}, tx.RequestCheckTx{}) }, "Recovered from non-Out-of-Gas panic") } -// outOfGasTxHandler is a test middleware that will throw OutOfGas panic. -type outOfGasTxHandler struct{} - -var _ tx.Handler = outOfGasTxHandler{} - -func (txh outOfGasTxHandler) DeliverTx(ctx context.Context, _ tx.Request) (tx.Response, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - overLimit := sdkCtx.GasMeter().Limit() + 1 +// customTxHandler is a test middleware that will run a custom function. +type customTxHandler struct { + fn func(context.Context, tx.Request) (tx.Response, error) +} - // Should panic with outofgas error - sdkCtx.GasMeter().ConsumeGas(overLimit, "test panic") +var _ tx.Handler = customTxHandler{} - panic("not reached") +func (h customTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return h.fn(ctx, req) +} +func (h customTxHandler) CheckTx(ctx context.Context, req tx.Request, _ tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { + res, err := h.fn(ctx, req) + return res, tx.ResponseCheckTx{}, err +} +func (h customTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { + return h.fn(ctx, req) } -func (txh outOfGasTxHandler) CheckTx(ctx context.Context, _ tx.Request, _ tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - overLimit := sdkCtx.GasMeter().Limit() + 1 - // Should panic with outofgas error - sdkCtx.GasMeter().ConsumeGas(overLimit, "test panic") +// noopTxHandler is a test middleware that returns an empty response. +var noopTxHandler = customTxHandler{func(_ context.Context, _ tx.Request) (tx.Response, error) { + return tx.Response{}, nil +}} - panic("not reached") -} -func (txh outOfGasTxHandler) SimulateTx(ctx context.Context, _ tx.Request) (tx.Response, error) { +// outOfGasTxHandler is a test middleware that panics with an outOfGas error. +var outOfGasTxHandler = customTxHandler{func(ctx context.Context, _ tx.Request) (tx.Response, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) overLimit := sdkCtx.GasMeter().Limit() + 1 @@ -120,19 +121,4 @@ func (txh outOfGasTxHandler) SimulateTx(ctx context.Context, _ tx.Request) (tx.R sdkCtx.GasMeter().ConsumeGas(overLimit, "test panic") panic("not reached") -} - -// noopTxHandler is a test middleware that does nothing. -type noopTxHandler struct{} - -var _ tx.Handler = noopTxHandler{} - -func (txh noopTxHandler) CheckTx(_ context.Context, _ tx.Request, _ tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { - return tx.Response{}, tx.ResponseCheckTx{}, nil -} -func (txh noopTxHandler) SimulateTx(_ context.Context, _ tx.Request) (tx.Response, error) { - return tx.Response{}, nil -} -func (txh noopTxHandler) DeliverTx(ctx context.Context, _ tx.Request) (tx.Response, error) { - return tx.Response{}, nil -} +}} diff --git a/x/auth/middleware/middleware_test.go b/x/auth/middleware/middleware_test.go index 417ac8e7fcaa..d923b84b2c3d 100644 --- a/x/auth/middleware/middleware_test.go +++ b/x/auth/middleware/middleware_test.go @@ -1025,6 +1025,7 @@ func (s *MWTestSuite) TestCustomSignatureVerificationGasConsumer() { return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized public key type: %T", pubkey) } }, + TxDecoder: s.clientCtx.TxConfig.TxDecoder(), }, ) s.Require().NoError(err) diff --git a/x/auth/middleware/sigverify_test.go b/x/auth/middleware/sigverify_test.go index b5f4d9c15966..01e8898336c7 100644 --- a/x/auth/middleware/sigverify_test.go +++ b/x/auth/middleware/sigverify_test.go @@ -27,7 +27,7 @@ func (s *MWTestSuite) TestSetPubKey() { txBuilder := s.clientCtx.TxConfig.NewTxBuilder() require := s.Require() txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.SetPubKeyMiddleware(s.app.AccountKeeper), ) @@ -127,7 +127,7 @@ func (s *MWTestSuite) TestSigVerification() { // make block height non-zero to ensure account numbers part of signBytes ctx = ctx.WithBlockHeight(1) txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.SetPubKeyMiddleware(s.app.AccountKeeper), middleware.SigVerificationMiddleware( s.app.AccountKeeper, @@ -239,7 +239,7 @@ func (s *MWTestSuite) TestSigVerification_ExplicitAmino() { gasLimit := testdata.NewTestGasLimit() txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.SetPubKeyMiddleware(s.app.AccountKeeper), middleware.SigVerificationMiddleware( s.app.AccountKeeper, @@ -342,7 +342,7 @@ func (s *MWTestSuite) runSigMiddlewares(params types.Params, _ bool, privs ...cr s.Require().NoError(err) txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.SetPubKeyMiddleware(s.app.AccountKeeper), middleware.SigGasConsumeMiddleware(s.app.AccountKeeper, middleware.DefaultSigVerificationGasConsumer), middleware.SigVerificationMiddleware( @@ -382,7 +382,7 @@ func (s *MWTestSuite) TestIncrementSequenceMiddleware() { s.Require().NoError(err) txHandler := middleware.ComposeMiddlewares( - noopTxHandler{}, + noopTxHandler, middleware.IncrementSequenceMiddleware(s.app.AccountKeeper), ) diff --git a/x/auth/middleware/testutil_test.go b/x/auth/middleware/testutil_test.go index 9d804fa17ae2..241615c488df 100644 --- a/x/auth/middleware/testutil_test.go +++ b/x/auth/middleware/testutil_test.go @@ -89,6 +89,7 @@ func (s *MWTestSuite) SetupTest(isCheckTx bool) sdk.Context { FeegrantKeeper: s.app.FeeGrantKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: middleware.DefaultSigVerificationGasConsumer, + TxDecoder: s.clientCtx.TxConfig.TxDecoder(), }) s.Require().NoError(err) s.txHandler = txHandler diff --git a/x/auth/middleware/tx_test.go b/x/auth/middleware/tx_test.go new file mode 100644 index 000000000000..f4309372c0ab --- /dev/null +++ b/x/auth/middleware/tx_test.go @@ -0,0 +1,67 @@ +package middleware_test + +import ( + "context" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/middleware" +) + +func (s *MWTestSuite) TestTxDecoderMiddleware() { + ctx := s.SetupTest(true) // setup + require := s.Require() + + // Create a tx. + priv1, _, addr1 := testdata.KeyTestPubAddr() + txBuilder := s.clientCtx.TxConfig.NewTxBuilder() + err := txBuilder.SetMsgs(testdata.NewTestMsg(addr1)) + require.NoError(err) + sdkTx, txBz, err := s.createTestTx(txBuilder, []cryptotypes.PrivKey{priv1}, []uint64{1}, []uint64{0}, ctx.ChainID()) + require.NoError(err) + + testcases := []struct { + name string + txHandler tx.Handler + req tx.Request + expErr bool + }{ + {"empty tx bz", noopTxHandler, tx.Request{}, true}, + { + "tx bz and tx populated", + customTxHandler{func(c context.Context, r tx.Request) (tx.Response, error) { + require.NotNil(r.Tx) + require.Equal(sdkTx.GetMsgs()[0], r.Tx.GetMsgs()[0]) + return tx.Response{}, nil + }}, + tx.Request{Tx: sdkTx, TxBytes: txBz}, + false, + }, + { + "tx bz populated only", + customTxHandler{func(c context.Context, r tx.Request) (tx.Response, error) { + require.NotNil(r.Tx) + require.Equal(sdkTx.GetMsgs()[0], r.Tx.GetMsgs()[0]) + return tx.Response{}, nil + }}, + tx.Request{TxBytes: txBz}, + false, + }, + } + for _, tc := range testcases { + s.Run(tc.name, func() { + txHandler := middleware.ComposeMiddlewares( + tc.txHandler, + middleware.NewTxDecoderMiddleware(s.clientCtx.TxConfig.TxDecoder()), + ) + _, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tc.req) + if tc.expErr { + require.Error(err) + } else { + require.NoError(err) + } + }) + } +} From c63122e14a69c1e8f4d4b26b139bc576a7186ccb Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Nov 2021 16:58:04 +0100 Subject: [PATCH 37/43] Fix some baseapp tests --- baseapp/baseapp_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 030b76135673..06c0c7b554c9 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" @@ -41,6 +42,7 @@ var ( capKey2 = sdk.NewKVStoreKey("key2") interfaceRegistry = testdata.NewTestInterfaceRegistry() + encCfg = simapp.MakeTestEncodingConfig() ) type paramStore struct { @@ -163,6 +165,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -958,6 +961,7 @@ func TestCheckTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, customHandlerTxTest(t, capKey1, counterKey), ) @@ -1018,6 +1022,7 @@ func TestDeliverTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1080,6 +1085,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1168,6 +1174,7 @@ func TestSimulateTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -1243,6 +1250,7 @@ func TestRunInvalidTransaction(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { return @@ -1367,6 +1375,7 @@ func TestTxGasLimits(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, ante, ) @@ -1454,6 +1463,7 @@ func TestMaxBlockGasLimits(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, ante, ) @@ -1540,6 +1550,7 @@ func TestBaseAppMiddleware(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1634,6 +1645,7 @@ func TestGasConsumptionBadTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, ante, ) @@ -1695,6 +1707,7 @@ func TestQuery(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), + TxDecoder: encCfg.TxConfig.TxDecoder(), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { store := ctx.KVStore(capKey1) @@ -2014,7 +2027,10 @@ func TestWithRouter(t *testing.T) { customRouter := &testCustomRouter{routes: sync.Map{}} r := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) customRouter.AddRoute(r) - txHandler := middleware.NewRunMsgsTxHandler(middleware.NewMsgServiceRouter(interfaceRegistry), customRouter) + txHandler := middleware.ComposeMiddlewares( + middleware.NewRunMsgsTxHandler(middleware.NewMsgServiceRouter(interfaceRegistry), customRouter), + middleware.NewTxDecoderMiddleware(encCfg.TxConfig.TxDecoder()), + ) bapp.SetTxHandler(txHandler) } app := setupBaseApp(t, txHandlerOpt) From 2deca27509c15bc9f07add0d1a37dc2aadd23f14 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 17:29:59 +0100 Subject: [PATCH 38/43] Fix some more tests --- baseapp/baseapp_test.go | 58 +++++++++++++++--------------- x/auth/middleware/priority_test.go | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 06c0c7b554c9..61320af8050f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -165,7 +165,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(codec), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -951,6 +951,10 @@ func TestCheckTx(t *testing.T) { // This ensures changes to the kvstore persist across successive CheckTx. counterKey := []byte("counter-key") + // Create same codec used in txDecoder + codec := codec.NewLegacyAmino() + registerTestCodec(codec) + txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() // TODO: can remove this once CheckTx doesnt process msgs. @@ -961,7 +965,7 @@ func TestCheckTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(codec), }, customHandlerTxTest(t, capKey1, counterKey), ) @@ -973,17 +977,13 @@ func TestCheckTx(t *testing.T) { nTxs := int64(5) app.InitChain(abci.RequestInitChain{}) - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - for i := int64(0); i < nTxs; i++ { tx := newTxCounter(i, 0) // no messages txBytes, err := codec.Marshal(tx) require.NoError(t, err) r := app.CheckTx(abci.RequestCheckTx{Tx: txBytes}) require.Empty(t, r.GetEvents()) - require.True(t, r.IsOK(), fmt.Sprintf("%v", r)) + require.True(t, r.IsOK(), fmt.Sprintf("%+v", r)) } checkStateStore := app.CheckState().Context().KVStore(capKey1) @@ -1014,6 +1014,11 @@ func TestDeliverTx(t *testing.T) { anteKey := []byte("ante-key") // test increments in the handler deliverKey := []byte("deliver-key") + + // Create same codec used in txDecoder + codec := codec.NewLegacyAmino() + registerTestCodec(codec) + txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) @@ -1022,7 +1027,7 @@ func TestDeliverTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(codec), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1031,10 +1036,6 @@ func TestDeliverTx(t *testing.T) { app := setupBaseApp(t, txHandlerOpt) app.InitChain(abci.RequestInitChain{}) - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - nBlocks := 3 txPerHeight := 5 @@ -1075,6 +1076,11 @@ func TestMultiMsgDeliverTx(t *testing.T) { // increment the msg counter deliverKey := []byte("deliver-key") deliverKey2 := []byte("deliver-key2") + + // Create same codec used in txDecoder + codec := codec.NewLegacyAmino() + registerTestCodec(codec) + txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r1 := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) @@ -1085,7 +1091,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(codec), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1093,10 +1099,6 @@ func TestMultiMsgDeliverTx(t *testing.T) { } app := setupBaseApp(t, txHandlerOpt) - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - // run a multi-msg tx // with all msgs the same route @@ -1155,6 +1157,10 @@ func TestConcurrentCheckDeliver(t *testing.T) { func TestSimulateTx(t *testing.T) { gasConsumed := uint64(5) + // Create same codec used in txDecoder + cdc := codec.NewLegacyAmino() + registerTestCodec(cdc) + txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { @@ -1174,7 +1180,7 @@ func TestSimulateTx(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(cdc), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -1184,10 +1190,6 @@ func TestSimulateTx(t *testing.T) { app.InitChain(abci.RequestInitChain{}) - // Create same codec used in txDecoder - cdc := codec.NewLegacyAmino() - registerTestCodec(cdc) - nBlocks := 3 for blockN := 0; blockN < nBlocks; blockN++ { count := int64(blockN + 1) @@ -1550,7 +1552,7 @@ func TestBaseAppMiddleware(t *testing.T) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: testTxDecoder(cdc), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -2023,23 +2025,23 @@ func TestWithRouter(t *testing.T) { // test increments in the handler deliverKey := []byte("deliver-key") + // Create same codec used in txDecoder + codec := codec.NewLegacyAmino() + registerTestCodec(codec) + txHandlerOpt := func(bapp *baseapp.BaseApp) { customRouter := &testCustomRouter{routes: sync.Map{}} r := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) customRouter.AddRoute(r) txHandler := middleware.ComposeMiddlewares( middleware.NewRunMsgsTxHandler(middleware.NewMsgServiceRouter(interfaceRegistry), customRouter), - middleware.NewTxDecoderMiddleware(encCfg.TxConfig.TxDecoder()), + middleware.NewTxDecoderMiddleware(testTxDecoder(codec)), ) bapp.SetTxHandler(txHandler) } app := setupBaseApp(t, txHandlerOpt) app.InitChain(abci.RequestInitChain{}) - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - nBlocks := 3 txPerHeight := 5 diff --git a/x/auth/middleware/priority_test.go b/x/auth/middleware/priority_test.go index a04e2065d971..388418644040 100644 --- a/x/auth/middleware/priority_test.go +++ b/x/auth/middleware/priority_test.go @@ -12,7 +12,7 @@ func (s *MWTestSuite) TestPriority() { ctx := s.SetupTest(true) // setup txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txHandler := middleware.ComposeMiddlewares(noopTxHandler{}, middleware.TxPriorityMiddleware) + txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.TxPriorityMiddleware) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() From 00f3681e44a3b3de2c500c60e3ea8458197100d9 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:07:25 +0100 Subject: [PATCH 39/43] Fix mock tests --- server/mock/app.go | 3 ++- server/mock/tx.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/mock/app.go b/server/mock/app.go index 80102d6afda6..8ef0ae405e51 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -23,6 +23,7 @@ import ( func testTxHandler(options middleware.TxHandlerOptions) tx.Handler { return middleware.ComposeMiddlewares( middleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter), + middleware.NewTxDecoderMiddleware(options.TxDecoder), middleware.GasTxMiddleware, middleware.RecoveryTxMiddleware, middleware.NewIndexEventsTxMiddleware(options.IndexEvents), @@ -59,7 +60,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + TxDecoder: decodeTx, }, ) baseApp.SetTxHandler(txHandler) diff --git a/server/mock/tx.go b/server/mock/tx.go index 0bd381443a45..bfa6e6ad6b4b 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -2,10 +2,12 @@ package mock import ( + "bytes" "fmt" "math" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/middleware" ) @@ -68,3 +70,22 @@ func (tx kvstoreTx) GetSigners() []sdk.AccAddress { func (tx kvstoreTx) GetGas() uint64 { return math.MaxUint64 } + +// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has +// all the signatures and can be used to authenticate. +func decodeTx(txBytes []byte) (sdk.Tx, error) { + var tx sdk.Tx + + split := bytes.Split(txBytes, []byte("=")) + if len(split) == 1 { + k := split[0] + tx = &kvstoreTx{k, k, txBytes} + } else if len(split) == 2 { + k, v := split[0], split[1] + tx = &kvstoreTx{k, v, txBytes} + } else { + return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='") + } + + return tx, nil +} From 77ca28a2a0010583980be9601b16e3fc3be00274 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:29:00 +0100 Subject: [PATCH 40/43] Fix middleware tests --- types/tx/middleware.go | 19 +++++++++++++------ x/auth/middleware/run_msgs_test.go | 5 ++++- x/auth/middleware/tx.go | 18 +++++++++--------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index e67b783796d9..17f1a97e6554 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -22,6 +22,19 @@ type ResponseSimulateTx struct { Result *sdk.Result } +// Request is the tx request type used in middlewares. +// At least one of Tx or TxBytes must be set. If only TxBytes is set, then +// Tx will be populated by the TxDecoderMiddleware. If only Tx is set, then +// some middleware (such as signature verification) will not work. +// +// In practice, the middleware stack is called from {Check,Deliver}Tx, which +// on passes the TxBytes. Then, the TxDecoderMiddleware decodes the bytes into +// the Tx field. +type Request struct { + Tx sdk.Tx + TxBytes []byte +} + // Response is the tx response type used in middlewares. type Response struct { GasWanted uint64 @@ -34,12 +47,6 @@ type Response struct { Events []abci.Event } -// Request is the tx request type used in middlewares. -type Request struct { - Tx sdk.Tx - TxBytes []byte -} - // RequestCheckTx is the additional request type used in middlewares CheckTx // method. type RequestCheckTx struct { diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 8d3fe1e6845b..0077e636cc28 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -1,11 +1,14 @@ package middleware_test import ( + "fmt" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" + "github.com/gogo/protobuf/proto" ) func (s *MWTestSuite) TestRunMsgs() { @@ -27,5 +30,5 @@ func (s *MWTestSuite) TestRunMsgs() { res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) s.Require().Len(res.MsgResponses, 1) - s.Require().Equal(sdk.MsgTypeURL(&testdata.MsgCreateDog{}), res.MsgResponses[0].TypeUrl) + s.Require().Equal(fmt.Sprintf("/%s", proto.MessageName(&testdata.MsgCreateDogResponse{})), res.MsgResponses[0].TypeUrl) } diff --git a/x/auth/middleware/tx.go b/x/auth/middleware/tx.go index e198cff713f4..57457a207466 100644 --- a/x/auth/middleware/tx.go +++ b/x/auth/middleware/tx.go @@ -55,17 +55,17 @@ func (h txDecoderTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx. // populateReq takes a tx.Request, and if its Tx field is not set, then // decodes the TxBytes and populates the decoded Tx field. func (h txDecoderTxHandler) populateReq(req tx.Request) (tx.Request, error) { - if req.Tx != nil && req.TxBytes != nil { - return req, nil + if len(req.TxBytes) == 0 && req.Tx == nil { + return tx.Request{}, sdkerrors.ErrInvalidRequest.Wrap("got empty tx request") } - if len(req.TxBytes) == 0 { - return tx.Request{}, sdkerrors.ErrInvalidRequest.Wrap("got empty tx bytes") - } - - sdkTx, err := h.txDecoder(req.TxBytes) - if err != nil { - return tx.Request{}, err + sdkTx := req.Tx + var err error + if len(req.TxBytes) != 0 { + sdkTx, err = h.txDecoder(req.TxBytes) + if err != nil { + return tx.Request{}, err + } } return tx.Request{Tx: sdkTx, TxBytes: req.TxBytes}, nil From 66085abe0a99e851a1322d7bcd51dddbc8c1c523 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:37:11 +0100 Subject: [PATCH 41/43] Add cl --- CHANGELOG.md | 1 + types/tx/middleware.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9251e3418cf5..2fec2f854da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/gov) [\#10373](https://github.com/cosmos/cosmos-sdk/pull/10373) Removed gov `keeper.{MustMarshal, MustUnmarshal}`. * [\#10348](https://github.com/cosmos/cosmos-sdk/pull/10348) StdSignBytes takes a new argument of type `*tx.Tip` for signing over tips using LEGACY_AMINO_JSON. * [\#10208](https://github.com/cosmos/cosmos-sdk/pull/10208) The `x/auth/signing.Tx` interface now also includes a new `GetTip() *tx.Tip` method for verifying tipped transactions. The `x/auth/types` expected BankKeeper interface now expects the `SendCoins` method too. +* [\#10612](https://github.com/cosmos/cosmos-sdk/pull/10612) `baseapp.NewBaseApp` constructor function doesn't take the `sdk.TxDecoder` anymore. This logic has been moved into the TxDecoderMiddleware. ### Client Breaking Changes diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 17f1a97e6554..14050550ede8 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -25,11 +25,11 @@ type ResponseSimulateTx struct { // Request is the tx request type used in middlewares. // At least one of Tx or TxBytes must be set. If only TxBytes is set, then // Tx will be populated by the TxDecoderMiddleware. If only Tx is set, then -// some middleware (such as signature verification) will not work. +// some middlewares (such as signature verification) will fail. // // In practice, the middleware stack is called from {Check,Deliver}Tx, which -// on passes the TxBytes. Then, the TxDecoderMiddleware decodes the bytes into -// the Tx field. +// only passes the TxBytes. Then, the TxDecoderMiddleware decodes the bytes +// intothe Tx field. type Request struct { Tx sdk.Tx TxBytes []byte From d6c42d77991998a9badc07220837b66db4348a19 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 2 Dec 2021 08:43:58 +0100 Subject: [PATCH 42/43] Fix tests --- baseapp/abci.go | 4 + baseapp/baseapp_test.go | 132 ++++++++++++----------------- x/auth/middleware/run_msgs_test.go | 1 - x/auth/middleware/tx.go | 21 +++-- x/auth/middleware/tx_test.go | 42 ++++----- 5 files changed, 86 insertions(+), 114 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index a89ae40a4a95..398673bd1662 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -257,6 +257,10 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { } abciRes, err := convertTxResponseToCheckTx(res, checkRes) + if err != nil { + return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace) + } + return abciRes } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 61320af8050f..0bc643fd29ab 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -41,10 +41,13 @@ var ( capKey1 = sdk.NewKVStoreKey("key1") capKey2 = sdk.NewKVStoreKey("key2") - interfaceRegistry = testdata.NewTestInterfaceRegistry() - encCfg = simapp.MakeTestEncodingConfig() + encCfg = simapp.MakeTestEncodingConfig() ) +func init() { + registerTestCodec(encCfg.Amino) +} + type paramStore struct { db *dbm.MemDB } @@ -96,9 +99,6 @@ func newBaseApp(name string, options ...func(*baseapp.BaseApp)) *baseapp.BaseApp } func registerTestCodec(cdc *codec.LegacyAmino) { - // register Tx, Msg - sdk.RegisterLegacyAminoCodec(cdc) - // register test types cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil) cdc.RegisterConcrete(&msgCounter{}, "cosmos-sdk/baseapp/msgCounter", nil) @@ -108,10 +108,7 @@ func registerTestCodec(cdc *codec.LegacyAmino) { } // aminoTxEncoder creates a amino TxEncoder for testing purposes. -func aminoTxEncoder() sdk.TxEncoder { - cdc := codec.NewLegacyAmino() - registerTestCodec(cdc) - +func aminoTxEncoder(cdc *codec.LegacyAmino) sdk.TxEncoder { return legacytx.StdTxConfig{Cdc: cdc}.TxEncoder() } @@ -164,8 +161,8 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(codec), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -204,7 +201,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options tx.Msgs = append(tx.Msgs, msgKeyValue{Key: key, Value: value}) keyCounter++ } - txBytes, err := codec.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) resp := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.True(t, resp.IsOK(), "%v", resp.String()) @@ -951,10 +948,6 @@ func TestCheckTx(t *testing.T) { // This ensures changes to the kvstore persist across successive CheckTx. counterKey := []byte("counter-key") - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() // TODO: can remove this once CheckTx doesnt process msgs. @@ -964,8 +957,8 @@ func TestCheckTx(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(codec), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, customHandlerTxTest(t, capKey1, counterKey), ) @@ -979,7 +972,7 @@ func TestCheckTx(t *testing.T) { for i := int64(0); i < nTxs; i++ { tx := newTxCounter(i, 0) // no messages - txBytes, err := codec.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) r := app.CheckTx(abci.RequestCheckTx{Tx: txBytes}) require.Empty(t, r.GetEvents()) @@ -1015,10 +1008,6 @@ func TestDeliverTx(t *testing.T) { // test increments in the handler deliverKey := []byte("deliver-key") - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) @@ -1026,8 +1015,8 @@ func TestDeliverTx(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(codec), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1047,7 +1036,7 @@ func TestDeliverTx(t *testing.T) { counter := int64(blockN*txPerHeight + i) tx := newTxCounter(counter, counter) - txBytes, err := codec.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1077,10 +1066,6 @@ func TestMultiMsgDeliverTx(t *testing.T) { deliverKey := []byte("deliver-key") deliverKey2 := []byte("deliver-key2") - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r1 := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) @@ -1090,8 +1075,8 @@ func TestMultiMsgDeliverTx(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(codec), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1105,7 +1090,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { header := tmproto.Header{Height: 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) tx := newTxCounter(0, 0, 1, 2) - txBytes, err := codec.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) @@ -1125,7 +1110,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { tx = newTxCounter(1, 3) tx.Msgs = append(tx.Msgs, msgCounter2{0}) tx.Msgs = append(tx.Msgs, msgCounter2{1}) - txBytes, err = codec.Marshal(tx) + txBytes, err = encCfg.Amino.Marshal(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) @@ -1157,10 +1142,6 @@ func TestConcurrentCheckDeliver(t *testing.T) { func TestSimulateTx(t *testing.T) { gasConsumed := uint64(5) - // Create same codec used in txDecoder - cdc := codec.NewLegacyAmino() - registerTestCodec(cdc) - txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { @@ -1179,8 +1160,8 @@ func TestSimulateTx(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(cdc), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { return ctx, nil }, ) @@ -1198,7 +1179,7 @@ func TestSimulateTx(t *testing.T) { tx := newTxCounter(count, count) tx.GasLimit = gasConsumed - txBytes, err := cdc.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.Nil(t, err) // simulate a message, check gas reported @@ -1251,8 +1232,8 @@ func TestRunInvalidTransaction(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { return @@ -1268,7 +1249,7 @@ func TestRunInvalidTransaction(t *testing.T) { // transaction with no messages { emptyTx := &txTest{} - _, result, err := app.SimDeliver(aminoTxEncoder(), emptyTx) + _, result, err := app.SimDeliver(aminoTxEncoder(encCfg.Amino), emptyTx) require.Nil(t, result) space, code, _ := sdkerrors.ABCIInfo(err, false) @@ -1294,7 +1275,7 @@ func TestRunInvalidTransaction(t *testing.T) { for _, testCase := range testCases { tx := testCase.tx - _, _, err := app.SimDeliver(aminoTxEncoder(), tx) + _, _, err := app.SimDeliver(aminoTxEncoder(encCfg.Amino), tx) if testCase.fail { require.Error(t, err) @@ -1311,7 +1292,7 @@ func TestRunInvalidTransaction(t *testing.T) { // transaction with no known route { unknownRouteTx := txTest{[]sdk.Msg{&msgNoRoute{}}, 0, false, math.MaxUint64} - _, result, err := app.SimDeliver(aminoTxEncoder(), unknownRouteTx) + _, result, err := app.SimDeliver(aminoTxEncoder(encCfg.Amino), unknownRouteTx) require.Error(t, err) require.Nil(t, result) @@ -1320,7 +1301,7 @@ func TestRunInvalidTransaction(t *testing.T) { require.EqualValues(t, sdkerrors.ErrUnknownRequest.ABCICode(), code, err) unknownRouteTx = txTest{[]sdk.Msg{&msgCounter{}, &msgNoRoute{}}, 0, false, math.MaxUint64} - _, result, err = app.SimDeliver(aminoTxEncoder(), unknownRouteTx) + _, result, err = app.SimDeliver(aminoTxEncoder(encCfg.Amino), unknownRouteTx) require.Error(t, err) require.Nil(t, result) @@ -1334,8 +1315,10 @@ func TestRunInvalidTransaction(t *testing.T) { tx := newTxCounter(0, 0) tx.Msgs = append(tx.Msgs, &msgNoDecode{}) - // new codec so we can encode the tx, but we shouldn't be able to decode + // new codec so we can encode the tx, but we shouldn't be able to decode, + // because baseapp's codec is not aware of msgNoDecode. newCdc := codec.NewLegacyAmino() + sdk.RegisterLegacyAminoCodec(newCdc) // register Tx, Msg registerTestCodec(newCdc) newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil) @@ -1376,8 +1359,8 @@ func TestTxGasLimits(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, ante, ) @@ -1416,7 +1399,7 @@ func TestTxGasLimits(t *testing.T) { for i, tc := range testCases { tx := tc.tx tx.GasLimit = gasGranted - gInfo, result, err := app.SimDeliver(aminoTxEncoder(), tx) + gInfo, result, err := app.SimDeliver(aminoTxEncoder(encCfg.Amino), tx) // check gas used and wanted require.Equal(t, tc.gasUsed, gInfo.GasUsed, fmt.Sprintf("tc #%d; gas: %v, result: %v, err: %s", i, gInfo, result, err)) @@ -1464,8 +1447,8 @@ func TestMaxBlockGasLimits(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, ante, ) @@ -1510,7 +1493,7 @@ func TestMaxBlockGasLimits(t *testing.T) { // execute the transaction multiple times for j := 0; j < tc.numDelivers; j++ { - _, result, err := app.SimDeliver(aminoTxEncoder(), tx) + _, result, err := app.SimDeliver(aminoTxEncoder(encCfg.Amino), tx) ctx := app.DeliverState().Context() @@ -1542,7 +1525,6 @@ func TestMaxBlockGasLimits(t *testing.T) { func TestBaseAppMiddleware(t *testing.T) { anteKey := []byte("ante-key") deliverKey := []byte("deliver-key") - cdc := codec.NewLegacyAmino() txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() @@ -1551,8 +1533,8 @@ func TestBaseAppMiddleware(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: testTxDecoder(cdc), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, customHandlerTxTest(t, capKey1, anteKey), ) @@ -1561,7 +1543,6 @@ func TestBaseAppMiddleware(t *testing.T) { app := setupBaseApp(t, txHandlerOpt) app.InitChain(abci.RequestInitChain{}) - registerTestCodec(cdc) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) @@ -1572,7 +1553,7 @@ func TestBaseAppMiddleware(t *testing.T) { // the next txs ante handler execution (customHandlerTxTest). tx := newTxCounter(0, 0) tx.setFailOnAnte(true) - txBytes, err := cdc.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.Empty(t, res.Events) @@ -1587,7 +1568,7 @@ func TestBaseAppMiddleware(t *testing.T) { tx = newTxCounter(0, 0) tx.setFailOnHandler(true) - txBytes, err = cdc.Marshal(tx) + txBytes, err = encCfg.Amino.Marshal(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1603,7 +1584,7 @@ func TestBaseAppMiddleware(t *testing.T) { // implicitly checked by previous tx executions tx = newTxCounter(1, 0) - txBytes, err = cdc.Marshal(tx) + txBytes, err = encCfg.Amino.Marshal(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1632,9 +1613,6 @@ func TestGasConsumptionBadTx(t *testing.T) { return ctx, nil } - cdc := codec.NewLegacyAmino() - registerTestCodec(cdc) - txHandlerOpt := func(bapp *baseapp.BaseApp) { legacyRouter := middleware.NewLegacyRouter() r := sdk.NewRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { @@ -1646,8 +1624,8 @@ func TestGasConsumptionBadTx(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, ante, ) @@ -1671,7 +1649,7 @@ func TestGasConsumptionBadTx(t *testing.T) { tx := newTxCounter(5, 0) tx.GasLimit = gasWanted tx.setFailOnAnte(true) - txBytes, err := cdc.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1679,7 +1657,7 @@ func TestGasConsumptionBadTx(t *testing.T) { // require next tx to fail due to black gas limit tx = newTxCounter(5, 0) - txBytes, err = cdc.Marshal(tx) + txBytes, err = encCfg.Amino.Marshal(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1708,8 +1686,8 @@ func TestQuery(t *testing.T) { txHandler := testTxHandler( middleware.TxHandlerOptions{ LegacyRouter: legacyRouter, - MsgServiceRouter: middleware.NewMsgServiceRouter(interfaceRegistry), - TxDecoder: encCfg.TxConfig.TxDecoder(), + MsgServiceRouter: middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), + TxDecoder: testTxDecoder(encCfg.Amino), }, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { store := ctx.KVStore(capKey1) @@ -1737,7 +1715,7 @@ func TestQuery(t *testing.T) { require.Equal(t, 0, len(res.Value)) // query is still empty after a CheckTx - _, resTx, err := app.SimCheck(aminoTxEncoder(), tx) + _, resTx, err := app.SimCheck(aminoTxEncoder(encCfg.Amino), tx) require.NoError(t, err) require.NotNil(t, resTx) res = app.Query(query) @@ -1747,7 +1725,7 @@ func TestQuery(t *testing.T) { header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) - _, resTx, err = app.SimDeliver(aminoTxEncoder(), tx) + _, resTx, err = app.SimDeliver(aminoTxEncoder(encCfg.Amino), tx) require.NoError(t, err) require.NotNil(t, resTx) res = app.Query(query) @@ -2025,17 +2003,13 @@ func TestWithRouter(t *testing.T) { // test increments in the handler deliverKey := []byte("deliver-key") - // Create same codec used in txDecoder - codec := codec.NewLegacyAmino() - registerTestCodec(codec) - txHandlerOpt := func(bapp *baseapp.BaseApp) { customRouter := &testCustomRouter{routes: sync.Map{}} r := sdk.NewRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) customRouter.AddRoute(r) txHandler := middleware.ComposeMiddlewares( - middleware.NewRunMsgsTxHandler(middleware.NewMsgServiceRouter(interfaceRegistry), customRouter), - middleware.NewTxDecoderMiddleware(testTxDecoder(codec)), + middleware.NewRunMsgsTxHandler(middleware.NewMsgServiceRouter(encCfg.InterfaceRegistry), customRouter), + middleware.NewTxDecoderMiddleware(testTxDecoder(encCfg.Amino)), ) bapp.SetTxHandler(txHandler) } @@ -2053,7 +2027,7 @@ func TestWithRouter(t *testing.T) { counter := int64(blockN*txPerHeight + i) tx := newTxCounter(counter, counter) - txBytes, err := codec.Marshal(tx) + txBytes, err := encCfg.Amino.Marshal(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 0fca7605034a..6278d5c023d2 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -10,7 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" - "github.com/gogo/protobuf/proto" ) func (s *MWTestSuite) TestRunMsgs() { diff --git a/x/auth/middleware/tx.go b/x/auth/middleware/tx.go index 57457a207466..f543524f3fa7 100644 --- a/x/auth/middleware/tx.go +++ b/x/auth/middleware/tx.go @@ -8,22 +8,26 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) -type txDecoderTxHandler struct { +type txDecoderHandler struct { next tx.Handler txDecoder sdk.TxDecoder } -// TxDecoderMiddleware +// NewTxDecoderMiddleware creates a new middleware that will decode tx bytes +// into a sdk.Tx. As input request, at least one of Tx or TxBytes must be set. +// If only TxBytes is set, then TxDecoderMiddleware will populate the Tx field. +// If only Tx is set, then TxBytes will be left empty, but some middlewares +// such as signature verification might fail. func NewTxDecoderMiddleware(txDecoder sdk.TxDecoder) tx.Middleware { return func(txh tx.Handler) tx.Handler { - return txDecoderTxHandler{next: txh, txDecoder: txDecoder} + return txDecoderHandler{next: txh, txDecoder: txDecoder} } } var _ tx.Handler = gasTxHandler{} // CheckTx implements tx.Handler.CheckTx. -func (h txDecoderTxHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { +func (h txDecoderHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) { newReq, err := h.populateReq(req) if err != nil { return tx.Response{}, tx.ResponseCheckTx{}, err @@ -33,7 +37,7 @@ func (h txDecoderTxHandler) CheckTx(ctx context.Context, req tx.Request, checkRe } // DeliverTx implements tx.Handler.DeliverTx. -func (h txDecoderTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { +func (h txDecoderHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) { newReq, err := h.populateReq(req) if err != nil { return tx.Response{}, err @@ -43,7 +47,7 @@ func (h txDecoderTxHandler) DeliverTx(ctx context.Context, req tx.Request) (tx.R } // SimulateTx implements tx.Handler.SimulateTx method. -func (h txDecoderTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { +func (h txDecoderHandler) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) { newReq, err := h.populateReq(req) if err != nil { return tx.Response{}, err @@ -53,8 +57,9 @@ func (h txDecoderTxHandler) SimulateTx(ctx context.Context, req tx.Request) (tx. } // populateReq takes a tx.Request, and if its Tx field is not set, then -// decodes the TxBytes and populates the decoded Tx field. -func (h txDecoderTxHandler) populateReq(req tx.Request) (tx.Request, error) { +// decodes the TxBytes and populates the decoded Tx field. It leaves +// req.TxBytes untouched. +func (h txDecoderHandler) populateReq(req tx.Request) (tx.Request, error) { if len(req.TxBytes) == 0 && req.Tx == nil { return tx.Request{}, sdkerrors.ErrInvalidRequest.Wrap("got empty tx request") } diff --git a/x/auth/middleware/tx_test.go b/x/auth/middleware/tx_test.go index f4309372c0ab..8624aadbfea2 100644 --- a/x/auth/middleware/tx_test.go +++ b/x/auth/middleware/tx_test.go @@ -22,38 +22,28 @@ func (s *MWTestSuite) TestTxDecoderMiddleware() { sdkTx, txBz, err := s.createTestTx(txBuilder, []cryptotypes.PrivKey{priv1}, []uint64{1}, []uint64{0}, ctx.ChainID()) require.NoError(err) + // Create a custom tx.Handler that checks that the req.Tx field is + // correctly populated. + txReqChecker := customTxHandler{func(c context.Context, r tx.Request) (tx.Response, error) { + require.NotNil(r.Tx) + require.Equal(sdkTx.GetMsgs()[0], r.Tx.GetMsgs()[0]) + return tx.Response{}, nil + }} + testcases := []struct { - name string - txHandler tx.Handler - req tx.Request - expErr bool + name string + req tx.Request + expErr bool }{ - {"empty tx bz", noopTxHandler, tx.Request{}, true}, - { - "tx bz and tx populated", - customTxHandler{func(c context.Context, r tx.Request) (tx.Response, error) { - require.NotNil(r.Tx) - require.Equal(sdkTx.GetMsgs()[0], r.Tx.GetMsgs()[0]) - return tx.Response{}, nil - }}, - tx.Request{Tx: sdkTx, TxBytes: txBz}, - false, - }, - { - "tx bz populated only", - customTxHandler{func(c context.Context, r tx.Request) (tx.Response, error) { - require.NotNil(r.Tx) - require.Equal(sdkTx.GetMsgs()[0], r.Tx.GetMsgs()[0]) - return tx.Response{}, nil - }}, - tx.Request{TxBytes: txBz}, - false, - }, + {"empty tx bz", tx.Request{}, true}, + {"tx bz and tx both given as inputs", tx.Request{Tx: sdkTx, TxBytes: txBz}, false}, + {"tx bz only given as input", tx.Request{TxBytes: txBz}, false}, + {"tx only given as input", tx.Request{Tx: sdkTx}, false}, } for _, tc := range testcases { s.Run(tc.name, func() { txHandler := middleware.ComposeMiddlewares( - tc.txHandler, + txReqChecker, middleware.NewTxDecoderMiddleware(s.clientCtx.TxConfig.TxDecoder()), ) _, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tc.req) From 1c6dab1d1d7897d54f19b3167c7d7f6f671608a4 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 2 Dec 2021 14:11:56 +0100 Subject: [PATCH 43/43] Update types/tx/middleware.go Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> --- types/tx/middleware.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/tx/middleware.go b/types/tx/middleware.go index 14050550ede8..abe29be672d8 100644 --- a/types/tx/middleware.go +++ b/types/tx/middleware.go @@ -29,7 +29,7 @@ type ResponseSimulateTx struct { // // In practice, the middleware stack is called from {Check,Deliver}Tx, which // only passes the TxBytes. Then, the TxDecoderMiddleware decodes the bytes -// intothe Tx field. +// into the Tx field. type Request struct { Tx sdk.Tx TxBytes []byte