feat: add endblocker with valsetupdate type (#15829)

This commit is contained in:
Marko
2023-04-14 09:41:29 +00:00
committed by GitHub
parent 722bea5b40
commit 8d6c23faa4
18 changed files with 200 additions and 73 deletions
+22
View File
@@ -29,6 +29,7 @@ needlessly defining many placeholder functions
package module
import (
"context"
"encoding/json"
"errors"
"fmt"
@@ -212,6 +213,11 @@ type EndBlockAppModule interface {
EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
}
type HasABCIEndblock interface {
AppModule
EndBlock(context.Context) ([]abci.ValidatorUpdate, error)
}
// GenesisOnlyAppModule is an AppModule that only has import/export functionality
type GenesisOnlyAppModule struct {
AppModuleGenesis
@@ -695,6 +701,22 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (abci.Resp
if err != nil {
return abci.ResponseEndBlock{}, err
}
} else if module, ok := m.Modules[moduleName].(HasABCIEndblock); ok {
moduleValUpdates, err := module.EndBlock(ctx)
if err != nil {
return abci.ResponseEndBlock{}, err
}
// use these validator updates if provided, the module manager assumes
// only one module will update the validator set
if len(moduleValUpdates) > 0 {
if len(validatorUpdates) > 0 {
return abci.ResponseEndBlock{}, errors.New("validator EndBlock updates already set by a previous module")
}
for _, updates := range moduleValUpdates {
validatorUpdates = append(validatorUpdates, abci.ValidatorUpdate{PubKey: updates.PubKey, Power: updates.Power})
}
}
} else {
continue
}