diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 9fbf4ae446..ec7eb6142f 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -38,6 +38,19 @@ type HasServices interface { RegisterServices(grpc.ServiceRegistrar) error } +// HasPrepareCheckState is an extension interface that contains information about the AppModule +// and PrepareCheckState. +type HasPrepareCheckState interface { + AppModule + PrepareCheckState(context.Context) error +} + +// HasPreommit is an extension interface that contains information about the AppModule and Precommit. +type HasPrecommit interface { + AppModule + Precommit(context.Context) error +} + // HasBeginBlocker is the extension interface that modules should implement to run // custom logic before transaction processing in a block. type HasBeginBlocker interface { diff --git a/docs/docs/building-modules/01-module-manager.md b/docs/docs/building-modules/01-module-manager.md index a420a6f098..3778d3d608 100644 --- a/docs/docs/building-modules/01-module-manager.md +++ b/docs/docs/building-modules/01-module-manager.md @@ -36,8 +36,8 @@ The above interfaces are mostly embedding smaller interfaces (extension interfac * [`HasConsensusVersion`](#hasconsensusversion): The extension interface for declaring a module consensus version. * [`BeginBlockAppModule`](#beginblockappmodule): The extension interface that contains information about the `AppModule` and `BeginBlock`. * [`EndBlockAppModule`](#endblockappmodule): The extension interface that contains information about the `AppModule` and `EndBlock`. -* [`PrecommitAppModule`](#precommitappmodule): The extension interface that contains information about the `AppModule` and `Precommit`. -* [`PrepareCheckStateAppModule`](#preparecheckstateappmodule): The extension interface that contains information about the `AppModule` and `PrepareCheckState`. +* [`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`. 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). @@ -169,15 +169,15 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/types/module/module.go#L20 * `EndBlock(sdk.Context, abci.RequestEndBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the end of each block. This is also where the module can inform the underlying consensus engine of validator set changes (e.g. the `staking` module). Implement empty if no logic needs to be triggered at the end of each block for this module. -### `PrecommitAppModule` +### `HasPrecommit` -The `PrecommitAppModule` is an extension interface from `AppModule`. All modules that have a `Precommit` method implement this interface. +`HasPrecommit` is an extension interface from `AppModule`. All modules that have a `Precommit` method implement this interface. * `Precommit(sdk.Context)`: This method gives module developers the option to implement logic that is automatically triggered during [`Commit'](../core/00-baseapp.md#commit) of each block using the [`deliverState`](../core/00-baseapp.md#state-updates) of the block to be committed. Implement empty if no logic needs to be triggered during `Commit` of each block for this module. -### `PrepareCheckStateAppModule` +### `HasPrepareCheckState` -The `PrepareCheckStateAppModule` is an extension interface from `AppModule`. All modules that have a `PrepareCheckState` method implement this interface. +`HasPrepareCheckState` is an extension interface from `AppModule`. All modules that have a `PrepareCheckState` method implement this interface. * `PrepareCheckState(sdk.Context)`: This method gives module developers the option to implement logic that is automatically triggered during [`Commit'](../core/00-baseapp.md#commit) of each block using the [`checkState`](../core/00-baseapp.md#state-updates) of the next block. Implement empty if no logic needs to be triggered during `Commit` of each block for this module. @@ -253,8 +253,8 @@ The module manager is used throughout the application whenever an action on a co * `ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export. * `BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)`: At the beginning of each block, this function is called from [`BaseApp`](../core/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each modules implementing the `BeginBlockAppModule` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../core/02-context.md) with an event manager to aggregate [events](../core/08-events.md) emitted from all modules. The function returns an `abci.ResponseBeginBlock` which contains the aforementioned events. * `EndBlock(ctx sdk.Context, req abci.RequestEndBlock)`: At the end of each block, this function is called from [`BaseApp`](../core/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `EndBlockAppModule` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../core/02-context.md) with an event manager to aggregate [events](../core/08-events.md) emitted from all modules. The function returns an `abci.ResponseEndBlock` which contains the aforementioned events, as well as validator set updates (if any). -* `Precommit(ctx sdk.Context)`: During [`Commit`](../core/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../core/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../core/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `PrecommitAppModule` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../core/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`deliverState`](../core/00-baseapp.md#state-updates). -* `PrepareCheckState(ctx sdk.Context)`: During [`Commit`](../core/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../core/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../core/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `PrepareCheckStateAppModule` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../core/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../core/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../core/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block. +* `Precommit(ctx sdk.Context)`: During [`Commit`](../core/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../core/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../core/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](../core/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`deliverState`](../core/00-baseapp.md#state-updates). +* `PrepareCheckState(ctx sdk.Context)`: During [`Commit`](../core/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../core/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../core/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](../core/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../core/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../core/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block. Here's an example of a concrete integration within an `simapp`: diff --git a/go.mod b/go.mod index 7ec18a4ec3..7ee046ff47 100644 --- a/go.mod +++ b/go.mod @@ -162,6 +162,7 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( + cosmossdk.io/core => ./core cosmossdk.io/store => ./store // TODO: remove after release 0.6.2 cosmossdk.io/x/tx => ./x/tx diff --git a/go.sum b/go.sum index 90a7fd5c8d..2265464421 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ cosmossdk.io/api v0.4.1 h1:0ikaYM6GyxTYYcfBiyR8YnLCfhNnhKpEFnaSepCTmqg= cosmossdk.io/api v0.4.1/go.mod h1:jR7k5ok90LxW2lFUXvd8Vpo/dr4PpiyVegxdm7b1ZdE= cosmossdk.io/collections v0.1.0 h1:nzJGeiq32KnZroSrhB6rPifw4I85Cgmzw/YAmr4luv8= cosmossdk.io/collections v0.1.0/go.mod h1:xbauc0YsbUF8qKMVeBZl0pFCunxBIhKN/WlxpZ3lBuo= -cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= -cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= diff --git a/simapp/go.mod b/simapp/go.mod index ed75d1924c..c792a21235 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -198,6 +198,7 @@ replace ( // TODO tag all extracted modules after SDK refactor cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 + cosmossdk.io/core => ../core cosmossdk.io/store => ../store cosmossdk.io/tools/confix => ../tools/confix cosmossdk.io/tools/rosetta => ../tools/rosetta diff --git a/simapp/go.sum b/simapp/go.sum index 95b17c37d9..3491bcc8ae 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -190,8 +190,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/collections v0.1.0 h1:nzJGeiq32KnZroSrhB6rPifw4I85Cgmzw/YAmr4luv8= cosmossdk.io/collections v0.1.0/go.mod h1:xbauc0YsbUF8qKMVeBZl0pFCunxBIhKN/WlxpZ3lBuo= -cosmossdk.io/core v0.6.2-0.20230323161322-ccd8d40119e4 h1:l1scDTT2VX18ZuR6P0irvT/bAP0h4297D/Lka5nz2vE= -cosmossdk.io/core v0.6.2-0.20230323161322-ccd8d40119e4/go.mod h1:J8R0E7soOpQFVqFiFd7EKepXCPpINa2n2t2EqbEsXnY= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= diff --git a/tests/go.mod b/tests/go.mod index 7ea3236610..9ad3d04cde 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -193,6 +193,7 @@ require ( replace ( // TODO tag all extracted modules after SDK refactor cosmossdk.io/api => ../api + cosmossdk.io/core => ../core cosmossdk.io/store => ../store cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant diff --git a/tests/go.sum b/tests/go.sum index 26f6653f40..28873dcc96 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -192,8 +192,6 @@ cosmossdk.io/client/v2 v2.0.0-20230309163709-87da587416ba h1:LuPHCncU2KLMNPItFEC cosmossdk.io/client/v2 v2.0.0-20230309163709-87da587416ba/go.mod h1:SXdwqO7cN5htalh/lhXWP8V4zKtBrhhcSTU+ytuEtmM= cosmossdk.io/collections v0.1.0 h1:nzJGeiq32KnZroSrhB6rPifw4I85Cgmzw/YAmr4luv8= cosmossdk.io/collections v0.1.0/go.mod h1:xbauc0YsbUF8qKMVeBZl0pFCunxBIhKN/WlxpZ3lBuo= -cosmossdk.io/core v0.6.2-0.20230323161322-ccd8d40119e4 h1:l1scDTT2VX18ZuR6P0irvT/bAP0h4297D/Lka5nz2vE= -cosmossdk.io/core v0.6.2-0.20230323161322-ccd8d40119e4/go.mod h1:J8R0E7soOpQFVqFiFd7EKepXCPpINa2n2t2EqbEsXnY= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index e1a6f23856..bd48567415 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -359,6 +359,34 @@ func (mr *MockCoreAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockCoreAppModule)(nil).IsOnePerModuleType)) } +// Precommit mocks base method. +func (m *MockCoreAppModule) 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 *MockCoreAppModuleMockRecorder) Precommit(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockCoreAppModule)(nil).Precommit), arg0) +} + +// PrepareCheckState mocks base method. +func (m *MockCoreAppModule) 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 *MockCoreAppModuleMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockCoreAppModule)(nil).PrepareCheckState), arg0) +} + // ValidateGenesis mocks base method. func (m *MockCoreAppModule) ValidateGenesis(arg0 appmodule.GenesisSource) error { m.ctrl.T.Helper() diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index e6e96e9c87..c406366748 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -881,232 +881,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 inter return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) } -// MockPrepareCheckStateAppModule is a mock of PrepareCheckStateAppModule interface. -type MockPrepareCheckStateAppModule struct { - ctrl *gomock.Controller - recorder *MockPrepareCheckStateAppModuleMockRecorder -} - -// MockPrepareCheckStateAppModuleMockRecorder is the mock recorder for MockPrepareCheckStateAppModule. -type MockPrepareCheckStateAppModuleMockRecorder struct { - mock *MockPrepareCheckStateAppModule -} - -// NewMockPrepareCheckStateAppModule creates a new mock instance. -func NewMockPrepareCheckStateAppModule(ctrl *gomock.Controller) *MockPrepareCheckStateAppModule { - mock := &MockPrepareCheckStateAppModule{ctrl: ctrl} - mock.recorder = &MockPrepareCheckStateAppModuleMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockPrepareCheckStateAppModule) EXPECT() *MockPrepareCheckStateAppModuleMockRecorder { - return m.recorder -} - -// GetQueryCmd mocks base method. -func (m *MockPrepareCheckStateAppModule) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockPrepareCheckStateAppModule) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).GetTxCmd)) -} - -// Name mocks base method. -func (m *MockPrepareCheckStateAppModule) Name() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Name") - ret0, _ := ret[0].(string) - return ret0 -} - -// Name indicates an expected call of Name. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) Name() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).Name)) -} - -// PrepareCheckState mocks base method. -func (m *MockPrepareCheckStateAppModule) PrepareCheckState(arg0 types1.Context) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "PrepareCheckState", arg0) -} - -// PrepareCheckState indicates an expected call of PrepareCheckState. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).PrepareCheckState), arg0) -} - -// RegisterGRPCGatewayRoutes mocks base method. -func (m *MockPrepareCheckStateAppModule) 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 *MockPrepareCheckStateAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) -} - -// RegisterInterfaces mocks base method. -func (m *MockPrepareCheckStateAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterInterfaces", arg0) -} - -// RegisterInterfaces indicates an expected call of RegisterInterfaces. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).RegisterInterfaces), arg0) -} - -// RegisterLegacyAminoCodec mocks base method. -func (m *MockPrepareCheckStateAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) -} - -// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. -func (mr *MockPrepareCheckStateAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockPrepareCheckStateAppModule)(nil).RegisterLegacyAminoCodec), arg0) -} - -// MockPrecommitAppModule is a mock of PrecommitAppModule interface. -type MockPrecommitAppModule struct { - ctrl *gomock.Controller - recorder *MockPrecommitAppModuleMockRecorder -} - -// MockPrecommitAppModuleMockRecorder is the mock recorder for MockPrecommitAppModule. -type MockPrecommitAppModuleMockRecorder struct { - mock *MockPrecommitAppModule -} - -// NewMockPrecommitAppModule creates a new mock instance. -func NewMockPrecommitAppModule(ctrl *gomock.Controller) *MockPrecommitAppModule { - mock := &MockPrecommitAppModule{ctrl: ctrl} - mock.recorder = &MockPrecommitAppModuleMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockPrecommitAppModule) EXPECT() *MockPrecommitAppModuleMockRecorder { - return m.recorder -} - -// GetQueryCmd mocks base method. -func (m *MockPrecommitAppModule) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockPrecommitAppModuleMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockPrecommitAppModule)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockPrecommitAppModule) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockPrecommitAppModuleMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockPrecommitAppModule)(nil).GetTxCmd)) -} - -// Name mocks base method. -func (m *MockPrecommitAppModule) Name() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Name") - ret0, _ := ret[0].(string) - return ret0 -} - -// Name indicates an expected call of Name. -func (mr *MockPrecommitAppModuleMockRecorder) Name() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockPrecommitAppModule)(nil).Name)) -} - -// Precommit mocks base method. -func (m *MockPrecommitAppModule) Precommit(arg0 types1.Context) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Precommit", arg0) -} - -// Precommit indicates an expected call of Precommit. -func (mr *MockPrecommitAppModuleMockRecorder) Precommit(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockPrecommitAppModule)(nil).Precommit), arg0) -} - -// RegisterGRPCGatewayRoutes mocks base method. -func (m *MockPrecommitAppModule) 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 *MockPrecommitAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockPrecommitAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) -} - -// RegisterInterfaces mocks base method. -func (m *MockPrecommitAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterInterfaces", arg0) -} - -// RegisterInterfaces indicates an expected call of RegisterInterfaces. -func (mr *MockPrecommitAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockPrecommitAppModule)(nil).RegisterInterfaces), arg0) -} - -// RegisterLegacyAminoCodec mocks base method. -func (m *MockPrecommitAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) -} - -// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. -func (mr *MockPrecommitAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockPrecommitAppModule)(nil).RegisterLegacyAminoCodec), arg0) -} - // MockHasABCIEndblock is a mock of HasABCIEndblock interface. type MockHasABCIEndblock struct { ctrl *gomock.Controller diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 9e35ebb232..eee7bb74a5 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -71,7 +71,8 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck // used for legacy testing + //nolint:staticcheck // used for legacy testing + simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 1066ac7322..cbefbd6df1 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -143,5 +143,6 @@ require ( replace ( cosmossdk.io/store => ../../store cosmossdk.io/x/tx => ../../x/tx + cosmossdk.io/core => ../../core github.com/cosmos/cosmos-sdk => ../.. ) diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index d53c6fae0c..d4aeb212b1 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -25,4 +25,6 @@ type CoreAppModule interface { appmodule.HasGenesis appmodule.HasBeginBlocker appmodule.HasEndBlocker + appmodule.HasPrecommit + appmodule.HasPrepareCheckState } diff --git a/types/module/module.go b/types/module/module.go index 492631f5a5..be144562eb 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -206,20 +206,6 @@ type EndBlockAppModule interface { AppModule EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } - -// PrepareCheckStateAppModule is an extension interface that contains information about the AppModule -// and PrepareCheckState. -type PrepareCheckStateAppModule interface { - AppModule - PrepareCheckState(sdk.Context) -} - -// PreommitAppModule is an extension interface that contains information about the AppModule and Precommit. -type PrecommitAppModule interface { - AppModule - Precommit(sdk.Context) -} - type HasABCIEndblock interface { AppModule EndBlock(context.Context) ([]abci.ValidatorUpdate, error) @@ -375,7 +361,7 @@ func (m *Manager) SetOrderPrepareCheckStaters(moduleNames ...string) { m.assertNoForgottenModules("SetOrderPrepareCheckStaters", moduleNames, func(moduleName string) bool { module := m.Modules[moduleName] - _, hasPrepareCheckState := module.(PrepareCheckStateAppModule) + _, hasPrepareCheckState := module.(appmodule.HasPrepareCheckState) return !hasPrepareCheckState }) m.OrderPrepareCheckStaters = moduleNames @@ -386,7 +372,7 @@ func (m *Manager) SetOrderPrecommiters(moduleNames ...string) { m.assertNoForgottenModules("SetOrderPrecommiters", moduleNames, func(moduleName string) bool { module := m.Modules[moduleName] - _, hasPrecommit := module.(PrecommitAppModule) + _, hasPrecommit := module.(appmodule.HasPrecommit) return !hasPrecommit }) m.OrderPrecommiters = moduleNames @@ -764,25 +750,31 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (abci.Resp } // Precommit performs precommit functionality for all modules. -func (m *Manager) Precommit(ctx sdk.Context) { +func (m *Manager) Precommit(ctx sdk.Context) error { for _, moduleName := range m.OrderPrecommiters { - module, ok := m.Modules[moduleName].(PrecommitAppModule) + module, ok := m.Modules[moduleName].(appmodule.HasPrecommit) if !ok { continue } - module.Precommit(ctx) + if err := module.Precommit(ctx); err != nil { + return err + } } + return nil } // PrepareCheckState performs functionality for preparing the check state for all modules. -func (m *Manager) PrepareCheckState(ctx sdk.Context) { +func (m *Manager) PrepareCheckState(ctx sdk.Context) error { for _, moduleName := range m.OrderPrepareCheckStaters { - module, ok := m.Modules[moduleName].(PrepareCheckStateAppModule) + module, ok := m.Modules[moduleName].(appmodule.HasPrepareCheckState) if !ok { continue } - module.PrepareCheckState(ctx) + if err := module.PrepareCheckState(ctx); err != nil { + return err + } } + return nil } // GetVersionMap gets consensus version from all modules diff --git a/types/module/module_test.go b/types/module/module_test.go index 2701309d12..ec3eb3ad80 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -106,52 +106,36 @@ func TestAssertNoForgottenModules(t *testing.T) { mockAppModule1 := mock.NewMockEndBlockAppModule(mockCtrl) mockAppModule2 := mock.NewMockBeginBlockAppModule(mockCtrl) mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl) - mockAppModule4 := mock.NewMockPrecommitAppModule(mockCtrl) - mockAppModule5 := mock.NewMockPrepareCheckStateAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") - mockAppModule4.EXPECT().Name().Times(2).Return("module4") - mockAppModule5.EXPECT().Name().Times(2).Return("module5") mm := module.NewManager( mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3), - mockAppModule4, - mockAppModule5, ) require.NotNil(t, mm) - require.Equal(t, 5, len(mm.Modules)) + require.Equal(t, 3, len(mm.Modules)) - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderInitGenesis) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderInitGenesis) require.PanicsWithValue(t, "all modules must be defined when setting SetOrderInitGenesis, missing: [module3]", func() { mm.SetOrderInitGenesis("module2", "module1") }) - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderExportGenesis) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderExportGenesis) require.PanicsWithValue(t, "all modules must be defined when setting SetOrderExportGenesis, missing: [module3]", func() { mm.SetOrderExportGenesis("module2", "module1") }) - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderBeginBlockers) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderBeginBlockers) require.PanicsWithValue(t, "all modules must be defined when setting SetOrderBeginBlockers, missing: [module2]", func() { mm.SetOrderBeginBlockers("module1", "module3") }) - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderEndBlockers) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderEndBlockers) require.PanicsWithValue(t, "all modules must be defined when setting SetOrderEndBlockers, missing: [module1]", func() { mm.SetOrderEndBlockers("module2", "module3") }) - - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderPrecommiters) - require.PanicsWithValue(t, "all modules must be defined when setting SetOrderPrecommiters, missing: [module4]", func() { - mm.SetOrderPrecommiters("module2", "module1") - }) - - require.Equal(t, []string{"module1", "module2", "module3", "module4", "module5"}, mm.OrderPrepareCheckStaters) - require.PanicsWithValue(t, "all modules must be defined when setting SetOrderPrepareCheckStaters, missing: [module5]", func() { - mm.SetOrderPrepareCheckStaters("module2", "module1") - }) } func TestManagerOrderSetters(t *testing.T) { @@ -381,40 +365,6 @@ func TestManager_EndBlock(t *testing.T) { require.Error(t, err) } -func TestManager_PrepareCheckState(t *testing.T) { - mockCtrl := gomock.NewController(t) - t.Cleanup(mockCtrl.Finish) - - mockAppModule1 := mock.NewMockPrepareCheckStateAppModule(mockCtrl) - mockAppModule2 := mock.NewMockPrepareCheckStateAppModule(mockCtrl) - mockAppModule1.EXPECT().Name().Times(2).Return("module1") - mockAppModule2.EXPECT().Name().Times(2).Return("module2") - mm := module.NewManager(mockAppModule1, mockAppModule2) - require.NotNil(t, mm) - require.Equal(t, 2, len(mm.Modules)) - - mockAppModule1.EXPECT().PrepareCheckState(gomock.Any()).Times(1) - mockAppModule2.EXPECT().PrepareCheckState(gomock.Any()).Times(1) - mm.PrepareCheckState(sdk.Context{}) -} - -func TestManager_Precommit(t *testing.T) { - mockCtrl := gomock.NewController(t) - t.Cleanup(mockCtrl.Finish) - - mockAppModule1 := mock.NewMockPrecommitAppModule(mockCtrl) - mockAppModule2 := mock.NewMockPrecommitAppModule(mockCtrl) - mockAppModule1.EXPECT().Name().Times(2).Return("module1") - mockAppModule2.EXPECT().Name().Times(2).Return("module2") - mm := module.NewManager(mockAppModule1, mockAppModule2) - require.NotNil(t, mm) - require.Equal(t, 2, len(mm.Modules)) - - mockAppModule1.EXPECT().Precommit(gomock.Any()).Times(1) - mockAppModule2.EXPECT().Precommit(gomock.Any()).Times(1) - mm.Precommit(sdk.Context{}) -} - // Core API exclusive tests func TestCoreAPIManager(t *testing.T) { mockCtrl := gomock.NewController(t) @@ -590,6 +540,52 @@ func TestCoreAPIManager_EndBlock(t *testing.T) { require.EqualError(t, err, "some error") } +func TestManager_PrepareCheckState(t *testing.T) { + mockCtrl := gomock.NewController(t) + t.Cleanup(mockCtrl.Finish) + + mockAppModule1 := mock.NewMockCoreAppModule(mockCtrl) + mockAppModule2 := mock.NewMockCoreAppModule(mockCtrl) + mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ + "module1": mockAppModule1, + "module2": mockAppModule2, + }) + require.NotNil(t, mm) + require.Equal(t, 2, len(mm.Modules)) + + mockAppModule1.EXPECT().PrepareCheckState(gomock.Any()).Times(1).Return(nil) + mockAppModule2.EXPECT().PrepareCheckState(gomock.Any()).Times(1).Return(nil) + err := mm.PrepareCheckState(sdk.Context{}) + require.NoError(t, err) + + mockAppModule1.EXPECT().PrepareCheckState(gomock.Any()).Times(1).Return(errors.New("some error")) + err = mm.PrepareCheckState(sdk.Context{}) + require.EqualError(t, err, "some error") +} + +func TestManager_Precommit(t *testing.T) { + mockCtrl := gomock.NewController(t) + t.Cleanup(mockCtrl.Finish) + + mockAppModule1 := mock.NewMockCoreAppModule(mockCtrl) + mockAppModule2 := mock.NewMockCoreAppModule(mockCtrl) + mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ + "module1": mockAppModule1, + "module2": mockAppModule2, + }) + require.NotNil(t, mm) + require.Equal(t, 2, len(mm.Modules)) + + mockAppModule1.EXPECT().Precommit(gomock.Any()).Times(1).Return(nil) + mockAppModule2.EXPECT().Precommit(gomock.Any()).Times(1).Return(nil) + err := mm.Precommit(sdk.Context{}) + require.NoError(t, err) + + mockAppModule1.EXPECT().Precommit(gomock.Any()).Times(1).Return(errors.New("some error")) + err = mm.Precommit(sdk.Context{}) + require.EqualError(t, err, "some error") +} + // MockCoreAppModule allows us to test functions like DefaultGenesis type MockCoreAppModule struct{}