From 2ea9acc4161697d798c86fb3b090274651aa50df Mon Sep 17 00:00:00 2001 From: huangyi Date: Wed, 11 Sep 2024 16:30:20 +0800 Subject: [PATCH] cleanup --- baseapp/abci.go | 52 +++++++++++++++++-------------------------- baseapp/baseapp.go | 4 ++-- baseapp/genesis.go | 2 +- baseapp/txexecutor.go | 4 ++-- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 6a60455ae025..3d3b6f11926e 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -841,52 +841,40 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request } func (app *BaseApp) executeTxs(ctx context.Context, txs [][]byte) ([]*abci.ExecTxResult, error) { - txResults := make([]*abci.ExecTxResult, len(txs)) - memTxs := make([]sdk.Tx, 0, len(txs)) - validTxs := make([]int, 0, len(txs)) + if app.txExecutor != nil { + return app.txExecutor(ctx, txs, app.finalizeBlockState.ms, func(i int, memTx sdk.Tx, ms storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult { + return app.deliverTxWithMultiStore(txs[i], memTx, i, ms, incarnationCache) + }) + } + + txResults := make([]*abci.ExecTxResult, 0, len(txs)) for i, rawTx := range txs { - memTx, err := app.txDecoder(rawTx) - if err != nil { + var response *abci.ExecTxResult + + if memTx, err := app.txDecoder(rawTx); err == nil { + response = app.deliverTx(rawTx, memTx, i) + } 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. - txResults[i] = sdkerrors.ResponseExecTxResultWithEvents( + response = sdkerrors.ResponseExecTxResultWithEvents( sdkerrors.ErrTxDecode, 0, 0, nil, false, ) - continue } - memTxs = append(memTxs, memTx) - validTxs = append(validTxs, i) - } - if app.txExecutor != nil { - validTxResults, err := app.txExecutor(ctx, memTxs, app.finalizeBlockState.ms, func(i int, ms storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult { - return app.deliverTxWithMultiStore(txs[validTxs[i]], memTxs[i], i, ms, incarnationCache) - }) - if err != nil { - return nil, err + // check after every tx if we should abort + select { + case <-ctx.Done(): + return nil, ctx.Err() + default: + // continue } - for i, res := range validTxResults { - txResults[validTxs[i]] = res - } - } else { - for i := range memTxs { - txIndex := validTxs[i] - txResults[txIndex] = app.deliverTx(txs[txIndex], i) - - // check after every tx if we should abort - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - // continue - } - } + txResults = append(txResults, response) } return txResults, nil } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index e47e21e6904e..55e0aa8469b3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -764,8 +764,8 @@ func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, er return resp, nil } -func (app *BaseApp) deliverTx(tx []byte, txIndex int) *abci.ExecTxResult { - return app.deliverTxWithMultiStore(tx, nil, txIndex, nil, nil) +func (app *BaseApp) deliverTx(tx []byte, memTx sdk.Tx, txIndex int) *abci.ExecTxResult { + return app.deliverTxWithMultiStore(tx, memTx, txIndex, nil, nil) } func (app *BaseApp) deliverTxWithMultiStore(tx []byte, memTx sdk.Tx, txIndex int, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult { diff --git a/baseapp/genesis.go b/baseapp/genesis.go index e9f611772e08..562bdca3b276 100644 --- a/baseapp/genesis.go +++ b/baseapp/genesis.go @@ -13,7 +13,7 @@ var _ genesis.TxHandler = (*BaseApp)(nil) // ExecuteGenesisTx implements genesis.GenesisState from // cosmossdk.io/core/genesis to set initial state in genesis func (ba BaseApp) ExecuteGenesisTx(tx []byte) error { - res := ba.deliverTx(tx, -1) + res := ba.deliverTx(tx, nil, -1) if res.Code != types.CodeTypeOK { return errors.New(res.Log) diff --git a/baseapp/txexecutor.go b/baseapp/txexecutor.go index 4003a5b40916..b09c204e06c0 100644 --- a/baseapp/txexecutor.go +++ b/baseapp/txexecutor.go @@ -11,7 +11,7 @@ import ( type TxExecutor func( ctx context.Context, - block []sdk.Tx, + block [][]byte, cms types.MultiStore, - deliverTxWithMultiStore func(int, types.MultiStore, map[string]any) *abci.ExecTxResult, + deliverTxWithMultiStore func(int, sdk.Tx, types.MultiStore, map[string]any) *abci.ExecTxResult, ) ([]*abci.ExecTxResult, error)