Skip to content

Commit

Permalink
refactor: introduce abciGenesis interface (backport #17554) (#17575)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
  • Loading branch information
mergify[bot] and tac0turtle authored Aug 31, 2023
1 parent b2627e9 commit 013889d
Show file tree
Hide file tree
Showing 40 changed files with 620 additions and 561 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (genutil) [#17571](https://github.com/cosmos/cosmos-sdk/pull/17571) Allow creation of `AppGenesis` without a file lookup.

### Improvments

* (types/module) [#17554](https://github.com/cosmos/cosmos-sdk/pull/17554) Introduce `HasABCIGenesis` which is implemented by a module only when a validatorset update needs to be returned

### Bug Fixes

* (baseapp) [#17518](https://github.com/cosmos/cosmos-sdk/pull/17518) Utilizing voting power from vote extensions (CometBFT) instead of the current bonded tokens (x/staking) to determine if a set of vote extensions are valid.
Expand Down
16 changes: 8 additions & 8 deletions baseapp/testutil/mock/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/appmodule/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// HasGenesis 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.
type HasGenesis interface {
AppModule

Expand Down
46 changes: 21 additions & 25 deletions docs/docs/building-modules/01-module-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ Application module interfaces exist to facilitate the composition of modules tog

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:
There are 2 main application module interfaces:

* [`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:

* (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.
* (legacy) [`module.HasGenesis`](#modulehasgenesis) for inter-dependent genesis-related module functionalities.
* (legacy) [`module.HasABCIGenesis`](#modulehasabcigenesis) for inter-dependent genesis-related module functionalities.
* (legacy) [`module.HasGenesisBasics`](#modulehasgenesisbasics): The legacy interface for stateless genesis methods.
* (legacy) `module.GenesisOnlyAppModule`: Defines an `AppModule` that only has import/export functionality
* [`appmodule.HasGenesis` / `module.HasGenesis`](#appmodulehasgenesis): 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`.
Expand Down Expand Up @@ -80,11 +80,9 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go

* `HasName` is an interface that has a method `Name()`. This method returns the name of the module as a `string`.

### `HasGenesisBasics`
### Genesis

:::note
Use `appmodule.HasGenesis` instead.
:::
#### module.HasGenesisBasics

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L76-L79
Expand All @@ -95,32 +93,30 @@ Let us go through the methods:
* `DefaultGenesis(codec.JSONCodec)`: Returns a default [`GenesisState`](./08-genesis.md#genesisstate) for the module, marshalled to `json.RawMessage`. The default `GenesisState` need to be defined by the module developer and is primarily used for testing.
* `ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage)`: Used to validate the `GenesisState` defined by a module, given in its `json.RawMessage` form. It will usually unmarshall the `json` before running a custom [`ValidateGenesis`](./08-genesis.md#validategenesis) function defined by the module developer.

### `AppModuleGenesis`

:::note
Use `appmodule.HasGenesis` instead.
:::
#### module.HasGenesis

The `AppModuleGenesis` interface is a simple embedding of the `AppModuleBasic` and `HasGenesis` interfaces.
`HasGenesis` is an extension interface for allowing modules to implement genesis functionalities.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L183-L186
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L189-L193
```

It does not have its own manager, and exists separately from [`AppModule`](#appmodule) only for modules that exist only to implement genesis functionalities, so that they can be managed without having to implement all of `AppModule`'s methods.

### `HasGenesis`
#### module.HasABCIGenesis`

The `HasGenesis` interface is an extension interface of `HasGenesisBasics`.
`HasABCIGenesis` is an extension interface for allowing modules to implement genesis functionalities and returns validator set updates.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/genesis.go#L10-L24
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L189-L193
```
<!-- TODO change link above after merge -->

## appmodule.HasGenesis

Let us go through the two added methods:
> Note: `appmodule.HasGenesis` is experimental and should be considered unstable, it is recommended to not use this interface at this time.
* `InitGenesis(context.Context, codec.JSONCodec, json.RawMessage)`: Initializes the subset of the state managed by the module. It is called at genesis (i.e. when the chain is first started).
* `ExportGenesis(context.Context, codec.JSONCodec)`: Exports the latest subset of the state managed by the module to be used in a new genesis file. `ExportGenesis` is called for each module when a new chain is started from the state of an existing chain.
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/genesis.go#L10-L24
```

### `AppModule`

Expand Down
2 changes: 1 addition & 1 deletion simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
mockModule := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockDefaultGenesis := json.RawMessage(`{"key": "value"}`)
mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1)
mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0))

app.ModuleManager.Modules["mock"] = mockModule
Expand Down
10 changes: 5 additions & 5 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ go 1.21
require (
cosmossdk.io/api v0.7.0
cosmossdk.io/client/v2 v2.0.0-20230818115413-c402c51a1508
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.10.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.1.2
cosmossdk.io/store v1.0.0-rc.0
cosmossdk.io/tools/confix v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/tx v0.9.1
cosmossdk.io/x/upgrade v0.0.0-20230818115413-c402c51a1508
github.com/cometbft/cometbft v0.38.0-rc3
Expand All @@ -37,7 +38,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/errors v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
16 changes: 8 additions & 8 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4=
cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk=
cosmossdk.io/tools/confix v0.0.0-20230818115413-c402c51a1508 h1:axKhxRa3M9QW2GdKJUsSyzo44gxcwSOTGeomtkbQClM=
cosmossdk.io/tools/confix v0.0.0-20230818115413-c402c51a1508/go.mod h1:qcJ1zwLIMefpDHZuYSa73yBe/k5HyQ5H1Jg9PWv30Ts=
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508 h1:9HRBpMbGgk+W4BIp4ezYH2EjbpuVl2fBlwyJ2GZgrS0=
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508/go.mod h1:BhFX0kD6lkctNQO3ZGYY3p6h0/wPLVbFhrOt3uQxEIM=
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508 h1:R9H1lDpcPSkrLOnt6IDE38o0Wp8xE/+BAxocb0oyX4I=
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508/go.mod h1:yjIo3J0QKDo9CJawK1QoTA1hBx0llafVJdPqI0+ry74=
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508 h1:TKqjhhTfLchU8nSo1WZRgaH7xZWzYUQXVRj9CePcbaw=
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508/go.mod h1:kOr8Rr10RoMeGGk/pfW5yo1R7GQTGu4KdRgKphVvjz4=
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508 h1:wLq+U1CpNiUJNTsxqOsM+wymX4qOd5RYHiSyfv8w1TM=
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508/go.mod h1:TrMWJBK8iJVTFejcMdPDjq4cZN5K4+t3wZ/MgW05FSM=
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1 h1:SbR6MUhK3YXuKVHv0Z1ofFknDLMhRCQQV8UH2zoHOQA=
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:ALy2NjqAWYoGJErqIpuIjv+6EgZTR+1qOGIoph8eRy4=
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1 h1:LK55x/lSPLxO9I8WILXxyXo7YG5ju9p/HNOiMpWOIlE=
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:33bXWFTGlCBR2RGW7XoISoPVyxQJWTyB9xFCntoXKSE=
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1 h1:sWyGV9xn/+5HyW9zF6GUaizQNZdYTvgoY7rPjrAIWNw=
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:LvCHtqYn7tA6VT2ZGSGfsqVlCudm/OFNVYxtt2+zL28=
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1 h1:YpE6N2yzG1NMvHzqkVbvObknB2S8q0G1rn5N7bP5gW4=
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:M4FXuqMk3cKuCm6K3HHCk337+3NEh+h7V5ocNnDo7PI=
cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI=
cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA=
cosmossdk.io/x/upgrade v0.0.0-20230818115413-c402c51a1508 h1:tZ5fSX+ev+QHQ15457Vhxug8BSZJcHeBhU8DpgwlkCc=
Expand Down
8 changes: 4 additions & 4 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ require (
cosmossdk.io/math v1.1.2
cosmossdk.io/simapp v0.0.0-20230620040119-e078f1a49e8b
cosmossdk.io/store v1.0.0-rc.0
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508 // indirect
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1 // indirect
cosmossdk.io/x/tx v0.9.1
cosmossdk.io/x/upgrade v0.0.0-20230818115413-c402c51a1508
github.com/cometbft/cometbft v0.38.0-rc3
Expand All @@ -39,7 +39,7 @@ require (
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/client/v2 v2.0.0-20230818115413-c402c51a1508 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508 // indirect
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM=
cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4=
cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk=
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508 h1:9HRBpMbGgk+W4BIp4ezYH2EjbpuVl2fBlwyJ2GZgrS0=
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508/go.mod h1:BhFX0kD6lkctNQO3ZGYY3p6h0/wPLVbFhrOt3uQxEIM=
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508 h1:R9H1lDpcPSkrLOnt6IDE38o0Wp8xE/+BAxocb0oyX4I=
cosmossdk.io/x/evidence v0.0.0-20230818115413-c402c51a1508/go.mod h1:yjIo3J0QKDo9CJawK1QoTA1hBx0llafVJdPqI0+ry74=
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508 h1:TKqjhhTfLchU8nSo1WZRgaH7xZWzYUQXVRj9CePcbaw=
cosmossdk.io/x/feegrant v0.0.0-20230818115413-c402c51a1508/go.mod h1:kOr8Rr10RoMeGGk/pfW5yo1R7GQTGu4KdRgKphVvjz4=
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508 h1:wLq+U1CpNiUJNTsxqOsM+wymX4qOd5RYHiSyfv8w1TM=
cosmossdk.io/x/nft v0.0.0-20230818115413-c402c51a1508/go.mod h1:TrMWJBK8iJVTFejcMdPDjq4cZN5K4+t3wZ/MgW05FSM=
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1 h1:SbR6MUhK3YXuKVHv0Z1ofFknDLMhRCQQV8UH2zoHOQA=
cosmossdk.io/x/circuit v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:ALy2NjqAWYoGJErqIpuIjv+6EgZTR+1qOGIoph8eRy4=
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1 h1:LK55x/lSPLxO9I8WILXxyXo7YG5ju9p/HNOiMpWOIlE=
cosmossdk.io/x/evidence v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:33bXWFTGlCBR2RGW7XoISoPVyxQJWTyB9xFCntoXKSE=
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1 h1:sWyGV9xn/+5HyW9zF6GUaizQNZdYTvgoY7rPjrAIWNw=
cosmossdk.io/x/feegrant v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:LvCHtqYn7tA6VT2ZGSGfsqVlCudm/OFNVYxtt2+zL28=
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1 h1:YpE6N2yzG1NMvHzqkVbvObknB2S8q0G1rn5N7bP5gW4=
cosmossdk.io/x/nft v0.0.0-20230830091712-93ab28fe0ea1/go.mod h1:M4FXuqMk3cKuCm6K3HHCk337+3NEh+h7V5ocNnDo7PI=
cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI=
cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA=
cosmossdk.io/x/upgrade v0.0.0-20230818115413-c402c51a1508 h1:tZ5fSX+ev+QHQ15457Vhxug8BSZJcHeBhU8DpgwlkCc=
Expand Down
Loading

0 comments on commit 013889d

Please sign in to comment.