Skip to content

Commit ab68cf1

Browse files
committed
refactor CheckTx
1 parent df421b4 commit ab68cf1

File tree

9 files changed

+1294
-11
lines changed

9 files changed

+1294
-11
lines changed

app/abci.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package app
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"time"
67

78
"github.com/cosmos/cosmos-sdk/telemetry"
89
sdk "github.com/cosmos/cosmos-sdk/types"
10+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
911
"github.com/sei-protocol/sei-chain/app/legacyabci"
1012
"github.com/sei-protocol/sei-chain/utils/metrics"
1113
abci "github.com/tendermint/tendermint/abci/types"
@@ -60,6 +62,45 @@ func (app *App) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (res abci.Re
6062
func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) (*abci.ResponseCheckTxV2, error) {
6163
_, span := app.GetBaseApp().TracingInfo.StartWithContext("CheckTx", ctx)
6264
defer span.End()
65+
if req.Type == abci.CheckTxTypeV2New {
66+
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")
67+
sdkCtx := app.GetCheckTxContext(req.Tx)
68+
tx, err := app.txDecoder(req.Tx)
69+
if err != nil {
70+
res := sdkerrors.ResponseCheckTx(err, 0, 0, false)
71+
return &abci.ResponseCheckTxV2{ResponseCheckTx: &res}, err
72+
}
73+
checksum := sha256.Sum256(req.Tx)
74+
gInfo, result, txCtx, err := legacyabci.CheckTx(sdkCtx, tx, app.GetTxConfig(), &app.CheckTxKeepers, checksum, func(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) {
75+
return app.CacheTxContext(ctx, checksum)
76+
}, app.GetCheckCtx, app.TracingInfo)
77+
if err != nil {
78+
res := sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, false)
79+
return &abci.ResponseCheckTxV2{ResponseCheckTx: &res}, err
80+
}
81+
82+
res := &abci.ResponseCheckTxV2{
83+
ResponseCheckTx: &abci.ResponseCheckTx{
84+
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
85+
Data: result.Data,
86+
Priority: txCtx.Priority(),
87+
GasEstimated: int64(gInfo.GasEstimate),
88+
},
89+
ExpireTxHandler: txCtx.ExpireTxHandler(),
90+
CheckTxCallback: txCtx.CheckTxCallback(),
91+
EVMNonce: txCtx.EVMNonce(),
92+
EVMSenderAddress: txCtx.EVMSenderAddress(),
93+
IsEVM: txCtx.IsEVM(),
94+
Priority: txCtx.Priority(),
95+
}
96+
if txCtx.PendingTxChecker() != nil {
97+
res.IsPendingTransaction = true
98+
res.Checker = txCtx.PendingTxChecker()
99+
}
100+
101+
return res, nil
102+
}
103+
// recheck case only
63104
return app.BaseApp.CheckTx(ctx, req)
64105
}
65106

0 commit comments

Comments
 (0)