Skip to content

Commit

Permalink
minor cleanup from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Aug 27, 2023
1 parent f3f033f commit f1576d7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 68 deletions.
11 changes: 4 additions & 7 deletions types/module/core_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var (
_ AppModuleBasic = coreAppModuleBasicAdaptor{}
_ HasGenesis = coreAppModuleBasicAdaptor{}
_ HasABCIGenesis = coreAppModuleBasicAdaptor{}
_ HasServices = coreAppModuleBasicAdaptor{}
)

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
51 changes: 3 additions & 48 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMe
panic(err)
}
}

}

// DefaultGenesis is an empty object
Expand Down

0 comments on commit f1576d7

Please sign in to comment.