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

chore(server/v2): create v2 subpackage in core #19499

Merged
merged 17 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 2 additions & 15 deletions core/appmodule/environment.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
package appmodule

import (
"cosmossdk.io/core/branch"
"cosmossdk.io/core/event"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/core/appmodule/v2"
)

// Environment is used to get all services to their respective module
type Environment struct {
BranchService branch.Service
EventService event.Service
GasService gas.Service
HeaderService header.Service
KVStoreService store.KVStoreService
MemStoreService store.MemoryStoreService
Logger log.Logger
}
type Environment = appmodule.Environment
21 changes: 6 additions & 15 deletions core/appmodule/migrations.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
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 MigrationHandler) error
}
type MigrationRegistrar = appmodule.MigrationRegistrar

// MigrationHandler is the migration function that each module registers.
type MigrationHandler func(context.Context) error
type MigrationHandler = appmodule.MigrationHandler

// VersionMap is a map of moduleName -> version
type VersionMap map[string]uint64
type VersionMap = appmodule.VersionMap
161 changes: 37 additions & 124 deletions core/appmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,40 @@ import (

"google.golang.org/grpc"

"cosmossdk.io/core/transaction"
"cosmossdk.io/core/appmodule/v2"
)

// AppModule is a tag interface for app module implementations to use as a basis
// for extension interfaces. It provides no functionality itself, but is the
// type that all valid app modules should provide so that they can be identified
// by other modules (usually via depinject) as app modules.
type AppModule interface {
// IsAppModule is a dummy method to tag a struct as implementing an AppModule.
IsAppModule()
type AppModule = appmodule.AppModule

// IsOnePerModuleType is a dummy method to help depinject resolve modules.
IsOnePerModuleType()
}
// HasMigrations is the extension interface that modules should implement to register migrations.
type HasMigrations = appmodule.HasMigrations

// HasServices is the extension interface that modules should implement to register
// implementations of services defined in .proto files.
type HasServices interface {
AppModule
// HasConsensusVersion is the interface for declaring a module consensus version.
type HasConsensusVersion = appmodule.HasConsensusVersion

// RegisterServices registers the module's services with the app's service
// registrar.
//
// Two types of services are currently supported:
// - read-only gRPC query services, which are the default.
// - transaction message services, which must have the protobuf service
// option "cosmos.msg.v1.service" (defined in "cosmos/msg/v1/service.proto")
// set to true.
//
// The service registrar will figure out which type of service you are
// implementing based on the presence (or absence) of protobuf options. You
// do not need to specify this in golang code.
RegisterServices(grpc.ServiceRegistrar) error
}
// HasBeginBlocker is the extension interface that modules should implement to run
// custom logic before transaction processing in a block.
type HasBeginBlocker = appmodule.HasBeginBlocker

