Skip to content

Commit 1bd3705

Browse files
authored
feat: add core and api for PreBlock (#17468)
1 parent 4e11394 commit 1bd3705

File tree

4 files changed

+188
-28
lines changed

4 files changed

+188
-28
lines changed

api/cosmos/app/runtime/v1alpha1/module.pulsar.go

Lines changed: 165 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
## [Unreleased]
3838

39+
* [#17468](https://github.com/cosmos/cosmos-sdk/pull/17468) Add `appmodule.HasPreBlocker` interface.
40+
3941
## [v0.10.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.10.0)
4042

4143
* [#17383](https://github.com/cosmos/cosmos-sdk/pull/17383) Add `appmoduke.UpgradeModule` interface.

core/appmodule/module.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ type HasPrecommit interface {
5252
Precommit(context.Context) error
5353
}
5454

55+
// ResponsePreBlock represents the response from the PreBlock method.
56+
// It can modify consensus parameters in storage and signal the caller through the return value.
57+
// When it returns ConsensusParamsChanged=true, the caller must refresh the consensus parameter in the finalize context.
58+
// The new context (ctx) must be passed to all the other lifecycle methods.
59+
type ResponsePreBlock interface {
60+
IsConsensusParamsChanged() bool
61+
}
62+
63+
// HasPreBlocker is the extension interface that modules should implement to run
64+
// custom logic before BeginBlock.
65+
type HasPreBlocker interface {
66+
AppModule
67+
// PreBlock is method that will be run before BeginBlock.
68+
PreBlock(context.Context) (ResponsePreBlock, error)
69+
}
70+
5571
// HasBeginBlocker is the extension interface that modules should implement to run
5672
// custom logic before transaction processing in a block.
5773
type HasBeginBlocker interface {

proto/cosmos/app/runtime/v1alpha1/module.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ message Module {
5252
// to call in the order in which they should be called. If this is left empty
5353
// no preparecheckstate function will be registered.
5454
repeated string prepare_check_staters = 9;
55+
56+
// pre_blockers specifies the module names of pre blockers
57+
// to call in the order in which they should be called. If this is left empty
58+
// no pre blocker will be registered.
59+
repeated string pre_blockers = 10;
5560
}
5661

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

0 commit comments

Comments
 (0)