2018-01-20 20:08:00 -08:00
|
|
|
package baseapp
|
2017-10-16 10:21:43 -07:00
|
|
|
|
|
|
|
import (
|
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 07:40:33 -07:00
|
|
|
"context"
|
2020-09-08 02:05:44 -07:00
|
|
|
"errors"
|
2017-12-01 09:10:17 -08:00
|
|
|
"fmt"
|
|
|
|
|
2018-06-28 17:54:47 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-07-02 13:34:06 -07:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2019-08-02 06:20:39 -07:00
|
|
|
dbm "github.com/tendermint/tm-db"
|
2017-10-16 10:21:43 -07:00
|
|
|
|
2020-10-15 06:07:59 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
2020-09-08 02:05:44 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/snapshots"
|
2018-01-22 05:44:24 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
2020-09-08 02:05:44 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
2021-10-04 09:36:38 -07:00
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
2018-01-12 13:59:19 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
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 07:40:33 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
2017-10-16 10:21:43 -07:00
|
|
|
)
|
|
|
|
|
2018-05-15 17:06:17 -07:00
|
|
|
const (
|
2019-10-23 07:43:58 -07:00
|
|
|
runTxModeCheck runTxMode = iota // Check a transaction
|
|
|
|
runTxModeReCheck // Recheck a (pending) transaction after a commit
|
|
|
|
runTxModeSimulate // Simulate a transaction
|
|
|
|
runTxModeDeliver // Deliver a transaction
|
2018-05-15 17:06:17 -07:00
|
|
|
)
|
|
|
|
|
2019-09-04 10:33:32 -07:00
|
|
|
var (
|
|
|
|
_ abci.Application = (*BaseApp)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Enum mode for app.runTx
|
|
|
|
runTxMode uint8
|
|
|
|
|
|
|
|
// StoreLoader defines a customizable function to control how we load the CommitMultiStore
|
|
|
|
// from disk. This is useful for state migration, when loading a datastore written with
|
|
|
|
// an older version of the software. In particular, if a module changed the substore key name
|
|
|
|
// (or removed a substore) between two versions of the software.
|
|
|
|
StoreLoader func(ms sdk.CommitMultiStore) error
|
|
|
|
)
|
2019-08-06 05:59:22 -07:00
|
|
|
|
2018-07-12 16:58:51 -07:00
|
|
|
// BaseApp reflects the ABCI application implementation.
|
2019-10-14 08:43:19 -07:00
|
|
|
type BaseApp struct { // nolint: maligned
|
2018-02-17 15:10:55 -08:00
|
|
|
// initialized on creation
|
2020-10-15 06:07:59 -07:00
|
|
|
logger log.Logger
|
|
|
|
name string // application name from abci.Info
|
|
|
|
db dbm.DB // common DB backend
|
|
|
|
cms sdk.CommitMultiStore // Main (uncached) state
|
|
|
|
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
|
|
|
|
queryRouter sdk.QueryRouter // router for redirecting query calls
|
|
|
|
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
|
|
|
|
interfaceRegistry types.InterfaceRegistry
|
2018-07-18 16:24:16 -07:00
|
|
|
|
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 07:40:33 -07:00
|
|
|
txHandler tx.Handler // txHandler for {Deliver,Check}Tx and simulations
|
2019-02-07 17:52:24 -08:00
|
|
|
initChainer sdk.InitChainer // initialize state with validators and state blob
|
|
|
|
beginBlocker sdk.BeginBlocker // logic to run before any txs
|
|
|
|
endBlocker sdk.EndBlocker // logic to run after all txs, and to determine valset changes
|
|
|
|
addrPeerFilter sdk.PeerFilter // filter peers by address and port
|
|
|
|
idPeerFilter sdk.PeerFilter // filter peers by node ID
|
|
|
|
fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed.
|
2018-01-12 11:49:53 -08:00
|
|
|
|
2020-09-08 02:05:44 -07:00
|
|
|
// manages snapshots, i.e. dumps of app state at certain intervals
|
|
|
|
snapshotManager *snapshots.Manager
|
|
|
|
snapshotInterval uint64 // block interval between state sync snapshots
|
|
|
|
snapshotKeepRecent uint32 // recent state sync snapshots to keep
|
|
|
|
|
2019-09-04 10:33:32 -07:00
|
|
|
// volatile states:
|
|
|
|
//
|
|
|
|
// checkState is set on InitChain and reset on Commit
|
|
|
|
// deliverState is set on InitChain and BeginBlock and set to nil on Commit
|
|
|
|
checkState *state // for CheckTx
|
|
|
|
deliverState *state // for DeliverTx
|
|
|
|
|
|
|
|
// an inter-block write-through cache provided to the context during deliverState
|
|
|
|
interBlockCache sdk.MultiStorePersistentCache
|
|
|
|
|
|
|
|
// absent validators from begin block
|
|
|
|
voteInfos []abci.VoteInfo
|
2018-07-31 21:23:25 -07:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
// paramStore is used to query for ABCI consensus parameters from an
|
|
|
|
// application parameter store.
|
|
|
|
paramStore ParamStore
|
2018-11-20 16:44:49 -08:00
|
|
|
|
2019-01-18 08:45:20 -08:00
|
|
|
// The minimum gas prices a validator is willing to accept for processing a
|
|
|
|
// transaction. This is mainly used for DoS and spam prevention.
|
|
|
|
minGasPrices sdk.DecCoins
|
2018-09-19 08:25:52 -07:00
|
|
|
|
2020-09-03 03:11:46 -07:00
|
|
|
// initialHeight is the initial height at which we start the baseapp
|
|
|
|
initialHeight int64
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// flag for sealing options and parameters to a BaseApp
|
2018-07-31 21:23:25 -07:00
|
|
|
sealed bool
|
2019-04-23 06:33:11 -07:00
|
|
|
|
2019-09-09 07:08:10 -07:00
|
|
|
// block height at which to halt the chain and gracefully shutdown
|
2019-04-23 06:33:11 -07:00
|
|
|
haltHeight uint64
|
2019-05-02 12:37:44 -07:00
|
|
|
|
2019-09-09 07:08:10 -07:00
|
|
|
// minimum block time (in Unix seconds) at which to halt the chain and gracefully shutdown
|
|
|
|
haltTime uint64
|
|
|
|
|
2020-09-14 07:12:49 -07:00
|
|
|
// minRetainBlocks defines the minimum block height offset from the current
|
|
|
|
// block being committed, such that all blocks past this offset are pruned
|
|
|
|
// from Tendermint. It is used as part of the process of determining the
|
|
|
|
// ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
|
|
|
|
// that no blocks should be pruned.
|
|
|
|
//
|
|
|
|
// Note: Tendermint block pruning is dependant on this parameter in conunction
|
|
|
|
// with the unbonding (safety threshold) period, state pruning and state sync
|
|
|
|
// snapshot parameters to determine the correct minimum value of
|
|
|
|
// ResponseCommit.RetainHeight.
|
|
|
|
minRetainBlocks uint64
|
|
|
|
|
2019-05-02 12:37:44 -07:00
|
|
|
// application's version string
|
2021-04-02 07:11:58 -07:00
|
|
|
version string
|
|
|
|
|
|
|
|
// application's protocol version that increments on every upgrade
|
|
|
|
// if BaseApp is passed to the upgrade keeper's NewKeeper method.
|
|
|
|
appVersion uint64
|
2020-06-05 09:48:18 -07:00
|
|
|
|
2020-07-05 09:56:17 -07:00
|
|
|
// trace set will return full stack traces for errors in ABCI Log field
|
|
|
|
trace bool
|
2020-08-20 09:19:16 -07:00
|
|
|
|
|
|
|
// indexEvents defines the set of events in the form {eventType}.{attributeKey},
|
|
|
|
// which informs Tendermint what to index. If empty, all events will be indexed.
|
|
|
|
indexEvents map[string]struct{}
|
2021-10-24 14:37:37 -07:00
|
|
|
|
|
|
|
// abciListeners for hooking into the ABCI message processing of the BaseApp
|
|
|
|
// and exposing the requests and responses to external consumers
|
|
|
|
abciListeners []ABCIListener
|
2017-10-16 10:21:43 -07:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
|
|
|
|
// variadic number of option functions, which act on the BaseApp to set
|
|
|
|
// configuration choices.
|
2018-07-12 16:58:51 -07:00
|
|
|
//
|
2018-03-28 05:33:48 -07:00
|
|
|
// NOTE: The db is used to store the version number for now.
|
2019-02-05 19:11:57 -08:00
|
|
|
func NewBaseApp(
|
2021-12-06 01:26:15 -08:00
|
|
|
name string, logger log.Logger, db dbm.DB, options ...func(*BaseApp),
|
2019-02-05 19:11:57 -08:00
|
|
|
) *BaseApp {
|
2018-07-12 18:32:48 -07:00
|
|
|
app := &BaseApp{
|
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 07:40:33 -07:00
|
|
|
logger: logger,
|
|
|
|
name: name,
|
|
|
|
db: db,
|
|
|
|
cms: store.NewCommitMultiStore(db),
|
|
|
|
storeLoader: DefaultStoreLoader,
|
|
|
|
queryRouter: NewQueryRouter(),
|
|
|
|
grpcQueryRouter: NewGRPCQueryRouter(),
|
|
|
|
fauxMerkleMode: false,
|
2017-12-01 09:10:17 -08:00
|
|
|
}
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2018-07-10 12:10:59 -07:00
|
|
|
for _, option := range options {
|
|
|
|
option(app)
|
|
|
|
}
|
2019-02-05 19:11:57 -08:00
|
|
|
|
2019-09-04 10:33:32 -07:00
|
|
|
if app.interBlockCache != nil {
|
|
|
|
app.cms.SetInterBlockCache(app.interBlockCache)
|
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
return app
|
2017-12-19 21:04:40 -08:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// Name returns the name of the BaseApp.
|
2018-01-20 20:08:00 -08:00
|
|
|
func (app *BaseApp) Name() string {
|
2017-12-21 23:30:44 -08:00
|
|
|
return app.name
|
|
|
|
}
|
|
|
|
|
2021-04-02 07:11:58 -07:00
|
|
|
// AppVersion returns the application's protocol version.
|
|
|
|
func (app *BaseApp) AppVersion() uint64 {
|
2019-05-02 12:37:44 -07:00
|
|
|
return app.appVersion
|
|
|
|
}
|
|
|
|
|
2021-04-02 07:11:58 -07:00
|
|
|
// Version returns the application's version string.
|
|
|
|
func (app *BaseApp) Version() string {
|
|
|
|
return app.version
|
|
|
|
}
|
|
|
|
|
2019-02-07 17:52:24 -08:00
|
|
|
// Logger returns the logger of the BaseApp.
|
|
|
|
func (app *BaseApp) Logger() log.Logger {
|
|
|
|
return app.logger
|
|
|
|
}
|
|
|
|
|
2021-06-24 03:51:30 -07:00
|
|
|
// Trace returns the boolean value for logging error stack traces.
|
|
|
|
func (app *BaseApp) Trace() bool {
|
|
|
|
return app.trace
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp
|
|
|
|
// multistore.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) {
|
2018-02-14 17:09:00 -08:00
|
|
|
for _, key := range keys {
|
2019-02-07 17:52:24 -08:00
|
|
|
switch key.(type) {
|
2021-10-04 09:36:38 -07:00
|
|
|
case *storetypes.KVStoreKey:
|
2019-02-07 17:52:24 -08:00
|
|
|
if !app.fauxMerkleMode {
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(key, storetypes.StoreTypeIAVL)
|
2019-02-07 17:52:24 -08:00
|
|
|
} else {
|
|
|
|
// StoreTypeDB doesn't do anything upon commit, and it doesn't
|
|
|
|
// retain history, but it's useful for faster simulation.
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(key, storetypes.StoreTypeDB)
|
2019-02-07 17:52:24 -08:00
|
|
|
}
|
2019-09-04 10:33:32 -07:00
|
|
|
|
2021-10-04 09:36:38 -07:00
|
|
|
case *storetypes.TransientStoreKey:
|
|
|
|
app.MountStore(key, storetypes.StoreTypeTransient)
|
2019-09-04 10:33:32 -07:00
|
|
|
|
2019-02-07 17:52:24 -08:00
|
|
|
default:
|
2021-10-18 01:37:55 -07:00
|
|
|
panic(fmt.Sprintf("Unrecognized store key type :%T", key))
|
2018-11-27 00:14:22 -08:00
|
|
|
}
|
2018-02-14 17:09:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:57:15 -07:00
|
|
|
// MountKVStores mounts all IAVL or DB stores to the provided keys in the
|
|
|
|
// BaseApp multistore.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) MountKVStores(keys map[string]*storetypes.KVStoreKey) {
|
2019-07-31 06:59:16 -07:00
|
|
|
for _, key := range keys {
|
|
|
|
if !app.fauxMerkleMode {
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(key, storetypes.StoreTypeIAVL)
|
2019-07-31 06:59:16 -07:00
|
|
|
} else {
|
|
|
|
// StoreTypeDB doesn't do anything upon commit, and it doesn't
|
|
|
|
// retain history, but it's useful for faster simulation.
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(key, storetypes.StoreTypeDB)
|
2019-07-31 06:59:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 05:53:35 -07:00
|
|
|
// MountTransientStores mounts all transient stores to the provided keys in
|
2020-07-27 10:57:15 -07:00
|
|
|
// the BaseApp multistore.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientStoreKey) {
|
2019-07-31 06:59:16 -07:00
|
|
|
for _, key := range keys {
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(key, storetypes.StoreTypeTransient)
|
2019-07-31 06:59:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:42:13 -07:00
|
|
|
// MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal
|
|
|
|
// commit multi-store.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) {
|
2020-04-16 09:42:13 -07:00
|
|
|
for _, memKey := range keys {
|
2021-10-04 09:36:38 -07:00
|
|
|
app.MountStore(memKey, storetypes.StoreTypeMemory)
|
2020-04-16 09:42:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// MountStore mounts a store to the provided key in the BaseApp multistore,
|
|
|
|
// using the default DB.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) MountStore(key storetypes.StoreKey, typ storetypes.StoreType) {
|
2018-04-13 03:44:20 -07:00
|
|
|
app.cms.MountStoreWithDB(key, typ, nil)
|
2018-01-24 11:47:51 -08:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// LoadLatestVersion loads the latest application version. It will panic if
|
|
|
|
// called more than once on a running BaseApp.
|
2020-04-16 08:10:39 -07:00
|
|
|
func (app *BaseApp) LoadLatestVersion() error {
|
2019-08-06 05:59:22 -07:00
|
|
|
err := app.storeLoader(app.cms)
|
2018-06-28 15:52:10 -07:00
|
|
|
if err != nil {
|
2020-04-16 08:10:39 -07:00
|
|
|
return fmt.Errorf("failed to load latest version: %w", err)
|
2018-06-28 15:52:10 -07:00
|
|
|
}
|
2020-04-16 08:10:39 -07:00
|
|
|
|
|
|
|
return app.init()
|
2017-12-19 21:04:40 -08:00
|
|
|
}
|
|
|
|
|
2019-08-06 05:59:22 -07:00
|
|
|
// DefaultStoreLoader will be used by default and loads the latest version
|
|
|
|
func DefaultStoreLoader(ms sdk.CommitMultiStore) error {
|
|
|
|
return ms.LoadLatestVersion()
|
|
|
|
}
|
|
|
|
|
2022-02-24 08:17:11 -08:00
|
|
|
// CommitMultiStore returns the root multi-store.
|
|
|
|
// App constructor can use this to access the `cms`.
|
|
|
|
// UNSAFE: only safe to use during app initialization.
|
|
|
|
func (app *BaseApp) CommitMultiStore() sdk.CommitMultiStore {
|
|
|
|
if app.sealed {
|
|
|
|
panic("cannot call CommitMultiStore() after baseapp is sealed")
|
|
|
|
}
|
|
|
|
return app.cms
|
|
|
|
}
|
|
|
|
|
|
|
|
// SnapshotManager returns the snapshot manager.
|
|
|
|
// application use this to register extra extension snapshotters.
|
|
|
|
func (app *BaseApp) SnapshotManager() *snapshots.Manager {
|
|
|
|
return app.snapshotManager
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// LoadVersion loads the BaseApp application version. It will panic if called
|
|
|
|
// more than once on a running baseapp.
|
2020-04-16 08:10:39 -07:00
|
|
|
func (app *BaseApp) LoadVersion(version int64) error {
|
2018-06-28 15:52:10 -07:00
|
|
|
err := app.cms.LoadVersion(version)
|
|
|
|
if err != nil {
|
2020-04-16 08:10:39 -07:00
|
|
|
return fmt.Errorf("failed to load version %d: %w", version, err)
|
2018-06-28 15:52:10 -07:00
|
|
|
}
|
2020-04-16 08:10:39 -07:00
|
|
|
|
|
|
|
return app.init()
|
2017-12-20 17:34:51 -08:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// LastCommitID returns the last CommitID of the multistore.
|
2021-10-04 09:36:38 -07:00
|
|
|
func (app *BaseApp) LastCommitID() storetypes.CommitID {
|
2018-01-26 04:19:33 -08:00
|
|
|
return app.cms.LastCommitID()
|
2017-12-26 17:04:48 -08:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// LastBlockHeight returns the last committed block height.
|
2018-01-20 20:08:00 -08:00
|
|
|
func (app *BaseApp) LastBlockHeight() int64 {
|
2018-01-26 04:19:33 -08:00
|
|
|
return app.cms.LastCommitID().Version
|
2017-12-26 17:04:48 -08:00
|
|
|
}
|
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
func (app *BaseApp) init() error {
|
|
|
|
if app.sealed {
|
|
|
|
panic("cannot call initFromMainStore: baseapp already sealed")
|
2018-11-20 16:44:49 -08:00
|
|
|
}
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
// needed for the export command which inits from store but never calls initchain
|
2020-08-14 10:58:53 -07:00
|
|
|
app.setCheckState(tmproto.Header{})
|
2018-07-31 21:23:25 -07:00
|
|
|
app.Seal()
|
|
|
|
|
2020-09-08 02:05:44 -07:00
|
|
|
// make sure the snapshot interval is a multiple of the pruning KeepEvery interval
|
|
|
|
if app.snapshotManager != nil && app.snapshotInterval > 0 {
|
2022-02-12 07:54:04 -08:00
|
|
|
if _, ok := app.cms.(*rootmulti.Store); !ok {
|
2020-09-08 02:05:44 -07:00
|
|
|
return errors.New("state sync snapshots require a rootmulti store")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 17:34:51 -08:00
|
|
|
return nil
|
2017-12-01 09:10:17 -08:00
|
|
|
}
|
|
|
|
|
2019-01-18 08:45:20 -08:00
|
|
|
func (app *BaseApp) setMinGasPrices(gasPrices sdk.DecCoins) {
|
|
|
|
app.minGasPrices = gasPrices
|
|
|
|
}
|
2018-09-19 08:25:52 -07:00
|
|
|
|
2019-09-09 07:08:10 -07:00
|
|
|
func (app *BaseApp) setHaltHeight(haltHeight uint64) {
|
|
|
|
app.haltHeight = haltHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *BaseApp) setHaltTime(haltTime uint64) {
|
|
|
|
app.haltTime = haltTime
|
2019-04-23 06:33:11 -07:00
|
|
|
}
|
|
|
|
|
2020-09-14 07:12:49 -07:00
|
|
|
func (app *BaseApp) setMinRetainBlocks(minRetainBlocks uint64) {
|
|
|
|
app.minRetainBlocks = minRetainBlocks
|
|
|
|
}
|
|
|
|
|
2019-09-04 10:33:32 -07:00
|
|
|
func (app *BaseApp) setInterBlockCache(cache sdk.MultiStorePersistentCache) {
|
|
|
|
app.interBlockCache = cache
|
|
|
|
}
|
|
|
|
|
2020-07-05 09:56:17 -07:00
|
|
|
func (app *BaseApp) setTrace(trace bool) {
|
|
|
|
app.trace = trace
|
|
|
|
}
|
|
|
|
|
2020-08-20 09:19:16 -07:00
|
|
|
func (app *BaseApp) setIndexEvents(ie []string) {
|
|
|
|
app.indexEvents = make(map[string]struct{})
|
|
|
|
|
|
|
|
for _, e := range ie {
|
|
|
|
app.indexEvents[e] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// QueryRouter returns the QueryRouter of a BaseApp.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (app *BaseApp) QueryRouter() sdk.QueryRouter { return app.queryRouter }
|
2018-02-27 20:46:27 -08:00
|
|
|
|
2019-02-05 19:11:57 -08:00
|
|
|
// Seal seals a BaseApp. It prohibits any further modifications to a BaseApp.
|
|
|
|
func (app *BaseApp) Seal() { app.sealed = true }
|
|
|
|
|
|
|
|
// IsSealed returns true if the BaseApp is sealed and false otherwise.
|
|
|
|
func (app *BaseApp) IsSealed() bool { return app.sealed }
|
2018-11-20 01:06:14 -08:00
|
|
|
|
2021-01-05 07:57:33 -08:00
|
|
|
// setCheckState sets the BaseApp's checkState with a branched multi-store
|
|
|
|
// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch,
|
2019-09-04 10:33:32 -07:00
|
|
|
// provided header, and minimum gas prices set. It is set on InitChain and reset
|
|
|
|
// on Commit.
|
2020-08-14 10:58:53 -07:00
|
|
|
func (app *BaseApp) setCheckState(header tmproto.Header) {
|
2018-02-27 20:46:27 -08:00
|
|
|
ms := app.cms.CacheMultiStore()
|
|
|
|
app.checkState = &state{
|
|
|
|
ms: ms,
|
2019-02-07 17:52:24 -08:00
|
|
|
ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices),
|
2018-02-27 20:46:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 07:57:33 -08:00
|
|
|
// setDeliverState sets the BaseApp's deliverState with a branched multi-store
|
|
|
|
// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch,
|
2019-09-04 10:33:32 -07:00
|
|
|
// and provided header. It is set on InitChain and BeginBlock and set to nil on
|
|
|
|
// Commit.
|
2020-08-14 10:58:53 -07:00
|
|
|
func (app *BaseApp) setDeliverState(header tmproto.Header) {
|
2018-02-27 20:46:27 -08:00
|
|
|
ms := app.cms.CacheMultiStore()
|
|
|
|
app.deliverState = &state{
|
|
|
|
ms: ms,
|
2019-02-07 17:52:24 -08:00
|
|
|
ctx: sdk.NewContext(ms, header, false, app.logger),
|
2018-02-17 15:10:55 -08:00
|
|
|
}
|
2018-02-16 17:15:38 -08:00
|
|
|
}
|
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
// GetConsensusParams returns the current consensus parameters from the BaseApp's
|
|
|
|
// ParamStore. If the BaseApp has no ParamStore defined, nil is returned.
|
2021-11-16 11:24:38 -08:00
|
|
|
func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *tmproto.ConsensusParams {
|
2020-04-16 08:10:39 -07:00
|
|
|
if app.paramStore == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 11:24:38 -08:00
|
|
|
cp := new(tmproto.ConsensusParams)
|
2020-04-16 08:10:39 -07:00
|
|
|
|
|
|
|
if app.paramStore.Has(ctx, ParamStoreKeyBlockParams) {
|
2021-11-16 11:24:38 -08:00
|
|
|
var bp tmproto.BlockParams
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
app.paramStore.Get(ctx, ParamStoreKeyBlockParams, &bp)
|
|
|
|
cp.Block = &bp
|
|
|
|
}
|
|
|
|
|
|
|
|
if app.paramStore.Has(ctx, ParamStoreKeyEvidenceParams) {
|
2020-08-14 10:58:53 -07:00
|
|
|
var ep tmproto.EvidenceParams
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
app.paramStore.Get(ctx, ParamStoreKeyEvidenceParams, &ep)
|
|
|
|
cp.Evidence = &ep
|
|
|
|
}
|
|
|
|
|
|
|
|
if app.paramStore.Has(ctx, ParamStoreKeyValidatorParams) {
|
2020-08-14 10:58:53 -07:00
|
|
|
var vp tmproto.ValidatorParams
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
app.paramStore.Get(ctx, ParamStoreKeyValidatorParams, &vp)
|
|
|
|
cp.Validator = &vp
|
|
|
|
}
|
|
|
|
|
|
|
|
return cp
|
2018-11-20 16:44:49 -08:00
|
|
|
}
|
|
|
|
|
2020-04-22 11:24:13 -07:00
|
|
|
// StoreConsensusParams sets the consensus parameters to the baseapp's param store.
|
2021-11-16 11:24:38 -08:00
|
|
|
func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *tmproto.ConsensusParams) {
|
2020-04-16 08:10:39 -07:00
|
|
|
if app.paramStore == nil {
|
|
|
|
panic("cannot store consensus params with no params store set")
|
2018-11-20 16:44:49 -08:00
|
|
|
}
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
if cp == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
app.paramStore.Set(ctx, ParamStoreKeyBlockParams, cp.Block)
|
|
|
|
app.paramStore.Set(ctx, ParamStoreKeyEvidenceParams, cp.Evidence)
|
|
|
|
app.paramStore.Set(ctx, ParamStoreKeyValidatorParams, cp.Validator)
|
2021-07-08 01:46:45 -07:00
|
|
|
// We're explicitly not storing the Tendermint app_version in the param store. It's
|
|
|
|
// stored instead in the x/upgrade store, with its own bump logic.
|
2018-11-20 16:44:49 -08:00
|
|
|
}
|
|
|
|
|
2019-03-07 21:52:19 -08:00
|
|
|
// getMaximumBlockGas gets the maximum gas from the consensus params. It panics
|
|
|
|
// if maximum block gas is less than negative one and returns zero if negative
|
|
|
|
// one.
|
2020-04-16 08:10:39 -07:00
|
|
|
func (app *BaseApp) getMaximumBlockGas(ctx sdk.Context) uint64 {
|
|
|
|
cp := app.GetConsensusParams(ctx)
|
|
|
|
if cp == nil || cp.Block == nil {
|
2018-11-20 16:44:49 -08:00
|
|
|
return 0
|
|
|
|
}
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2020-04-16 08:10:39 -07:00
|
|
|
maxGas := cp.Block.MaxGas
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2019-03-07 21:52:19 -08:00
|
|
|
switch {
|
|
|
|
case maxGas < -1:
|
|
|
|
panic(fmt.Sprintf("invalid maximum block gas: %d", maxGas))
|
|
|
|
|
|
|
|
case maxGas == -1:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
default:
|
|
|
|
return uint64(maxGas)
|
|
|
|
}
|
2018-11-20 16:44:49 -08:00
|
|
|
}
|
|
|
|
|
2019-03-07 21:52:19 -08:00
|
|
|
func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error {
|
|
|
|
if req.Header.Height < 1 {
|
|
|
|
return fmt.Errorf("invalid height: %d", req.Header.Height)
|
|
|
|
}
|
|
|
|
|
2020-09-03 03:11:46 -07:00
|
|
|
// expectedHeight holds the expected height to validate.
|
|
|
|
var expectedHeight int64
|
|
|
|
if app.LastBlockHeight() == 0 && app.initialHeight > 1 {
|
|
|
|
// In this case, we're validating the first block of the chain (no
|
|
|
|
// previous commit). The height we're expecting is the initial height.
|
|
|
|
expectedHeight = app.initialHeight
|
|
|
|
} else {
|
|
|
|
// This case can means two things:
|
|
|
|
// - either there was already a previous commit in the store, in which
|
|
|
|
// case we increment the version from there,
|
|
|
|
// - or there was no previous commit, and initial version was not set,
|
|
|
|
// in which case we start at version 1.
|
|
|
|
expectedHeight = app.LastBlockHeight() + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.Header.Height != expectedHeight {
|
|
|
|
return fmt.Errorf("invalid height: %d; expected: %d", req.Header.Height, expectedHeight)
|
2019-03-07 21:52:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-04 10:33:32 -07:00
|
|
|
// Returns the applications's deliverState if app is in runTxModeDeliver,
|
|
|
|
// otherwise it returns the application's checkstate.
|
|
|
|
func (app *BaseApp) getState(mode runTxMode) *state {
|
2019-10-23 07:43:58 -07:00
|
|
|
if mode == runTxModeDeliver {
|
|
|
|
return app.deliverState
|
2019-09-04 10:33:32 -07:00
|
|
|
}
|
|
|
|
|
2019-10-23 07:43:58 -07:00
|
|
|
return app.checkState
|
2019-09-04 10:33:32 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 01:06:14 -08:00
|
|
|
// retrieve the context for the tx w/ txBytes and other memoized values.
|
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 07:40:33 -07:00
|
|
|
func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) context.Context {
|
2019-10-23 07:43:58 -07:00
|
|
|
ctx := app.getState(mode).ctx.
|
2018-11-20 01:06:14 -08:00
|
|
|
WithTxBytes(txBytes).
|
2020-04-16 08:10:39 -07:00
|
|
|
WithVoteInfos(app.voteInfos)
|
|
|
|
|
|
|
|
ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx))
|
2019-02-05 19:11:57 -08:00
|
|
|
|
2019-10-23 07:43:58 -07:00
|
|
|
if mode == runTxModeReCheck {
|
|
|
|
ctx = ctx.WithIsReCheckTx(true)
|
|
|
|
}
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2018-11-20 01:06:14 -08:00
|
|
|
if mode == runTxModeSimulate {
|
|
|
|
ctx, _ = ctx.CacheContext()
|
2018-06-26 18:53:41 -07:00
|
|
|
}
|
2019-02-05 19:11:57 -08:00
|
|
|
|
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 07:40:33 -07:00
|
|
|
return sdk.WrapSDKContext(ctx)
|
2019-02-05 19:11:57 -08:00
|
|
|
}
|