Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Sep 11, 2024
1 parent 0577744 commit 2ea9acc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 37 deletions.
52 changes: 20 additions & 32 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions baseapp/txexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2ea9acc

Please sign in to comment.