From 209580a8215a6c92bde3e296c3e4c4299949e5f7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 15:59:34 +0200 Subject: [PATCH 1/4] docs: precise compiler assertions --- UPGRADING.md | 22 +++++++++++++++++++--- x/circuit/module.go | 4 ++-- x/gov/module.go | 8 +++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index fcd949e96e6b..90d4b36b933f 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -343,7 +343,7 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch * `x/slashing` * `x/upgrade` -* BeginBlock and EndBlock have changed their signature, so it is important that any module implementing them are updated accordingly. +* `BeginBlock` and `EndBlock` have changed their signature, so it is important that any module implementing them are updated accordingly. ```diff - BeginBlock(sdk.Context, abci.RequestBeginBlock) @@ -362,11 +362,27 @@ In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it c + EndBlock(context.Context) ([]abci.ValidatorUpdate, error) ``` -`GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. +:::tip +You can ensure that a module implements the correct interfaces by using interface checks in your `x/{moduleName}/module.go`: + +```go +var ( + _ module.AppModule = (*AppModule)(nil) + _ module.AppModuleBasic = (*AppModuleBasic)(nil) + _ module.AppModuleSimulation = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) + _ appmodule.AppModule = (*AppModule)(nil) + _ appmodule.HasBeginBlocker = (*AppModule)(nil) +) +``` + +::: +* `GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. -To find out more please read the [signer field](./05-protobuf-annotations.md#signer) & [here](https://github.com/cosmos/cosmos-sdk/blob/7352d0bce8e72121e824297df453eb1059c28da8/docs/docs/build/building-modules/02-messages-and-queries.md#L40)documentation. +To find out more please read the [signer field](./05-protobuf-annotations.md#signer) & [here](https://github.com/cosmos/cosmos-sdk/blob/7352d0bce8e72121e824297df453eb1059c28da8/docs/docs/build/building-modules/02-messages-and-queries.md#L40) documentation. + #### `x/auth` For ante handler construction via `ante.NewAnteHandler`, the field `ante.HandlerOptions.SignModeHandler` has been updated to `x/tx/signing/HandlerMap` from `x/auth/signing/SignModeHandler`. Callers typically fetch this value from `client.TxConfig.SignModeHandler()` (which is also changed) so this change should be transparent to most users. diff --git a/x/circuit/module.go b/x/circuit/module.go index 182e81737692..af54cfed68c4 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -35,6 +35,8 @@ const ConsensusVersion = 1 var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the circuit module. @@ -90,8 +92,6 @@ type AppModule struct { keeper keeper.Keeper } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/gov/module.go b/x/gov/module.go index 0309564f466a..9b6f22a75703 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -42,6 +42,9 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the gov module. @@ -148,11 +151,6 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} From 2bd204ae07bb34aea915ffa65a4f29762afb458e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 16:20:55 +0200 Subject: [PATCH 2/4] updates --- UPGRADING.md | 10 +++++++--- x/auth/module.go | 17 +++++------------ x/auth/vesting/module.go | 11 ++++------- x/authz/module/module.go | 19 +++++++------------ x/bank/module.go | 11 ++++------- x/circuit/module.go | 2 +- x/consensus/module.go | 8 +++----- x/crisis/module.go | 20 ++++++++------------ x/distribution/module.go | 17 +++++------------ x/evidence/module.go | 19 ++++++------------- x/feegrant/module/module.go | 19 +++++++------------ x/genutil/module.go | 6 +++--- x/gov/module.go | 5 ----- x/group/module/module.go | 18 ++++++------------ x/mint/module.go | 19 +++++-------------- x/nft/module/module.go | 18 +++++------------- x/params/module.go | 7 +++---- x/slashing/module.go | 19 +++++-------------- x/staking/module.go | 20 +++++--------------- x/upgrade/module.go | 15 ++++++++------- 20 files changed, 97 insertions(+), 183 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 90d4b36b933f..94997b7a1320 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -363,19 +363,23 @@ In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it c ``` :::tip -You can ensure that a module implements the correct interfaces by using interface checks in your `x/{moduleName}/module.go`: +It is possible to ensure that a module implements the correct interfaces by using compiler assertions in your `x/{moduleName}/module.go`: ```go var ( - _ module.AppModule = (*AppModule)(nil) - _ module.AppModuleBasic = (*AppModuleBasic)(nil) + _ module.AppModuleBasic = (*AppModule)(nil) _ module.AppModuleSimulation = (*AppModule)(nil) _ module.HasGenesis = (*AppModule)(nil) + _ appmodule.AppModule = (*AppModule)(nil) _ appmodule.HasBeginBlocker = (*AppModule)(nil) + _ appmodule.HasEndBlocker = (*AppModule)(nil) + ... ) ``` +Read more on those interfaces [here](https://docs.cosmos.network/v0.50/building-modules/module-manager#application-module-interfaces). + ::: * `GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. diff --git a/x/auth/module.go b/x/auth/module.go index ae942a774e5c..9e709c650091 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -33,9 +32,11 @@ const ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the auth module. @@ -92,8 +93,6 @@ type AppModule struct { legacySubspace exported.Subspace } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -110,11 +109,6 @@ func NewAppModule(cdc codec.Codec, accountKeeper keeper.AccountKeeper, randGenAc } } -// Name returns the auth module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { @@ -141,11 +135,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.accountKeeper.InitGenesis(ctx, genesisState) - return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the auth diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 98a411c01105..139efb1af0de 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -24,8 +24,10 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the sub-vesting @@ -87,11 +89,6 @@ func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index a933d4fa7d91..248a75b8584b 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -29,8 +29,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the authz module. @@ -97,6 +102,7 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { // AppModule implements the sdk.AppModule interface type AppModule struct { AppModuleBasic + keeper keeper.Keeper accountKeeper authz.AccountKeeper bankKeeper authz.BankKeeper @@ -114,23 +120,12 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the authz module's name. -func (AppModule) Name() string { - return authz.ModuleName -} - // InitGenesis performs genesis initialization for the authz module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { diff --git a/x/bank/module.go b/x/bank/module.go index 2a1fc8105321..87df7cf56746 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -36,10 +36,12 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the bank module. @@ -103,8 +105,6 @@ type AppModule struct { legacySubspace exported.Subspace } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -140,9 +140,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.Acc } } -// Name returns the bank module's name. -func (AppModule) Name() string { return types.ModuleName } - // RegisterInvariants registers the bank module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/circuit/module.go b/x/circuit/module.go index af54cfed68c4..16c6b5a38461 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -33,7 +33,7 @@ import ( const ConsensusVersion = 1 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.HasGenesis = AppModule{} _ appmodule.AppModule = AppModule{} diff --git a/x/consensus/module.go b/x/consensus/module.go index 3a962b5b12b3..873516ca67e6 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -27,8 +27,9 @@ import ( const ConsensusVersion = 1 var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the consensus module. @@ -89,9 +90,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { } } -// Name returns the consensus module's name. -func (AppModule) Name() string { return types.ModuleName } - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } diff --git a/x/crisis/module.go b/x/crisis/module.go index a40698d8a6cb..87bb60efa273 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -35,7 +35,14 @@ import ( // ConsensusVersion defines the current x/crisis module consensus version. const ConsensusVersion = 2 -var _ module.AppModuleBasic = AppModuleBasic{} +var ( + _ module.AppModuleBasic = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} +) // Module init related flags const ( @@ -114,12 +121,6 @@ func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool, ss exported } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -131,11 +132,6 @@ func AddModuleInitFlags(startCmd *cobra.Command) { startCmd.Flags().Bool(FlagSkipGenesisInvariants, false, "Skip x/crisis invariants check on startup") } -// Name returns the crisis module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), am.keeper) diff --git a/x/distribution/module.go b/x/distribution/module.go index 4fb70658a94a..72c1a3d80e40 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -33,8 +33,12 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the distribution module. @@ -114,23 +118,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the distribution module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterInvariants registers the distribution module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/evidence/module.go b/x/evidence/module.go index 12a24b75cb02..d9bb011ba57c 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -30,8 +30,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // ---------------------------------------------------------------------------- @@ -117,24 +122,12 @@ func NewAppModule(keeper keeper.Keeper) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the evidence module's name. -func (am AppModule) Name() string { - return am.AppModuleBasic.Name() -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper)) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 287daa903f60..82103c7a81cd 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -28,8 +28,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) // ---------------------------------------------------------------------------- @@ -104,6 +109,7 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { // AppModule implements an application module for the feegrant module. type AppModule struct { AppModuleBasic + keeper keeper.Keeper accountKeeper feegrant.AccountKeeper bankKeeper feegrant.BankKeeper @@ -121,23 +127,12 @@ func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKe } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the feegrant module's name. -func (AppModule) Name() string { - return feegrant.ModuleName -} - // InitGenesis performs genesis initialization for the feegrant module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { diff --git a/x/genutil/module.go b/x/genutil/module.go index 11d613d3c7c3..5d3337ba24ab 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -21,8 +21,10 @@ import ( ) var ( + _ module.AppModuleBasic = AppModule{} _ module.HasABCIGenesis = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the genutil module. @@ -91,8 +93,6 @@ func NewAppModule(accountKeeper types.AccountKeeper, }) } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (AppModule) IsOnePerModuleType() {} diff --git a/x/gov/module.go b/x/gov/module.go index 9b6f22a75703..0b07cf87cee6 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -265,11 +265,6 @@ func InvokeSetHooks(keeper *keeper.Keeper, govHooks map[string]govtypes.GovHooks return nil } -// Name returns the gov module's name. -func (AppModule) Name() string { - return govtypes.ModuleName -} - // RegisterInvariants registers module invariants func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper, am.bankKeeper) diff --git a/x/group/module/module.go b/x/group/module/module.go index 46bfa2a583c0..53b8fe66fa6c 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -31,8 +31,13 @@ import ( const ConsensusVersion = 2 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) type AppModule struct { @@ -54,12 +59,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak group.AccountKeeper, } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -113,11 +112,6 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { group.RegisterLegacyAminoCodec(cdc) } -// Name returns the group module's name. -func (AppModule) Name() string { - return group.ModuleName -} - // RegisterInvariants does nothing, there are no invariants to enforce func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/mint/module.go b/x/mint/module.go index 6eeb04e9e387..eda0ad771035 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -29,8 +29,12 @@ import ( const ConsensusVersion = 2 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the mint module. @@ -38,8 +42,6 @@ type AppModuleBasic struct { cdc codec.Codec } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the mint module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -115,23 +117,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the mint module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers a gRPC query service to respond to the // module-specific gRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 5f75d0ff08fd..9338870b0dbd 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -28,9 +28,12 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the nft module. @@ -109,23 +112,12 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak nft.AccountKeeper, b } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the nft module's name. -func (AppModule) Name() string { - return nft.ModuleName -} - // InitGenesis performs genesis initialization for the nft module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { diff --git a/x/params/module.go b/x/params/module.go index ada51ae1e7dd..de0a01868baf 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -22,9 +22,10 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // ConsensusVersion defines the current x/params module consensus version. @@ -69,8 +70,6 @@ func NewAppModule(k keeper.Keeper) AppModule { } } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/slashing/module.go b/x/slashing/module.go index 8d8af2e505bb..617d2d737971 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -33,8 +33,12 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the slashing module. @@ -42,8 +46,6 @@ type AppModuleBasic struct { cdc codec.Codec } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the slashing module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -122,23 +124,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the slashing module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) diff --git a/x/staking/module.go b/x/staking/module.go index 1e0809cf1d3e..5bebaa4ed66a 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -36,11 +36,13 @@ const ( ) var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasABCIEndblock = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.HasABCIEndblock = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the staking module. @@ -49,8 +51,6 @@ type AppModuleBasic struct { ak types.AccountKeeper } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the staking module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -123,22 +123,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the staking module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterInvariants registers the staking module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 7d73cfc2e80e..d96566f3d242 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -38,7 +38,14 @@ func init() { // ConsensusVersion defines the current x/upgrade module consensus version. const ConsensusVersion uint64 = 3 -var _ module.AppModuleBasic = AppModuleBasic{} +var ( + _ module.AppModuleBasic = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasPreBlocker = AppModule{} +) // AppModuleBasic implements the sdk.AppModuleBasic interface type AppModuleBasic struct { @@ -86,12 +93,6 @@ func NewAppModule(keeper *keeper.Keeper, ac address.Codec) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasPreBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} From fd59a7574dcc29ea80d7a80636c5031d368945ee Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 16:33:47 +0200 Subject: [PATCH 3/4] updates --- x/auth/module.go | 1 + x/bank/module.go | 1 + x/circuit/module.go | 1 + x/consensus/module.go | 8 ++------ x/distribution/module.go | 2 ++ x/gov/module.go | 2 ++ x/group/module/module.go | 1 + x/mint/module.go | 1 + x/params/module.go | 1 + x/slashing/module.go | 1 + x/staking/module.go | 1 + 11 files changed, 14 insertions(+), 6 deletions(-) diff --git a/x/auth/module.go b/x/auth/module.go index 9e709c650091..52e9b93cac85 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -35,6 +35,7 @@ var ( _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} _ appmodule.AppModule = AppModule{} ) diff --git a/x/bank/module.go b/x/bank/module.go index 87df7cf56746..4de21846524b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -40,6 +40,7 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} ) diff --git a/x/circuit/module.go b/x/circuit/module.go index 16c6b5a38461..dd49a874e7ce 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -35,6 +35,7 @@ const ConsensusVersion = 1 var ( _ module.AppModuleBasic = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} _ appmodule.AppModule = AppModule{} ) diff --git a/x/consensus/module.go b/x/consensus/module.go index 873516ca67e6..4df4c60ba3d2 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -29,7 +29,8 @@ const ConsensusVersion = 1 var ( _ module.AppModuleBasic = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the consensus module. @@ -64,11 +65,6 @@ type AppModule struct { keeper keeper.Keeper } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/distribution/module.go b/x/distribution/module.go index 72c1a3d80e40..533a54fbbe4c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -36,6 +36,8 @@ var ( _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} diff --git a/x/gov/module.go b/x/gov/module.go index 0b07cf87cee6..a30b718ca1e2 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -42,6 +42,8 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasEndBlocker = AppModule{} diff --git a/x/group/module/module.go b/x/group/module/module.go index 53b8fe66fa6c..889d22ab1787 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -35,6 +35,7 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasEndBlocker = AppModule{} diff --git a/x/mint/module.go b/x/mint/module.go index eda0ad771035..5a90a517b1c3 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -32,6 +32,7 @@ var ( _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} diff --git a/x/params/module.go b/x/params/module.go index de0a01868baf..8dfe121bea9b 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -24,6 +24,7 @@ import ( var ( _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasServices = AppModule{} _ appmodule.AppModule = AppModule{} ) diff --git a/x/slashing/module.go b/x/slashing/module.go index 617d2d737971..93a954835c7f 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -36,6 +36,7 @@ var ( _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} diff --git a/x/staking/module.go b/x/staking/module.go index 5bebaa4ed66a..557a82a4b3b9 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -40,6 +40,7 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasABCIEndblock = AppModule{} _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} From 70e4c7f6a8cf9266f3c34f42af772145281847c3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 16:51:42 +0200 Subject: [PATCH 4/4] fix mocks and docs --- UPGRADING.md | 2 +- .../building-modules/01-module-manager.md | 10 +- .../06-beginblock-endblock.md | 2 +- testutil/mock/types_mock_appmodule.go | 170 ++++++++++++++++-- testutil/mock/types_module_module.go | 52 +++--- types/module/mock_appmodule_test.go | 9 +- types/module/module.go | 12 +- types/module/module_test.go | 8 +- x/staking/module.go | 3 +- 9 files changed, 206 insertions(+), 62 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 94997b7a1320..3b4c55587b74 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -355,7 +355,7 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch + EndBlock(context.Context) error ``` -In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it can use the `HasABCIEndblock` interface instead. +In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it can use the `HasABCIEndBlock` interface instead. ```diff - EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate diff --git a/docs/docs/build/building-modules/01-module-manager.md b/docs/docs/build/building-modules/01-module-manager.md index 7b0cc9974441..570a60c0b41e 100644 --- a/docs/docs/build/building-modules/01-module-manager.md +++ b/docs/docs/build/building-modules/01-module-manager.md @@ -42,7 +42,7 @@ The above interfaces are mostly embedding smaller interfaces (extension interfac * [`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.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. +* [`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. @@ -198,7 +198,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.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 @@ -206,9 +206,9 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. * `EndBlock(context.Context) error`: This method gives module developers the option to implement logic that is automatically triggered at the end of each block. -### `HasABCIEndblock` +### `HasABCIEndBlock` -The `HasABCIEndblock` is an extension interface from `module.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 @@ -309,7 +309,7 @@ The module manager is used throughout the application whenever an action on a co * `ExportGenesisForModules(ctx context.Context, cdc codec.JSONCodec, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export. * `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from each modules. * `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). -* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndblock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). +* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). * `Precommit(ctx context.Context)`: During [`Commit`](../../develop/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../develop/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../develop/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../develop/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../develop/advanced/00-baseapp.md#state-updates). * `PrepareCheckState(ctx context.Context)`: During [`Commit`](../../develop/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../../develop/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../develop/advanced/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `HasPrepareCheckState` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../../develop/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../../develop/advanced/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../../develop/advanced/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block. diff --git a/docs/docs/build/building-modules/06-beginblock-endblock.md b/docs/docs/build/building-modules/06-beginblock-endblock.md index 9472b0b759eb..35b5bb350b2e 100644 --- a/docs/docs/build/building-modules/06-beginblock-endblock.md +++ b/docs/docs/build/building-modules/06-beginblock-endblock.md @@ -20,7 +20,7 @@ sidebar_position: 1 In 0.47.0, Prepare and Process Proposal were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in BeginBlock. If an application required `BeginBlock` to execute prior to any sort of work is done then this is not possible today (0.50.0). -When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndblocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in `abci.go`. +When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndBlocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in `abci.go`. The actual implementation of `BeginBlocker` and `EndBlocker` in `abci.go` are very similar to that of a [`Msg` service](./03-msg-services.md): diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index c1d22f377963..48cc6f49a35a 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -541,35 +541,125 @@ func (mr *MockCoreAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModule)(nil).ValidateGenesis), arg0) } -// MockCoreModuleWithPreBlock is a mock of CoreModuleWithPreBlock interface. -type MockCoreModuleWithPreBlock struct { - MockCoreAppModule - recorder *MockCoreModuleWithPreBlockMockRecorder +// MockCoreAppModuleWithPreBlock is a mock of CoreAppModuleWithPreBlock interface. +type MockCoreAppModuleWithPreBlock struct { + ctrl *gomock.Controller + recorder *MockCoreAppModuleWithPreBlockMockRecorder } -// MockCoreModuleWithPreBlockMockRecorder is the mock recorder for MockCoreModuleWithPreBlock. -type MockCoreModuleWithPreBlockMockRecorder struct { - mock *MockCoreModuleWithPreBlock +// MockCoreAppModuleWithPreBlockMockRecorder is the mock recorder for MockCoreAppModuleWithPreBlock. +type MockCoreAppModuleWithPreBlockMockRecorder struct { + mock *MockCoreAppModuleWithPreBlock } -// NewMockCoreModuleWithPreBlock creates a new mock instance. -func NewMockCoreModuleWithPreBlock(ctrl *gomock.Controller) *MockCoreModuleWithPreBlock { - mock := &MockCoreModuleWithPreBlock{ - MockCoreAppModule: MockCoreAppModule{ - ctrl: ctrl, - }, - } - mock.recorder = &MockCoreModuleWithPreBlockMockRecorder{mock} +// NewMockCoreAppModuleWithPreBlock creates a new mock instance. +func NewMockCoreAppModuleWithPreBlock(ctrl *gomock.Controller) *MockCoreAppModuleWithPreBlock { + mock := &MockCoreAppModuleWithPreBlock{ctrl: ctrl} + mock.recorder = &MockCoreAppModuleWithPreBlockMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCoreModuleWithPreBlock) EXPECT() *MockCoreModuleWithPreBlockMockRecorder { +func (m *MockCoreAppModuleWithPreBlock) EXPECT() *MockCoreAppModuleWithPreBlockMockRecorder { return m.recorder } +// BeginBlock mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) BeginBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).BeginBlock), arg0) +} + +// DefaultGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).DefaultGenesis), arg0) +} + +// EndBlock mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).EndBlock), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).ExportGenesis), arg0, arg1) +} + +// InitGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).InitGenesis), arg0, arg1) +} + +// IsAppModule mocks base method. +func (m *MockCoreAppModuleWithPreBlock) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockCoreAppModuleWithPreBlock) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).IsOnePerModuleType)) +} + // PreBlock mocks base method. -func (m *MockCoreModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.ResponsePreBlock, error) { +func (m *MockCoreAppModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.ResponsePreBlock, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PreBlock", arg0) ret0, _ := ret[0].(appmodule.ResponsePreBlock) @@ -578,7 +668,49 @@ func (m *MockCoreModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.R } // PreBlock indicates an expected call of PreBlock. -func (mr *MockCoreModuleWithPreBlockMockRecorder) PreBlock(arg0 interface{}) *gomock.Call { +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) PreBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).PreBlock), arg0) +} + +// Precommit mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) Precommit(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).Precommit), arg0) +} + +// PrepareCheckState mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).PrepareCheckState), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) 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 *MockCoreAppModuleWithPreBlockMockRecorder) ValidateGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreBlock", reflect.TypeOf((*MockCoreModuleWithPreBlock)(nil).PreBlock), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).ValidateGenesis), arg0) } diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 9859d1212b32..186cd4d7ca7f 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -516,31 +516,31 @@ func (mr *MockHasConsensusVersionMockRecorder) ConsensusVersion() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockHasConsensusVersion)(nil).ConsensusVersion)) } -// MockHasABCIEndblock is a mock of HasABCIEndblock interface. -type MockHasABCIEndblock struct { +// MockHasABCIEndBlock is a mock of HasABCIEndBlock interface. +type MockHasABCIEndBlock struct { ctrl *gomock.Controller - recorder *MockHasABCIEndblockMockRecorder + recorder *MockHasABCIEndBlockMockRecorder } -// MockHasABCIEndblockMockRecorder is the mock recorder for MockHasABCIEndblock. -type MockHasABCIEndblockMockRecorder struct { - mock *MockHasABCIEndblock +// MockHasABCIEndBlockMockRecorder is the mock recorder for MockHasABCIEndBlock. +type MockHasABCIEndBlockMockRecorder struct { + mock *MockHasABCIEndBlock } -// NewMockHasABCIEndblock creates a new mock instance. -func NewMockHasABCIEndblock(ctrl *gomock.Controller) *MockHasABCIEndblock { - mock := &MockHasABCIEndblock{ctrl: ctrl} - mock.recorder = &MockHasABCIEndblockMockRecorder{mock} +// NewMockHasABCIEndBlock creates a new mock instance. +func NewMockHasABCIEndBlock(ctrl *gomock.Controller) *MockHasABCIEndBlock { + mock := &MockHasABCIEndBlock{ctrl: ctrl} + mock.recorder = &MockHasABCIEndBlockMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasABCIEndblock) EXPECT() *MockHasABCIEndblockMockRecorder { +func (m *MockHasABCIEndBlock) EXPECT() *MockHasABCIEndBlockMockRecorder { return m.recorder } // EndBlock mocks base method. -func (m *MockHasABCIEndblock) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { +func (m *MockHasABCIEndBlock) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0) ret0, _ := ret[0].([]types.ValidatorUpdate) @@ -549,13 +549,13 @@ func (m *MockHasABCIEndblock) EndBlock(arg0 context.Context) ([]types.ValidatorU } // EndBlock indicates an expected call of EndBlock. -func (mr *MockHasABCIEndblockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndblock)(nil).EndBlock), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndBlock)(nil).EndBlock), arg0) } // Name mocks base method. -func (m *MockHasABCIEndblock) Name() string { +func (m *MockHasABCIEndBlock) Name() string { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Name") ret0, _ := ret[0].(string) @@ -563,45 +563,45 @@ func (m *MockHasABCIEndblock) Name() string { } // Name indicates an expected call of Name. -func (mr *MockHasABCIEndblockMockRecorder) Name() *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) Name() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIEndblock)(nil).Name)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIEndBlock)(nil).Name)) } // RegisterGRPCGatewayRoutes mocks base method. -func (m *MockHasABCIEndblock) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { +func (m *MockHasABCIEndBlock) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) } // RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. -func (mr *MockHasABCIEndblockMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) } // RegisterInterfaces mocks base method. -func (m *MockHasABCIEndblock) RegisterInterfaces(arg0 types0.InterfaceRegistry) { +func (m *MockHasABCIEndBlock) RegisterInterfaces(arg0 types0.InterfaceRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInterfaces", arg0) } // RegisterInterfaces indicates an expected call of RegisterInterfaces. -func (mr *MockHasABCIEndblockMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterInterfaces), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterInterfaces), arg0) } // RegisterLegacyAminoCodec mocks base method. -func (m *MockHasABCIEndblock) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { +func (m *MockHasABCIEndBlock) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) } // RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. -func (mr *MockHasABCIEndblockMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterLegacyAminoCodec), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterLegacyAminoCodec), arg0) } // MockgenesisOnlyModule is a mock of genesisOnlyModule interface. diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index 27049cf54000..07c9c6389f51 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -14,7 +14,7 @@ type AppModuleWithAllExtensions interface { module.HasGenesis module.HasInvariants module.HasConsensusVersion - module.HasABCIEndblock + module.HasABCIEndBlock module.HasName } @@ -25,7 +25,7 @@ type AppModuleWithAllExtensionsABCI interface { module.HasABCIGenesis module.HasInvariants module.HasConsensusVersion - module.HasABCIEndblock + module.HasABCIEndBlock module.HasName } @@ -39,3 +39,8 @@ type CoreAppModule interface { appmodule.HasPrecommit appmodule.HasPrepareCheckState } + +type CoreAppModuleWithPreBlock interface { + CoreAppModule + appmodule.HasPreBlocker +} diff --git a/types/module/module.go b/types/module/module.go index 086e281a7cf6..a3c7b2ed62f0 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -197,6 +197,7 @@ type HasABCIGenesis interface { // AppModule is the form for an application module. Most of // its functionality has been moved to extension interfaces. +// Deprecated: use appmodule.AppModule with a combination of extension interfaes interfaces instead. type AppModule interface { AppModuleBasic } @@ -222,7 +223,12 @@ type HasConsensusVersion interface { ConsensusVersion() uint64 } -type HasABCIEndblock interface { +// HasABCIEndblock is a released typo of HasABCIEndBlock. +// Deprecated: use HasABCIEndBlock instead. +type HasABCIEndblock HasABCIEndBlock + +// HasABCIEndBlock is the interface for modules that need to run code at the end of the block. +type HasABCIEndBlock interface { AppModule EndBlock(context.Context) ([]abci.ValidatorUpdate, error) } @@ -397,7 +403,7 @@ func (m *Manager) SetOrderEndBlockers(moduleNames ...string) { return !hasEndBlock } - _, hasABCIEndBlock := module.(HasABCIEndblock) + _, hasABCIEndBlock := module.(HasABCIEndBlock) return !hasABCIEndBlock }) m.OrderEndBlockers = moduleNames @@ -788,7 +794,7 @@ func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { if err != nil { return sdk.EndBlock{}, err } - } else if module, ok := m.Modules[moduleName].(HasABCIEndblock); ok { + } else if module, ok := m.Modules[moduleName].(HasABCIEndBlock); ok { moduleValUpdates, err := module.EndBlock(ctx) if err != nil { return sdk.EndBlock{}, err diff --git a/types/module/module_test.go b/types/module/module_test.go index bd5111a6692b..2a348667eb3a 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -95,7 +95,7 @@ func TestBasicManager(t *testing.T) { func TestAssertNoForgottenModules(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl) + mockAppModule1 := mock.NewMockHasABCIEndBlock(mockCtrl) mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") @@ -320,8 +320,8 @@ func TestManager_EndBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl) - mockAppModule2 := mock.NewMockHasABCIEndblock(mockCtrl) + mockAppModule1 := mock.NewMockHasABCIEndBlock(mockCtrl) + mockAppModule2 := mock.NewMockHasABCIEndBlock(mockCtrl) mockAppModule3 := mock.NewMockAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") @@ -473,7 +473,7 @@ func TestCoreAPIManager_PreBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockCoreModuleWithPreBlock(mockCtrl) + mockAppModule1 := mock.NewMockCoreAppModuleWithPreBlock(mockCtrl) mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ "module1": mockAppModule1, "module2": mock.NewMockCoreAppModule(mockCtrl), diff --git a/x/staking/module.go b/x/staking/module.go index 557a82a4b3b9..196114037ca7 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -38,9 +38,10 @@ const ( var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} - _ module.HasABCIEndblock = AppModule{} _ module.HasServices = AppModule{} _ module.HasInvariants = AppModule{} + _ module.HasABCIGenesis = AppModule{} + _ module.HasABCIEndBlock = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{}