Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add PrepareCheckState and Precommit callbacks #14860

Merged
merged 23 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cda4b81
Add Commit callback
prettymuchbryce Jan 31, 2023
862b4d8
Add tests for Commiter change (#5)
prettymuchbryce Feb 3, 2023
1d72615
add precommit callback (#7)
dydxwill Feb 23, 2023
74ef20a
lint
prettymuchbryce Mar 22, 2023
a491aaf
Rename Commit to PrepareCheckState
prettymuchbryce Mar 24, 2023
d01e7ff
Add documentation to module manager
prettymuchbryce Mar 28, 2023
c32d39a
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Mar 28, 2023
ee7016a
Fix implementation and docs
prettymuchbryce Mar 28, 2023
1f05374
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Mar 28, 2023
f4f81e2
Add CHANGELOG entry
prettymuchbryce Mar 28, 2023
a557977
Add assertions for Precommit/PrepareCheckState and tests
prettymuchbryce Mar 29, 2023
17ba453
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Mar 29, 2023
b7dc52d
Add new callbacks to config
prettymuchbryce Mar 29, 2023
eb40e33
Update mod file with api
prettymuchbryce Mar 29, 2023
ea68fee
Update NewManagerFromMap
prettymuchbryce Mar 30, 2023
caa2cde
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Mar 30, 2023
a0616d0
Add api to tests package go.mod
prettymuchbryce Mar 30, 2023
22095a4
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Mar 30, 2023
5393018
Add api to tests package go.mod
prettymuchbryce Mar 30, 2023
f20ee96
Set callbacks during Load
prettymuchbryce Apr 5, 2023
cf4674e
Fix comment
prettymuchbryce Apr 5, 2023
d40920f
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Apr 5, 2023
bd73f81
Merge branch 'main' into prettymuchbryce/add-commiter
prettymuchbryce Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
// empty/reset the deliver state
app.deliverState = nil

if app.commiter != nil {
app.commiter(app.checkState.ctx)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).Commit (baseapp/abci.go:426)

var halt bool

switch {
Expand Down
1 change: 1 addition & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type BaseApp struct { //nolint: maligned
processProposal sdk.ProcessProposalHandler // the handler which runs on ABCI ProcessProposal
prepareProposal sdk.PrepareProposalHandler // the handler which runs on ABCI PrepareProposal
endBlocker sdk.EndBlocker // logic to run after all txs, and to determine valset changes
commiter sdk.Commiter // logic to run during commit
addrPeerFilter sdk.PeerFilter // filter peers by address and port
idPeerFilter sdk.PeerFilter // filter peers by node ID
fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed.
Expand Down
8 changes: 8 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ func (app *BaseApp) SetEndBlocker(endBlocker sdk.EndBlocker) {
app.endBlocker = endBlocker
}

func (app *BaseApp) SetCommiter(commiter sdk.Commiter) {
if app.sealed {
panic("SetCommiter() on sealed BaseApp")
}

app.commiter = commiter
}

func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
if app.sealed {
panic("SetAnteHandler() on sealed BaseApp")
Expand Down
1 change: 1 addition & 0 deletions telemetry/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
const (
MetricKeyBeginBlocker = "begin_blocker"
MetricKeyEndBlocker = "end_blocker"
MetricKeyCommiter = "commiter"
prettymuchbryce marked this conversation as resolved.
Show resolved Hide resolved
MetricLabelNameModule = "module"
)

Expand Down
4 changes: 4 additions & 0 deletions types/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) (abci.ResponseBe
// e.g. BFT timestamps rather than block height for any periodic EndBlock logic
type EndBlocker func(ctx Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error)

// Commiter runs code during commit after the block has been committed, and the `checkState` has been
// branched for the new block.
type Commiter func(ctx Context)

// PeerFilter responds to p2p filtering queries from Tendermint
type PeerFilter func(info string) abci.ResponseQuery

Expand Down
24 changes: 24 additions & 0 deletions types/module/module.go
prettymuchbryce marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ type EndBlockAppModule interface {
EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
}

// CommitAppModule is an extension interface that contains information about the AppModule and Commit.
type CommitAppModule interface {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
AppModule
Commit(sdk.Context)
}

// GenesisOnlyAppModule is an AppModule that only has import/export functionality
type GenesisOnlyAppModule struct {
AppModuleGenesis
Expand Down Expand Up @@ -258,6 +264,7 @@ type Manager struct {
OrderExportGenesis []string
OrderBeginBlockers []string
OrderEndBlockers []string
OrderCommiters []string
OrderMigrations []string
}

Expand All @@ -276,6 +283,7 @@ func NewManager(modules ...AppModule) *Manager {
OrderExportGenesis: modulesStr,
OrderBeginBlockers: modulesStr,
OrderEndBlockers: modulesStr,
OrderCommiters: modulesStr,
}
}

Expand Down Expand Up @@ -351,6 +359,11 @@ func (m *Manager) SetOrderEndBlockers(moduleNames ...string) {
m.OrderEndBlockers = moduleNames
}

// SetOrderCommiters sets the order of set commiter calls
func (m *Manager) SetOrderCommiters(moduleNames ...string) {
m.OrderCommiters = moduleNames
}

// SetOrderMigrations sets the order of migrations to be run. If not set
// then migrations will be run with an order defined in `DefaultMigrationsOrder`.
func (m *Manager) SetOrderMigrations(moduleNames ...string) {
Expand Down Expand Up @@ -706,6 +719,17 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (abci.Resp
}, nil
}

// Commit performs commit functionality for all modules.
func (m *Manager) Commit(ctx sdk.Context) {
for _, moduleName := range m.OrderCommiters {
module, ok := m.Modules[moduleName].(CommitAppModule)
if !ok {
continue
}
module.Commit(ctx)
}
}

// GetVersionMap gets consensus version from all modules
func (m *Manager) GetVersionMap() VersionMap {
vermap := make(VersionMap)
Expand Down