From 8099205622492d4e3a6fd5dcea5cd443f1954477 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 01:43:06 +0200 Subject: [PATCH] feat: app wiring setup for tx's and ante/post handlers (#12193) ## Description Closes: #12056 --- ### 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... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] 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) --- app.go | 52 +--------------------------------------------------- app.yaml | 6 +++++- 2 files changed, 6 insertions(+), 52 deletions(-) diff --git a/app.go b/app.go index 6117ba4ce127..91181ea53b9b 100644 --- a/app.go +++ b/app.go @@ -23,7 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -34,10 +33,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -377,23 +375,7 @@ func NewSimApp( app.MountMemoryStores(app.memKeys) // initialize BaseApp - app.SetTxDecoder(encodingConfig.TxConfig.TxDecoder()) app.SetInitChainer(app.InitChainer) - app.setAnteHandler(encodingConfig.TxConfig, cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))) - // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like - // antehandlers, but are run _after_ the `runMsgs` execution. They are also - // defined as a chain, and have the same signature as antehandlers. - // - // In baseapp, postHandlers are run in the same store branch as `runMsgs`, - // meaning that both `runMsgs` and `postHandler` state will be committed if - // both are successful, and both will be reverted if any of the two fails. - // - // The SDK exposes a default empty postHandlers chain. - // - // Please note that changing any of the anteHandler or postHandler chain is - // likely to be a state-machine breaking change, which needs a coordinated - // upgrade. - app.setPostHandler() if err := app.Load(loadLatest); err != nil { panic(err) @@ -402,38 +384,6 @@ func NewSimApp( return app } -func (app *SimApp) setAnteHandler(txConfig client.TxConfig, indexEventsStr []string) { - indexEvents := map[string]struct{}{} - for _, e := range indexEventsStr { - indexEvents[e] = struct{}{} - } - anteHandler, err := ante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - SignModeHandler: txConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - ) - if err != nil { - panic(err) - } - - app.SetAnteHandler(anteHandler) -} - -func (app *SimApp) setPostHandler() { - postHandler, err := posthandler.NewPostHandler( - posthandler.HandlerOptions{}, - ) - if err != nil { - panic(err) - } - - app.SetPostHandler(postHandler) -} - // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } diff --git a/app.yaml b/app.yaml index 6f3ca8f71172..3d17a11d6cad 100644 --- a/app.yaml +++ b/app.yaml @@ -79,6 +79,10 @@ modules: config: "@type": cosmos.params.module.v1.Module + - name: tx + config: + "@type": cosmos.tx.module.v1.Module + - name: feegrant config: "@type": cosmos.feegrant.module.v1.Module @@ -86,7 +90,7 @@ modules: - name: bank config: "@type": cosmos.bank.module.v1.Module - + - name: authz config: "@type": cosmos.authz.module.v1.Module