refactor: reduce decoding steps in baseapp (#20863)

This commit is contained in:
Marko 2024-07-03 17:21:00 +02:00 committed by GitHub
parent 979f1e839b
commit 1bbb499cdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 16 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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)
}