cosmos-sdk/types
Amaury a15d7e31d4
refactor!: BaseApp {Check,Deliver}Tx with middleware design (#9920)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

ref: #9585 

This PR if the 1st step (out of 2) in the #9585 refactor. It transforms baseapp's ABCI {Check,Deliver}Tx into middleware stacks. A middleware is defined by the following interfaces:

```go
// types/tx package

type Handler interface {
	CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error)
	DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error)
	SimulateTx(ctx context.Context, tx sdk.Tx, req RequestSimulateTx) (ResponseSimulateTx, error)
}

type Middleware func(Handler) Handler
```

This Pr doesn't migrate antehandlers, but only baseapp's runTx and runMsgs as middlewares. It bundles antehandlers into one single middleware (for now).

More specifically, it introduces the 5 following middlewares:

| Middleware              | Description                                                                                                                                                                                                                                                                                                                                                                                            |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| RunMsgsTxMiddleware     | This middleware replaces the old baseapp's `runMsgs`.                                                                                                                                                                                                                                                                                                                                                  |
| LegacyAnteMiddleware    | This middleware is temporary, it bundles all antehandlers into one middleware. It's only created for the purpose of breaking the refactor into 2 pieces. **It will be removed in Part 2**, and each antehandler will be replaced by its own middleware.                                                                                                                                                                                                  |
| IndexEventsTxMiddleware | This is a simple middleware that chooses which events to index in Tendermint. Replaces `baseapp.indexEvents` (which unfortunately still exists in baseapp too, because it's used to index Begin/EndBlock events)                                                                                                                                                                                        |
| RecoveryTxMiddleware    | This index recovers from panics. It replaces baseapp.runTx's panic recovery.                                                                                                                                                                                                                                                                                                                           |
| GasTxMiddleware         | This replaces the [`Setup`](https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/ante/setup.go) Antehandler. It sets a GasMeter on sdk.Context. Note that before, GasMeter was set on sdk.Context inside the antehandlers, and there was some mess around the fact that antehandlers had their own panic recovery system so that the GasMeter could be read by baseapp's recovery system. Now, this mess is all removed: one middleware sets GasMeter, another one handles recovery. |

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-08-25 14:40:33 +00:00
..
address feat!: Add bech32 prefix to authkeeper (#9759) 2021-08-25 11:17:18 +00:00
bech32 codec: Rename codec and marshaler interfaces (#9226) 2021-04-29 10:46:22 +00:00
errors feat!: support debug trace QueryResult (#9576) 2021-07-08 09:25:40 +00:00
grpc Add GRPCBlockHeightHeader in clientCtx gRPC requests (#7021) 2020-08-12 14:42:10 +00:00
kv fix: check store keys length before accessing (#9639) 2021-07-08 13:29:12 +02:00
module chore: Add log messages for InitGenesis (#9675) 2021-08-12 12:32:36 -04:00
msgservice Cleanup remains of ServiceMsg (#9236) 2021-05-07 09:31:20 +00:00
query refactor(test)!: refactor `simapp.Setup` function (#9938) 2021-08-17 00:52:06 +00:00
simulation refactor: Rename x/{mod}/legacy to x/{mod}/migrations (#9628) 2021-07-05 14:55:51 +00:00
tx refactor!: BaseApp {Check,Deliver}Tx with middleware design (#9920) 2021-08-25 14:40:33 +00:00
abci.go Merge PR #4613: Only change rootmultistore hash when substore hashes change 2019-06-25 13:11:22 -04:00
abci.pb.go Update gogo proto deps with v1.3.2 security fixes (#8350) 2021-01-15 19:45:34 +00:00
address.go feat!: Add bech32 prefix to authkeeper (#9759) 2021-08-25 11:17:18 +00:00
address_race_test.go cosmos-reflection: extend to support writing by reflection clients (#8965) 2021-04-07 00:33:54 +01:00
address_test.go Remove bech32 PubKey support (#7477) 2021-03-25 14:53:22 +00:00
bench_test.go run make format (#8642) 2021-02-19 15:02:53 +00:00
codec.go Remove ServiceMsgs from ADR-031 (#9139) 2021-04-30 11:00:47 +00:00
coin.go fix: Fix testnet command (#9454) 2021-06-03 15:08:21 +00:00
coin.pb.go Update gogo proto deps with v1.3.2 security fixes (#8350) 2021-01-15 19:45:34 +00:00
coin_benchmark_test.go test: fix BenchmarkCoinsAdditionIntersect panic (#9904) 2021-08-11 02:13:17 -07:00
coin_internal_test.go add sorted check for the coins sub/add fun parameter (#9240) 2021-05-05 15:55:28 +00:00
coin_test.go add sorted check for the coins sub/add fun parameter (#9240) 2021-05-05 15:55:28 +00:00
config.go Deprecate SetFullFundraiserPath in favor of SetPurpose and SetCoinType (#8629) 2021-02-22 15:14:09 +00:00
config_test.go Deprecate SetFullFundraiserPath in favor of SetPurpose and SetCoinType (#8629) 2021-02-22 15:14:09 +00:00
context.go feat: add header hash to `Context` (#9390) 2021-05-26 08:36:42 +00:00
context_test.go feat: add header hash to `Context` (#9390) 2021-05-26 08:36:42 +00:00
dec_coin.go types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn (#7989) 2020-11-20 19:37:45 +00:00
dec_coin_test.go test: Added tests for DecCoins to increase code coverage (#9752) 2021-07-26 20:51:22 +00:00
decimal.go fix: Handle MAX_INT_256 (#9511) 2021-06-16 14:18:02 +00:00
decimal_internal_test.go types: tests -> test suites migration (#7400) 2020-09-28 12:46:49 +02:00
decimal_test.go feat: add Dec.Float64() function (#9382) 2021-05-26 09:02:14 +00:00
denom.go cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
denom_internal_test.go cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
events.go feat: add tx fee event (#9860) 2021-08-09 14:50:01 +00:00
events_test.go init: Implement ADR 032 typed events (#7564) 2020-10-28 11:02:39 +00:00
handler.go fix types.ChainAnteDecorators() panic (#5742) 2020-03-03 16:57:33 +00:00
handler_test.go test: fix mockgen version (#9127) 2021-05-25 09:18:59 +00:00
int.go types: fix nil pointer panic on `NewIntFromBigInt` (#9627) 2021-07-05 08:36:35 -04:00
int_internal_test.go fix: Handle MAX_INT_256 (#9511) 2021-06-16 14:18:02 +00:00
int_test.go types: fix nil pointer panic on `NewIntFromBigInt` (#9627) 2021-07-05 08:36:35 -04:00
invariant.go Merge PR #4832: print all failed invariants only 2019-08-05 14:21:44 -04:00
invariant_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
proto.go linter: enable nolintlint (#6162) 2020-05-08 08:46:12 +00:00
queryable.go Merge PR #5421: Refactor Error Handling 2019-12-27 12:57:54 -05:00
result.go Refactor x/bank according to ADR 031 (#7520) 2020-10-13 09:05:46 +00:00
result_test.go Refactor x/bank according to ADR 031 (#7520) 2020-10-13 09:05:46 +00:00
router.go Remove duplicated Module.Route calls (#7716) 2020-10-29 22:01:09 +00:00
router_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
staking.go simply default power reduction definition 2021-03-21 20:29:39 -04:00
staking_test.go on-chain power reduction param conversion basic work 2021-01-27 20:24:00 +10:00
store.go fix: store key uniqueness (#9363) 2021-05-20 18:13:09 +00:00
store_internal_test.go fix: store key uniqueness (#9363) 2021-05-20 18:13:09 +00:00
store_test.go fix: store key uniqueness (#9363) 2021-05-20 18:13:09 +00:00
tx_msg.go refactor!: change GetSigners return type to []sdk.AccAddress (#9915) 2021-08-13 15:34:00 +00:00
tx_msg_test.go refactor!: change GetSigners return type to []sdk.AccAddress (#9915) 2021-08-13 15:34:00 +00:00
uint.go various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
uint_internal_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
uint_test.go types: use (*math/big.Int).BitLen() == 0 to check if value is 0 (#8580) 2021-02-15 10:53:10 +00:00
utils.go tendermint: update to rc3 (#6892) 2020-08-14 13:58:53 -04:00
utils_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00