Skip to content

Commit a09a63b

Browse files
yihuangmmsqe
authored andcommitted
Problem: tx executor can't do dependency analysis (cosmos#744)
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
1 parent f232a64 commit a09a63b

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

baseapp/abci.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,17 +845,17 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request
845845

846846
func (app *BaseApp) executeTxs(ctx context.Context, txs [][]byte) ([]*abci.ExecTxResult, error) {
847847
if app.txExecutor != nil {
848-
return app.txExecutor(ctx, len(txs), app.finalizeBlockState.ms, func(i int, ms storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult {
849-
return app.deliverTxWithMultiStore(txs[i], i, ms, incarnationCache)
848+
return app.txExecutor(ctx, txs, app.finalizeBlockState.ms, func(i int, memTx sdk.Tx, ms storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult {
849+
return app.deliverTxWithMultiStore(txs[i], memTx, i, ms, incarnationCache)
850850
})
851851
}
852852

853853
txResults := make([]*abci.ExecTxResult, 0, len(txs))
854854
for i, rawTx := range txs {
855855
var response *abci.ExecTxResult
856856

857-
if _, err := app.txDecoder(rawTx); err == nil {
858-
response = app.deliverTx(rawTx, i)
857+
if memTx, err := app.txDecoder(rawTx); err == nil {
858+
response = app.deliverTx(rawTx, memTx, i)
859859
} else {
860860
// In the case where a transaction included in a block proposal is malformed,
861861
// we still want to return a default response to comet. This is because comet

baseapp/baseapp.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,11 @@ func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, er
770770
return resp, nil
771771
}
772772

773-
func (app *BaseApp) deliverTx(tx []byte, txIndex int) *abci.ExecTxResult {
774-
return app.deliverTxWithMultiStore(tx, txIndex, nil, nil)
773+
func (app *BaseApp) deliverTx(tx []byte, memTx sdk.Tx, txIndex int) *abci.ExecTxResult {
774+
return app.deliverTxWithMultiStore(tx, memTx, txIndex, nil, nil)
775775
}
776776

777-
func (app *BaseApp) deliverTxWithMultiStore(tx []byte, txIndex int, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult {
777+
func (app *BaseApp) deliverTxWithMultiStore(tx []byte, memTx sdk.Tx, txIndex int, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult {
778778
gInfo := sdk.GasInfo{}
779779
resultStr := "successful"
780780

@@ -787,7 +787,7 @@ func (app *BaseApp) deliverTxWithMultiStore(tx []byte, txIndex int, txMultiStore
787787
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
788788
}()
789789

790-
gInfo, result, anteEvents, err := app.runTxWithMultiStore(execModeFinalize, tx, txIndex, txMultiStore, incarnationCache)
790+
gInfo, result, anteEvents, err := app.runTxWithMultiStore(execModeFinalize, tx, memTx, txIndex, txMultiStore, incarnationCache)
791791
if err != nil {
792792
resultStr = "failed"
793793
resp = sdkerrors.ResponseExecTxResultWithEvents(
@@ -845,10 +845,17 @@ func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) {
845845
// returned if the tx does not run out of gas and if all the messages are valid
846846
// and execute successfully. An error is returned otherwise.
847847
func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
848-
return app.runTxWithMultiStore(mode, txBytes, -1, nil, nil)
848+
return app.runTxWithMultiStore(mode, txBytes, nil, -1, nil, nil)
849849
}
850850

851-
func (app *BaseApp) runTxWithMultiStore(mode execMode, txBytes []byte, txIndex int, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
851+
func (app *BaseApp) runTxWithMultiStore(
852+
mode execMode,
853+
txBytes []byte,
854+
tx sdk.Tx,
855+
txIndex int,
856+
txMultiStore storetypes.MultiStore,
857+
incarnationCache map[string]any,
858+
) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
852859
// NOTE: GasWanted should be returned by the AnteHandler. GasUsed is
853860
// determined by the GasMeter. We need access to the context to get the gas
854861
// meter, so we initialize upfront.
@@ -900,9 +907,11 @@ func (app *BaseApp) runTxWithMultiStore(mode execMode, txBytes []byte, txIndex i
900907
defer consumeBlockGas()
901908
}
902909

903-
tx, err := app.txDecoder(txBytes)
904-
if err != nil {
905-
return sdk.GasInfo{}, nil, nil, err
910+
if tx == nil {
911+
tx, err = app.txDecoder(txBytes)
912+
if err != nil {
913+
return sdk.GasInfo{}, nil, nil, err
914+
}
906915
}
907916

908917
msgs := tx.GetMsgs()

baseapp/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _ genesis.TxHandler = (*BaseApp)(nil)
1313
// ExecuteGenesisTx implements genesis.GenesisState from
1414
// cosmossdk.io/core/genesis to set initial state in genesis
1515
func (ba BaseApp) ExecuteGenesisTx(tx []byte) error {
16-
res := ba.deliverTx(tx, -1)
16+
res := ba.deliverTx(tx, nil, -1)
1717

1818
if res.Code != types.CodeTypeOK {
1919
return errors.New(res.Log)

baseapp/txexecutor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"context"
55

66
abci "github.com/cometbft/cometbft/abci/types"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
78

89
"cosmossdk.io/store/types"
910
)
1011

1112
type TxExecutor func(
1213
ctx context.Context,
13-
blockSize int,
14+
block [][]byte,
1415
cms types.MultiStore,
15-
deliverTxWithMultiStore func(int, types.MultiStore, map[string]any) *abci.ExecTxResult,
16+
deliverTxWithMultiStore func(int, sdk.Tx, types.MultiStore, map[string]any) *abci.ExecTxResult,
1617
) ([]*abci.ExecTxResult, error)

0 commit comments

Comments
 (0)