From 10663c5273a4c0e445efa3dba9dc68b6d73f5d95 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 4 Sep 2024 00:20:05 +0200 Subject: [PATCH] docs(core): add core documentation and principles (#21511) Co-authored-by: Aaron Craelius (cherry picked from commit 6fc677faecf83178114d9d1e9b6e2378b6f7f4ca) # Conflicts: # core/README.md # core/appmodule/doc.go # core/appmodule/environment.go # core/appmodule/genesis.go # core/appmodule/migrations.go # core/appmodule/module.go # core/appmodule/v2/environment.go # core/appmodule/v2/genesis.go # core/appmodule/v2/handlers.go # core/appmodule/v2/migrations.go # core/appmodule/v2/module.go # core/appmodule/v2/tx_validator.go # core/context/context.go # core/context/server_context.go # core/gas/service.go # core/legacy/amino.go # core/registry/legacy.go # core/transaction/service.go # core/transaction/transaction.go # server/v2/stf/stf_router_test.go --- core/README.md | 19 ++++ core/appmodule/doc.go | 4 + core/appmodule/environment.go | 9 ++ core/appmodule/genesis.go | 59 ++++++++++++ core/appmodule/migrations.go | 20 ++++ core/appmodule/module.go | 72 ++++++++++++++ core/appmodule/v2/doc.go | 3 + core/appmodule/v2/environment.go | 29 ++++++ core/appmodule/v2/genesis.go | 37 +++++++ core/appmodule/v2/handlers.go | 62 ++++++++++++ core/appmodule/v2/migrations.go | 41 ++++++++ core/appmodule/v2/module.go | 106 +++++++++++++++++++++ core/appmodule/v2/tx_validator.go | 13 +++ core/context/context.go | 22 +++++ core/context/server_context.go | 13 +++ core/gas/service.go | 54 +++++++++++ core/genesis/doc.go | 3 + core/legacy/amino.go | 16 ++++ core/registry/legacy.go | 27 ++++++ core/transaction/service.go | 25 +++++ core/transaction/transaction.go | 37 +++++++ server/v2/cometbft/abci.go | 2 +- server/v2/stf/stf_router_test.go | 60 ++++++++++++ testutil/mock/types_mock_appmodule.go | 6 +- x/accounts/defaults/base/utils_test.go | 4 +- x/accounts/defaults/lockup/utils_test.go | 4 +- x/accounts/defaults/multisig/utils_test.go | 4 +- x/auth/ante/basic.go | 10 +- x/auth/ante/basic_test.go | 4 +- x/auth/ante/unordered.go | 6 +- x/auth/tx/config/depinject.go | 28 +++--- x/bank/types/send_authorization.go | 4 +- x/bank/types/send_authorization_test.go | 4 +- x/consensus/keeper/keeper.go | 2 +- x/feegrant/basic_fee_test.go | 4 +- x/feegrant/filtered_fee_test.go | 4 +- x/feegrant/periodic_fee_test.go | 4 +- x/staking/types/authz_test.go | 4 +- 38 files changed, 778 insertions(+), 47 deletions(-) create mode 100644 core/README.md create mode 100644 core/appmodule/doc.go create mode 100644 core/appmodule/environment.go create mode 100644 core/appmodule/genesis.go create mode 100644 core/appmodule/migrations.go create mode 100644 core/appmodule/module.go create mode 100644 core/appmodule/v2/doc.go 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/migrations.go create mode 100644 core/appmodule/v2/module.go create mode 100644 core/appmodule/v2/tx_validator.go create mode 100644 core/context/context.go create mode 100644 core/context/server_context.go create mode 100644 core/gas/service.go create mode 100644 core/genesis/doc.go create mode 100644 core/legacy/amino.go create mode 100644 core/registry/legacy.go create mode 100644 core/transaction/service.go create mode 100644 core/transaction/transaction.go create mode 100644 server/v2/stf/stf_router_test.go diff --git a/core/README.md b/core/README.md new file mode 100644 index 000000000000..6ab95a67a6f1 --- /dev/null +++ b/core/README.md @@ -0,0 +1,19 @@ +# Cosmos SDK Core + +The [cosmossdk.io/core](https://pkg.go.dev/cosmossdk.io/core) Go module defines essential APIs and interfaces for the Cosmos SDK ecosystem. It serves as a foundation for building modular blockchain applications. + +Key features and principles: + +1. Provides stable, long-term maintained APIs for module development and app composition. +2. Focuses on interface definitions without implementation details. +3. Implementations are housed in the runtime(/v2) or individual modules. +4. Modules depend solely on core APIs for maximum compatibility. +5. New API additions undergo thorough consideration to maintain stability. +6. Adheres to a no-breaking-changes policy for reliable dependency management. +7. Aimed to have zero dependencies, ensuring a lightweight and self-contained foundation. + +The core module offers the [appmodule](https://pkg.go.dev/cosmossdk.io/core/appmodule) and [appmodule/v2](https://pkg.go.dev/cosmossdk.io/core/appmodule/v2) packages that include APIs to describe how modules can be written. +Additionally, it contains all core services APIs that can be used in modules to interact with the SDK, majoritarily via the `appmodule.Environment` struct. +Last but not least, it provides codecs and packages for the Cosmos SDK's core types (think of, for instance, logger, store interface or an address codec). + +Developers and contributors approach core API design with careful deliberation, ensuring that additions provide significant value while maintaining the module's stability and simplicity. diff --git a/core/appmodule/doc.go b/core/appmodule/doc.go new file mode 100644 index 000000000000..311f6e25a271 --- /dev/null +++ b/core/appmodule/doc.go @@ -0,0 +1,4 @@ +// Package appmodule defines what is needed for an module to be used in the Cosmos SDK (runtime). +// It is equivalent to the appmodulev2 package, but less flexible to stay compatible with baseapp instead of server/v2. +// If you are looking at integrating dependency injection into your module please see depinject appconfig documentation. +package appmodule diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go new file mode 100644 index 000000000000..8e4079066661 --- /dev/null +++ b/core/appmodule/environment.go @@ -0,0 +1,9 @@ +package appmodule + +import ( + appmodulev2 "cosmossdk.io/core/appmodule/v2" +) + +// Environment is used to get all services to their respective module. +// Contract: All fields of environment are always populated by runtime. +type Environment = appmodulev2.Environment diff --git a/core/appmodule/genesis.go b/core/appmodule/genesis.go new file mode 100644 index 000000000000..ca312a2b8c93 --- /dev/null +++ b/core/appmodule/genesis.go @@ -0,0 +1,59 @@ +package appmodule + +import ( + "context" + "encoding/json" + "io" + + appmodulev2 "cosmossdk.io/core/appmodule/v2" +) + +// HasGenesisBasics is the legacy interface for stateless genesis methods. +type HasGenesisBasics interface { + DefaultGenesis() json.RawMessage + ValidateGenesis(json.RawMessage) error +} + +// HasGenesis defines a custom genesis handling API implementation. +type HasGenesis = appmodulev2.HasGenesis + +// HasABCIGenesis defines a custom genesis handling API implementation for ABCI. +// (stateful genesis methods which returns validator updates) +// Most modules should not implement this interface. +type HasABCIGenesis = appmodulev2.HasABCIGenesis + +// HasGenesisAuto is the extension interface that modules should implement to handle +// genesis data and state initialization. +// WARNING: This interface is experimental and may change at any time and has been dropped in v2. +type HasGenesisAuto interface { + appmodulev2.AppModule + + // DefaultGenesis writes the default genesis for this module to the target. + DefaultGenesis(GenesisTarget) error + + // ValidateGenesis validates the genesis data read from the source. + ValidateGenesis(GenesisSource) error + + // InitGenesis initializes module state from the genesis source. + InitGenesis(context.Context, GenesisSource) error + + // ExportGenesis exports module state to the genesis target. + ExportGenesis(context.Context, GenesisTarget) error +} + +// GenesisSource is a source for genesis data in JSON format. It may abstract over a +// single JSON object or separate files for each field in a JSON object that can +// be streamed over. Modules should open a separate io.ReadCloser for each field that +// is required. When fields represent arrays they can efficiently be streamed +// over. If there is no data for a field, this function should return nil, nil. It is +// important that the caller closes the reader when done with it. +type GenesisSource = func(field string) (io.ReadCloser, error) + +// GenesisTarget is a target for writing genesis data in JSON format. It may +// abstract over a single JSON object or JSON in separate files that can be +// streamed over. Modules should open a separate io.WriteCloser for each field +// and should prefer writing fields as arrays when possible to support efficient +// iteration. It is important the caller closers the writer AND checks the error +// when done with it. It is expected that a stream of JSON data is written +// to the writer. +type GenesisTarget = func(field string) (io.WriteCloser, error) diff --git a/core/appmodule/migrations.go b/core/appmodule/migrations.go new file mode 100644 index 000000000000..5632e55424d1 --- /dev/null +++ b/core/appmodule/migrations.go @@ -0,0 +1,20 @@ +package appmodule + +import ( + appmodulev2 "cosmossdk.io/core/appmodule/v2" +) + +// HasConsensusVersion is the interface for declaring a module consensus version. +type HasConsensusVersion = appmodulev2.HasConsensusVersion + +// HasMigrations is implemented by a module which upgrades or has upgraded to a new consensus version. +type HasMigrations = appmodulev2.HasMigrations + +// MigrationRegistrar is the interface for registering in-place store migrations. +type MigrationRegistrar = appmodulev2.MigrationRegistrar + +// MigrationHandler is the migration function that each module registers. +type MigrationHandler = appmodulev2.MigrationHandler + +// VersionMap is a map of moduleName -> version +type VersionMap = appmodulev2.VersionMap diff --git a/core/appmodule/module.go b/core/appmodule/module.go new file mode 100644 index 000000000000..279b3c8d6fad --- /dev/null +++ b/core/appmodule/module.go @@ -0,0 +1,72 @@ +package appmodule + +import ( + "context" + + appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/legacy" +) + +// 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 = appmodulev2.AppModule + +// HasPreBlocker is the extension interface that modules should implement to run +// custom logic before BeginBlock. +type HasPreBlocker = appmodulev2.HasPreBlocker + +// HasBeginBlocker is the extension interface that modules should implement to run +// custom logic before transaction processing in a block. +type HasBeginBlocker = appmodulev2.HasBeginBlocker + +// HasEndBlocker is the extension interface that modules should implement to run +// custom logic after transaction processing in a block. +type HasEndBlocker = appmodulev2.HasEndBlocker + +// HasRegisterInterfaces is the interface for modules to register their msg types. +type HasRegisterInterfaces = appmodulev2.HasRegisterInterfaces + +// ValidatorUpdate defines a validator update. +type ValidatorUpdate = appmodulev2.ValidatorUpdate + +// HasServices is the extension interface that modules should implement to register +// implementations of services defined in .proto files. +// This API is supported by the Cosmos SDK module managers but is excluded from core to limit dependencies. +// type HasServices interface { +// AppModule + +// // 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 +// } + +// HasPrepareCheckState is an extension interface that contains information about the AppModule +// and PrepareCheckState. +type HasPrepareCheckState interface { + appmodulev2.AppModule + PrepareCheckState(context.Context) error +} + +// HasPrecommit is an extension interface that contains information about the appmodule.AppModule and Precommit. +type HasPrecommit interface { + appmodulev2.AppModule + Precommit(context.Context) error +} + +// HasAminoCodec is an extension interface that module must implement to support JSON encoding and decoding of its types +// through amino. This is used in genesis & the CLI client. +type HasAminoCodec interface { + RegisterLegacyAminoCodec(legacy.Amino) +} diff --git a/core/appmodule/v2/doc.go b/core/appmodule/v2/doc.go new file mode 100644 index 000000000000..4953f90ac4f7 --- /dev/null +++ b/core/appmodule/v2/doc.go @@ -0,0 +1,3 @@ +// Package appmodule defines what is needed for an module to be used in the Cosmos SDK (runtime/v2). +// If you are looking at integrating dependency injection into your module please see depinject appconfig documentation. +package appmodulev2 diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go new file mode 100644 index 000000000000..450e10e162fe --- /dev/null +++ b/core/appmodule/v2/environment.go @@ -0,0 +1,29 @@ +package appmodulev2 + +import ( + "cosmossdk.io/core/branch" + "cosmossdk.io/core/event" + "cosmossdk.io/core/gas" + "cosmossdk.io/core/header" + "cosmossdk.io/core/log" + "cosmossdk.io/core/router" + "cosmossdk.io/core/store" + "cosmossdk.io/core/transaction" +) + +// Environment is used to get all services to their respective module. +// Contract: All fields of environment are always populated by runtime. +type Environment struct { + Logger log.Logger + + BranchService branch.Service + EventService event.Service + GasService gas.Service + HeaderService header.Service + QueryRouterService router.Service + MsgRouterService router.Service + TransactionService transaction.Service + + KVStoreService store.KVStoreService + MemStoreService store.MemoryStoreService +} diff --git a/core/appmodule/v2/genesis.go b/core/appmodule/v2/genesis.go new file mode 100644 index 000000000000..907d29f864a7 --- /dev/null +++ b/core/appmodule/v2/genesis.go @@ -0,0 +1,37 @@ +package appmodulev2 + +import ( + "context" + "encoding/json" +) + +// HasGenesis defines a custom genesis handling API implementation. +// WARNING: this API is meant as a short-term solution to allow for the +// migration of existing modules to the new app module API. +// It is intended to be replaced by an automatic genesis with collections/orm. +type HasGenesis interface { + AppModule + + DefaultGenesis() json.RawMessage + ValidateGenesis(data json.RawMessage) error + InitGenesis(ctx context.Context, data json.RawMessage) error + ExportGenesis(ctx context.Context) (json.RawMessage, error) +} + +// HasABCIGenesis defines a custom genesis handling API implementation for ABCI. +// (stateful genesis methods which returns validator updates) +// Most modules should not implement this interface. +type HasABCIGenesis interface { + AppModule + + DefaultGenesis() json.RawMessage + ValidateGenesis(data json.RawMessage) error + InitGenesis(ctx context.Context, data json.RawMessage) ([]ValidatorUpdate, error) + ExportGenesis(ctx context.Context) (json.RawMessage, error) +} + +// GenesisDecoder is an alternative to the InitGenesis method. +// It is implemented by the genutil module to decode genTxs. +type GenesisDecoder interface { + DecodeGenesisJSON(data json.RawMessage) ([]json.RawMessage, error) +} diff --git a/core/appmodule/v2/handlers.go b/core/appmodule/v2/handlers.go new file mode 100644 index 000000000000..c446a46cebd2 --- /dev/null +++ b/core/appmodule/v2/handlers.go @@ -0,0 +1,62 @@ +package appmodulev2 + +import ( + "context" + + transaction "cosmossdk.io/core/transaction" +) + +type ( + // PreMsgHandler is a handler that is executed before Handler. If it errors the execution reverts. + PreMsgHandler = func(ctx context.Context, msg transaction.Msg) error + // Handler handles the state transition of the provided message. + Handler = func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, 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, msgResp transaction.Msg) error +) + +// msg handler + +type PreMsgRouter interface { + // RegisterPreHandler will register a specific message handler hooking into the message with + // the provided name. + RegisterPreHandler(msgName string, handler PreMsgHandler) + // RegisterGlobalPreHandler will register a global message handler hooking into any message + // being executed. + RegisterGlobalPreHandler(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 { + // RegisterPostHandler will register a specific message handler hooking after the execution of message with + // the provided name. + RegisterPostHandler(msgName string, handler PostMsgHandler) + // RegisterGlobalPostHandler will register a global message handler hooking after the execution of any message. + RegisterGlobalPostHandler(handler PostMsgHandler) +} + +type HasPostMsgHandlers interface { + RegisterPostMsgHandlers(router PostMsgRouter) +} + +// query handler + +type QueryRouter interface { + Register(queryName string, handler Handler) +} + +type HasQueryHandlers interface { + RegisterQueryHandlers(router QueryRouter) +} diff --git a/core/appmodule/v2/migrations.go b/core/appmodule/v2/migrations.go new file mode 100644 index 000000000000..a363e1a4a383 --- /dev/null +++ b/core/appmodule/v2/migrations.go @@ -0,0 +1,41 @@ +package appmodulev2 + +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 +} + +// MigrationRegistrar is the interface for registering in-place store migrations. +type MigrationRegistrar interface { + // Register registers an in-place store migration for a module. The + // handler is a migration script to perform in-place migrations from version + // `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 000000000000..e01818cdaf45 --- /dev/null +++ b/core/appmodule/v2/module.go @@ -0,0 +1,106 @@ +package appmodulev2 + +import ( + "context" + + "cosmossdk.io/core/registry" + "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() +} + +// HasPreBlocker is the extension interface that modules should implement to run +// custom logic before BeginBlock. +type HasPreBlocker interface { + AppModule + // PreBlock is method that will be run before BeginBlock. + PreBlock(context.Context) error +} + +// HasBeginBlocker is the extension interface that modules should implement to run +// custom logic before transaction processing in a block. +type HasBeginBlocker interface { + 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 +} + +// HasTxValidator is the extension interface that modules should implement to run +// custom logic for validating transactions. +// It was previously known as AnteHandler/Decorator. +type HasTxValidator[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 validator +} + +// HasRegisterInterfaces is the interface for modules to register their msg types. +type HasRegisterInterfaces interface { + RegisterInterfaces(registry.InterfaceRegistrar) +} diff --git a/core/appmodule/v2/tx_validator.go b/core/appmodule/v2/tx_validator.go new file mode 100644 index 000000000000..0886fe03ef81 --- /dev/null +++ b/core/appmodule/v2/tx_validator.go @@ -0,0 +1,13 @@ +package appmodulev2 + +import ( + "context" + + "cosmossdk.io/core/transaction" +) + +// TxValidator represent the method that a TxValidator should implement. +// It was previously known as AnteHandler/Decorator.AnteHandle +type TxValidator[T transaction.Tx] interface { + ValidateTx(ctx context.Context, tx T) error +} diff --git a/core/context/context.go b/core/context/context.go new file mode 100644 index 000000000000..2d97bacbd654 --- /dev/null +++ b/core/context/context.go @@ -0,0 +1,22 @@ +package context + +type ( + execModeKey struct{} + cometInfoKey struct{} + initInfoKey struct{} + environmentKey struct{} +) + +var ( + // ExecModeKey is the context key for setting the execution mode. + ExecModeKey = execModeKey{} + // CometInfoKey is the context key for allowing modules to get CometInfo. + CometInfoKey = cometInfoKey{} + // CometParamsInitInfoKey is the context key for setting consensus params from genesis in the consensus module. + CometParamsInitInfoKey = initInfoKey{} + + // EnvironmentContextKey is the context key for the environment. + // A caller should not assume the environment is available in each context. + // ref: https://github.com/cosmos/cosmos-sdk/issues/19640 + EnvironmentContextKey = environmentKey{} +) diff --git a/core/context/server_context.go b/core/context/server_context.go new file mode 100644 index 000000000000..82b725f86083 --- /dev/null +++ b/core/context/server_context.go @@ -0,0 +1,13 @@ +package context + +type ( + loggerContextKey struct{} + viperContextKey struct{} +) + +var ( + // LoggerContextKey is the context key where the logger can be found. + LoggerContextKey loggerContextKey + // ViperContextKey is the context key where the viper instance can be found. + ViperContextKey viperContextKey +) diff --git a/core/gas/service.go b/core/gas/service.go new file mode 100644 index 000000000000..ca095a9aa33a --- /dev/null +++ b/core/gas/service.go @@ -0,0 +1,54 @@ +// Package gas provides a basic API for app modules to track gas usage. +package gas + +import ( + "context" + "errors" + "math" +) + +// ErrOutOfGas must be used by GasMeter implementers to signal +// that the state transition consumed all the allowed computational +// gas. +var ErrOutOfGas = errors.New("out of gas") + +// Gas defines type alias of uint64 for gas consumption. Gas is used +// to measure computational overhead when executing state transitions, +// it might be related to storage access and not only. +type Gas = uint64 + +// NoGasLimit signals that no gas limit must be applied. +const NoGasLimit Gas = math.MaxUint64 + +// Service represents a gas service which can retrieve and set a gas meter in a context. +// gas.Service is a core API type that should be provided by the runtime module being used to +// build an app via depinject. +type Service interface { + // GasMeter returns the current transaction-level gas meter. A non-nil meter + // is always returned. When one is unavailable in the context an infinite gas meter + // will be returned. + GasMeter(context.Context) Meter + + // GasConfig returns the gas costs. + GasConfig(ctx context.Context) GasConfig +} + +// Meter represents a gas meter for modules consumption +type Meter interface { + Consume(amount Gas, descriptor string) error + Refund(amount Gas, descriptor string) error + Remaining() Gas + Consumed() Gas + Limit() Gas +} + +// GasConfig defines the gas costs for the application. +type GasConfig struct { + HasCost Gas + DeleteCost Gas + ReadCostFlat Gas + ReadCostPerByte Gas + WriteCostFlat Gas + WriteCostPerByte Gas + IterNextCostFlat Gas +} diff --git a/core/genesis/doc.go b/core/genesis/doc.go new file mode 100644 index 000000000000..1891fdc18364 --- /dev/null +++ b/core/genesis/doc.go @@ -0,0 +1,3 @@ +// package genesis is used to define appmodule.HasGenesisAuto experimental auto genesis. +// This genesis package isn't supported in server/v2. +package genesis diff --git a/core/legacy/amino.go b/core/legacy/amino.go new file mode 100644 index 000000000000..eefcfd0c5576 --- /dev/null +++ b/core/legacy/amino.go @@ -0,0 +1,16 @@ +package legacy + +// Amino is an interface that allow to register concrete types and interfaces with the Amino codec. +type Amino interface { + // RegisterInterface registers an interface and its concrete type with the Amino codec. + RegisterInterface(interfacePtr any, iopts *InterfaceOptions) + + // RegisterConcrete registers a concrete type with the Amino codec. + RegisterConcrete(cdcType interface{}, name string) +} + +// InterfaceOptions defines options for registering an interface with the Amino codec. +type InterfaceOptions struct { + Priority []string // Disamb priority. + AlwaysDisambiguate bool // If true, include disamb for all types. +} diff --git a/core/registry/legacy.go b/core/registry/legacy.go new file mode 100644 index 000000000000..c1141751e18a --- /dev/null +++ b/core/registry/legacy.go @@ -0,0 +1,27 @@ +package registry + +import ( + "cosmossdk.io/core/transaction" +) + +// InterfaceRegistrar is an interface for registering interfaces and their implementation. +// It is a subset of the Cosmos SDK InterfaceRegistry for registration only. +type InterfaceRegistrar interface { + // RegisterInterface associates protoName as the public name for the + // interface passed in as iface. This is to be used primarily to create + // a public facing registry of interface implementations for clients. + // protoName should be a well-chosen public facing name that remains stable. + // RegisterInterface takes an optional list of impls to be registered + // as implementations of iface. + // + // Ex: + // registry.RegisterInterface("cosmos.base.v1beta1.Msg", (*sdk.Msg)(nil)) + RegisterInterface(protoName string, iface interface{}, impls ...transaction.Msg) + + // RegisterImplementations registers impls as concrete implementations of + // the interface iface. + // + // Ex: + // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{}) + RegisterImplementations(iface interface{}, impls ...transaction.Msg) +} diff --git a/core/transaction/service.go b/core/transaction/service.go new file mode 100644 index 000000000000..57ec9c7be6ba --- /dev/null +++ b/core/transaction/service.go @@ -0,0 +1,25 @@ +package transaction + +import "context" + +// ExecMode defines the execution mode +type ExecMode uint8 + +// All possible execution modes. +// For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package. +const ( + ExecModeCheck ExecMode = iota + ExecModeReCheck + ExecModeSimulate + _ + _ + _ + _ + ExecModeFinalize +) + +// Service creates a transaction service. +type Service interface { + // ExecMode returns the current execution mode. + ExecMode(ctx context.Context) ExecMode +} diff --git a/core/transaction/transaction.go b/core/transaction/transaction.go new file mode 100644 index 000000000000..5211c54c66e2 --- /dev/null +++ b/core/transaction/transaction.go @@ -0,0 +1,37 @@ +package transaction + +type ( + // Msg uses structural types to define the interface for a message. + Msg = interface { + Reset() + String() string + ProtoMessage() + } + Identity = []byte +) + +// Codec defines the TX codec, which converts a TX from bytes to its concrete representation. +type Codec[T Tx] interface { + // Decode decodes the tx bytes into a DecodedTx, containing + // both concrete and bytes representation of the tx. + Decode([]byte) (T, error) + // DecodeJSON decodes the tx JSON bytes into a DecodedTx + DecodeJSON([]byte) (T, error) +} + +// Tx defines the interface for a transaction. +// All custom transactions must implement this interface. +type Tx interface { + // Hash returns the unique identifier for the Tx. + Hash() [32]byte + // GetMessages returns the list of state transitions of the Tx. + GetMessages() ([]Msg, error) + // GetSenders returns the tx state transition sender. + GetSenders() ([]Identity, error) // TODO reduce this to a single identity if accepted + // GetGasLimit returns the gas limit of the tx. Must return math.MaxUint64 for infinite gas + // txs. + GetGasLimit() (uint64, error) + // Bytes returns the encoded version of this tx. Note: this is ideally cached + // from the first instance of the decoding of the tx. + Bytes() []byte +} diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 5a625a1efee5..549e39543ffd 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -245,7 +245,7 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe } if req.ConsensusParams != nil { - ctx = context.WithValue(ctx, corecontext.InitInfoKey, &consensustypes.MsgUpdateParams{ + ctx = context.WithValue(ctx, corecontext.CometParamsInitInfoKey, &consensustypes.MsgUpdateParams{ Authority: c.consensusAuthority, Block: req.ConsensusParams.Block, Evidence: req.ConsensusParams.Evidence, diff --git a/server/v2/stf/stf_router_test.go b/server/v2/stf/stf_router_test.go new file mode 100644 index 000000000000..0a63ae4b79d4 --- /dev/null +++ b/server/v2/stf/stf_router_test.go @@ -0,0 +1,60 @@ +package stf + +import ( + "context" + "reflect" + "testing" + + gogoproto "github.com/cosmos/gogoproto/proto" + gogotypes "github.com/cosmos/gogoproto/types" + + appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/transaction" +) + +func TestRouter(t *testing.T) { + expectedMsg := &gogotypes.BoolValue{Value: true} + expectedMsgName := gogoproto.MessageName(expectedMsg) + + expectedResp := &gogotypes.StringValue{Value: "test"} + + router := coreRouterImpl{handlers: map[string]appmodulev2.Handler{ + gogoproto.MessageName(expectedMsg): func(ctx context.Context, gotMsg transaction.Msg) (msgResp transaction.Msg, err error) { + if !reflect.DeepEqual(expectedMsg, gotMsg) { + t.Errorf("expected message: %v, got: %v", expectedMsg, gotMsg) + } + return expectedResp, nil + }, + }} + + t.Run("can invoke message by name", func(t *testing.T) { + err := router.CanInvoke(context.Background(), expectedMsgName) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + }) + + t.Run("can invoke message by type URL", func(t *testing.T) { + err := router.CanInvoke(context.Background(), "/"+expectedMsgName) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + }) + + t.Run("cannot invoke unknown message", func(t *testing.T) { + err := router.CanInvoke(context.Background(), "not exist") + if err == nil { + t.Error("expected error, got nil") + } + }) + + t.Run("invoke", func(t *testing.T) { + gotResp, err := router.Invoke(context.Background(), expectedMsg) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if !reflect.DeepEqual(expectedResp, gotResp) { + t.Errorf("expected response: %v, got: %v", expectedResp, gotResp) + } + }) +} diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index b0b94179ae99..016660bb0f18 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -10,7 +10,7 @@ import ( reflect "reflect" appmodule "cosmossdk.io/core/appmodule" - appmodule0 "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" types "github.com/cosmos/cosmos-sdk/types" module "github.com/cosmos/cosmos-sdk/types/module" gomock "github.com/golang/mock/gomock" @@ -269,10 +269,10 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) ExportGenesis(ctx inte } // InitGenesis mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(ctx context.Context, data json.RawMessage) ([]appmodule0.ValidatorUpdate, error) { +func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(ctx context.Context, data json.RawMessage) ([]appmodulev2.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", ctx, data) - ret0, _ := ret[0].([]appmodule0.ValidatorUpdate) + ret0, _ := ret[0].([]appmodulev2.ValidatorUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/x/accounts/defaults/base/utils_test.go b/x/accounts/defaults/base/utils_test.go index 1be354d04358..93cd76ea8495 100644 --- a/x/accounts/defaults/base/utils_test.go +++ b/x/accounts/defaults/base/utils_test.go @@ -8,7 +8,7 @@ import ( signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/collections" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/event" "cosmossdk.io/core/header" "cosmossdk.io/core/store" @@ -73,7 +73,7 @@ func makeMockDependencies(storeservice store.KVStoreService) accountstd.Dependen SchemaBuilder: sb, AddressCodec: addressCodec{}, LegacyStateCodec: mockStateCodec{}, - Environment: appmodule.Environment{ + Environment: appmodulev2.Environment{ EventService: eventService{}, HeaderService: headerService{}, }, diff --git a/x/accounts/defaults/lockup/utils_test.go b/x/accounts/defaults/lockup/utils_test.go index 79104e356fc1..6d5ce14af7ed 100644 --- a/x/accounts/defaults/lockup/utils_test.go +++ b/x/accounts/defaults/lockup/utils_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/collections" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/header" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" @@ -114,7 +114,7 @@ func makeMockDependencies(storeservice store.KVStoreService) accountstd.Dependen SchemaBuilder: sb, AddressCodec: addressCodec{}, LegacyStateCodec: mockStateCodec{}, - Environment: appmodule.Environment{ + Environment: appmodulev2.Environment{ HeaderService: headerService{}, }, } diff --git a/x/accounts/defaults/multisig/utils_test.go b/x/accounts/defaults/multisig/utils_test.go index 86f6c62551d6..586be634a3ab 100644 --- a/x/accounts/defaults/multisig/utils_test.go +++ b/x/accounts/defaults/multisig/utils_test.go @@ -11,7 +11,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/collections" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/event" "cosmossdk.io/core/header" "cosmossdk.io/core/store" @@ -185,7 +185,7 @@ func makeMockDependencies(storeservice store.KVStoreService, timefn func() time. SchemaBuilder: sb, AddressCodec: addressCodec{}, LegacyStateCodec: mockStateCodec{}, - Environment: appmodule.Environment{ + Environment: appmodulev2.Environment{ HeaderService: headerService{timefn}, EventService: eventService{}, }, diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 6e568ab5c04d..3f288460e8f7 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -4,7 +4,7 @@ import ( "context" "time" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -24,10 +24,10 @@ import ( // ValidateBasicDecorator decorator will not get executed on ReCheckTx since it // is not dependent on application state. type ValidateBasicDecorator struct { - env appmodule.Environment + env appmodulev2.Environment } -func NewValidateBasicDecorator(env appmodule.Environment) ValidateBasicDecorator { +func NewValidateBasicDecorator(env appmodulev2.Environment) ValidateBasicDecorator { return ValidateBasicDecorator{ env: env, } @@ -219,7 +219,7 @@ type ( // TxTimeoutHeightDecorator defines an AnteHandler decorator that checks for a // tx height timeout. TxTimeoutHeightDecorator struct { - env appmodule.Environment + env appmodulev2.Environment } // TxWithTimeoutHeight defines the interface a tx must implement in order for @@ -234,7 +234,7 @@ type ( // TxTimeoutHeightDecorator defines an AnteHandler decorator that checks for a // tx height timeout. -func NewTxTimeoutHeightDecorator(env appmodule.Environment) TxTimeoutHeightDecorator { +func NewTxTimeoutHeightDecorator(env appmodulev2.Environment) TxTimeoutHeightDecorator { return TxTimeoutHeightDecorator{ env: env, } diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 18af011dd521..389096d3d7c6 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" @@ -189,7 +189,7 @@ func TestTxHeightTimeoutDecorator(t *testing.T) { suite := SetupTestSuite(t, true) mockHeaderService := &mockHeaderService{} - antehandler := sdk.ChainAnteDecorators(ante.NewTxTimeoutHeightDecorator(appmodule.Environment{HeaderService: mockHeaderService})) + antehandler := sdk.ChainAnteDecorators(ante.NewTxTimeoutHeightDecorator(appmodulev2.Environment{HeaderService: mockHeaderService})) // keys and addresses priv1, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/auth/ante/unordered.go b/x/auth/ante/unordered.go index 39ea3ab5a1df..f494c78c49e0 100644 --- a/x/auth/ante/unordered.go +++ b/x/auth/ante/unordered.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/gogoproto/proto" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" @@ -47,14 +47,14 @@ type UnorderedTxDecorator struct { // maxUnOrderedTTL defines the maximum TTL a transaction can define. maxTimeoutDuration time.Duration txManager *unorderedtx.Manager - env appmodule.Environment + env appmodulev2.Environment sha256Cost uint64 } func NewUnorderedTxDecorator( maxDuration time.Duration, m *unorderedtx.Manager, - env appmodule.Environment, + env appmodulev2.Environment, gasCost uint64, ) *UnorderedTxDecorator { return &UnorderedTxDecorator{ diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 9b7d8f0268ca..7bd438c6767d 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -15,7 +15,7 @@ import ( bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/address" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -53,25 +53,25 @@ type ModuleInputs struct { ValidatorAddressCodec address.ValidatorAddressCodec Codec codec.Codec ProtoFileResolver txsigning.ProtoFileResolver - Environment appmodule.Environment + Environment appmodulev2.Environment // BankKeeper is the expected bank keeper to be passed to AnteHandlers / Tx Validators - BankKeeper authtypes.BankKeeper `optional:"true"` - MetadataBankKeeper BankKeeper `optional:"true"` - AccountKeeper ante.AccountKeeper `optional:"true"` - FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` - AccountAbstractionKeeper ante.AccountAbstractionKeeper `optional:"true"` - CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"` - CustomGetSigners []txsigning.CustomGetSigner `optional:"true"` - ExtraTxValidators []appmodule.TxValidator[transaction.Tx] `optional:"true"` - UnorderedTxManager *unorderedtx.Manager `optional:"true"` - TxFeeChecker ante.TxFeeChecker `optional:"true"` - Viper *viper.Viper `optional:"true"` // server v2 + BankKeeper authtypes.BankKeeper `optional:"true"` + MetadataBankKeeper BankKeeper `optional:"true"` + AccountKeeper ante.AccountKeeper `optional:"true"` + FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` + AccountAbstractionKeeper ante.AccountAbstractionKeeper `optional:"true"` + CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"` + CustomGetSigners []txsigning.CustomGetSigner `optional:"true"` + ExtraTxValidators []appmodulev2.TxValidator[transaction.Tx] `optional:"true"` + UnorderedTxManager *unorderedtx.Manager `optional:"true"` + TxFeeChecker ante.TxFeeChecker `optional:"true"` + Viper *viper.Viper `optional:"true"` // server v2 } type ModuleOutputs struct { depinject.Out - Module appmodule.AppModule // This is only useful for chains using server/v2. It setup tx validators that don't belong to other modules. + Module appmodulev2.AppModule // This is only useful for chains using server/v2. It setup tx validators that don't belong to other modules. BaseAppOption runtime.BaseAppOption // This is only useful for chains using baseapp. Server/v2 chains use TxValidator. TxConfig client.TxConfig TxConfigOptions tx.ConfigOptions diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 9aefd18dddf6..405cdcae390d 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -4,7 +4,7 @@ import ( "context" "cosmossdk.io/core/address" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +42,7 @@ func (a SendAuthorization) Accept(ctx context.Context, msg sdk.Msg) (authz.Accep return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit") } - authzEnv, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodule.Environment) + authzEnv, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodulev2.Environment) if !ok { return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrap("environment not set") } diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index 7c9473c50138..bb12f5d2a5f7 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" coregas "cosmossdk.io/core/gas" coreheader "cosmossdk.io/core/header" @@ -54,7 +54,7 @@ func (m mockGasMeter) Consume(amount coregas.Gas, descriptor string) error { func TestSendAuthorization(t *testing.T) { ac := codectestutil.CodecOptions{}.GetAddressCodec() sdkCtx := testutil.DefaultContextWithDB(t, storetypes.NewKVStoreKey(types.StoreKey), storetypes.NewTransientStoreKey("transient_test")).Ctx.WithHeaderInfo(coreheader.Info{}) - ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodule.Environment{ + ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodulev2.Environment{ HeaderService: headerService{}, GasService: mockGasService{}, }) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 77de268293d7..76f74ffbaebf 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -47,7 +47,7 @@ func (k *Keeper) GetAuthority() string { // InitGenesis initializes the initial state of the module func (k *Keeper) InitGenesis(ctx context.Context) error { - value, ok := ctx.Value(corecontext.InitInfoKey).(*types.MsgUpdateParams) + value, ok := ctx.Value(corecontext.CometParamsInitInfoKey).(*types.MsgUpdateParams) if !ok || value == nil { // no error for appv1 and appv2 return nil diff --git a/x/feegrant/basic_fee_test.go b/x/feegrant/basic_fee_test.go index 5f086ebc43a9..cde6d2877e51 100644 --- a/x/feegrant/basic_fee_test.go +++ b/x/feegrant/basic_fee_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" @@ -140,7 +140,7 @@ func TestBasicFeeValidAllow(t *testing.T) { ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: tc.blockTime}) // now try to deduct - removed, err := tc.allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{ + removed, err := tc.allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{ HeaderService: mockHeaderService{}, GasService: mockGasService{}, }), tc.fee, []sdk.Msg{}) diff --git a/x/feegrant/filtered_fee_test.go b/x/feegrant/filtered_fee_test.go index 9ca967bc0d4c..8d9b5c60e935 100644 --- a/x/feegrant/filtered_fee_test.go +++ b/x/feegrant/filtered_fee_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" @@ -158,7 +158,7 @@ func TestFilteredFeeValidAllow(t *testing.T) { require.NoError(t, err) // now try to deduct - removed, err := allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{ + removed, err := allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{ HeaderService: mockHeaderService{}, GasService: mockGasService{}, }), tc.fee, []sdk.Msg{&call}) diff --git a/x/feegrant/periodic_fee_test.go b/x/feegrant/periodic_fee_test.go index 6a675beb3990..5c5e46b7fbc9 100644 --- a/x/feegrant/periodic_fee_test.go +++ b/x/feegrant/periodic_fee_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" @@ -223,7 +223,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) { ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: tc.blockTime}) // now try to deduct // Set environment to ctx - remove, err := tc.allow.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{ + remove, err := tc.allow.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{ HeaderService: mockHeaderService{}, GasService: mockGasService{}, }), tc.fee, []sdk.Msg{}) diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index 62b939e79478..1a8a66420dc0 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "cosmossdk.io/core/appmodule/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" coregas "cosmossdk.io/core/gas" coreheader "cosmossdk.io/core/header" @@ -69,7 +69,7 @@ func TestAuthzAuthorizations(t *testing.T) { key := storetypes.NewKVStoreKey(stakingtypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) sdkCtx := testCtx.Ctx.WithHeaderInfo(coreheader.Info{}) - ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodule.Environment{ + ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodulev2.Environment{ HeaderService: headerService{}, GasService: mockGasService{}, })