Skip to content

Commit ed7f612

Browse files
stackman27mergify[bot]
authored andcommitted
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 b65f3fe) # Conflicts: # CHANGELOG.md # x/authz/module/module.go # x/params/module.go # x/slashing/module.go # x/upgrade/module.go
1 parent db2949e commit ed7f612

File tree

20 files changed

+236
-74
lines changed

20 files changed

+236
-74
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242
### Features
4343

4444
* (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry.
45+
<<<<<<< HEAD
46+
=======
47+
* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins.
48+
* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces
49+
>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603))
4550
4651
### Improvements
4752

types/module/module.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ type AppModule interface {
169169
// introduced by the module. To avoid wrong/empty versions, the initial version
170170
// should be set to 1.
171171
ConsensusVersion() uint64
172+
}
172173

173-
// ABCI
174+
// BeginBlockAppModule is an extension interface that contains information about the AppModule and BeginBlock.
175+
type BeginBlockAppModule interface {
176+
AppModule
174177
BeginBlock(sdk.Context, abci.RequestBeginBlock)
178+
}
179+
180+
// EndBlockAppModule is an extension interface that contains information about the AppModule and EndBlock.
181+
type EndBlockAppModule interface {
182+
AppModule
175183
EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
176184
}
177185

@@ -468,7 +476,10 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
468476
ctx = ctx.WithEventManager(sdk.NewEventManager())
469477

470478
for _, moduleName := range m.OrderBeginBlockers {
471-
m.Modules[moduleName].BeginBlock(ctx, req)
479+
module, ok := m.Modules[moduleName].(BeginBlockAppModule)
480+
if ok {
481+
module.BeginBlock(ctx, req)
482+
}
472483
}
473484

474485
return abci.ResponseBeginBlock{
@@ -484,7 +495,11 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
484495
validatorUpdates := []abci.ValidatorUpdate{}
485496

486497
for _, moduleName := range m.OrderEndBlockers {
487-
moduleValUpdates := m.Modules[moduleName].EndBlock(ctx, req)
498+
module, ok := m.Modules[moduleName].(EndBlockAppModule)
499+
if !ok {
500+
continue
501+
}
502+
moduleValUpdates := module.EndBlock(ctx, req)
488503

489504
// use these validator updates if provided, the module manager assumes
490505
// only one module will update the validator set

types/module/module_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ func TestGenesisOnlyAppModule(t *testing.T) {
7979

8080
// no-op
8181
goam.RegisterInvariants(mockInvariantRegistry)
82-
goam.BeginBlock(sdk.Context{}, abci.RequestBeginBlock{})
83-
require.Equal(t, []abci.ValidatorUpdate{}, goam.EndBlock(sdk.Context{}, abci.RequestEndBlock{}))
8482
}
8583

8684
func TestManagerOrderSetters(t *testing.T) {

x/auth/module.go

-9
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
155155
// ConsensusVersion implements AppModule/ConsensusVersion.
156156
func (AppModule) ConsensusVersion() uint64 { return 3 }
157157

158-
// BeginBlock returns the begin blocker for the auth module.
159-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
160-
161-
// EndBlock returns the end blocker for the auth module. It returns no validator
162-
// updates.
163-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
164-
return []abci.ValidatorUpdate{}
165-
}
166-
167158
// AppModuleSimulation functions
168159

169160
// GenerateGenesisState creates a randomized GenState of the auth module

x/auth/vesting/module.go

-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMess
111111
return []abci.ValidatorUpdate{}
112112
}
113113

114-
// BeginBlock performs a no-op.
115-
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
116-
117-
// EndBlock performs a no-op.
118-
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
119-
return []abci.ValidatorUpdate{}
120-
}
121-
122114
// ExportGenesis is always empty, as InitGenesis does nothing either.
123115
func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage {
124116
return am.DefaultGenesis(cdc)

x/authz/module/module.go

+39
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,48 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
162162
BeginBlocker(ctx, am.keeper)
163163
}
164164

