refactor(core)!: clean-up core and simplify preblock (#19672)

This commit is contained in:
Julien Robert
2024-03-11 14:39:37 +00:00
committed by GitHub
parent defab1a1a1
commit fea88d13c5
21 changed files with 110 additions and 177 deletions
+14 -13
View File
@@ -1,16 +1,17 @@
package appmodule
import "context"
import (
"cosmossdk.io/core/appmodule/v2"
)
type MigrationRegistrar interface {
// Register registers an in-place store migration for a module. The
// handler is a migration script to perform in-place migrations from version
// `fromVersion` to version `fromVersion+1`.
//
// EACH TIME a module's ConsensusVersion increments, a new migration MUST
// be registered using this function. If a migration handler is missing for
// a particular function, the upgrade logic (see RunMigrations function)
// will panic. If the ConsensusVersion bump does not introduce any store
// changes, then a no-op function must be registered here.
Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error
}
// HasConsensusVersion is the interface for declaring a module consensus version.
type HasConsensusVersion = appmodule.HasConsensusVersion
// HasMigrations is implemented by a module which upgrades or has upgraded to a new consensus version.
type HasMigrations = appmodule.HasMigrations
// MigrationRegistrar is the interface for registering in-place store migrations.
type MigrationRegistrar = appmodule.MigrationRegistrar
// MigrationHandler is the migration function that each module registers.
type MigrationHandler = appmodule.MigrationHandler
+12 -51
View File
@@ -4,7 +4,6 @@ import (
"context"
"google.golang.org/grpc"
"google.golang.org/protobuf/runtime/protoiface"
"cosmossdk.io/core/appmodule/v2"
)
@@ -15,16 +14,20 @@ import (
// by other modules (usually via depinject) as app modules.
type AppModule = appmodule.AppModule
// HasMigrations is the extension interface that modules should implement to register migrations.
type HasMigrations interface {
AppModule
// HasPreBlocker is the extension interface that modules should implement to run
// custom logic before BeginBlock.
type HasPreBlocker = appmodule.HasPreBlocker
// RegisterMigrations registers the module's migrations with the app's migrator.
RegisterMigrations(MigrationRegistrar) error
}
// HasBeginBlocker is the extension interface that modules should implement to run
// custom logic before transaction processing in a block.
type HasBeginBlocker = appmodule.HasBeginBlocker
// HasConsensusVersion is the interface for declaring a module consensus version.
type HasConsensusVersion = appmodule.HasConsensusVersion
// HasEndBlocker is the extension interface that modules should implement to run
// custom logic after transaction processing in a block.
type HasEndBlocker = appmodule.HasEndBlocker
// HasRegisterInterfaces is the interface for modules to register their msg types.
type HasRegisterInterfaces = appmodule.HasRegisterInterfaces
// HasServices is the extension interface that modules should implement to register
// implementations of services defined in .proto files.
@@ -46,48 +49,6 @@ type HasServices interface {
RegisterServices(grpc.ServiceRegistrar) 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.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 = appmodule.HasBeginBlocker
// HasEndBlocker is the extension interface that modules should implement to run
// custom logic after transaction processing in a block.
type HasEndBlocker = appmodule.HasEndBlocker
// HasRegisterInterfaces is the interface for modules to register their msg types.
type HasRegisterInterfaces = appmodule.HasRegisterInterfaces
// MsgHandlerRouter is implemented by the runtime provider.
type MsgHandlerRouter interface {
// RegisterHandler is called by modules to register msg handler functions.
RegisterHandler(name string, handler func(ctx context.Context, msg protoiface.MessageV1) (msgResp protoiface.MessageV1, err error))
}
// HasMsgHandler is implemented by modules that instead of exposing msg server expose
// a set of handlers.
type HasMsgHandler interface {
// RegisterMsgHandlers is implemented by the module that will register msg handlers.
RegisterMsgHandlers(router MsgHandlerRouter)
}
// ---------------------------------------------------------------------------- //
// HasPrepareCheckState is an extension interface that contains information about the AppModule
// and PrepareCheckState.
type HasPrepareCheckState interface {
+2 -2
View File
@@ -11,8 +11,7 @@ type HasConsensusVersion interface {
ConsensusVersion() uint64
}
// HasMigrations is implemented by a module which upgrades or has upgraded
// to a new consensus version.
// HasMigrations is implemented by a module which upgrades or has upgraded to a new consensus version.
type HasMigrations interface {
AppModule
HasConsensusVersion
@@ -21,6 +20,7 @@ type HasMigrations interface {
RegisterMigrations(MigrationRegistrar) error
}
// MigrationRegistrar is the interface for registering in-place store migrations.
type MigrationRegistrar interface {
// Register registers an in-place store migration for a module. The
// handler is a migration script to perform in-place migrations from version
@@ -19,6 +19,14 @@ type AppModule interface {
IsOnePerModuleType()
}
// 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) error
}
// HasBeginBlocker is the extension interface that modules should implement to run
// custom logic before transaction processing in a block.
type HasBeginBlocker interface {