Skip to content

Commit 5aa0614

Browse files
mergify[bot]stackman27tac0turtlejulienrbrt
authored
feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces (backport #12603) (#12637)
* 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 * remove conflicts * remove conflicts * update changelog Co-authored-by: Sishir Giri <[email protected]> Co-authored-by: marbar3778 <[email protected]> Co-authored-by: Julien Robert <[email protected]>
1 parent db2949e commit 5aa0614

File tree

20 files changed

+23
-98
lines changed

20 files changed

+23
-98
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3737

3838
## [Unreleased]
3939

40+
* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces
41+
42+
### Features
43+
4044
## [v0.46.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc3) - 2022-07-18
4145

4246
### Features

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

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

165-
// EndBlock does nothing
166-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
167-
return []abci.ValidatorUpdate{}
168-
}
169-
170165
// ____________________________________________________________________________
171166

172167
// AppModuleSimulation functions

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

-8
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,3 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess
139139

140140
// ConsensusVersion implements AppModule/ConsensusVersion.
141141
func (AppModule) ConsensusVersion() uint64 { return 1 }
142-
143-
// BeginBlock performs a no-op.
144-
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
145-
146-
// EndBlock performs a no-op.
147-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
148-
return []abci.ValidatorUpdate{}
149-
}

x/slashing/module.go

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

163-
// EndBlock returns the end blocker for the slashing module. It returns no validator
164-
// updates.
165-
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
166-
return []abci.ValidatorUpdate{}
167-
}
168-
169163
// AppModuleSimulation functions
170164

171165
// GenerateGenesisState creates a randomized GenState of the slashing module.

x/upgrade/abci_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
type TestSuite struct {
27-
module module.AppModule
27+
module module.BeginBlockAppModule
2828
keeper keeper.Keeper
2929
querier sdk.Querier
3030
handler govtypes.Handler

x/upgrade/module.go

-5
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,3 @@ func (AppModule) ConsensusVersion() uint64 { return consensusVersion }
133133
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
134134
BeginBlocker(am.keeper, ctx, req)
135135
}
136-
137-
// EndBlock does nothing
138-
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
139-
return []abci.ValidatorUpdate{}
140-
}

0 commit comments

Comments
 (0)