Skip to content

Commit

Permalink
feat: add core and api for PreBlock (#17468)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Aug 20, 2023
1 parent 4e11394 commit 1bd3705
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 28 deletions.
193 changes: 165 additions & 28 deletions api/cosmos/app/runtime/v1alpha1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

* [#17468](https://github.com/cosmos/cosmos-sdk/pull/17468) Add `appmodule.HasPreBlocker` interface.

## [v0.10.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.10.0)

* [#17383](https://github.com/cosmos/cosmos-sdk/pull/17383) Add `appmoduke.UpgradeModule` interface.
Expand Down
16 changes: 16 additions & 0 deletions core/appmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ type HasPrecommit interface {
Precommit(context.Context) error
}

// ResponsePreBlock represents the response from the PreBlock method.
// It can modify consensus parameters in storage and signal the caller through the return value.
// When it returns ConsensusParamsChanged=true, the caller must refresh the consensus parameter in the finalize context.
// The new context (ctx) must be passed to all the other lifecycle methods.
type ResponsePreBlock interface {
IsConsensusParamsChanged() bool
}

// HasPreBlocker is the extension interface that modules should implement to run
// custom logic before BeginBlock.
type HasPreBlocker interface {
AppModule
// PreBlock is method that will be run before BeginBlock.
PreBlock(context.Context) (ResponsePreBlock, error)
}

// HasBeginBlocker is the extension interface that modules should implement to run
// custom logic before transaction processing in a block.
type HasBeginBlocker interface {
Expand Down
5 changes: 5 additions & 0 deletions proto/cosmos/app/runtime/v1alpha1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ message Module {
// to call in the order in which they should be called. If this is left empty
// no preparecheckstate function will be registered.
repeated string prepare_check_staters = 9;

// pre_blockers specifies the module names of pre blockers
// to call in the order in which they should be called. If this is left empty
// no pre blocker will be registered.
repeated string pre_blockers = 10;
}

// StoreKeyConfig may be supplied to override the default module store key, which
Expand Down

0 comments on commit 1bd3705

Please sign in to comment.