From f1576d7b4a1b5b75d155ce2378dcfe4c77857d02 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sun, 27 Aug 2023 23:35:45 +0200 Subject: [PATCH] minor cleanup from comments --- types/module/core_module.go | 11 +++----- types/module/module.go | 51 +++---------------------------------- types/module/module_test.go | 12 --------- x/upgrade/module.go | 1 - 4 files changed, 7 insertions(+), 68 deletions(-) diff --git a/types/module/core_module.go b/types/module/core_module.go index e6d3afaf0be4..1060edde4357 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -19,7 +19,7 @@ import ( var ( _ AppModuleBasic = coreAppModuleBasicAdaptor{} - _ HasGenesis = coreAppModuleBasicAdaptor{} + _ HasABCIGenesis = coreAppModuleBasicAdaptor{} _ HasServices = coreAppModuleBasicAdaptor{} ) @@ -107,7 +107,7 @@ func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx sdk.Context, cdc codec.JSON } // InitGenesis implements HasGenesis -func (c coreAppModuleBasicAdaptor) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { +func (c coreAppModuleBasicAdaptor) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { if module, ok := c.module.(appmodule.HasGenesis); ok { // core API genesis source, err := genesis.SourceFromRawJSON(bz) @@ -123,13 +123,10 @@ func (c coreAppModuleBasicAdaptor) InitGenesis(ctx sdk.Context, cdc codec.JSONCo if mod, ok := c.module.(HasGenesis); ok { mod.InitGenesis(ctx, cdc, bz) + return nil } -} - -// InitGenesis implements HasGenesis -func (c coreAppModuleBasicAdaptor) InitABCIGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { if mod, ok := c.module.(HasABCIGenesis); ok { - return mod.InitABCIGenesis(ctx, cdc, bz) + return mod.InitGenesis(ctx, cdc, bz) } return nil } diff --git a/types/module/module.go b/types/module/module.go index 1eb3f8ada2f8..5bd4c43e85eb 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -182,12 +182,6 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { } } -// AppModuleGenesis is the standard form for an application module genesis functions -type AppModuleGenesis interface { - AppModuleBasic - HasGenesisBasics -} - // HasGenesis is the extension interface for stateful genesis methods. type HasGenesis interface { HasGenesisBasics @@ -197,7 +191,7 @@ type HasGenesis interface { type HasABCIGenesis interface { HasGenesisBasics - InitABCIGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate + InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage } @@ -233,44 +227,6 @@ type HasABCIEndblock interface { EndBlock(context.Context) ([]abci.ValidatorUpdate, error) } -// GenesisOnlyAppModule is an AppModule that only has import/export functionality -type GenesisOnlyAppModule struct { - AppModuleGenesis -} - -// NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object -func NewGenesisOnlyAppModule(amg AppModuleGenesis) GenesisOnlyAppModule { - return GenesisOnlyAppModule{ - AppModuleGenesis: amg, - } -} - -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (GenesisOnlyAppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (GenesisOnlyAppModule) IsAppModule() {} - -// RegisterInvariants is a placeholder function register no invariants -func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// QuerierRoute returns an empty module querier route -func (GenesisOnlyAppModule) QuerierRoute() string { return "" } - -// RegisterServices registers all services. -func (gam GenesisOnlyAppModule) RegisterServices(Configurator) {} - -// ConsensusVersion implements AppModule/ConsensusVersion. -func (gam GenesisOnlyAppModule) ConsensusVersion() uint64 { return 1 } - -// BeginBlock returns an empty module begin-block -func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context) error { return nil } - -// EndBlock returns an empty module end-block -func (GenesisOnlyAppModule) EndBlock(sdk.Context) ([]abci.ValidatorUpdate, error) { - return []abci.ValidatorUpdate{}, nil -} - // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { @@ -476,7 +432,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData module.InitGenesis(ctx, cdc, genesisData[moduleName]) } else if module, ok := mod.(HasABCIGenesis); ok { ctx.Logger().Debug("running initialization for module", "module", moduleName) - moduleValUpdates := module.InitABCIGenesis(ctx, cdc, genesisData[moduleName]) + moduleValUpdates := module.InitGenesis(ctx, cdc, genesisData[moduleName]) // use these validator updates if provided, the module manager assumes // only one module will update the validator set @@ -702,10 +658,9 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver module1, ok := m.Modules[moduleName].(HasGenesis) if ok { module1.InitGenesis(sdkCtx, c.cdc, module1.DefaultGenesis(c.cdc)) - } if module2, ok := m.Modules[moduleName].(HasABCIGenesis); ok { - moduleValUpdates := module2.InitABCIGenesis(sdkCtx, c.cdc, module1.DefaultGenesis(c.cdc)) + moduleValUpdates := module2.InitGenesis(sdkCtx, c.cdc, module1.DefaultGenesis(c.cdc)) // The module manager assumes only one module will update the // validator set, and it can't be a new module. if len(moduleValUpdates) > 0 { diff --git a/types/module/module_test.go b/types/module/module_test.go index 7e77a98a453c..f73d10986d61 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -92,18 +92,6 @@ func TestBasicManager(t *testing.T) { require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, expDefaultGenesis)) } -func TestGenesisOnlyAppModule(t *testing.T) { - mockCtrl := gomock.NewController(t) - t.Cleanup(mockCtrl.Finish) - - mockModule := mock.NewMockAppModuleGenesis(mockCtrl) - mockInvariantRegistry := mock.NewMockInvariantRegistry(mockCtrl) - goam := module.NewGenesisOnlyAppModule(mockModule) - - // no-op - goam.RegisterInvariants(mockInvariantRegistry) -} - func TestAssertNoForgottenModules(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 336780fb85aa..9ae3b1a9fbb7 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -133,7 +133,6 @@ func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMe panic(err) } } - } // DefaultGenesis is an empty object