From 1bbb499cdf32dbf2bed3607860c30693c3f5674a Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 3 Jul 2024 17:21:00 +0200 Subject: [PATCH] refactor: reduce decoding steps in baseapp (#20863) --- baseapp/abci.go | 18 ++---------------- baseapp/baseapp.go | 2 +- baseapp/baseapp_test.go | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 68a65249dfd7..513d8667fc76 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -817,22 +817,8 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz // vote extensions, so skip those. txResults := make([]*abci.ExecTxResult, 0, len(req.Txs)) for _, rawTx := range req.Txs { - var response *abci.ExecTxResult - - if _, err := app.txDecoder(rawTx); err == nil { - response = app.deliverTx(rawTx) - } else { - // In the case where a transaction included in a block proposal is malformed, - // we still want to return a default response to comet. This is because comet - // expects a response for each transaction included in a block proposal. - response = responseExecTxResultWithEvents( - sdkerrors.ErrTxDecode, - 0, - 0, - nil, - false, - ) - } + + response := app.deliverTx(rawTx) // check after every tx if we should abort select { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0d33a391f7f5..d23207c667c2 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -868,7 +868,7 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res tx, err := app.txDecoder(txBytes) if err != nil { - return sdk.GasInfo{}, nil, nil, err + return sdk.GasInfo{GasUsed: 0, GasWanted: 0}, nil, nil, sdkerrors.ErrTxDecode.Wrap(err.Error()) } msgs := tx.GetMsgs() diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 95e4df2b2538..aa5060ae7242 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -893,3 +893,24 @@ func TestLoadVersionPruning(t *testing.T) { require.Nil(t, err) testLoadVersionHelper(t, app, int64(7), lastCommitID) } + +func TestABCI_FinalizeWithInvalidTX(t *testing.T) { + suite := NewBaseAppSuite(t) + baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), CounterServerImplGasMeterOnly{}) + + _, err := suite.baseApp.InitChain(&abci.InitChainRequest{ConsensusParams: &cmtproto.ConsensusParams{}}) + require.NoError(t, err) + + tx := newTxCounter(t, suite.txConfig, 0, 0) + bz, err := suite.txConfig.TxEncoder()(tx) + require.NoError(t, err) + + // when + gotRsp, gotErr := suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{ + Height: 1, + Txs: [][]byte{bz[0 : len(bz)-5]}, + }) + require.NoError(t, gotErr) + require.Len(t, gotRsp.TxResults, 1) + require.Equal(t, uint32(2), gotRsp.TxResults[0].Code) +}