-
Notifications
You must be signed in to change notification settings - Fork 180
/
baseapp_checktx.go
87 lines (73 loc) · 2.73 KB
/
baseapp_checktx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package baseapp
import (
"encoding/json"
"fmt"
"sync/atomic"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/libs/tendermint/global"
)
// CheckTx implements the ABCI interface and executes a tx in CheckTx mode. In
// CheckTx mode, messages are not executed. This means messages are only validated
// and only the AnteHandler is executed. State is persisted to the BaseApp's
// internal CheckTx state if the AnteHandler passes. Otherwise, the ResponseCheckTx
// will contain releveant error information. Regardless of tx execution outcome,
// the ResponseCheckTx will contain relevant gas execution context.
func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
tx, err := app.txDecoder(req.Tx, global.GetGlobalHeight())
if err != nil {
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
}
var mode runTxMode
switch {
case req.Type == abci.CheckTxType_New:
mode = runTxModeCheck
atomic.AddInt64(&app.checkTxNum, 1)
if app.updateCMTxNonceHandler != nil {
app.updateCMTxNonceHandler(tx, req.Nonce)
}
case req.Type == abci.CheckTxType_Recheck:
mode = runTxModeReCheck
case req.Type == abci.CheckTxType_WrappedCheck:
mode = runTxModeWrappedCheck
atomic.AddInt64(&app.wrappedCheckTxNum, 1)
default:
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}
if abci.GetDisableCheckTx() {
var ctx sdk.Context
ctx = app.getContextForTx(mode, req.Tx)
exTxInfo := app.GetTxInfo(ctx, tx)
data, _ := json.Marshal(exTxInfo)
app.updateCheckTxResponseNonce(tx, mode, exTxInfo.SenderNonce)
return abci.ResponseCheckTx{
Tx: tx,
SenderNonce: exTxInfo.SenderNonce,
Data: data,
}
}
info, err := app.runTx(mode, req.Tx, tx, LatestSimulateTxHeight, req.From)
if err != nil {
return sdkerrors.ResponseCheckTx(err, info.gInfo.GasWanted, info.gInfo.GasUsed, app.trace)
}
app.updateCheckTxResponseNonce(tx, mode, info.accountNonce)
return abci.ResponseCheckTx{
Tx: tx,
SenderNonce: info.accountNonce,
GasWanted: int64(info.gInfo.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(info.gInfo.GasUsed), // TODO: Should type accept unsigned ints?
Log: info.result.Log,
Data: info.result.Data,
Events: info.result.Events.ToABCIEvents(),
}
}
// for adaptive the same sender multi-tx in mempool can add to TxQueue
func (app *BaseApp) updateCheckTxResponseNonce(tx sdk.Tx, mode runTxMode, senderNonce uint64) {
if tx.GetNonce() == 0 &&
app.updateCMTxNonceHandler != nil &&
mode == runTxModeCheck &&
senderNonce != 0 {
app.updateCMTxNonceHandler(tx, senderNonce)
}
}