// HasMigrations is the extension interface that modules should implement to register migrations.
type HasMigrations interface {
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

// RegisterMigrations registers the module's migrations with the app's migrator.
RegisterMigrations(MigrationRegistrar) error
// HasPrepareCheckState is an extension interface that contains information about the AppModule
// and PrepareCheckState.
type HasPrepareCheckState interface {
AppModule
PrepareCheckState(context.Context) error
}

// HasConsensusVersion is the interface for declaring a module consensus version.
type HasConsensusVersion interface {
// ConsensusVersion is a sequence number for state-breaking change of the
// module. It should be incremented on each consensus-breaking change
// introduced by the module. To avoid wrong/empty versions, the initial version
// should be set to 1.
ConsensusVersion() uint64
// HasPrecommit is an extension interface that contains information about the AppModule and Precommit.
type HasPrecommit interface {
AppModule
Precommit(context.Context) error
}

// ResponsePreBlock represents the response from the PreBlock method.
Expand All @@ -74,92 +57,22 @@ type HasPreBlocker interface {
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 {
AppModule

// BeginBlock is a method that will be run before transactions are processed in
// a block.
BeginBlock(context.Context) error
}

// HasEndBlocker is the extension interface that modules should implement to run
// custom logic after transaction processing in a block.
type HasEndBlocker interface {
AppModule

// EndBlock is a method that will be run after transactions are processed in
// a block.
EndBlock(context.Context) error
}

// HasTxValidation is the extension interface that modules should implement to run
// custom logic for validating transactions.
// It was previously known as AnteHandler/Decorator.
type HasTxValidation[T transaction.Tx] interface {
AppModule

// TxValidator is a method that will be run on each transaction.
// If an error is returned:
// ,---.
// / |
// / |
// You shall not pass! / |
// / |
// \ ___,' |
// < -' :
// `-.__..--'``-,_\_
// |o/ <o>` :,.)_`>
// :/ ` ||/)
// (_.).__,-` |\
// /( `.`` `| :
// \'`-.) ` ; ;
// | ` /-<
// | ` / `.
// ,-_-..____ /| ` :__..-'\
// /,'-.__\\ ``-./ :` ; \
// `\ `\ `\\ \ : ( ` / , `. \
// \` \ \\ | | ` : : .\ \
// \ `\_ )) : ; | | ): :
// (`-.-'\ || |\ \ ` ; ; | |
// \-_ `;;._ ( ` / /_ | |
// `-.-.// ,'`-._\__/_,' ; |
// \:: : / ` , / |
// || | ( ,' / / |
// || ,' / |
TxValidator(ctx context.Context, tx T) error
}

// HasUpdateValidators is an extension interface that contains information about the AppModule and UpdateValidators.
// It can be seen as the alternative of the Cosmos SDK' HasABCIEndBlocker.
// Both are still supported.
type HasUpdateValidators interface {
AppModule

UpdateValidators(ctx context.Context) ([]ValidatorUpdate, error)
}

// ValidatorUpdate defines a validator update.
type ValidatorUpdate struct {
PubKey []byte
PubKeyType string
Power int64 // updated power of the validtor
}

// **********************************************
// The following interfaces are baseapp specific and will be deprecated in the future.
// **********************************************

// HasPrepareCheckState is an extension interface that contains information about the AppModule
// and PrepareCheckState.
type HasPrepareCheckState interface {
// HasServices is the extension interface that modules should implement to register
// implementations of services defined in .proto files.
type HasServices interface {
AppModule
PrepareCheckState(context.Context) error
}

// HasPrecommit is an extension interface that contains information about the AppModule and Precommit.
type HasPrecommit interface {
AppModule
Precommit(context.Context) error
// RegisterServices registers the module's services with the app's service
// registrar.
//
// Two types of services are currently supported:
// - read-only gRPC query services, which are the default.
// - transaction message services, which must have the protobuf service
// option "cosmos.msg.v1.service" (defined in "cosmos/msg/v1/service.proto")
// set to true.
//
// The service registrar will figure out which type of service you are
// implementing based on the presence (or absence) of protobuf options. You
// do not need to specify this in golang code.
RegisterServices(grpc.ServiceRegistrar) error
}
21 changes: 21 additions & 0 deletions core/appmodule/v2/environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package appmodule

import (
"cosmossdk.io/core/branch"
"cosmossdk.io/core/event"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
)

// Environment is used to get all services to their respective module
type Environment struct {
BranchService branch.Service
EventService event.Service
GasService gas.Service
HeaderService header.Service
KVStoreService store.KVStoreService
MemStoreService store.MemoryStoreService
Logger log.Logger
}
15 changes: 15 additions & 0 deletions core/appmodule/v2/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package appmodule

import (
"context"
)

// HasGenesis defines a custom genesis handling API implementation.
Copy link
Member

@julienrbrt julienrbrt Feb 26, 2024

Choose a reason for hiding this comment

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

What are we going to do about genesis in core v1?
I feel like we should delete if when there is consensus about the api, as we never pushed people to use it.
However, I don't think we agreed on this proposed api yet 👀.

Copy link
Member Author

Choose a reason for hiding this comment

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

leaving a todo here and we can discuss on the server call

// TODO: finalize this API
type HasGenesis interface {
AppModule
DefaultGenesis() Message
ValidateGenesis(data Message) error
InitGenesis(ctx context.Context, data Message) error
ExportGenesis(ctx context.Context) (Message, error)
}
Loading
Loading