From f5858aa57bf110ac054d6edcec19b7d25e813c58 Mon Sep 17 00:00:00 2001 From: testinginprod Date: Tue, 20 Feb 2024 12:46:38 +0100 Subject: [PATCH 01/13] add appmodule v2 --- core/appmodule/environment.go | 17 +--- core/appmodule/migrations.go | 21 ++-- core/appmodule/module.go | 165 ++++++++----------------------- core/appmodule/v2/environment.go | 21 ++++ core/appmodule/v2/genesis.go | 14 +++ core/appmodule/v2/handlers.go | 142 ++++++++++++++++++++++++++ core/appmodule/v2/message.go | 21 ++++ core/appmodule/v2/migrations.go | 41 ++++++++ core/appmodule/v2/module.go | 92 +++++++++++++++++ core/go.mod | 3 + core/go.sum | 4 + 11 files changed, 387 insertions(+), 154 deletions(-) create mode 100644 core/appmodule/v2/environment.go create mode 100644 core/appmodule/v2/genesis.go create mode 100644 core/appmodule/v2/handlers.go create mode 100644 core/appmodule/v2/message.go create mode 100644 core/appmodule/v2/migrations.go create mode 100644 core/appmodule/v2/module.go diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index 17ab778191c..d65c32a5f83 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -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 diff --git a/core/appmodule/migrations.go b/core/appmodule/migrations.go index fa63b7a92c8..ca2b6fab1f6 100644 --- a/core/appmodule/migrations.go +++ b/core/appmodule/migrations.go @@ -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 diff --git a/core/appmodule/module.go b/core/appmodule/module.go index bb6b3cd22d6..8936c121c1c 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -3,7 +3,7 @@ package appmodule import ( "context" - "cosmossdk.io/core/transaction" + "cosmossdk.io/core/appmodule/v2" "google.golang.org/grpc" ) @@ -11,50 +11,37 @@ import ( // 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 + +// ********************************************** +// The following interfaces are baseapp specific and will be deprecated in the future. +// ********************************************** - // 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. @@ -73,92 +60,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/ ` :,.)_`> - // :/ ` ||/) - // (_.).__,-` |\ - // /( `.`` `| : - // \'`-.) ` ; ; - // | ` /-< - // | ` / `. - // ,-_-..____ /| ` :__..-'\ - // /,'-.__\\ ``-./ :` ; \ - // `\ `\ `\\ \ : ( ` / , `. \ - // \` \ \\ | | ` : : .\ \ - // \ `\_ )) : ; | | ): : - // (`-.-'\ || |\ \ ` ; ; | | - // \-_ `;;._ ( ` / /_ | | - // `-.-.// ,'`-._\__/_,' ; | - // \:: : / ` , / | - // || | ( ,' / / | - // || ,' / | - 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 } diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go new file mode 100644 index 00000000000..17ab778191c --- /dev/null +++ b/core/appmodule/v2/environment.go @@ -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 +} diff --git a/core/appmodule/v2/genesis.go b/core/appmodule/v2/genesis.go new file mode 100644 index 00000000000..19767e1d458 --- /dev/null +++ b/core/appmodule/v2/genesis.go @@ -0,0 +1,14 @@ +package appmodule + +import ( + "context" +) + +// HasGenesis defines a custom genesis handling API implementation. +type HasGenesis interface { + AppModule + DefaultGenesis() Message + ValidateGenesis(data Message) error + InitGenesis(ctx context.Context, data Message) error + ExportGenesis(ctx context.Context) (Message, error) +} diff --git a/core/appmodule/v2/handlers.go b/core/appmodule/v2/handlers.go new file mode 100644 index 00000000000..f7753c4723e --- /dev/null +++ b/core/appmodule/v2/handlers.go @@ -0,0 +1,142 @@ +package appmodule + +import ( + "context" + "fmt" +) + +type ( + // PreMsgHandler is a handler that is executed before Handler. If it errors the execution reverts. + PreMsgHandler = func(ctx context.Context, msg Message) error + // Handler handles the state transition of the provided message. + Handler = func(ctx context.Context, msg Message) (msgResp Message, err error) + // PostMsgHandler runs after Handler, only if Handler does not error. If PostMsgHandler errors + // then the execution is reverted. + PostMsgHandler = func(ctx context.Context, msg Message, msgResp Message) error +) + +// RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the +// QueryRouter or MsgRouter. Example usage: +// ```go +// +// func (k Keeper) QueryBalance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { +// ... query logic ... +// } +// +// func (m Module) RegisterQueryHandlers(router appmodule.QueryRouter) { +// appmodule.RegisterHandler(router, keeper.QueryBalance) +// } +// +// ``` +func RegisterHandler[R interface{ Register(string, Handler) }, Req, Resp Message]( + router R, + handler func(ctx context.Context, msg Req) (msgResp Resp, err error), +) { + untypedHandler := func(ctx context.Context, m Message) (Message, error) { + typed, ok := m.(Req) + if !ok { + return nil, fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req)) + } + return handler(ctx, typed) + } + router.Register(messageName[Req](), untypedHandler) +} + +// RegisterPreHandler is a helper function that modules can use to not lose type safety when registering PreMsgHandler to the +// PreMsgRouter. Example usage: +// ```go +// +// func (k Keeper) BeforeSend(ctx context.Context, req *types.MsgSend) (*types.QueryBalanceResponse, error) { +// ... before send logic ... +// } +// +// func (m Module) RegisterPreMsgHandlers(router appmodule.PreMsgRouter) { +// appmodule.RegisterPreHandler(router, keeper.BeforeSend) +// } +// +// ``` +func RegisterPreHandler[Req Message]( + router PreMsgRouter, + handler func(ctx context.Context, msg Req) error, +) { + untypedHandler := func(ctx context.Context, m Message) error { + typed, ok := m.(Req) + if !ok { + return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req)) + } + return handler(ctx, typed) + } + router.Register(messageName[Req](), untypedHandler) +} + +// RegisterPostHandler is a helper function that modules can use to not lose type safety when registering handlers to the +// PostMsgRouter. Example usage: +// ```go +// +// func (k Keeper) AfterSend(ctx context.Context, req *types.MsgSend, resp *types.MsgSendResponse) error { +// ... query logic ... +// } +// +// func (m Module) RegisterPostMsgHandlers(router appmodule.PostMsgRouter) { +// appmodule.RegisterPostHandler(router, keeper.AfterSend) +// } +// +// ``` +func RegisterPostHandler[Req, Resp Message]( + router PostMsgRouter, + handler func(ctx context.Context, msg Req, msgResp Resp) error, +) { + untypedHandler := func(ctx context.Context, m Message, mResp Message) error { + typed, ok := m.(Req) + if !ok { + return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req)) + } + typedResp, ok := mResp.(Resp) + if !ok { + return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Resp)) + } + return handler(ctx, typed, typedResp) + } + router.Register(messageName[Req](), untypedHandler) +} + +// msg handler + +type PreMsgRouter interface { + // Register will register a specific message handler hooking into the message with + // the provided name. + Register(msgName string, handler PreMsgHandler) + // RegisterGlobal will register a global message handler hooking into any message + // being executed. + RegisterGlobal(handler PreMsgHandler) +} + +type HasPreMsgHandlers interface { + RegisterPreMsgHandlers(router PreMsgRouter) +} + +type MsgRouter interface { + Register(msgName string, handler Handler) +} + +type HasMsgHandlers interface { + RegisterMsgHandlers(router MsgRouter) +} + +type PostMsgRouter interface { + // Register will register a specific message handler hooking after the execution of message with + // the provided name. + Register(msgName string, handler PostMsgHandler) + // RegisterGlobal will register a global message handler hooking after the execution of any message. + RegisterGlobal(handler PreMsgHandler) +} + +// query handler + +type QueryRouter interface { + Register(queryName string, handler Handler) +} + +type HasQueryHandlers interface { + RegisterQueryHandlers(router QueryRouter) +} diff --git a/core/appmodule/v2/message.go b/core/appmodule/v2/message.go new file mode 100644 index 00000000000..8a8753c9195 --- /dev/null +++ b/core/appmodule/v2/message.go @@ -0,0 +1,21 @@ +package appmodule + +import ( + gogoproto "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" +) + +// Message aliases protoiface.MessageV1 for convenience. +type Message = protoiface.MessageV1 + +func messageName[M Message]() string { + switch m := any(*new(M)).(type) { + case protov2.Message: + return string(m.ProtoReflect().Descriptor().FullName()) + case gogoproto.Message: + return gogoproto.MessageName(m) + default: + panic("unknown message type") + } +} diff --git a/core/appmodule/v2/migrations.go b/core/appmodule/v2/migrations.go new file mode 100644 index 00000000000..794fb4a28cc --- /dev/null +++ b/core/appmodule/v2/migrations.go @@ -0,0 +1,41 @@ +package appmodule + +import "context" + +// 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 +} + +// HasMigrations is implemented by a module which upgrades or has upgraded +// to a new consensus version. +type HasMigrations interface { + AppModule + HasConsensusVersion + + // RegisterMigrations registers the module's migrations with the app's migrator. + RegisterMigrations(MigrationRegistrar) error +} + +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 +} + +// MigrationHandler is the migration function that each module registers. +type MigrationHandler func(context.Context) error + +// VersionMap is a map of moduleName -> version +type VersionMap map[string]uint64 diff --git a/core/appmodule/v2/module.go b/core/appmodule/v2/module.go new file mode 100644 index 00000000000..eb44c9f513b --- /dev/null +++ b/core/appmodule/v2/module.go @@ -0,0 +1,92 @@ +package appmodule + +import ( + "context" + + "cosmossdk.io/core/transaction" +) + +// 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() + + // IsOnePerModuleType is a dummy method to help depinject resolve modules. + IsOnePerModuleType() +} + +// 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/ ` :,.)_`> + // :/ ` ||/) + // (_.).__,-` |\ + // /( `.`` `| : + // \'`-.) ` ; ; + // | ` /-< + // | ` / `. + // ,-_-..____ /| ` :__..-'\ + // /,'-.__\\ ``-./ :` ; \ + // `\ `\ `\\ \ : ( ` / , `. \ + // \` \ \\ | | ` : : .\ \ + // \ `\_ )) : ; | | ): : + // (`-.-'\ || |\ \ ` ; ; | | + // \-_ `;;._ ( ` / /_ | | + // `-.-.// ,'`-._\__/_,' ; | + // \:: : / ` , / | + // || | ( ,' / / | + // || ,' / | + 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 +} diff --git a/core/go.mod b/core/go.mod index 7a15dc7aacb..541f46106c1 100644 --- a/core/go.mod +++ b/core/go.mod @@ -4,6 +4,7 @@ go 1.21 require ( cosmossdk.io/log v1.3.1 + github.com/cosmos/gogoproto v1.4.11 github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.61.1 google.golang.org/protobuf v1.32.0 @@ -12,6 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -19,6 +21,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/zerolog v1.32.0 // indirect + golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/core/go.sum b/core/go.sum index bf7ff128621..05c18888a31 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,6 +1,8 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= +github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -37,6 +39,8 @@ github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From f27418df41d35afdd29b5c7b77466b7ad52e831f Mon Sep 17 00:00:00 2001 From: testinginprod Date: Tue, 20 Feb 2024 13:13:46 +0100 Subject: [PATCH 02/13] update --- core/appmodule/module.go | 10 ++-------- core/appmodule/v2/comet.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 core/appmodule/v2/comet.go diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 8936c121c1c..cb676226e97 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -48,17 +48,11 @@ type HasPrecommit interface { // 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 -} +type ResponsePreBlock = appmodule.ResponsePreBlock // 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) -} +type HasPreBlocker = appmodule.HasPreBlocker // HasServices is the extension interface that modules should implement to register // implementations of services defined in .proto files. diff --git a/core/appmodule/v2/comet.go b/core/appmodule/v2/comet.go new file mode 100644 index 00000000000..055c2597a24 --- /dev/null +++ b/core/appmodule/v2/comet.go @@ -0,0 +1,19 @@ +package appmodule + +import "context" + +// 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) +} From ae64a57c10d842ac253b45e0fc06ea5a8652a13c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 20 Feb 2024 14:35:47 +0100 Subject: [PATCH 03/13] v1 preblock is different than v2 --- core/appmodule/module.go | 10 ++++++++-- core/appmodule/v2/comet.go | 10 +--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/appmodule/module.go b/core/appmodule/module.go index cb676226e97..8936c121c1c 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -48,11 +48,17 @@ type HasPrecommit interface { // 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 = appmodule.ResponsePreBlock +type ResponsePreBlock interface { + IsConsensusParamsChanged() bool +} // HasPreBlocker is the extension interface that modules should implement to run // custom logic before BeginBlock. -type HasPreBlocker = appmodule.HasPreBlocker +type HasPreBlocker interface { + AppModule + // PreBlock is method that will be run before BeginBlock. + PreBlock(context.Context) (ResponsePreBlock, error) +} // HasServices is the extension interface that modules should implement to register // implementations of services defined in .proto files. diff --git a/core/appmodule/v2/comet.go b/core/appmodule/v2/comet.go index 055c2597a24..70c25446ada 100644 --- a/core/appmodule/v2/comet.go +++ b/core/appmodule/v2/comet.go @@ -2,18 +2,10 @@ package appmodule import "context" -// 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) + PreBlock(context.Context) error } From bc067a8fc162312e2f89a053d5174a23e249a7e1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 20 Feb 2024 14:50:14 +0100 Subject: [PATCH 04/13] fix build --- core/appmodule/module.go | 3 ++- core/appmodule/v2/handlers.go | 4 ++-- runtime/v2/manager.go | 13 +++++++------ server/v2/cometbft/utils.go | 4 ++-- server/v2/core/appmanager/app.go | 8 ++++---- server/v2/core/go.mod | 5 ----- server/v2/core/go.sum | 15 --------------- server/v2/stf/go.mod | 5 ----- server/v2/stf/go.sum | 15 --------------- server/v2/stf/stf.go | 12 ++++++------ server/v2/stf/stf_test.go | 8 ++++---- simapp/app_test.go | 5 +++-- x/auth/module.go | 9 +++++---- x/upgrade/abci_test.go | 13 ++++++------- x/upgrade/keeper/grpc_query_test.go | 6 +++--- x/upgrade/keeper/keeper.go | 14 +++++++------- x/upgrade/keeper/keeper_test.go | 20 +++++++++++--------- x/upgrade/types/handler.go | 4 ++-- 18 files changed, 64 insertions(+), 99 deletions(-) diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 8936c121c1c..75ebcf68dd7 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -3,8 +3,9 @@ package appmodule import ( "context" - "cosmossdk.io/core/appmodule/v2" "google.golang.org/grpc" + + "cosmossdk.io/core/appmodule/v2" ) // AppModule is a tag interface for app module implementations to use as a basis diff --git a/core/appmodule/v2/handlers.go b/core/appmodule/v2/handlers.go index f7753c4723e..7bfc46bf24c 100644 --- a/core/appmodule/v2/handlers.go +++ b/core/appmodule/v2/handlers.go @@ -12,7 +12,7 @@ type ( Handler = func(ctx context.Context, msg Message) (msgResp Message, err error) // PostMsgHandler runs after Handler, only if Handler does not error. If PostMsgHandler errors // then the execution is reverted. - PostMsgHandler = func(ctx context.Context, msg Message, msgResp Message) error + PostMsgHandler = func(ctx context.Context, msg, msgResp Message) error ) // RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the @@ -86,7 +86,7 @@ func RegisterPostHandler[Req, Resp Message]( router PostMsgRouter, handler func(ctx context.Context, msg Req, msgResp Resp) error, ) { - untypedHandler := func(ctx context.Context, m Message, mResp Message) error { + untypedHandler := func(ctx context.Context, m, mResp Message) error { typed, ok := m.(Req) if !ok { return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req)) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 25c3b20e2c0..c7ec14c59f7 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -16,6 +16,7 @@ import ( runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2" cosmosmsg "cosmossdk.io/api/cosmos/msg/v1" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/log" "cosmossdk.io/runtime/v2/protocompat" @@ -84,7 +85,7 @@ func (m *MM) BeginBlock() func(ctx context.Context) error { } // EndBlock runs the end-block logic of all modules and tx validator updates -func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error)) { +func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error)) { validatorUpdates := []abci.ValidatorUpdate{} endBlock := func(ctx context.Context) error { @@ -118,12 +119,12 @@ func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate fun return nil } - valUpdate := func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { - valUpdates := []appmodule.ValidatorUpdate{} + valUpdate := func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { + valUpdates := []appmodulev2.ValidatorUpdate{} // get validator updates of legacy modules using HasABCIEndBlock for i, v := range validatorUpdates { - valUpdates[i] = appmodule.ValidatorUpdate{ + valUpdates[i] = appmodulev2.ValidatorUpdate{ PubKey: v.PubKey.GetEd25519(), Power: v.Power, } @@ -131,7 +132,7 @@ func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate fun // get validator updates of modules implementing directly the new HasUpdateValidators interface for _, v := range m.modules { - if module, ok := v.(appmodule.HasUpdateValidators); ok { + if module, ok := v.(appmodulev2.HasUpdateValidators); ok { up, err := module.UpdateValidators(ctx) if err != nil { return nil, err @@ -170,7 +171,7 @@ func (m *MM) PreBlocker() func(ctx context.Context, txs []transaction.Tx) error func (m *MM) TxValidation() func(ctx context.Context, tx transaction.Tx) error { return func(ctx context.Context, tx transaction.Tx) error { for _, moduleName := range m.config.TxValidation { - if module, ok := m.modules[moduleName].(appmodule.HasTxValidation[transaction.Tx]); ok { + if module, ok := m.modules[moduleName].(appmodulev2.HasTxValidation[transaction.Tx]); ok { if err := module.TxValidator(ctx, tx); err != nil { return fmt.Errorf("failed to run txvalidator for %s: %w", moduleName, err) } diff --git a/server/v2/cometbft/utils.go b/server/v2/cometbft/utils.go index 6e6914eb9d7..81cfc7db181 100644 --- a/server/v2/cometbft/utils.go +++ b/server/v2/cometbft/utils.go @@ -20,7 +20,7 @@ import ( v1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" sdkabci "cosmossdk.io/api/tendermint/abci" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" errorsmod "cosmossdk.io/errors" "cosmossdk.io/server/v2/core/appmanager" @@ -124,7 +124,7 @@ func finalizeBlockResponse( return resp, nil } -func intoABCIValidatorUpdates(updates []appmodule.ValidatorUpdate) []abci.ValidatorUpdate { +func intoABCIValidatorUpdates(updates []appmodulev2.ValidatorUpdate) []abci.ValidatorUpdate { valsetUpdates := make([]abci.ValidatorUpdate, len(updates)) for i := range updates { diff --git a/server/v2/core/appmanager/app.go b/server/v2/core/appmanager/app.go index 799c5c70843..6a3e2e294c1 100644 --- a/server/v2/core/appmanager/app.go +++ b/server/v2/core/appmanager/app.go @@ -4,7 +4,7 @@ import ( "context" "time" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/core/event" "cosmossdk.io/server/v2/core/store" @@ -39,7 +39,7 @@ type BlockRequest[T any] struct { type BlockResponse struct { Apphash []byte - ValidatorUpdates []appmodule.ValidatorUpdate + ValidatorUpdates []appmodulev2.ValidatorUpdate PreBlockEvents []event.Event BeginBlockEvents []event.Event TxResults []TxResult @@ -49,13 +49,13 @@ type BlockResponse struct { type RequestInitChain struct { Time time.Time ChainId string - Validators []appmodule.ValidatorUpdate + Validators []appmodulev2.ValidatorUpdate AppStateBytes []byte InitialHeight int64 } type ResponseInitChain struct { - Validators []appmodule.ValidatorUpdate + Validators []appmodulev2.ValidatorUpdate AppHash []byte } diff --git a/server/v2/core/go.mod b/server/v2/core/go.mod index 3c0db362b3c..fde74bb4ac6 100644 --- a/server/v2/core/go.mod +++ b/server/v2/core/go.mod @@ -12,16 +12,11 @@ require ( require ( cosmossdk.io/log v1.3.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rs/zerolog v1.32.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect - google.golang.org/grpc v1.61.1 // indirect ) diff --git a/server/v2/core/go.sum b/server/v2/core/go.sum index 1c1b30a3271..6c775b18f2f 100644 --- a/server/v2/core/go.sum +++ b/server/v2/core/go.sum @@ -4,10 +4,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -23,22 +19,11 @@ github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk= -google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= -google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index 8ff434cb433..90305ebf03d 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -19,7 +19,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect github.com/cosmos/gogoproto v1.4.11 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/kr/text v0.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -28,10 +27,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/zerolog v1.32.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect - google.golang.org/grpc v1.61.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index b0403260768..cc21a9a6c97 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -6,10 +6,6 @@ github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSoht github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -38,22 +34,11 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk= -google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= -google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/server/v2/stf/stf.go b/server/v2/stf/stf.go index cadb538b465..1584aff9fd8 100644 --- a/server/v2/stf/stf.go +++ b/server/v2/stf/stf.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" coreevent "cosmossdk.io/core/event" "cosmossdk.io/core/gas" @@ -25,7 +25,7 @@ type STF[T transaction.Tx] struct { doPreBlock func(ctx context.Context, txs []T) error doBeginBlock func(ctx context.Context) error doEndBlock func(ctx context.Context) error - doValidatorUpdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) + doValidatorUpdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) doTxValidation func(ctx context.Context, tx T) error // TODO: rewrite antehandlers remove simulate postTxExec func(ctx context.Context, tx T, success bool) error @@ -43,7 +43,7 @@ func NewSTF[T transaction.Tx]( doBeginBlock func(ctx context.Context) error, doEndBlock func(ctx context.Context) error, doTxValidation func(ctx context.Context, tx T) error, - doValidatorUpdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error), + doValidatorUpdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error), branch func(store store.ReaderMap) store.WriterMap, ) *STF[T] { return &STF[T]{ @@ -260,7 +260,7 @@ func (s STF[T]) beginBlock(ctx context.Context, state store.WriterMap) (beginBlo return bbCtx.events, nil } -func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodule.ValidatorUpdate, error) { +func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { ebCtx := s.makeContext(ctx, []transaction.Identity{runtimeIdentity}, state, gas.NoGasLimit, corecontext.ExecModeFinalize) err := s.doEndBlock(ebCtx) if err != nil { @@ -285,7 +285,7 @@ func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Ev } // validatorUpdates returns the validator updates for the current block. It is called by endBlock after the endblock execution has concluded -func (s STF[T]) validatorUpdates(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodule.ValidatorUpdate, error) { +func (s STF[T]) validatorUpdates(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { ebCtx := s.makeContext(ctx, []transaction.Identity{runtimeIdentity}, state, gas.NoGasLimit, corecontext.ExecModeFinalize) valSetUpdates, err := s.doValidatorUpdate(ebCtx) if err != nil { @@ -375,7 +375,7 @@ func applyStateChanges(dst, src store.WriterMap) error { return dst.ApplyStateChanges(changes) } -// isCtxCancelled reports if the context was cancelled. +// isCtxCancelled reports if the context was canceled. func isCtxCancelled(ctx context.Context) error { select { case <-ctx.Done(): diff --git a/server/v2/stf/stf_test.go b/server/v2/stf/stf_test.go index 7718c12a72d..fbb1cb6ae47 100644 --- a/server/v2/stf/stf_test.go +++ b/server/v2/stf/stf_test.go @@ -5,16 +5,16 @@ import ( "fmt" "testing" - coregas "cosmossdk.io/core/gas" - "cosmossdk.io/server/v2/stf/gas" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/wrapperspb" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" + coregas "cosmossdk.io/core/gas" "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/core/appmanager" "cosmossdk.io/server/v2/core/store" "cosmossdk.io/server/v2/stf/branch" + "cosmossdk.io/server/v2/stf/gas" "cosmossdk.io/server/v2/stf/mock" ) @@ -41,7 +41,7 @@ func TestSTF(t *testing.T) { kvSet(t, ctx, "end-block") return nil }, - doValidatorUpdate: func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { return nil, nil }, + doValidatorUpdate: func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { return nil, nil }, doTxValidation: func(ctx context.Context, tx mock.Tx) error { kvSet(t, ctx, "validate") return nil diff --git a/simapp/app_test.go b/simapp/app_test.go index e693a729998..9fac84fe370 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/x/accounts" @@ -247,7 +248,7 @@ func TestInitGenesisOnMigration(t *testing.T) { // Run migrations only for "mock" module. We exclude it from // the VersionMap to simulate upgrading with a new module. _, err := app.ModuleManager.RunMigrations(ctx, app.Configurator(), - module.VersionMap{ + appmodulev2.VersionMap{ "bank": bank.AppModule{}.ConsensusVersion(), "auth": auth.AppModule{}.ConsensusVersion(), "authz": authzmodule.AppModule{}.ConsensusVersion(), @@ -279,7 +280,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx) require.NoError(t, err) for v, i := range app.ModuleManager.Modules { - if i, ok := i.(module.HasConsensusVersion); ok { + if i, ok := i.(appmodulev2.HasConsensusVersion); ok { require.Equal(t, vm[v], i.ConsensusVersion()) } } diff --git a/x/auth/module.go b/x/auth/module.go index f1d8e800ac3..2ac31d3a984 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/runtime/v2" "cosmossdk.io/x/auth/ante" @@ -36,10 +37,10 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasTxValidation[transaction.Tx] = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodulev2.HasTxValidation[transaction.Tx] = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} ) // AppModuleBasic defines the basic application module used by the auth module. diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 57168293d93..f1b0376f63d 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -25,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -48,7 +47,7 @@ func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height: 11: ") t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -66,7 +65,7 @@ func (s *TestSuite) VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, pro require.ErrorContains(t, err, "UPGRADE \""+proposalName+"\" NEEDED at height: ") t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -167,7 +166,7 @@ func TestHaltIfTooNew(t *testing.T) { s := setupTest(t, 10, map[int64]bool{}) t.Log("Verify that we don't panic with registered plan not in database at all") var called int - s.keeper.SetUpgradeHandler("future", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("future", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { called++ return vm, nil }) @@ -413,7 +412,7 @@ func TestBinaryVersion(t *testing.T) { { "test not panic: upgrade handler is present for last applied upgrade", func() sdk.Context { - s.keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -478,7 +477,7 @@ func TestDowngradeVerification(t *testing.T) { ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1}) // set the handler. - k.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + k.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -493,7 +492,7 @@ func TestDowngradeVerification(t *testing.T) { }{ "valid binary": { preRun: func(k *keeper.Keeper, ctx sdk.Context, name string) { - k.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + k.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) }, diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 93974687276..59b6744656a 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" @@ -19,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -45,7 +45,7 @@ func (suite *UpgradeTestSuite) SetupTest() { suite.Require().NoError(err) suite.encodedAuthority = authority suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, suite.T().TempDir(), nil, authority) - err = suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, module.VersionMap{ + err = suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, appmodule.VersionMap{ "bank": 0, }) suite.Require().NoError(err) @@ -133,7 +133,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { err := suite.upgradeKeeper.ScheduleUpgrade(suite.ctx, plan) suite.Require().NoError(err) suite.ctx = suite.ctx.WithHeaderInfo(header.Info{Height: expHeight}) - suite.upgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + suite.upgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) err = suite.upgradeKeeper.ApplyUpgrade(suite.ctx, plan) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 3c9689aad2b..75c52ecdfd4 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/go-metrics" + "cosmossdk.io/core/appmodule" corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" @@ -28,7 +29,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/types/module" ) type Keeper struct { @@ -40,7 +40,7 @@ type Keeper struct { versionModifier xp.AppVersionModifier // implements setting the protocol version field on BaseApp downgradeVerified bool // tells if we've already sanity checked that this binary version isn't being used against an old state. authority string // the address capable of executing and canceling an upgrade. Usually the gov module account - initVersionMap module.VersionMap // the module version map at init genesis + initVersionMap appmodule.VersionMap // the module version map at init genesis } // NewKeeper constructs an upgrade Keeper which requires the following arguments: @@ -69,13 +69,13 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeService corestore.KVStore // SetInitVersionMap sets the initial version map. // This is only used in app wiring and should not be used in any other context. -func (k *Keeper) SetInitVersionMap(vm module.VersionMap) { +func (k *Keeper) SetInitVersionMap(vm appmodule.VersionMap) { k.initVersionMap = vm } // GetInitVersionMap gets the initial version map // This is only used in upgrade InitGenesis and should not be used in any other context. -func (k *Keeper) GetInitVersionMap() module.VersionMap { +func (k *Keeper) GetInitVersionMap() appmodule.VersionMap { return k.initVersionMap } @@ -87,7 +87,7 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl } // SetModuleVersionMap saves a given version map to state -func (k Keeper) SetModuleVersionMap(ctx context.Context, vm module.VersionMap) error { +func (k Keeper) SetModuleVersionMap(ctx context.Context, vm appmodule.VersionMap) error { if len(vm) > 0 { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) versionStore := prefix.NewStore(store, []byte{types.VersionMapByte}) @@ -115,7 +115,7 @@ func (k Keeper) SetModuleVersionMap(ctx context.Context, vm module.VersionMap) e // GetModuleVersionMap returns a map of key module name and value module consensus version // as defined in ADR-041. -func (k Keeper) GetModuleVersionMap(ctx context.Context) (module.VersionMap, error) { +func (k Keeper) GetModuleVersionMap(ctx context.Context) (appmodule.VersionMap, error) { store := k.storeService.OpenKVStore(ctx) prefix := []byte{types.VersionMapByte} it, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) @@ -124,7 +124,7 @@ func (k Keeper) GetModuleVersionMap(ctx context.Context) (module.VersionMap, err } defer it.Close() - vm := make(module.VersionMap) + vm := make(appmodule.VersionMap) for ; it.Valid(); it.Next() { moduleBytes := it.Key() // first byte is prefix key, so we remove it here diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index ee87c2f23d8..ea1642bddb0 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/header" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -23,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -166,7 +166,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.upgradeKeeper.SetUpgradeHandler("all-good", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetUpgradeHandler("all-good", func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) err := s.upgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ @@ -287,7 +287,9 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { err = s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) s.Require().EqualError(err, "ApplyUpgrade should never be called without first checking HasHandler") - s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { + return vm, nil + }) err = s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) s.Require().NoError(err) upgradedProtocolVersion, err := s.baseApp.AppVersion(s.ctx) @@ -299,13 +301,13 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { // Tests that the underlying state of x/upgrade is set correctly after // an upgrade. func (s *KeeperTestSuite) TestMigrations() { - initialVM := module.VersionMap{"bank": uint64(1)} + initialVM := appmodule.VersionMap{"bank": uint64(1)} err := s.upgradeKeeper.SetModuleVersionMap(s.ctx, initialVM) s.Require().NoError(err) vmBefore, err := s.upgradeKeeper.GetModuleVersionMap(s.ctx) s.Require().NoError(err) - s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { // simulate upgrading the bank module vm["bank"]++ return vm, nil @@ -332,7 +334,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { require.Equal(int64(0), height) require.NoError(err) - keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -349,7 +351,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { require.Equal(int64(10), height) require.NoError(err) - keeper.SetUpgradeHandler("test1", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test1", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -374,7 +376,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() { require := s.Require() // apply first upgrade - keeper.SetUpgradeHandler("test-v0.9", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.9", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -390,7 +392,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() { require.NoError(err) // apply second upgrade - keeper.SetUpgradeHandler("test-v0.10", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.10", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) diff --git a/x/upgrade/types/handler.go b/x/upgrade/types/handler.go index 80d57da469e..386fd321017 100644 --- a/x/upgrade/types/handler.go +++ b/x/upgrade/types/handler.go @@ -3,7 +3,7 @@ package types import ( context "context" - "github.com/cosmos/cosmos-sdk/types/module" + "cosmossdk.io/core/appmodule" ) // UpgradeHandler specifies the type of function that is called when an upgrade @@ -24,4 +24,4 @@ import ( // function. // // Please also refer to docs/core/upgrade.md for more information. -type UpgradeHandler func(ctx context.Context, plan Plan, fromVM module.VersionMap) (module.VersionMap, error) +type UpgradeHandler func(ctx context.Context, plan Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) From 0cd479dc73466b079ddd9ef5fbf2cf8032470488 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 20 Feb 2024 15:54:06 +0100 Subject: [PATCH 05/13] gas meter --- server/v2/stf/branch/writer_map.go | 4 ++-- server/v2/stf/core_services.go | 3 +-- server/v2/stf/gas/defaults.go | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/server/v2/stf/branch/writer_map.go b/server/v2/stf/branch/writer_map.go index 189f3eb2591..0eb6dd2e97e 100644 --- a/server/v2/stf/branch/writer_map.go +++ b/server/v2/stf/branch/writer_map.go @@ -9,8 +9,8 @@ import ( func NewWriterMap( state store.ReaderMap, - branch func(readonlyState store.Reader) store.Writer) store.WriterMap { - + branch func(readonlyState store.Reader) store.Writer, +) store.WriterMap { return WriterMap{ state: state, branchedWriterState: make(map[string]store.Writer), diff --git a/server/v2/stf/core_services.go b/server/v2/stf/core_services.go index d05edf2de8d..735fb3de9c7 100644 --- a/server/v2/stf/core_services.go +++ b/server/v2/stf/core_services.go @@ -45,8 +45,7 @@ func NewGasMeterService() gas.Service { return gasService{} } -type gasService struct { -} +type gasService struct{} func (g gasService) GetGasMeter(ctx context.Context) gas.Meter { return ctx.(*executionContext).meter diff --git a/server/v2/stf/gas/defaults.go b/server/v2/stf/gas/defaults.go index 3e34f8004f3..52fa3586d2c 100644 --- a/server/v2/stf/gas/defaults.go +++ b/server/v2/stf/gas/defaults.go @@ -33,8 +33,7 @@ var DefaultConfig = StoreConfig{ IterNextCostFlat: 30, } -type NoOpMeter struct { -} +type NoOpMeter struct{} func (n NoOpMeter) Consumed() coregas.Gas { return 0 } From 4b2aa9bbeebb029ebf4cb60831e87cea1f07e714 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 23 Feb 2024 08:45:50 +0100 Subject: [PATCH 06/13] cleanup --- server/v2/cometbft/handlers/defaults.go | 3 ++- server/v2/cometbft/utils.go | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/v2/cometbft/handlers/defaults.go b/server/v2/cometbft/handlers/defaults.go index 6d6ba398a8a..65f6721317f 100644 --- a/server/v2/cometbft/handlers/defaults.go +++ b/server/v2/cometbft/handlers/defaults.go @@ -7,9 +7,10 @@ import ( "github.com/cosmos/gogoproto/proto" // TODO: use protov2 + abci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" - abci "cosmossdk.io/api/tendermint/abci" "cosmossdk.io/core/transaction" + "cosmossdk.io/server/v2/cometbft/mempool" "cosmossdk.io/server/v2/core/appmanager" ) diff --git a/server/v2/cometbft/utils.go b/server/v2/cometbft/utils.go index f251b820a46..7de54cd2e59 100644 --- a/server/v2/cometbft/utils.go +++ b/server/v2/cometbft/utils.go @@ -10,7 +10,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - types1 "github.com/cometbft/cometbft/proto/tendermint/types" gogoproto "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" @@ -18,9 +17,9 @@ import ( "google.golang.org/protobuf/types/dynamicpb" "google.golang.org/protobuf/types/known/anypb" + sdkabci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" v1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" - sdkabci "cosmossdk.io/api/tendermint/abci" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" "cosmossdk.io/core/event" @@ -196,7 +195,7 @@ func intoABCISimulationResponse(txRes appmanager.TxResult, indexSet map[string]s abciEvents := make([]*sdkabci.Event, len(txRes.Events)) for i, e := range txRes.Events { abciEvents[i] = &sdkabci.Event{ - Type_: e.Type, + Type: e.Type, Attributes: make([]*sdkabci.EventAttribute, len(e.Attributes)), } @@ -348,22 +347,22 @@ func (c *Consensus[T]) GetConsensusParams(ctx context.Context) (*cmtproto.Consen } else { // convert our params to cometbft params evidenceMaxDuration := time.Duration(r.Params.Evidence.MaxAgeDuration.Seconds) - cs = &types1.ConsensusParams{ - Block: &types1.BlockParams{ + cs = &cmtproto.ConsensusParams{ + Block: &cmtproto.BlockParams{ MaxBytes: r.Params.Block.MaxBytes, MaxGas: r.Params.Block.MaxGas, }, - Evidence: &types1.EvidenceParams{ + Evidence: &cmtproto.EvidenceParams{ MaxAgeNumBlocks: r.Params.Evidence.MaxAgeNumBlocks, MaxAgeDuration: evidenceMaxDuration, }, - Validator: &types1.ValidatorParams{ + Validator: &cmtproto.ValidatorParams{ PubKeyTypes: r.Params.Validator.PubKeyTypes, }, - Version: &types1.VersionParams{ + Version: &cmtproto.VersionParams{ App: r.Params.Version.App, }, - Abci: &types1.ABCIParams{ + Abci: &cmtproto.ABCIParams{ VoteExtensionsEnableHeight: r.Params.Abci.VoteExtensionsEnableHeight, }, } From 0230dec094b44721eaa3c09165598169dab45205 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 23 Feb 2024 08:48:34 +0100 Subject: [PATCH 07/13] add non consensus database --- core/store/database.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core/store/database.go diff --git a/core/store/database.go b/core/store/database.go new file mode 100644 index 00000000000..dcac5751aff --- /dev/null +++ b/core/store/database.go @@ -0,0 +1,22 @@ +package store + +// Database provides access to the underlying data base for get set and delete operations of nonconsensus Data +type DatabaseService interface { + GetDataBase() NonConsensusStore +} + +// NonConsensusStore is a simple key-value store that is used to store non-consensus data. +// Note the non-consensus data is not committed to the blockchain and does not allow iteration +type NonConsensusStore interface { + // Get returns nil iff key doesn't exist. Errors on nil key. + Get(key []byte) ([]byte, error) + + // Has checks if a key exists. Errors on nil key. + Has(key []byte) (bool, error) + + // Set sets the key. Errors on nil key or value. + Set(key, value []byte) error + + // Delete deletes the key. Errors on nil key. + Delete(key []byte) error +} From 3bffa716c97eebd3dc6c23c3028c6108cf6f1305 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 23 Feb 2024 08:56:35 +0100 Subject: [PATCH 08/13] lint fix --- server/v2/cometbft/abci.go | 1 - server/v2/cometbft/handlers/defaults.go | 3 +-- server/v2/cometbft/handlers/tx_selector.go | 3 ++- server/v2/cometbft/streaming.go | 3 +-- server/v2/cometbft/utils.go | 2 +- server/v2/stf/stf_test.go | 1 - 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 0c18d8a305a..04ae26f9d7c 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -191,7 +191,6 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abci.RequestQuery) (*abci // InitChain implements types.Application. func (c *Consensus[T]) InitChain(ctx context.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - // TODO: won't work for now return &abci.ResponseInitChain{ ConsensusParams: req.ConsensusParams, diff --git a/server/v2/cometbft/handlers/defaults.go b/server/v2/cometbft/handlers/defaults.go index 65f6721317f..1eb92d59f47 100644 --- a/server/v2/cometbft/handlers/defaults.go +++ b/server/v2/cometbft/handlers/defaults.go @@ -5,12 +5,11 @@ import ( "errors" "fmt" + abci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" "github.com/cosmos/gogoproto/proto" // TODO: use protov2 - abci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" "cosmossdk.io/core/transaction" - "cosmossdk.io/server/v2/cometbft/mempool" "cosmossdk.io/server/v2/core/appmanager" ) diff --git a/server/v2/cometbft/handlers/tx_selector.go b/server/v2/cometbft/handlers/tx_selector.go index 9536fd8a3dd..f2e11cfd1c5 100644 --- a/server/v2/cometbft/handlers/tx_selector.go +++ b/server/v2/cometbft/handlers/tx_selector.go @@ -3,8 +3,9 @@ package handlers import ( "context" - "cosmossdk.io/core/transaction" cmttypes "github.com/cometbft/cometbft/types" + + "cosmossdk.io/core/transaction" ) // TxSelector defines a helper type that assists in selecting transactions during diff --git a/server/v2/cometbft/streaming.go b/server/v2/cometbft/streaming.go index 0765d6bcb81..ef2a5d70d68 100644 --- a/server/v2/cometbft/streaming.go +++ b/server/v2/cometbft/streaming.go @@ -18,9 +18,8 @@ func (c *Consensus[T]) streamDeliverBlockChanges( events []event.Event, stateChanges []store.StateChanges, ) error { - // convert txresults to streaming txresults - var streamingTxResults = make([]*streaming.ExecTxResult, len(txResults)) + streamingTxResults := make([]*streaming.ExecTxResult, len(txResults)) for i, txResult := range txResults { // TODO populate this info streamingTxResults[i] = &streaming.ExecTxResult{ diff --git a/server/v2/cometbft/utils.go b/server/v2/cometbft/utils.go index 7de54cd2e59..6131fec142d 100644 --- a/server/v2/cometbft/utils.go +++ b/server/v2/cometbft/utils.go @@ -7,6 +7,7 @@ import ( "strings" "time" + sdkabci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" abci "github.com/cometbft/cometbft/abci/types" cmtcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -17,7 +18,6 @@ import ( "google.golang.org/protobuf/types/dynamicpb" "google.golang.org/protobuf/types/known/anypb" - sdkabci "buf.build/gen/go/tendermint/tendermint/protocolbuffers/go/tendermint/abci" v1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" appmodulev2 "cosmossdk.io/core/appmodule/v2" diff --git a/server/v2/stf/stf_test.go b/server/v2/stf/stf_test.go index 5c108bda03f..fbb1cb6ae47 100644 --- a/server/v2/stf/stf_test.go +++ b/server/v2/stf/stf_test.go @@ -11,7 +11,6 @@ import ( appmodulev2 "cosmossdk.io/core/appmodule/v2" coregas "cosmossdk.io/core/gas" "cosmossdk.io/core/transaction" - "cosmossdk.io/server/v2/core/appmanager" "cosmossdk.io/server/v2/core/store" "cosmossdk.io/server/v2/stf/branch" From c98f4751cec1efe5774064ee0550c9ea55019582 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 23 Feb 2024 11:14:58 +0100 Subject: [PATCH 09/13] use v2 in modules --- core/appmodule/module.go | 4 ---- simapp/app_v1_di.go | 14 -------------- x/auth/module.go | 4 ++-- x/bank/module.go | 7 ++++--- x/circuit/module.go | 3 ++- x/consensus/module.go | 4 ++-- x/distribution/module.go | 9 +++++---- x/evidence/module.go | 6 +++--- x/feegrant/module/module.go | 9 +++++---- x/gov/module.go | 9 +++++---- x/mint/module.go | 9 +++++---- x/nft/module/module.go | 4 ++-- x/protocolpool/module.go | 3 ++- x/staking/module.go | 9 +++++---- x/upgrade/module.go | 9 +++++---- 15 files changed, 47 insertions(+), 56 deletions(-) diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 75ebcf68dd7..b1cb6c693cd 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -28,10 +28,6 @@ type HasBeginBlocker = appmodule.HasBeginBlocker // custom logic after transaction processing in a block. type HasEndBlocker = appmodule.HasEndBlocker -// ********************************************** -// 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 { diff --git a/simapp/app_v1_di.go b/simapp/app_v1_di.go index 03d5150d2f8..d49e9f4ac5b 100644 --- a/simapp/app_v1_di.go +++ b/simapp/app_v1_di.go @@ -23,10 +23,7 @@ import ( distrkeeper "cosmossdk.io/x/distribution/keeper" evidencekeeper "cosmossdk.io/x/evidence/keeper" feegrantkeeper "cosmossdk.io/x/feegrant/keeper" - "cosmossdk.io/x/gov" - govclient "cosmossdk.io/x/gov/client" govkeeper "cosmossdk.io/x/gov/keeper" - govtypes "cosmossdk.io/x/gov/types" groupkeeper "cosmossdk.io/x/group/keeper" mintkeeper "cosmossdk.io/x/mint/keeper" nftkeeper "cosmossdk.io/x/nft/keeper" @@ -48,8 +45,6 @@ import ( testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" "github.com/cosmos/cosmos-sdk/types/module" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // DefaultNodeHome default home directories for the application daemon @@ -106,15 +101,6 @@ func AppConfig() depinject.Config { return depinject.Configs( // appconfig.LoadYAML(AppConfigYAML), appConfig, - depinject.Supply( - // supply custom module basics - map[string]module.AppModuleBasic{ - genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), - govtypes.ModuleName: gov.NewAppModuleBasic( - []govclient.ProposalHandler{}, - ), - }, - ), ) } diff --git a/x/auth/module.go b/x/auth/module.go index 0d4695aff35..ba64d67786e 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -36,10 +36,10 @@ var ( _ module.HasName = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodulev2.AppModule = AppModule{} _ appmodulev2.HasTxValidation[transaction.Tx] = AppModule{} _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the auth module. diff --git a/x/bank/module.go b/x/bank/module.go index f233d0115b4..958a14e271b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/bank/client/cli" "cosmossdk.io/x/bank/keeper" "cosmossdk.io/x/bank/simulation" @@ -37,9 +38,9 @@ var ( _ module.HasGenesis = AppModule{} _ module.HasInvariants = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the bank module. diff --git a/x/circuit/module.go b/x/circuit/module.go index 852b74d6654..23e7910c100 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/circuit/keeper" "cosmossdk.io/x/circuit/types" @@ -29,7 +30,7 @@ var ( _ module.HasRegisterInterfaces = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodulev2.AppModule = AppModule{} _ appmodule.HasServices = AppModule{} ) diff --git a/x/consensus/module.go b/x/consensus/module.go index de10392824d..6de81384f17 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -6,7 +6,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -25,7 +25,7 @@ var ( _ module.HasGRPCGateway = AppModule{} _ module.HasRegisterInterfaces = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodulev2.AppModule = AppModule{} ) // AppModule implements an application module diff --git a/x/distribution/module.go b/x/distribution/module.go index 2caf7ab534e..abca53f0f82 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/distribution/client/cli" "cosmossdk.io/x/distribution/keeper" "cosmossdk.io/x/distribution/simulation" @@ -35,10 +36,10 @@ var ( _ module.HasGenesis = AppModule{} _ module.HasInvariants = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the distribution module. diff --git a/x/evidence/module.go b/x/evidence/module.go index b09183dbb50..c1bb6916d7c 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" eviclient "cosmossdk.io/x/evidence/client" "cosmossdk.io/x/evidence/client/cli" "cosmossdk.io/x/evidence/keeper" @@ -31,8 +31,8 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasBeginBlocker = AppModule{} ) const ConsensusVersion = 1 diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 969708da943..2aa5f21ea99 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/errors" "cosmossdk.io/x/feegrant" @@ -30,10 +31,10 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the feegrant module. diff --git a/x/gov/module.go b/x/gov/module.go index 85c95353513..c352ab31ed3 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" govclient "cosmossdk.io/x/gov/client" "cosmossdk.io/x/gov/client/cli" "cosmossdk.io/x/gov/keeper" @@ -37,10 +38,10 @@ var ( _ module.HasGenesis = AppModule{} _ module.HasInvariants = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the gov module. diff --git a/x/mint/module.go b/x/mint/module.go index 3f8e9fbabfb..6bb18cea95a 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/mint/keeper" "cosmossdk.io/x/mint/simulation" "cosmossdk.io/x/mint/types" @@ -31,10 +32,10 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements an application module for the mint module. diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 8f213b1305c..aff6365698a 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -7,7 +7,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/errors" "cosmossdk.io/x/nft" "cosmossdk.io/x/nft/keeper" @@ -27,7 +27,7 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodulev2.AppModule = AppModule{} ) const ConsensusVersion = 1 diff --git a/x/protocolpool/module.go b/x/protocolpool/module.go index 0257e69960e..e0b1fae2133 100644 --- a/x/protocolpool/module.go +++ b/x/protocolpool/module.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/protocolpool/keeper" "cosmossdk.io/x/protocolpool/types" @@ -30,7 +31,7 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodulev2.AppModule = AppModule{} _ appmodule.HasServices = AppModule{} ) diff --git a/x/staking/module.go b/x/staking/module.go index 2e4254133d1..ff47e1fc20e 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/depinject" "cosmossdk.io/x/staking/client/cli" "cosmossdk.io/x/staking/keeper" @@ -37,10 +38,10 @@ var ( _ module.HasABCIGenesis = AppModule{} _ module.HasABCIEndBlock = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodulev2.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} _ depinject.OnePerModuleType = AppModule{} ) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 7a609ae4b25..4925fe8afc1 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/x/upgrade/client/cli" "cosmossdk.io/x/upgrade/keeper" "cosmossdk.io/x/upgrade/types" @@ -34,10 +35,10 @@ var ( _ module.HasRegisterInterfaces = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasPreBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodulev2.AppModule = AppModule{} + _ appmodule.HasPreBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodulev2.HasMigrations = AppModule{} ) // AppModule implements the sdk.AppModule interface From b8a0b7ccb4c84c4a5b0253f1c3ddea2c4a50cdab Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 25 Feb 2024 15:31:22 +0100 Subject: [PATCH 10/13] Update core/store/database.go Co-authored-by: Aleksandr Bezobchuk --- core/store/database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/store/database.go b/core/store/database.go index dcac5751aff..a4035526c4c 100644 --- a/core/store/database.go +++ b/core/store/database.go @@ -1,6 +1,6 @@ package store -// Database provides access to the underlying data base for get set and delete operations of nonconsensus Data +// Database provides access to the underlying database for CRUD operations of non-consensus data. type DatabaseService interface { GetDataBase() NonConsensusStore } From ad1bf8a61621613f38e448acf692d63f08946c1e Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 25 Feb 2024 15:31:27 +0100 Subject: [PATCH 11/13] Update core/store/database.go Co-authored-by: Aleksandr Bezobchuk --- core/store/database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/store/database.go b/core/store/database.go index a4035526c4c..e536d14e4b8 100644 --- a/core/store/database.go +++ b/core/store/database.go @@ -2,7 +2,7 @@ package store // Database provides access to the underlying database for CRUD operations of non-consensus data. type DatabaseService interface { - GetDataBase() NonConsensusStore + GetDatabase() NonConsensusStore } // NonConsensusStore is a simple key-value store that is used to store non-consensus data. From 354f84187a6ab023ab7d4b4665c083f6025915d1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 26 Feb 2024 11:58:24 +0100 Subject: [PATCH 12/13] remove new preblocker --- core/appmodule/v2/comet.go | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 core/appmodule/v2/comet.go diff --git a/core/appmodule/v2/comet.go b/core/appmodule/v2/comet.go deleted file mode 100644 index 70c25446ada..00000000000 --- a/core/appmodule/v2/comet.go +++ /dev/null @@ -1,11 +0,0 @@ -package appmodule - -import "context" - -// 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 -} From 93b4094d975034228a1f624450ff15f1fefd0b54 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 26 Feb 2024 18:21:10 +0100 Subject: [PATCH 13/13] add todo --- core/appmodule/v2/genesis.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/appmodule/v2/genesis.go b/core/appmodule/v2/genesis.go index 19767e1d458..51cdb00fc08 100644 --- a/core/appmodule/v2/genesis.go +++ b/core/appmodule/v2/genesis.go @@ -5,6 +5,7 @@ import ( ) // HasGenesis defines a custom genesis handling API implementation. +// TODO: finalize this API type HasGenesis interface { AppModule DefaultGenesis() Message