165+
<<<<<<< HEAD
165166
// EndBlock does nothing
166167
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
167168
return []abci.ValidatorUpdate{}
169+
=======
170+
func init() {
171+
appmodule.Register(
172+
&modulev1.Module{},
173+
appmodule.Provide(
174+
provideModuleBasic,
175+
provideModule,
176+
),
177+
)
178+
}
179+
180+
func provideModuleBasic() runtime.AppModuleBasicWrapper {
181+
return runtime.WrapAppModuleBasic(AppModuleBasic{})
182+
}
183+
184+
type authzInputs struct {
185+
depinject.In
186+
187+
Key *store.KVStoreKey
188+
Cdc codec.Codec
189+
AccountKeeper authz.AccountKeeper
190+
BankKeeper authz.BankKeeper
191+
Registry cdctypes.InterfaceRegistry
192+
MsgServiceRouter *baseapp.MsgServiceRouter
193+
}
194+
195+
type authzOutputs struct {
196+
depinject.Out
197+
198+
AuthzKeeper keeper.Keeper
199+
Module runtime.AppModuleWrapper
200+
}
201+
202+
func provideModule(in authzInputs) authzOutputs {
203+
k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper)
204+
m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry)
205+
return authzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)}
206+
>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603))
168207
}
169208

170209
// ____________________________________________________________________________

x/bank/module.go

-9
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
160160
// ConsensusVersion implements AppModule/ConsensusVersion.
161161
func (AppModule) ConsensusVersion() uint64 { return 3 }
162162

163-
// BeginBlock performs a no-op.
164-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
165-
166-
// EndBlock returns the end blocker for the bank module. It returns no validator
167-
// updates.
168-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
169-
return []abci.ValidatorUpdate{}
170-
}
171-
172163
// AppModuleSimulation functions
173164

174165
// GenerateGenesisState creates a randomized GenState of the bank module.

x/capability/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
148148
am.keeper.InitMemStore(ctx)
149149
}
150150

151-
// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
152-
// returns no validator updates.
153-
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
154-
return []abci.ValidatorUpdate{}
155-
}
156-
157151
// GenerateGenesisState creates a randomized GenState of the capability module.
158152
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
159153
simulation.RandomizedGenState(simState)

x/crisis/module.go

-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
155155
// ConsensusVersion implements AppModule/ConsensusVersion.
156156
func (AppModule) ConsensusVersion() uint64 { return 1 }
157157

158-
// BeginBlock performs a no-op.
159-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
160-
161158
// EndBlock returns the end blocker for the crisis module. It returns no validator
162159
// updates.
163160
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {

x/distribution/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
163163
BeginBlocker(ctx, req, am.keeper)
164164
}
165165

166-
// EndBlock returns the end blocker for the distribution module. It returns no validator
167-
// updates.
168-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
169-
return []abci.ValidatorUpdate{}
170-
}
171-
172166
// AppModuleSimulation functions
173167

174168
// GenerateGenesisState creates a randomized GenState of the distribution module.

x/evidence/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
170170
BeginBlocker(ctx, req, am.keeper)
171171
}
172172

173-
// EndBlock executes all ABCI EndBlock logic respective to the evidence module. It
174-
// returns no validator updates.
175-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
176-
return []abci.ValidatorUpdate{}
177-
}
178-
179173
// AppModuleSimulation functions
180174

181175
// GenerateGenesisState creates a randomized GenState of the evidence module.

x/feegrant/module/module.go

-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
176176
// ConsensusVersion implements AppModule/ConsensusVersion.
177177
func (AppModule) ConsensusVersion() uint64 { return 2 }
178178

