Skip to content

Commit

Permalink
refactor: reduce decoding steps in baseapp (#20863)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Jul 3, 2024
1 parent 979f1e8 commit 1bbb499
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
18 changes: 2 additions & 16 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 1bbb499

Please sign in to comment.