Skip to content

Commit b65f3fe

Browse files
authored
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)
1 parent e716e41 commit b65f3fe

File tree

20 files changed

+20
-98
lines changed

20 files changed

+20
-98
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343
* (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX.
4444
* (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry.
4545
* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins.
46+
* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces
4647

4748
### Improvements
4849

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
@@ -171,15 +171,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
171171
// ConsensusVersion implements AppModule/ConsensusVersion.
172172
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
173173

174-
// BeginBlock returns the begin blocker for the auth module.
175-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
176-
177-
// EndBlock returns the end blocker for the auth module. It returns no validator
178-
// updates.
179-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
180-
return []abci.ValidatorUpdate{}
181-
}
182-
183174
// AppModuleSimulation functions
184175

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

x/auth/vesting/module.go

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

119-
// BeginBlock performs a no-op.
120-
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
121-
122-
// EndBlock performs a no-op.
123-
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
124-
return []abci.ValidatorUpdate{}
125-
}
126-
127119
// ExportGenesis is always empty, as InitGenesis does nothing either.
128120
func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage {
129121
return am.DefaultGenesis(cdc)

x/authz/module/module.go

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

172-
// EndBlock does nothing
173-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
174-
return []abci.ValidatorUpdate{}
175-
}
176-
177172
func init() {
178173
appmodule.Register(
179174
&modulev1.Module{},

x/bank/module.go

-9
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
172172
// ConsensusVersion implements AppModule/ConsensusVersion.
173173
func (AppModule) ConsensusVersion() uint64 { return 4 }
174174

175-
// BeginBlock performs a no-op.
176-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
177-
178-
// EndBlock returns the end blocker for the bank module. It returns no validator
179-
// updates.
180-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
181-
return []abci.ValidatorUpdate{}
182-
}
183-
184175
// AppModuleSimulation functions
185176

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

x/capability/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
160160
}
161161
}
162162

163-
// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
164-
// returns no validator updates.
165-
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
166-
return []abci.ValidatorUpdate{}
167-
}
168-
169163
// GenerateGenesisState creates a randomized GenState of the capability module.
170164
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
171165
simulation.RandomizedGenState(simState)

x/crisis/module.go

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

182-
// BeginBlock performs a no-op.
183-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
184-
185182
// EndBlock returns the end blocker for the crisis module. It returns no validator
186183
// updates.
187184
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {

x/distribution/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
186186
BeginBlocker(ctx, req, am.keeper)
187187
}
188188

189-
// EndBlock returns the end blocker for the distribution module. It returns no validator
190-
// updates.
191-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
192-
return []abci.ValidatorUpdate{}
193-
}
194-
195189
// AppModuleSimulation functions
196190

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

x/evidence/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
176176
BeginBlocker(ctx, req, am.keeper)
177177
}
178178

179-
// EndBlock executes all ABCI EndBlock logic respective to the evidence module. It
180-
// returns no validator updates.
181-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
182-
return []abci.ValidatorUpdate{}
183-
}
184-
185179
// AppModuleSimulation functions
186180

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

x/feegrant/module/module.go

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

185-
// BeginBlock returns the begin blocker for the feegrant module.
186-
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
187-
188185
// EndBlock returns the end blocker for the feegrant module. It returns no validator
189186
// updates.
190187
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {

x/gov/module.go

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

297-
// BeginBlock performs a no-op.
298-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
299-
300297
// EndBlock returns the end blocker for the gov module. It returns no validator
301298
// updates.
302299
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
@@ -153,8 +153,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
153153
// ConsensusVersion implements AppModule/ConsensusVersion.
154154
func (AppModule) ConsensusVersion() uint64 { return 1 }
155155

156-
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
157-
158156
// EndBlock implements the group module's EndBlock.
159157
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
160158
EndBlocker(ctx, am.keeper)

x/mint/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
188188
BeginBlocker(ctx, am.keeper, am.inflationCalculator)
189189
}
190190

191-
// EndBlock returns the end blocker for the mint module. It returns no validator
192-
// updates.
193-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
194-
return []abci.ValidatorUpdate{}
195-
}
196-
197191
// AppModuleSimulation functions
198192

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

x/nft/module/module.go

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

160-
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
161-
162-
// EndBlock does nothing
163-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
164-
return []abci.ValidatorUpdate{}
165-
}
166-
167160
// ____________________________________________________________________________
168161

169162
// AppModuleSimulation functions

x/params/module.go

-8
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess
149149
// ConsensusVersion implements AppModule/ConsensusVersion.
150150
func (AppModule) ConsensusVersion() uint64 { return 1 }
151151

152-
// BeginBlock performs a no-op.
153-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
154-
155-
// EndBlock performs a no-op.
156-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
157-
return []abci.ValidatorUpdate{}
158-
}
159-
160152
//
161153
// New App Wiring Setup
162154
//

x/slashing/module.go

-6
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
184184
BeginBlocker(ctx, req, am.keeper)
185185
}
186186

187-
// EndBlock returns the end blocker for the slashing module. It returns no validator
188-
// updates.
189-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
190-
return []abci.ValidatorUpdate{}
191-
}
192-
193187
// _____________________________________________________________________________________
194188

195189
func init() {

x/upgrade/abci_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
type TestSuite struct {
31-
module module.AppModule
31+
module module.BeginBlockAppModule
3232
keeper keeper.Keeper
3333
querier sdk.Querier
3434
handler govtypes.Handler

x/upgrade/module.go

-5
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
151151
BeginBlocker(am.keeper, ctx, req)
152152
}
153153

154-
// EndBlock does nothing
155-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
156-
return []abci.ValidatorUpdate{}
157-
}
158-
159154
//
160155
// New App Wiring Setup
161156
//

0 commit comments

Comments
 (0)