Skip to content

Commit 10fa944

Browse files
authored
docs: update CheckTx handler docs to match SDK API (#25666)
1 parent 452dbed commit 10fa944

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

docs/docs/build/abci/04-checktx.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ https://github.com/cosmos/cosmos-sdk/blob/31c604762a434c7b676b6a89897ecbd7c4653a
2020

2121
## CheckTx Handler
2222

23-
`CheckTxHandler` allows users to extend the logic of `CheckTx`. `CheckTxHandler` is called by passing context and the transaction bytes received through ABCI. It is required that the handler returns deterministic results given the same transaction bytes.
24-
25-
:::note
26-
we return the raw decoded transaction here to avoid decoding it twice.
27-
:::
23+
`CheckTxHandler` allows applications to extend the logic of `CheckTx`. It is invoked with the ABCI request and a `RunTx` function that executes the standard `CheckTx` pipeline (ante handlers, gas accounting and mempool interaction). The implementation of `CheckTxHandler` MUST be deterministic for a given `RequestCheckTx`.
2824

2925
```go
30-
type CheckTxHandler func(ctx sdk.Context, tx []byte) (Tx, error)
26+
type CheckTxHandler func(RunTx, *abci.RequestCheckTx) (*abci.ResponseCheckTx, error)
3127
```
3228

33-
Setting a custom `CheckTxHandler` is optional. It can be done from your app.go file:
29+
The provided `RunTx` function does not override ante handlers and does not allow changing the execution mode; it simply runs the transaction through the normal `CheckTx` path and returns the result that can be used to construct a `ResponseCheckTx`.
30+
31+
Setting a custom `CheckTxHandler` is optional. It can be done from your `app.go` file by setting the handler on `BaseApp`:
3432

3533
```go
3634
func NewSimApp(
@@ -41,10 +39,16 @@ func NewSimApp(
4139
appOpts servertypes.AppOptions,
4240
baseAppOptions ...func(*baseapp.BaseApp),
4341
) *SimApp {
44-
...
45-
// Create ChecktxHandler
46-
checktxHandler := abci.NewCustomCheckTxHandler(...)
47-
app.SetCheckTxHandler(checktxHandler)
48-
...
42+
...
43+
checkTxOpt := func(app *baseapp.BaseApp) {
44+
app.SetCheckTxHandler(func(runTx sdk.RunTx, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
45+
// custom pre- or post-processing logic can be added here
46+
return runTx(req.Tx, nil)
47+
})
48+
}
49+
baseAppOptions = append(baseAppOptions, checkTxOpt)
50+
...
4951
}
5052
```
53+
54+
When `RequestCheckTx.Type` is `abci.CheckTxType_New`, the transaction is evaluated for admission into the mempool; when it is `abci.CheckTxType_Recheck`, the existing mempool transaction is re-evaluated and may be removed if it no longer passes validation. Successful `CheckTx` executions update an internal CheckTx state, which is reset when a block is committed.

0 commit comments

Comments
 (0)