179-
// BeginBlock returns the begin blocker for the feegrant module.
180-
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
181-
182179
// EndBlock returns the end blocker for the feegrant module. It returns no validator
183180
// updates.
184181
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {

x/gov/module.go

-3
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
193193
// ConsensusVersion implements AppModule/ConsensusVersion.
194194
func (AppModule) ConsensusVersion() uint64 { return 3 }
195195

196-
// BeginBlock performs a no-op.
197-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
198-
199196
// EndBlock returns the end blocker for the gov module. It returns no validator
200197
// updates.
201198
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {

x/group/module/module.go

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
147147
// ConsensusVersion implements AppModule/ConsensusVersion.
148148
func (AppModule) ConsensusVersion() uint64 { return 1 }
149149

150-
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
151-
152150
// EndBlock implements the group module's EndBlock.
153151
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
154152
EndBlocker(ctx, am.keeper)

x/mint/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
155155
BeginBlocker(ctx, am.keeper, am.inflationCalculator)
156156
}
157157

158-
// EndBlock returns the end blocker for the mint module. It returns no validator
159-
// updates.
160-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
161-
return []abci.ValidatorUpdate{}
162-
}
163-
164158
// AppModuleSimulation functions
165159

166160
// GenerateGenesisState creates a randomized GenState of the mint module.

x/nft/module/module.go

-7
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
152152
// ConsensusVersion implements AppModule/ConsensusVersion.
153153
func (AppModule) ConsensusVersion() uint64 { return 1 }
154154

155-
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
156-
157-
// EndBlock does nothing
158-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
159-
return []abci.ValidatorUpdate{}
160-
}
161-
162155
// ____________________________________________________________________________
163156

164157
// AppModuleSimulation functions

x/params/module.go

+65
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,75 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess
140140
// ConsensusVersion implements AppModule/ConsensusVersion.
141141
func (AppModule) ConsensusVersion() uint64 { return 1 }
142142

143+
<<<<<<< HEAD
143144
// BeginBlock performs a no-op.
144145
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
145146

146147
// EndBlock performs a no-op.
147148
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
148149
return []abci.ValidatorUpdate{}
150+
=======
151+
//
152+
// New App Wiring Setup
153+
//
154+
155+
func init() {
156+
appmodule.Register(&modulev1.Module{},
157+
appmodule.Provide(
158+
provideModuleBasic,
159+
provideModule,
160+
provideSubspace,
161+
))
162+
}
163+
164+
func provideModuleBasic() runtime.AppModuleBasicWrapper {
165+
return runtime.WrapAppModuleBasic(AppModuleBasic{})
166+
}
167+
168+
type paramsInputs struct {
169+
depinject.In
170+
171+
KvStoreKey *store.KVStoreKey
172+
TransientStoreKey *store.TransientStoreKey
173+
Cdc codec.Codec
174+
LegacyAmino *codec.LegacyAmino
175+
}
176+
177+
type paramsOutputs struct {
178+
depinject.Out
179+
180+
ParamsKeeper keeper.Keeper
181+
BaseAppOption runtime.BaseAppOption
182+
Module runtime.AppModuleWrapper
183+
GovHandler govv1beta1.HandlerRoute
184+
}
185+
186+
func provideModule(in paramsInputs) paramsOutputs {
187+
k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey)
188+
baseappOpt := func(app *baseapp.BaseApp) {
189+
app.SetParamStore(k.Subspace(baseapp.Paramspace).WithKeyTable(types.ConsensusParamsKeyTable()))
190+
}
191+
m := runtime.WrapAppModule(NewAppModule(k))
192+
govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)}
193+
194+
return paramsOutputs{ParamsKeeper: k, BaseAppOption: baseappOpt, Module: m, GovHandler: govHandler}
195+
}
196+
197+
type subspaceInputs struct {
198+
depinject.In
199+
200+
Key depinject.ModuleKey
201+
Keeper keeper.Keeper
202+
KeyTables map[string]types.KeyTable
203+
}
204+
205+
func provideSubspace(in subspaceInputs) types.Subspace {
206+
moduleName := in.Key.Name()
207+
kt, exists := in.KeyTables[moduleName]
208+
if !exists {
209+
return in.Keeper.Subspace(moduleName)
210+
} else {
211+
return in.Keeper.Subspace(moduleName).WithKeyTable(kt)
212+
}
213+
>>>>>>> b65f3fe07 (feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (#12603))
149214
}

0 commit comments

Comments
 (0)