From e3a3df2a824bc46c422a6511dffc5a9a825bc3e5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 16 Aug 2023 16:11:49 +0200 Subject: [PATCH] refactor: move `UpgradeModule` interface to appmodule and fix mocks (#17383) Co-authored-by: Marko --- client/docs/swagger-ui/swagger.yaml | 92 ++++------ core/CHANGELOG.md | 4 + core/appmodule/module.go | 7 + .../building-modules/01-module-manager.md | 89 +++++++--- go.mod | 2 +- go.sum | 4 +- simapp/go.mod | 2 +- simapp/go.sum | 4 +- simapp/gomod2nix.toml | 4 +- tests/go.mod | 2 +- tests/go.sum | 4 +- tests/starship/tests/go.mod | 2 +- testutil/mock/types_mock_appmodule.go | 168 ++++++++++++++++-- types/module/mock_appmodule_test.go | 6 + types/module/module.go | 17 +- types/module/module_test.go | 2 +- x/evidence/go.mod | 2 +- x/evidence/go.sum | 4 +- x/evidence/testutil/expected_keepers_mocks.go | 2 +- 19 files changed, 287 insertions(+), 130 deletions(-) diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 385961a80a..e096d92be6 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -17657,13 +17657,13 @@ paths: delegator_address: type: string description: >- - delegator_address is the bech32-encoded address of - the delegator. + delegator_address is the encoded address of the + delegator. validator_address: type: string description: >- - validator_address is the bech32-encoded address of - the validator. + validator_address is the encoded address of the + validator. shares: type: string description: shares define the delegation shares received. @@ -18450,12 +18450,12 @@ paths: delegator_address: type: string description: >- - delegator_address is the bech32-encoded address of the + delegator_address is the encoded address of the delegator. validator_address: type: string description: >- - validator_address is the bech32-encoded address of the + validator_address is the encoded address of the validator. entries: type: array @@ -22260,13 +22260,13 @@ paths: delegator_address: type: string description: >- - delegator_address is the bech32-encoded address of - the delegator. + delegator_address is the encoded address of the + delegator. validator_address: type: string description: >- - validator_address is the bech32-encoded address of - the validator. + validator_address is the encoded address of the + validator. shares: type: string description: shares define the delegation shares received. @@ -22598,12 +22598,12 @@ paths: delegator_address: type: string description: >- - delegator_address is the bech32-encoded address of the + delegator_address is the encoded address of the delegator. validator_address: type: string description: >- - validator_address is the bech32-encoded address of the + validator_address is the encoded address of the validator. shares: type: string @@ -22864,14 +22864,10 @@ paths: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. entries: type: array items: @@ -23153,12 +23149,12 @@ paths: delegator_address: type: string description: >- - delegator_address is the bech32-encoded address of the + delegator_address is the encoded address of the delegator. validator_address: type: string description: >- - validator_address is the bech32-encoded address of the + validator_address is the encoded address of the validator. entries: type: array @@ -51501,10 +51497,10 @@ definitions: properties: delegator_address: type: string - description: delegator_address is the bech32-encoded address of the delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: validator_address is the bech32-encoded address of the validator. + description: validator_address is the encoded address of the validator. shares: type: string description: shares define the delegation shares received. @@ -51520,10 +51516,10 @@ definitions: properties: delegator_address: type: string - description: delegator_address is the bech32-encoded address of the delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: validator_address is the bech32-encoded address of the validator. + description: validator_address is the encoded address of the validator. shares: type: string description: shares define the delegation shares received. @@ -52022,14 +52018,10 @@ definitions: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. shares: type: string description: shares define the delegation shares received. @@ -52078,14 +52070,10 @@ definitions: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. shares: type: string description: shares define the delegation shares received. @@ -52151,14 +52139,10 @@ definitions: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. entries: type: array items: @@ -53500,10 +53484,10 @@ definitions: properties: delegator_address: type: string - description: delegator_address is the bech32-encoded address of the delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: validator_address is the bech32-encoded address of the validator. + description: validator_address is the encoded address of the validator. entries: type: array items: @@ -53560,14 +53544,10 @@ definitions: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. shares: type: string description: shares define the delegation shares received. @@ -53943,14 +53923,10 @@ definitions: properties: delegator_address: type: string - description: >- - delegator_address is the bech32-encoded address of the - delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: >- - validator_address is the bech32-encoded address of the - validator. + description: validator_address is the encoded address of the validator. entries: type: array items: @@ -54627,10 +54603,10 @@ definitions: properties: delegator_address: type: string - description: delegator_address is the bech32-encoded address of the delegator. + description: delegator_address is the encoded address of the delegator. validator_address: type: string - description: validator_address is the bech32-encoded address of the validator. + description: validator_address is the encoded address of the validator. entries: type: array items: diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 1a73a15d29..2673b35d49 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v0.10.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.10.0) + +* [#17383](https://github.com/cosmos/cosmos-sdk/pull/17383) Add `appmoduke.UpgradeModule` interface. + ## [v0.9.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.9.0) * [#16739](https://github.com/cosmos/cosmos-sdk/pull/16739) Add `AppHash` to header.Info. diff --git a/core/appmodule/module.go b/core/appmodule/module.go index c6a923340e..6f4c9b4e2a 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -71,3 +71,10 @@ type HasEndBlocker interface { // a block. EndBlock(context.Context) error } + +// UpgradeModule is the extension interface that upgrade module should implement to differentiate +// it from other modules, migration handler need ensure the upgrade module's migration is executed +// before the rest of the modules. +type UpgradeModule interface { + IsUpgradeModule() +} diff --git a/docs/docs/building-modules/01-module-manager.md b/docs/docs/building-modules/01-module-manager.md index bfe977b0b6..f292e016d8 100644 --- a/docs/docs/building-modules/01-module-manager.md +++ b/docs/docs/building-modules/01-module-manager.md @@ -17,26 +17,35 @@ Cosmos SDK modules need to implement the [`AppModule` interfaces](#application-m ## Application Module Interfaces Application module interfaces exist to facilitate the composition of modules together to form a functional Cosmos SDK application. + +:::note + +It is recommended to implement interfaces from the [Core API](https://docs.cosmos.network/main/architecture/adr-063-core-module-api) `appmodule` package. This makes modules less dependent on the SDK. +For legacy reason modules can still implement interfaces from the SDK `module` package. + +::: + There are 4 main application module interfaces: -* [`AppModuleBasic`](#appmodulebasic) for independent module functionalities. -* [`AppModule`](#appmodule) for inter-dependent module functionalities (except genesis-related functionalities). -* [`AppModuleGenesis`](#appmodulegenesis) for inter-dependent genesis-related module functionalities. -* `GenesisOnlyAppModule`: Defines an `AppModule` that only has import/export functionality +* [`appmodule.AppModule` / `module.AppModule`](#appmodule) for inter-dependent module functionalities (except genesis-related functionalities). +* (legacy) [`module.AppModuleBasic`](#appmodulebasic) for independent module functionalities. New modules can use `module.CoreAppModuleBasicAdaptor` instead. +* (legacy) [`module.AppModuleGenesis`](#appmodulegenesis) for inter-dependent genesis-related module functionalities. +* (legacy) `module.GenesisOnlyAppModule`: Defines an `AppModule` that only has import/export functionality The above interfaces are mostly embedding smaller interfaces (extension interfaces), that defines specific functionalities: -* `HasName`: Allows the module to provide its own name for legacy purposes. -* [`HasGenesisBasics`](#hasgenesisbasics): The legacy interface for stateless genesis methods. -* [`HasGenesis`](#hasgenesis): The extension interface for stateful genesis methods. -* [`HasInvariants`](#hasinvariants): The extension interface for registering invariants. -* [`HasServices`](#hasservices): The extension interface for modules to register services. -* [`HasConsensusVersion`](#hasconsensusversion): The extension interface for declaring a module consensus version. -* [`HasBeginBlocker`](#hasbeginblocker): The extension interface that contains information about the `AppModule` and `BeginBlock`. -* [`HasEndBlocker`](#hasendblocker): The extension interface that contains information about the `AppModule` and `EndBlock`. -* [`HasABCIEndblock`](#hasabciendblock): The extension interface that contains information about the `AppModule`, `EndBlock` and returns an updated validator set. -* [`HasPrecommit`](#hasprecommit): The extension interface that contains information about the `AppModule` and `Precommit`. -* [`HasPrepareCheckState`](#haspreparecheckstate): The extension interface that contains information about the `AppModule` and `PrepareCheckState`. +* (legacy) `module.HasName`: Allows the module to provide its own name for legacy purposes. +* (legacy) [`module.HasGenesisBasics`](#hasgenesisbasics): The legacy interface for stateless genesis methods. +* [`appmodule.HasGenesis` / `module.HasGenesis`](#hasgenesis): The extension interface for stateful genesis methods. +* [`appmodule.HasBeginBlocker`](#hasbeginblocker): The extension interface that contains information about the `AppModule` and `BeginBlock`. +* [`appmodule.HasEndBlocker`](#hasendblocker): The extension interface that contains information about the `AppModule` and `EndBlock`. +* [`appmodule.HasPrecommit`](#hasprecommit): The extension interface that contains information about the `AppModule` and `Precommit`. +* [`appmodule.HasPrepareCheckState`](#haspreparecheckstate): The extension interface that contains information about the `AppModule` and `PrepareCheckState`. +* [`appmodule.UpgradeModule`]: The extension interface that signify if the `AppModule` if the module is an upgrade module. +* [`appmodule.HasService` / `module.HasServices`](#hasservices): The extension interface for modules to register services. +* [`module.HasABCIEndblock`](#hasabciendblock): The extension interface that contains information about the `AppModule`, `EndBlock` and returns an updated validator set. +* (legacy) [`module.HasInvariants`](#hasinvariants): The extension interface for registering invariants. +* (legacy) [`module.HasConsensusVersion`](#hasconsensusversion): The extension interface for declaring a module consensus version. The `AppModuleBasic` interface exists to define independent methods of the module, i.e. those that do not depend on other modules in the application. This allows for the construction of the basic application structure early in the application definition, generally in the `init()` function of the [main application file](../basics/00-app-anatomy.md#core-application-file). @@ -46,6 +55,10 @@ The usage of extension interfaces allows modules to define only the functionalit ### `AppModuleBasic` +:::note +Use `module.CoreAppModuleBasicAdaptor` instead for creating an `AppModuleBasic` from an `appmodule.AppModule`. +::: + The `AppModuleBasic` interface defines the independent methods modules need to implement. ```go reference @@ -70,6 +83,10 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go ### `HasGenesisBasics` +:::note +Use `appmodule.HasGenesis` instead. +::: + ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L76-L79 ``` @@ -81,6 +98,10 @@ Let us go through the methods: ### `AppModuleGenesis` +:::note +Use `appmodule.HasGenesis` instead. +::: + The `AppModuleGenesis` interface is a simple embedding of the `AppModuleBasic` and `HasGenesis` interfaces. ```go reference @@ -105,17 +126,24 @@ Let us go through the two added methods: ### `AppModule` The `AppModule` interface defines a module. Modules can declare their functionalities by implementing extensions interfaces. - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L197-L99 -``` - `AppModule`s are managed by the [module manager](#manager), which checks which extension interfaces are implemented by the module. +#### `appmodule.AppModule` + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/6afece6/core/appmodule/module.go#L11-L20 +``` + +#### `module.AppModule` + :::note -Previously the `AppModule` interface was containing all the methods that are defined in the extensions interfaces. This was leading to much boilerplate for modules that did not need all the functionalities. +Previously the `module.AppModule` interface was containing all the methods that are defined in the extensions interfaces. This was leading to much boilerplate for modules that did not need all the functionalities. ::: +```go reference +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L195-L199 +``` + ### `HasInvariants` This interface defines one method. It allows to checks if a module can register invariants. @@ -130,6 +158,14 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go This interface defines one method. It allows to checks if a module can register invariants. +#### `appmodule.HasService` + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/6afece6/core/appmodule/module.go#L22-L40 +``` + +#### `module.HasServices` + ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L208-L211 ``` @@ -148,7 +184,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go ### `HasBeginBlocker` -The `HasBeginBlocker` is an extension interface from `AppModule`. All modules that have an `BeginBlock` method implement this interface. +The `HasBeginBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `BeginBlock` method implement this interface. ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.go#L56-L63 @@ -158,7 +194,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. ### `HasEndBlocker` -The `HasEndBlocker` is an extension interface from `AppModule`. All modules that have an `EndBlock` method implement this interface. If a module need to return validator set updates (staking), they can use `HasABCIEndblock` +The `HasEndBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `EndBlock` method implement this interface. If a module need to return validator set updates (staking), they can use `HasABCIEndblock` ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.go#L66-L72 @@ -168,7 +204,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. ### `HasABCIEndblock` -The `HasABCIEndblock` is an extension interface from `AppModule`. All modules that have an `EndBlock` which return validator set updates implement this interface. +The `HasABCIEndblock` is an extension interface from `module.AppModule`. All modules that have an `EndBlock` which return validator set updates implement this interface. ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L222-L225 @@ -178,7 +214,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go ### `HasPrecommit` -`HasPrecommit` is an extension interface from `AppModule`. All modules that have a `Precommit` method implement this interface. +`HasPrecommit` is an extension interface from `appmodule.AppModule`. All modules that have a `Precommit` method implement this interface. ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.go#L49-L52 @@ -188,7 +224,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. ### `HasPrepareCheckState` -`HasPrepareCheckState` is an extension interface from `AppModule`. All modules that have a `PrepareCheckState` method implement this interface. +`HasPrepareCheckState` is an extension interface from `appmodule.AppModule`. All modules that have a `PrepareCheckState` method implement this interface. ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.go#L49-L52 @@ -233,6 +269,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go It implements the following methods: * `NewBasicManager(modules ...AppModuleBasic)`: Constructor function. It takes a list of the application's `AppModuleBasic` and builds a new `BasicManager`. This function is generally called in the `init()` function of [`app.go`](../basics/00-app-anatomy.md#core-application-file) to quickly initialize the independent elements of the application's modules (click [here](https://github.com/cosmos/gaia/blob/main/app/app.go#L59-L74) to see an example). +* `NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]AppModuleBasic)`: Contructor function. It creates a new `BasicManager` from a `Manager`. The `BasicManager` will contain all `AppModuleBasic` from the `AppModule` manager using `CoreAppModuleBasicAdaptor` whenever possible. Module's `AppModuleBasic` can be overridden by passing a custom AppModuleBasic map * `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec.LegacyAmino`s](../core/05-encoding.md#amino) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../basics/00-app-anatomy.md#constructor). * `RegisterInterfaces(registry codectypes.InterfaceRegistry)`: Registers interface types and implementations of each of the application's `AppModuleBasic`. * `DefaultGenesis(cdc codec.JSONCodec)`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis(cdc codec.JSONCodec)`](./08-genesis.md#defaultgenesis) function of each module. It only calls the modules that implements the `HasGenesisBasics` interfaces. diff --git a/go.mod b/go.mod index 39fff2c21a..7e514d9f15 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ module github.com/cosmos/cosmos-sdk require ( cosmossdk.io/api v0.7.0 cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 - cosmossdk.io/core v0.9.0 + cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 cosmossdk.io/log v1.2.0 diff --git a/go.sum b/go.sum index 9640f5aa18..293289bb99 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E= -cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic= -cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 h1:djIIHB7INVUMGDpaM02Js6iCA7CzlJo9KG4GYZCtsqI= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9/go.mod h1:MygXNld9DvMgYY4yE76DM/mdZpgfeyRjy6FPjEEehlY= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= diff --git a/simapp/go.mod b/simapp/go.mod index 296a64b623..db80670675 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( cosmossdk.io/api v0.7.0 cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 - cosmossdk.io/core v0.9.0 + cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/log v1.2.0 cosmossdk.io/math v1.0.1 diff --git a/simapp/go.sum b/simapp/go.sum index 3483623bb9..88ff620cce 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -191,8 +191,8 @@ cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E= -cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic= -cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 h1:djIIHB7INVUMGDpaM02Js6iCA7CzlJo9KG4GYZCtsqI= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9/go.mod h1:MygXNld9DvMgYY4yE76DM/mdZpgfeyRjy6FPjEEehlY= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= diff --git a/simapp/gomod2nix.toml b/simapp/gomod2nix.toml index 291acedd6f..a75560d2c2 100644 --- a/simapp/gomod2nix.toml +++ b/simapp/gomod2nix.toml @@ -23,8 +23,8 @@ schema = 3 version = "v0.3.1-0.20230808102719-f04fefdc7a68" hash = "sha256-YnT8xyA06uI9zg583bIkbmZKh/Db+xy3dbGyOS7eBtc=" [mod."cosmossdk.io/core"] - version = "v0.9.0" - hash = "sha256-NrBNg+nJjVLZnyjaSzKw0L6gp3ubam0ODbPl8uJwwW0=" + version = "v0.9.1-0.20230814191920-98b67a87e5c9" + hash = "sha256-FvRTQ+RGCVhq7PepJ9Pv8VFv0gHZbKLCzXlhC2ZmZQc=" [mod."cosmossdk.io/depinject"] version = "v1.0.0-alpha.4" hash = "sha256-xpLH0K6ivQznFrLw2hmhWIIyYgqjstV47OhTEj/c1oQ=" diff --git a/tests/go.mod b/tests/go.mod index edc4d6734a..ccec2bbde0 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( cosmossdk.io/api v0.7.0 cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 - cosmossdk.io/core v0.9.0 + cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 cosmossdk.io/log v1.2.0 diff --git a/tests/go.sum b/tests/go.sum index 05278396c2..3995f4f082 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -191,8 +191,8 @@ cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E= -cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic= -cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 h1:djIIHB7INVUMGDpaM02Js6iCA7CzlJo9KG4GYZCtsqI= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9/go.mod h1:MygXNld9DvMgYY4yE76DM/mdZpgfeyRjy6FPjEEehlY= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= diff --git a/tests/starship/tests/go.mod b/tests/starship/tests/go.mod index 5e652a397b..5adc9c2845 100644 --- a/tests/starship/tests/go.mod +++ b/tests/starship/tests/go.mod @@ -50,7 +50,7 @@ require ( cosmossdk.io/api v0.7.0 // indirect cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 // indirect cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 // indirect - cosmossdk.io/core v0.9.0 // indirect + cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/errors v1.0.0 // indirect cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982 // indirect diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index da310e69d4..2277c8354a 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -361,39 +361,173 @@ func (mr *MockCoreAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModule)(nil).ValidateGenesis), arg0) } -// MockUpgradeModule is a mock of UpgradeModule interface. -type MockUpgradeModule struct { - *MockCoreAppModule - recorder *MockUpgradeModuleMockRecorder +// MockCoreUpgradeAppModule is a mock of CoreUpgradeAppModule interface. +type MockCoreUpgradeAppModule struct { + ctrl *gomock.Controller + recorder *MockCoreUpgradeAppModuleMockRecorder } -// MockUpgradeModuleMockRecorder is the mock recorder for MockUpgradeModule. -type MockUpgradeModuleMockRecorder struct { - *MockCoreAppModuleMockRecorder +// MockCoreUpgradeAppModuleMockRecorder is the mock recorder for MockCoreUpgradeAppModule. +type MockCoreUpgradeAppModuleMockRecorder struct { + mock *MockCoreUpgradeAppModule } -// NewMockUpgradeModule creates a new mock instance. -func NewMockUpgradeModule(ctrl *gomock.Controller) *MockUpgradeModule { - mock := &MockUpgradeModule{ - MockCoreAppModule: NewMockCoreAppModule(ctrl), - } - mock.recorder = &MockUpgradeModuleMockRecorder{mock.MockCoreAppModule.recorder} +// NewMockCoreUpgradeAppModule creates a new mock instance. +func NewMockCoreUpgradeAppModule(ctrl *gomock.Controller) *MockCoreUpgradeAppModule { + mock := &MockCoreUpgradeAppModule{ctrl: ctrl} + mock.recorder = &MockCoreUpgradeAppModuleMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockUpgradeModule) EXPECT() *MockUpgradeModuleMockRecorder { +func (m *MockCoreUpgradeAppModule) EXPECT() *MockCoreUpgradeAppModuleMockRecorder { return m.recorder } +// BeginBlock mocks base method. +func (m *MockCoreUpgradeAppModule) BeginBlock(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BeginBlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockCoreUpgradeAppModuleMockRecorder) BeginBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).BeginBlock), arg0) +} + +// DefaultGenesis mocks base method. +func (m *MockCoreUpgradeAppModule) DefaultGenesis(arg0 appmodule.GenesisTarget) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockCoreUpgradeAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).DefaultGenesis), arg0) +} + +// EndBlock mocks base method. +func (m *MockCoreUpgradeAppModule) EndBlock(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockCoreUpgradeAppModuleMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).EndBlock), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockCoreUpgradeAppModule) ExportGenesis(arg0 context.Context, arg1 appmodule.GenesisTarget) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockCoreUpgradeAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).ExportGenesis), arg0, arg1) +} + +// InitGenesis mocks base method. +func (m *MockCoreUpgradeAppModule) InitGenesis(arg0 context.Context, arg1 appmodule.GenesisSource) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockCoreUpgradeAppModuleMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).InitGenesis), arg0, arg1) +} + +// IsAppModule mocks base method. +func (m *MockCoreUpgradeAppModule) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockCoreUpgradeAppModuleMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockCoreUpgradeAppModule) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockCoreUpgradeAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsOnePerModuleType)) +} + // IsUpgradeModule mocks base method. -func (m *MockUpgradeModule) IsUpgradeModule() { +func (m *MockCoreUpgradeAppModule) IsUpgradeModule() { m.ctrl.T.Helper() m.ctrl.Call(m, "IsUpgradeModule") } // IsUpgradeModule indicates an expected call of IsUpgradeModule. -func (mr *MockUpgradeModuleMockRecorder) IsUpgradeModule() *gomock.Call { +func (mr *MockCoreUpgradeAppModuleMockRecorder) IsUpgradeModule() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUpgradeModule", reflect.TypeOf((*MockUpgradeModule)(nil).IsUpgradeModule)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUpgradeModule", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsUpgradeModule)) +} + +// Precommit mocks base method. +func (m *MockCoreUpgradeAppModule) Precommit(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Precommit", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Precommit indicates an expected call of Precommit. +func (mr *MockCoreUpgradeAppModuleMockRecorder) Precommit(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).Precommit), arg0) +} + +// PrepareCheckState mocks base method. +func (m *MockCoreUpgradeAppModule) PrepareCheckState(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareCheckState", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// PrepareCheckState indicates an expected call of PrepareCheckState. +func (mr *MockCoreUpgradeAppModuleMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).PrepareCheckState), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockCoreUpgradeAppModule) ValidateGenesis(arg0 appmodule.GenesisSource) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockCoreUpgradeAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).ValidateGenesis), arg0) } diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index 486ae24ed0..9c109badd6 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -15,6 +15,7 @@ type AppModuleWithAllExtensions interface { module.HasInvariants module.HasConsensusVersion module.HasABCIEndblock + module.HasName } // CoreAppModule is solely here for the purpose of generating @@ -27,3 +28,8 @@ type CoreAppModule interface { appmodule.HasPrecommit appmodule.HasPrepareCheckState } + +type CoreUpgradeAppModule interface { + CoreAppModule + appmodule.UpgradeModule +} diff --git a/types/module/module.go b/types/module/module.go index 2eacd3b804..b2fe431142 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -36,7 +36,7 @@ import ( "sort" abci "github.com/cometbft/cometbft/abci/types" - gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "golang.org/x/exp/maps" @@ -57,7 +57,7 @@ type AppModuleBasic interface { HasName RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(types.InterfaceRegistry) - RegisterGRPCGatewayRoutes(client.Context, *gwruntime.ServeMux) + RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) } // HasName allows the module to provide its own name for legacy purposes. @@ -67,13 +67,6 @@ type HasName interface { Name() string } -// UpgradeModule is the extension interface that upgrade module should implement to differentiate -// it from other modules, migration handler need ensure the upgrade module's migration is executed -// before the rest of the modules. -type UpgradeModule interface { - IsUpgradeModule() -} - // HasGenesisBasics is the legacy interface for stateless genesis methods. type HasGenesisBasics interface { DefaultGenesis(codec.JSONCodec) json.RawMessage @@ -157,7 +150,7 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEn } // RegisterGRPCGatewayRoutes registers all module rest routes -func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *gwruntime.ServeMux) { +func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) { for _, b := range bm { b.RegisterGRPCGatewayRoutes(clientCtx, rtr) } @@ -709,7 +702,7 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver func (m *Manager) RunMigrationBeginBlock(ctx sdk.Context) (bool, error) { for _, moduleName := range m.OrderBeginBlockers { if mod, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { - if _, ok := mod.(UpgradeModule); ok { + if _, ok := mod.(appmodule.UpgradeModule); ok { err := mod.BeginBlock(ctx) return err == nil, err } @@ -725,7 +718,7 @@ func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) for _, moduleName := range m.OrderBeginBlockers { if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { - if _, ok := module.(UpgradeModule); !ok { + if _, ok := module.(appmodule.UpgradeModule); !ok { if err := module.BeginBlock(ctx); err != nil { return sdk.BeginBlock{}, err } diff --git a/types/module/module_test.go b/types/module/module_test.go index 9235b420a3..dffb6c34a7 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -472,7 +472,7 @@ func TestCoreAPIManager_RunMigrationBeginBlock(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockAppModule1 := mock.NewMockCoreAppModule(mockCtrl) - mockAppModule2 := mock.NewMockUpgradeModule(mockCtrl) + mockAppModule2 := mock.NewMockCoreUpgradeAppModule(mockCtrl) mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ "module1": mockAppModule1, "module2": mockAppModule2, diff --git a/x/evidence/go.mod b/x/evidence/go.mod index c48aa27d62..ee1f83f2a9 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( cosmossdk.io/api v0.7.0 cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 - cosmossdk.io/core v0.9.0 + cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 cosmossdk.io/log v1.2.0 diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 2d3c09ebb0..0d30759c94 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -39,8 +39,8 @@ cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg= cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E= -cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic= -cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9 h1:djIIHB7INVUMGDpaM02Js6iCA7CzlJo9KG4GYZCtsqI= +cosmossdk.io/core v0.9.1-0.20230814191920-98b67a87e5c9/go.mod h1:MygXNld9DvMgYY4yE76DM/mdZpgfeyRjy6FPjEEehlY= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= diff --git a/x/evidence/testutil/expected_keepers_mocks.go b/x/evidence/testutil/expected_keepers_mocks.go index 496495242c..b04232f6de 100644 --- a/x/evidence/testutil/expected_keepers_mocks.go +++ b/x/evidence/testutil/expected_keepers_mocks.go @@ -9,8 +9,8 @@ import ( reflect "reflect" time "time" - address "cosmossdk.io/core/address" stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1" + address "cosmossdk.io/core/address" comet "cosmossdk.io/core/comet" math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/crypto/types"