Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: BaseApp {Check,Deliver}Tx with middleware design #9920

Merged
merged 39 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
48da6e2
Replace abci calls with txHandler
amaury1093 Aug 12, 2021
3e4d7b6
still WIP
amaury1093 Aug 12, 2021
096d103
Use inner
amaury1093 Aug 12, 2021
11bd37f
runTx middleware
amaury1093 Aug 13, 2021
c666dc9
Fix some tests
amaury1093 Aug 13, 2021
664f8d7
Simplify runMsgs
amaury1093 Aug 13, 2021
25a643e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/m…
amaury1093 Aug 13, 2021
ac74030
Fix ante event emitting
amaury1093 Aug 13, 2021
0b8f940
Use context.Context
amaury1093 Aug 16, 2021
080c6af
Small refactor
amaury1093 Aug 16, 2021
c3911f8
Fix antehandler events
amaury1093 Aug 16, 2021
6582496
Add Simulate
amaury1093 Aug 16, 2021
a900541
Fix gasInfo
amaury1093 Aug 16, 2021
6b1f9d7
Add gas tx middleware
amaury1093 Aug 16, 2021
bbf2872
Fix baseapp_test
amaury1093 Aug 16, 2021
dd32108
Fix tests
amaury1093 Aug 17, 2021
60d43dc
Fix grpc SimulateTx test
amaury1093 Aug 18, 2021
4451a4b
Fix slashing test
amaury1093 Aug 18, 2021
7f071da
Merge branch 'master' into am/middleware
amaury1093 Aug 18, 2021
c5c0247
Fix mock tests
amaury1093 Aug 18, 2021
67a2cd5
Fix antehandlers test
amaury1093 Aug 19, 2021
788d7a0
Merge branch 'master' into am/middleware
alexanderbez Aug 20, 2021
8fee5b9
Address reviews
amaury1093 Aug 23, 2021
43c4de0
Merge branch 'am/middleware' of ssh://github.com/cosmos/cosmos-sdk in…
amaury1093 Aug 23, 2021
00fce8c
More reviews
amaury1093 Aug 23, 2021
e5a076f
Fix tests
amaury1093 Aug 23, 2021
dd70e91
Merge branch 'master' into am/middleware
alexanderbez Aug 23, 2021
61d1013
Switch ComposeMiddlewares order
amaury1093 Aug 24, 2021
74167e9
Fix test
amaury1093 Aug 24, 2021
0bb9c48
Merge branch 'master' into am/middleware
amaury1093 Aug 24, 2021
c66c5d2
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/m…
amaury1093 Aug 25, 2021
f2432fb
Add changelog
amaury1093 Aug 25, 2021
1c3e321
add error to NewDefaultTxHandler
amaury1093 Aug 25, 2021
23d1652
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/m…
amaury1093 Aug 25, 2021
9cc1883
Fix build
amaury1093 Aug 25, 2021
d8662f6
Update x/auth/middleware/run_msgs.go
amaury1093 Aug 25, 2021
964cf4f
fix nit
amaury1093 Aug 25, 2021
cac72ea
fix test
amaury1093 Aug 25, 2021
880ff6b
Merge branch 'master' into am/middleware
amaury1093 Aug 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9650](https://github.com/cosmos/cosmos-sdk/pull/9650) Removed deprecated message handler implementation from the SDK modules.
* (x/bank) [\#9832] (https://github.com/cosmos/cosmos-sdk/pull/9832) `AddressFromBalancesStore` renamed to `AddressAndDenomFromBalancesStore`.
* (tests) [\#9938](https://github.com/cosmos/cosmos-sdk/pull/9938) `simapp.Setup` accepts additional `testing.T` argument.

* (baseapp) [\#9920](https://github.com/cosmos/cosmos-sdk/pull/9920) BaseApp `{Check,Deliver,Simulate}Tx` methods are now replaced by a middleware stack.
* Replace the Antehandler interface with the `tx.Handler` and `tx.Middleware` interfaces.
* Replace `baseapp.SetAnteHandler` with `baseapp.SetTxHandler`.
* Move Msg routers from BaseApp to middlewares.
* Move Baseapp panic recovery into a middleware.
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}`.

### Client Breaking Changes

Expand Down
43 changes: 16 additions & 27 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,18 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}

gInfo, result, err := app.runTx(mode, req.Tx)
tx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
}

return abci.ResponseCheckTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints?
Log: result.Log,
Data: result.Data,
Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents),
ctx := app.getContextForTx(mode, req.Tx)
res, err := app.txHandler.CheckTx(ctx, tx, req)
if err != nil {
return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace)
}

return res
}

// DeliverTx implements the ABCI interface and executes a tx in DeliverTx mode.
Expand All @@ -262,29 +262,18 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx")

gInfo := sdk.GasInfo{}
resultStr := "successful"

defer func() {
telemetry.IncrCounter(1, "tx", "count")
telemetry.IncrCounter(1, "tx", resultStr)
telemetry.SetGauge(float32(gInfo.GasUsed), "tx", "gas", "used")
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
}()

gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx)
tx, err := app.txDecoder(req.Tx)
if err != nil {
resultStr = "failed"
return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
return sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace)
}

return abci.ResponseDeliverTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints?
Log: result.Log,
Data: result.Data,
Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents),
ctx := app.getContextForTx(runTxModeDeliver, req.Tx)
res, err := app.txHandler.DeliverTx(ctx, tx, req)
if err != nil {
return sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace)
}

return res
}

// Commit implements the ABCI interface. It will commit all state that exists in
Expand Down
Loading