Skip to content

Commit

Permalink
chore: remove params dep from crisis, gov and mint (#17837)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Sep 22, 2023
1 parent 076ab3b commit d5c78a6
Show file tree
Hide file tree
Showing 37 changed files with 44 additions and 1,809 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#17818](https://github.com/cosmos/cosmos-sdk/pull/17818) Remove params requirement from `NewAppModule`
* (x/slashing & x/auth) [#17820](https://github.com/cosmos/cosmos-sdk/pull/17820) Remove params requirement from `NewAppModule`
* (x/distribution & x/staking) [#17834](https://github.com/cosmos/cosmos-sdk/pull/17834) Remove params requirement from `NewAppModule`
* (x/mint & x/gov & x/crisis) [#17837](https://github.com/cosmos/cosmos-sdk/pull/17837) Remove params requirement from `NewAppModule`

### Client Breaking Changes

Expand Down
6 changes: 3 additions & 3 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ func NewSimApp(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func initFixture(tb testing.TB) *fixture {
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
distrModule := distribution.NewAppModule(cdc, distrKeeper, accountKeeper, bankKeeper, stakingKeeper)
govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper, nil)
govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{
authtypes.ModuleName: authModule,
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Example() {
// here bankkeeper and staking keeper is nil because we are not testing them
// subspace is nil because we don't test params (which is legacy anyway)
mintKeeper := mintkeeper.NewKeeper(encodingCfg.Codec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), nil, accountKeeper, nil, authtypes.FeeCollectorName, authority)
mintModule := mint.NewAppModule(encodingCfg.Codec, mintKeeper, accountKeeper, nil, nil)
mintModule := mint.NewAppModule(encodingCfg.Codec, mintKeeper, accountKeeper, nil)

// create the application and register all the modules from the previous step
integrationApp := integration.NewIntegrationApp(
Expand Down
18 changes: 0 additions & 18 deletions x/crisis/exported/exported.go

This file was deleted.

12 changes: 4 additions & 8 deletions x/crisis/keeper/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/exported"
v2 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v2"
)

// Migrator is a struct for handling in-place state migrations.
type Migrator struct {
keeper *Keeper
legacySubspace exported.Subspace
keeper *Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(k *Keeper, ss exported.Subspace) Migrator {
func NewMigrator(k *Keeper) Migrator {
return Migrator{
keeper: k,
legacySubspace: ss,
keeper: k,
}
}

Expand All @@ -25,5 +21,5 @@ func NewMigrator(k *Keeper, ss exported.Subspace) Migrator {
// and managed by the x/params modules and stores them directly into the x/crisis
// module state.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
return nil
}
40 changes: 0 additions & 40 deletions x/crisis/migrations/v2/migrate.go

This file was deleted.

47 changes: 0 additions & 47 deletions x/crisis/migrations/v2/migrate_test.go

This file was deleted.

14 changes: 3 additions & 11 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
"github.com/cosmos/cosmos-sdk/x/crisis/exported"
"github.com/cosmos/cosmos-sdk/x/crisis/keeper"
"github.com/cosmos/cosmos-sdk/x/crisis/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -101,21 +100,17 @@ type AppModule struct {
// executed.
keeper *keeper.Keeper

// legacySubspace is used solely for migration of x/params managed parameters
legacySubspace exported.Subspace

skipGenesisInvariants bool
}

// NewAppModule creates a new AppModule object. If initChainAssertInvariants is set,
// we will call keeper.AssertInvariants during InitGenesis (it may take a significant time)
// - which doesn't impact the chain security unless 66+% of validators have a wrongly
// modified genesis file.
func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool, ss exported.Subspace) AppModule {
func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
legacySubspace: ss,

skipGenesisInvariants: skipGenesisInvariants,
}
Expand All @@ -136,7 +131,7 @@ func AddModuleInitFlags(startCmd *cobra.Command) {
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)

m := keeper.NewMigrator(am.keeper, am.legacySubspace)
m := keeper.NewMigrator(am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
}
Expand Down Expand Up @@ -192,9 +187,6 @@ type ModuleInputs struct {

BankKeeper types.SupplyKeeper
AddressCodec address.Codec

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace exported.Subspace `optional:"true"`
}

type ModuleOutputs struct {
Expand Down Expand Up @@ -236,7 +228,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
skipGenesisInvariants = cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants))
}

m := NewAppModule(k, skipGenesisInvariants, in.LegacySubspace)
m := NewAppModule(k, skipGenesisInvariants)

return ModuleOutputs{CrisisKeeper: k, Module: m}
}
18 changes: 0 additions & 18 deletions x/gov/exported/exported.go

This file was deleted.

18 changes: 6 additions & 12 deletions x/gov/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,34 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/exported"
v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2"
v3 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v3"
v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4"
v5 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v5"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper *Keeper
legacySubspace exported.ParamSubspace
keeper *Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper *Keeper, legacySubspace exported.ParamSubspace) Migrator {
func NewMigrator(keeper *Keeper) Migrator {
return Migrator{
keeper: keeper,
legacySubspace: legacySubspace,
keeper: keeper,
}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
return nil
}

// Migrate2to3 migrates from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
return nil
}

// Migrate3to4 migrates from version 3 to 4.
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v4.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
return nil
}

// Migrate4to5 migrates from version 4 to 5.
Expand Down
Loading

0 comments on commit d5c78a6

Please sign in to comment.