From ed7f6129289b3161e1ce51a7fe2fd1678c50e99b Mon Sep 17 00:00:00 2001 From: Sishir Giri Date: Tue, 19 Jul 2022 10:19:23 -0700 Subject: [PATCH 1/4] feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603) ## Description Most modules right now have a no-op for AppModule.BeginBlock and AppModule.EndBlock. We should move these methods off the AppModule interface so we have less deadcode, and instead move them to extension interfaces. 1. I added `BeginBlockAppModule` and `EndBlockAppModule` interface. 2. Remove the dead-code from modules that do no implement them 3. Add type casting in the the module code to use the new interface Closes: #12462 --- ### 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) (cherry picked from commit b65f3fe070c57cf8841d25f5afe110f5fd951aa3) # Conflicts: # CHANGELOG.md # x/authz/module/module.go # x/params/module.go # x/slashing/module.go # x/upgrade/module.go --- CHANGELOG.md | 5 +++ types/module/module.go | 21 ++++++++++-- types/module/module_test.go | 2 -- x/auth/module.go | 9 ----- x/auth/vesting/module.go | 8 ----- x/authz/module/module.go | 39 ++++++++++++++++++++++ x/bank/module.go | 9 ----- x/capability/module.go | 6 ---- x/crisis/module.go | 3 -- x/distribution/module.go | 6 ---- x/evidence/module.go | 6 ---- x/feegrant/module/module.go | 3 -- x/gov/module.go | 3 -- x/group/module/module.go | 2 -- x/mint/module.go | 6 ---- x/nft/module/module.go | 7 ---- x/params/module.go | 65 +++++++++++++++++++++++++++++++++++++ x/slashing/module.go | 53 ++++++++++++++++++++++++++++++ x/upgrade/abci_test.go | 2 +- x/upgrade/module.go | 55 +++++++++++++++++++++++++++++++ 20 files changed, 236 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2e54259ee..dc1bdc61bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry. +<<<<<<< HEAD +======= +* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins. +* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces +>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) ### Improvements diff --git a/types/module/module.go b/types/module/module.go index 81bd7b24691..bbf4abcadba 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -169,9 +169,17 @@ type AppModule interface { // introduced by the module. To avoid wrong/empty versions, the initial version // should be set to 1. ConsensusVersion() uint64 +} - // ABCI +// BeginBlockAppModule is an extension interface that contains information about the AppModule and BeginBlock. +type BeginBlockAppModule interface { + AppModule BeginBlock(sdk.Context, abci.RequestBeginBlock) +} + +// EndBlockAppModule is an extension interface that contains information about the AppModule and EndBlock. +type EndBlockAppModule interface { + AppModule EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } @@ -468,7 +476,10 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R ctx = ctx.WithEventManager(sdk.NewEventManager()) for _, moduleName := range m.OrderBeginBlockers { - m.Modules[moduleName].BeginBlock(ctx, req) + module, ok := m.Modules[moduleName].(BeginBlockAppModule) + if ok { + module.BeginBlock(ctx, req) + } } return abci.ResponseBeginBlock{ @@ -484,7 +495,11 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo validatorUpdates := []abci.ValidatorUpdate{} for _, moduleName := range m.OrderEndBlockers { - moduleValUpdates := m.Modules[moduleName].EndBlock(ctx, req) + module, ok := m.Modules[moduleName].(EndBlockAppModule) + if !ok { + continue + } + moduleValUpdates := module.EndBlock(ctx, req) // use these validator updates if provided, the module manager assumes // only one module will update the validator set diff --git a/types/module/module_test.go b/types/module/module_test.go index 37bbf088cc7..926a4a4ab3f 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -79,8 +79,6 @@ func TestGenesisOnlyAppModule(t *testing.T) { // no-op goam.RegisterInvariants(mockInvariantRegistry) - goam.BeginBlock(sdk.Context{}, abci.RequestBeginBlock{}) - require.Equal(t, []abci.ValidatorUpdate{}, goam.EndBlock(sdk.Context{}, abci.RequestEndBlock{})) } func TestManagerOrderSetters(t *testing.T) { diff --git a/x/auth/module.go b/x/auth/module.go index 3bb68ca7e71..cd15593a7c7 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -155,15 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock returns the begin blocker for the auth module. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock returns the end blocker for the auth module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the auth module diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 49925dd61f2..06f9b8d995e 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -111,14 +111,6 @@ func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMess return []abci.ValidatorUpdate{} } -// BeginBlock performs a no-op. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock performs a no-op. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ExportGenesis is always empty, as InitGenesis does nothing either. func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { return am.DefaultGenesis(cdc) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 7ff061c691f..f12ce2e2856 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -162,9 +162,48 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, am.keeper) } +<<<<<<< HEAD // EndBlock does nothing func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} +======= +func init() { + appmodule.Register( + &modulev1.Module{}, + appmodule.Provide( + provideModuleBasic, + provideModule, + ), + ) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type authzInputs struct { + depinject.In + + Key *store.KVStoreKey + Cdc codec.Codec + AccountKeeper authz.AccountKeeper + BankKeeper authz.BankKeeper + Registry cdctypes.InterfaceRegistry + MsgServiceRouter *baseapp.MsgServiceRouter +} + +type authzOutputs struct { + depinject.Out + + AuthzKeeper keeper.Keeper + Module runtime.AppModuleWrapper +} + +func provideModule(in authzInputs) authzOutputs { + k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) + return authzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)} +>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) } // ____________________________________________________________________________ diff --git a/x/bank/module.go b/x/bank/module.go index bfeee7eed6b..1db195adb26 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -160,15 +160,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock returns the end blocker for the bank module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the bank module. diff --git a/x/capability/module.go b/x/capability/module.go index e2ac1709795..8fba1eddb3a 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -148,12 +148,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { am.keeper.InitMemStore(ctx) } -// EndBlock executes all ABCI EndBlock logic respective to the capability module. It -// returns no validator updates. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // GenerateGenesisState creates a randomized GenState of the capability module. func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) diff --git a/x/crisis/module.go b/x/crisis/module.go index 7c058a4f22e..6538beec4ea 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -155,9 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the crisis module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/distribution/module.go b/x/distribution/module.go index dc54a64a9b7..8a663f2ffcb 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -163,12 +163,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// EndBlock returns the end blocker for the distribution module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the distribution module. diff --git a/x/evidence/module.go b/x/evidence/module.go index 0dcf1ac3fac..d160dd19767 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -170,12 +170,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// EndBlock executes all ABCI EndBlock logic respective to the evidence module. It -// returns no validator updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the evidence module. diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 6752b16f233..fe0c23ea53b 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -176,9 +176,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } -// BeginBlock returns the begin blocker for the feegrant module. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the feegrant module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/gov/module.go b/x/gov/module.go index b93dab8f1f0..a495bfea2b0 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -193,9 +193,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the gov module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/group/module/module.go b/x/group/module/module.go index 7b8baf8538b..800292789a3 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -147,8 +147,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} - // EndBlock implements the group module's EndBlock. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { EndBlocker(ctx, am.keeper) diff --git a/x/mint/module.go b/x/mint/module.go index 658d49ecd60..3e6231053fb 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -155,12 +155,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { BeginBlocker(ctx, am.keeper, am.inflationCalculator) } -// EndBlock returns the end blocker for the mint module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the mint module. diff --git a/x/nft/module/module.go b/x/nft/module/module.go index ab6fc9633cc..63999d68157 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -152,13 +152,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} - -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ____________________________________________________________________________ // AppModuleSimulation functions diff --git a/x/params/module.go b/x/params/module.go index ddee65dc582..31a8f0bad1d 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -140,10 +140,75 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } +<<<<<<< HEAD // BeginBlock performs a no-op. func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} // EndBlock performs a no-op. func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} +======= +// +// New App Wiring Setup +// + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide( + provideModuleBasic, + provideModule, + provideSubspace, + )) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type paramsInputs struct { + depinject.In + + KvStoreKey *store.KVStoreKey + TransientStoreKey *store.TransientStoreKey + Cdc codec.Codec + LegacyAmino *codec.LegacyAmino +} + +type paramsOutputs struct { + depinject.Out + + ParamsKeeper keeper.Keeper + BaseAppOption runtime.BaseAppOption + Module runtime.AppModuleWrapper + GovHandler govv1beta1.HandlerRoute +} + +func provideModule(in paramsInputs) paramsOutputs { + k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey) + baseappOpt := func(app *baseapp.BaseApp) { + app.SetParamStore(k.Subspace(baseapp.Paramspace).WithKeyTable(types.ConsensusParamsKeyTable())) + } + m := runtime.WrapAppModule(NewAppModule(k)) + govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)} + + return paramsOutputs{ParamsKeeper: k, BaseAppOption: baseappOpt, Module: m, GovHandler: govHandler} +} + +type subspaceInputs struct { + depinject.In + + Key depinject.ModuleKey + Keeper keeper.Keeper + KeyTables map[string]types.KeyTable +} + +func provideSubspace(in subspaceInputs) types.Subspace { + moduleName := in.Key.Name() + kt, exists := in.KeyTables[moduleName] + if !exists { + return in.Keeper.Subspace(moduleName) + } else { + return in.Keeper.Subspace(moduleName).WithKeyTable(kt) + } +>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) } diff --git a/x/slashing/module.go b/x/slashing/module.go index 47f2aec8387..0b770b9bf94 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -160,12 +160,65 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } +<<<<<<< HEAD // EndBlock returns the end blocker for the slashing module. It returns no validator // updates. func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } +======= +// _____________________________________________________________________________________ + +func init() { + appmodule.Register( + &modulev1.Module{}, + appmodule.Provide( + provideModuleBasic, + provideModule, + ), + ) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type slashingInputs struct { + depinject.In + + Key *store.KVStoreKey + Cdc codec.Codec + LegacyAmino *codec.LegacyAmino + AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` + BankKeeper types.BankKeeper `key:"cosmos.bank.v1.Keeper"` + StakingKeeper types.StakingKeeper `key:"cosmos.staking.v1.Keeper"` + + // LegacySubspace is used solely for migration of x/params managed parameters + LegacySubspace exported.Subspace +} + +type slashingOutputs struct { + depinject.Out + + Keeper keeper.Keeper + Module runtime.AppModuleWrapper + Hooks staking.StakingHooksWrapper +} + +func provideModule(in slashingInputs) slashingOutputs { + k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.Key, in.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) + return slashingOutputs{ + Keeper: k, + Module: runtime.WrapAppModule(m), + Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, + } +} + +// _____________________________________________________________________________________ + +>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the slashing module. diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 8f3b8f52dbf..aa38e8ab5da 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -24,7 +24,7 @@ import ( ) type TestSuite struct { - module module.AppModule + module module.BeginBlockAppModule keeper keeper.Keeper querier sdk.Querier handler govtypes.Handler diff --git a/x/upgrade/module.go b/x/upgrade/module.go index e4e2ad5a006..977faebca23 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -134,7 +134,62 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(am.keeper, ctx, req) } +<<<<<<< HEAD // EndBlock does nothing func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} +======= +// +// New App Wiring Setup +// + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide(provideModuleBasic, provideModule), + ) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type upgradeInputs struct { + depinject.In + + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + + AppOpts servertypes.AppOptions `optional:"true"` +} + +type upgradeOutputs struct { + depinject.Out + + UpgradeKeeper keeper.Keeper + Module runtime.AppModuleWrapper + GovHandler govv1beta1.HandlerRoute +} + +func provideModule(in upgradeInputs) upgradeOutputs { + var ( + homePath string + skipUpgradeHeights = make(map[int64]bool) + ) + + if in.AppOpts != nil { + for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { + skipUpgradeHeights[int64(h)] = true + } + + homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome)) + } + + // set the governance module account as the authority for conducting upgrades + k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + m := NewAppModule(k) + gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} + + return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m), GovHandler: gh} +>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) } From 6b3f2681776cc30d448c123d3a483473e2676fd0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 19 Jul 2022 19:51:42 +0200 Subject: [PATCH 2/4] remove conflicts --- x/authz/module/module.go | 44 ------------------------ x/params/module.go | 73 ---------------------------------------- x/slashing/module.go | 59 -------------------------------- x/upgrade/module.go | 60 --------------------------------- 4 files changed, 236 deletions(-) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index f12ce2e2856..b92deb2e3e1 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -162,50 +162,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, am.keeper) } -<<<<<<< HEAD -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -======= -func init() { - appmodule.Register( - &modulev1.Module{}, - appmodule.Provide( - provideModuleBasic, - provideModule, - ), - ) -} - -func provideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - -type authzInputs struct { - depinject.In - - Key *store.KVStoreKey - Cdc codec.Codec - AccountKeeper authz.AccountKeeper - BankKeeper authz.BankKeeper - Registry cdctypes.InterfaceRegistry - MsgServiceRouter *baseapp.MsgServiceRouter -} - -type authzOutputs struct { - depinject.Out - - AuthzKeeper keeper.Keeper - Module runtime.AppModuleWrapper -} - -func provideModule(in authzInputs) authzOutputs { - k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return authzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)} ->>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) -} - // ____________________________________________________________________________ // AppModuleSimulation functions diff --git a/x/params/module.go b/x/params/module.go index 31a8f0bad1d..ab8192d2a7f 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -139,76 +139,3 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } - -<<<<<<< HEAD -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock performs a no-op. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -======= -// -// New App Wiring Setup -// - -func init() { - appmodule.Register(&modulev1.Module{}, - appmodule.Provide( - provideModuleBasic, - provideModule, - provideSubspace, - )) -} - -func provideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - -type paramsInputs struct { - depinject.In - - KvStoreKey *store.KVStoreKey - TransientStoreKey *store.TransientStoreKey - Cdc codec.Codec - LegacyAmino *codec.LegacyAmino -} - -type paramsOutputs struct { - depinject.Out - - ParamsKeeper keeper.Keeper - BaseAppOption runtime.BaseAppOption - Module runtime.AppModuleWrapper - GovHandler govv1beta1.HandlerRoute -} - -func provideModule(in paramsInputs) paramsOutputs { - k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey) - baseappOpt := func(app *baseapp.BaseApp) { - app.SetParamStore(k.Subspace(baseapp.Paramspace).WithKeyTable(types.ConsensusParamsKeyTable())) - } - m := runtime.WrapAppModule(NewAppModule(k)) - govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)} - - return paramsOutputs{ParamsKeeper: k, BaseAppOption: baseappOpt, Module: m, GovHandler: govHandler} -} - -type subspaceInputs struct { - depinject.In - - Key depinject.ModuleKey - Keeper keeper.Keeper - KeyTables map[string]types.KeyTable -} - -func provideSubspace(in subspaceInputs) types.Subspace { - moduleName := in.Key.Name() - kt, exists := in.KeyTables[moduleName] - if !exists { - return in.Keeper.Subspace(moduleName) - } else { - return in.Keeper.Subspace(moduleName).WithKeyTable(kt) - } ->>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) -} diff --git a/x/slashing/module.go b/x/slashing/module.go index 0b770b9bf94..06b5b3ef622 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -160,65 +160,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -<<<<<<< HEAD -// EndBlock returns the end blocker for the slashing module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - -======= -// _____________________________________________________________________________________ - -func init() { - appmodule.Register( - &modulev1.Module{}, - appmodule.Provide( - provideModuleBasic, - provideModule, - ), - ) -} - -func provideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - -type slashingInputs struct { - depinject.In - - Key *store.KVStoreKey - Cdc codec.Codec - LegacyAmino *codec.LegacyAmino - AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` - BankKeeper types.BankKeeper `key:"cosmos.bank.v1.Keeper"` - StakingKeeper types.StakingKeeper `key:"cosmos.staking.v1.Keeper"` - - // LegacySubspace is used solely for migration of x/params managed parameters - LegacySubspace exported.Subspace -} - -type slashingOutputs struct { - depinject.Out - - Keeper keeper.Keeper - Module runtime.AppModuleWrapper - Hooks staking.StakingHooksWrapper -} - -func provideModule(in slashingInputs) slashingOutputs { - k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.Key, in.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) - return slashingOutputs{ - Keeper: k, - Module: runtime.WrapAppModule(m), - Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, - } -} - -// _____________________________________________________________________________________ - ->>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the slashing module. diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 977faebca23..9a31d21241b 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -133,63 +133,3 @@ func (AppModule) ConsensusVersion() uint64 { return consensusVersion } func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(am.keeper, ctx, req) } - -<<<<<<< HEAD -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -======= -// -// New App Wiring Setup -// - -func init() { - appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), - ) -} - -func provideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - -type upgradeInputs struct { - depinject.In - - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec - - AppOpts servertypes.AppOptions `optional:"true"` -} - -type upgradeOutputs struct { - depinject.Out - - UpgradeKeeper keeper.Keeper - Module runtime.AppModuleWrapper - GovHandler govv1beta1.HandlerRoute -} - -func provideModule(in upgradeInputs) upgradeOutputs { - var ( - homePath string - skipUpgradeHeights = make(map[int64]bool) - ) - - if in.AppOpts != nil { - for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true - } - - homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome)) - } - - // set the governance module account as the authority for conducting upgrades - k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - m := NewAppModule(k) - gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} - - return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m), GovHandler: gh} ->>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) -} From 8d7c6fd6aad0eaf0ee01d2212470d34989aa0501 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 19 Jul 2022 19:52:22 +0200 Subject: [PATCH 3/4] remove conflicts --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1bdc61bcd..fa685c45a27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,11 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry. -<<<<<<< HEAD -======= -* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins. * (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces ->>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603)) ### Improvements From ba7f90f498a78b8e5da2554b72449d604758421d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 19 Jul 2022 20:25:39 +0200 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa685c45a27..19eedb234b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,12 +37,15 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces + +### Features + ## [v0.46.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc3) - 2022-07-18 ### Features * (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry. -* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces ### Improvements