From e756d025d39ed8d896e2de418c6a5eb9b87f64f2 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 10:11:46 +0200 Subject: [PATCH 01/11] remove params dep from crisis, gov and mint --- simapp/app.go | 6 +- tests/integration/gov/keeper/keeper_test.go | 2 +- testutil/integration/example_test.go | 2 +- x/crisis/exported/exported.go | 18 --- x/crisis/keeper/migrator.go | 12 +- x/crisis/migrations/v2/migrate.go | 40 ----- x/crisis/migrations/v2/migrate_test.go | 47 ------ x/crisis/module.go | 14 +- x/gov/keeper/migrations.go | 18 +-- x/gov/migrations/v1/types.go | 164 ------------------- x/gov/migrations/v2/json.go | 31 ---- x/gov/migrations/v2/json_test.go | 125 --------------- x/gov/migrations/v2/keys.go | 6 - x/gov/migrations/v2/store.go | 102 ------------ x/gov/migrations/v2/store_test.go | 117 -------------- x/gov/migrations/v3/convert.go | 5 + x/gov/migrations/v3/json.go | 34 ---- x/gov/migrations/v3/json_test.go | 165 -------------------- x/gov/migrations/v3/keys.go | 6 - x/gov/migrations/v3/store.go | 98 ------------ x/gov/migrations/v3/store_test.go | 98 ------------ x/gov/migrations/v4/json.go | 41 ----- x/gov/migrations/v4/json_test.go | 98 ------------ x/gov/migrations/v4/keys.go | 28 ---- x/gov/migrations/v4/store.go | 138 ---------------- x/gov/migrations/v4/store_test.go | 138 ---------------- x/gov/migrations/v5/store.go | 10 +- x/gov/migrations/v5/store_test.go | 5 +- x/gov/module.go | 13 +- x/gov/types/expected_keepers.go | 6 - x/mint/exported/exported.go | 18 --- x/mint/keeper/migrator.go | 12 +- x/mint/migrations/v2/migrate.go | 37 ----- x/mint/migrations/v2/migrator_test.go | 50 ------ x/mint/module.go | 13 +- 35 files changed, 41 insertions(+), 1676 deletions(-) delete mode 100644 x/crisis/exported/exported.go delete mode 100644 x/crisis/migrations/v2/migrate.go delete mode 100644 x/crisis/migrations/v2/migrate_test.go delete mode 100644 x/gov/migrations/v1/types.go delete mode 100644 x/gov/migrations/v2/json.go delete mode 100644 x/gov/migrations/v2/json_test.go delete mode 100644 x/gov/migrations/v2/keys.go delete mode 100644 x/gov/migrations/v2/store.go delete mode 100644 x/gov/migrations/v2/store_test.go delete mode 100644 x/gov/migrations/v3/json.go delete mode 100644 x/gov/migrations/v3/json_test.go delete mode 100644 x/gov/migrations/v3/keys.go delete mode 100644 x/gov/migrations/v3/store.go delete mode 100644 x/gov/migrations/v3/store_test.go delete mode 100644 x/gov/migrations/v4/json.go delete mode 100644 x/gov/migrations/v4/json_test.go delete mode 100644 x/gov/migrations/v4/keys.go delete mode 100644 x/gov/migrations/v4/store.go delete mode 100644 x/gov/migrations/v4/store_test.go delete mode 100644 x/mint/exported/exported.go delete mode 100644 x/mint/migrations/v2/migrate.go delete mode 100644 x/mint/migrations/v2/migrator_test.go diff --git a/simapp/app.go b/simapp/app.go index 6439a13816c7..68cee5a26e7a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -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), diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 771a1dcc25be..2dfafdd05060 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -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, diff --git a/testutil/integration/example_test.go b/testutil/integration/example_test.go index d2607773b48b..9a82d366acfb 100644 --- a/testutil/integration/example_test.go +++ b/testutil/integration/example_test.go @@ -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( diff --git a/x/crisis/exported/exported.go b/x/crisis/exported/exported.go deleted file mode 100644 index 8b43ec74fca4..000000000000 --- a/x/crisis/exported/exported.go +++ /dev/null @@ -1,18 +0,0 @@ -package exported - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -type ( - ParamSet = paramtypes.ParamSet - - // Subspace defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - Subspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - } -) diff --git a/x/crisis/keeper/migrator.go b/x/crisis/keeper/migrator.go index f3b692bebd0f..fe4c0d8cf599 100644 --- a/x/crisis/keeper/migrator.go +++ b/x/crisis/keeper/migrator.go @@ -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, } } @@ -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 } diff --git a/x/crisis/migrations/v2/migrate.go b/x/crisis/migrations/v2/migrate.go deleted file mode 100644 index 47a34433b07a..000000000000 --- a/x/crisis/migrations/v2/migrate.go +++ /dev/null @@ -1,40 +0,0 @@ -package v2 - -import ( - storetypes "cosmossdk.io/core/store" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/crisis/exported" -) - -const ( - ModuleName = "crisis" -) - -var ( - ConstantFee = []byte("ConstantFee") - ConstantFeeKey = []byte{0x01} -) - -// MigrateStore migrates the x/crisis module state from the consensus version 1 to -// version 2. Specifically, it takes the `ConstantFee` parameter that is currently stored -// and managed by the x/params module and stores it directly into the x/crisis -// module state. -func MigrateStore(ctx sdk.Context, storeService storetypes.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { - store := storeService.OpenKVStore(ctx) - var currConstantFee sdk.Coin - legacySubspace.Get(ctx, ConstantFee, &currConstantFee) - - if !currConstantFee.IsValid() { - return errors.ErrInvalidCoins.Wrap("constant fee") - } - - bz, err := cdc.Marshal(&currConstantFee) - if err != nil { - return err - } - - return store.Set(ConstantFeeKey, bz) -} diff --git a/x/crisis/migrations/v2/migrate_test.go b/x/crisis/migrations/v2/migrate_test.go deleted file mode 100644 index c1dddc05a53b..000000000000 --- a/x/crisis/migrations/v2/migrate_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package v2_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/crisis" - v2 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v2" - "github.com/cosmos/cosmos-sdk/x/crisis/types" -) - -type mockSubspace struct { - constantFee sdk.Coin -} - -func newMockSubspace(fee sdk.Coin) mockSubspace { - return mockSubspace{constantFee: fee} -} - -func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { - *ptr.(*sdk.Coin) = ms.constantFee -} - -func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}).Codec - storeKey := storetypes.NewKVStoreKey(v2.ModuleName) - storeService := runtime.NewKVStoreService(storeKey) - tKey := storetypes.NewTransientStoreKey("transient_test") - ctx := testutil.DefaultContext(storeKey, tKey) - store := ctx.KVStore(storeKey) - - legacySubspace := newMockSubspace(types.DefaultGenesisState().ConstantFee) - require.NoError(t, v2.MigrateStore(ctx, storeService, legacySubspace, cdc)) - - var res sdk.Coin - bz := store.Get(v2.ConstantFeeKey) - require.NoError(t, cdc.Unmarshal(bz, &res)) - require.NotNil(t, res) - require.Equal(t, legacySubspace.constantFee, res) -} diff --git a/x/crisis/module.go b/x/crisis/module.go index 87bb60efa273..d6308f1018d8 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -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" @@ -101,9 +100,6 @@ type AppModule struct { // executed. keeper *keeper.Keeper - // legacySubspace is used solely for migration of x/params managed parameters - legacySubspace exported.Subspace - skipGenesisInvariants bool } @@ -111,11 +107,10 @@ type AppModule struct { // 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, } @@ -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)) } @@ -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 { @@ -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} } diff --git a/x/gov/keeper/migrations.go b/x/gov/keeper/migrations.go index af12c2e5a8a8..c8190275c02d 100644 --- a/x/gov/keeper/migrations.go +++ b/x/gov/keeper/migrations.go @@ -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. diff --git a/x/gov/migrations/v1/types.go b/x/gov/migrations/v1/types.go deleted file mode 100644 index 74d671ce55bd..000000000000 --- a/x/gov/migrations/v1/types.go +++ /dev/null @@ -1,164 +0,0 @@ -package v1 - -// Package v1 (v0.40) is copy-pasted from: -// https://github.com/cosmos/cosmos-sdk/blob/v0.41.0/x/gov/types/keys.go - -import ( - "encoding/binary" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/kv" -) - -const ( - // ModuleName is the name of the module - ModuleName = "gov" - - // StoreKey is the store key string for gov - StoreKey = ModuleName - - // RouterKey is the message route for gov - RouterKey = ModuleName - - // QuerierRoute is the querier route for gov - QuerierRoute = ModuleName - - addrLen = 20 -) - -// Keys for governance store -// Items are stored with the following key: values -// -// - 0x00: Proposal -// -// - 0x01: activeProposalID -// -// - 0x02: inactiveProposalID -// -// - 0x03: nextProposalID -// -// - 0x10: Deposit -// -// - 0x20: Voter -var ( - ProposalsKeyPrefix = []byte{0x00} - ActiveProposalQueuePrefix = []byte{0x01} - InactiveProposalQueuePrefix = []byte{0x02} - ProposalIDKey = []byte{0x03} - - DepositsKeyPrefix = []byte{0x10} - - VotesKeyPrefix = []byte{0x20} -) - -var lenTime = len(sdk.FormatTimeBytes(time.Now())) - -// GetProposalIDBytes returns the byte representation of the proposalID -func GetProposalIDBytes(proposalID uint64) (proposalIDBz []byte) { - proposalIDBz = make([]byte, 8) - binary.BigEndian.PutUint64(proposalIDBz, proposalID) - return -} - -// GetProposalIDFromBytes returns proposalID in uint64 format from a byte array -func GetProposalIDFromBytes(bz []byte) (proposalID uint64) { - return binary.BigEndian.Uint64(bz) -} - -// ProposalKey gets a specific proposal from the store -func ProposalKey(proposalID uint64) []byte { - return append(ProposalsKeyPrefix, GetProposalIDBytes(proposalID)...) -} - -// ActiveProposalByTimeKey gets the active proposal queue key by endTime -func ActiveProposalByTimeKey(endTime time.Time) []byte { - return append(ActiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...) -} - -// ActiveProposalQueueKey returns the key for a proposalID in the activeProposalQueue -func ActiveProposalQueueKey(proposalID uint64, endTime time.Time) []byte { - return append(ActiveProposalByTimeKey(endTime), GetProposalIDBytes(proposalID)...) -} - -// InactiveProposalByTimeKey gets the inactive proposal queue key by endTime -func InactiveProposalByTimeKey(endTime time.Time) []byte { - return append(InactiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...) -} - -// InactiveProposalQueueKey returns the key for a proposalID in the inactiveProposalQueue -func InactiveProposalQueueKey(proposalID uint64, endTime time.Time) []byte { - return append(InactiveProposalByTimeKey(endTime), GetProposalIDBytes(proposalID)...) -} - -// DepositsKey gets the first part of the deposits key based on the proposalID -func DepositsKey(proposalID uint64) []byte { - return append(DepositsKeyPrefix, GetProposalIDBytes(proposalID)...) -} - -// DepositKey key of a specific deposit from the store -func DepositKey(proposalID uint64, depositorAddr sdk.AccAddress) []byte { - return append(DepositsKey(proposalID), depositorAddr.Bytes()...) -} - -// VotesKey gets the first part of the votes key based on the proposalID -func VotesKey(proposalID uint64) []byte { - return append(VotesKeyPrefix, GetProposalIDBytes(proposalID)...) -} - -// VoteKey key of a specific vote from the store -func VoteKey(proposalID uint64, voterAddr sdk.AccAddress) []byte { - return append(VotesKey(proposalID), voterAddr.Bytes()...) -} - -// Split keys function; used for iterators - -// SplitProposalKey split the proposal key and returns the proposal id -func SplitProposalKey(key []byte) (proposalID uint64) { - kv.AssertKeyLength(key[1:], 8) - - return GetProposalIDFromBytes(key[1:]) -} - -// SplitActiveProposalQueueKey split the active proposal key and returns the proposal id and endTime -func SplitActiveProposalQueueKey(key []byte) (proposalID uint64, endTime time.Time) { - return splitKeyWithTime(key) -} - -// SplitInactiveProposalQueueKey split the inactive proposal key and returns the proposal id and endTime -func SplitInactiveProposalQueueKey(key []byte) (proposalID uint64, endTime time.Time) { - return splitKeyWithTime(key) -} - -// SplitKeyDeposit split the deposits key and returns the proposal id and depositor address -func SplitKeyDeposit(key []byte) (proposalID uint64, depositorAddr sdk.AccAddress) { - return splitKeyWithAddress(key) -} - -// SplitKeyVote split the votes key and returns the proposal id and voter address -func SplitKeyVote(key []byte) (proposalID uint64, voterAddr sdk.AccAddress) { - return splitKeyWithAddress(key) -} - -// private functions - -func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) { - kv.AssertKeyLength(key[1:], 8+lenTime) - - endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime]) - if err != nil { - panic(err) - } - - proposalID = GetProposalIDFromBytes(key[1+lenTime:]) - return -} - -func splitKeyWithAddress(key []byte) (proposalID uint64, addr sdk.AccAddress) { - kv.AssertKeyLength(key[1:], 8+addrLen) - - kv.AssertKeyAtLeastLength(key, 10) - proposalID = GetProposalIDFromBytes(key[1:9]) - addr = sdk.AccAddress(key[9:]) - return -} diff --git a/x/gov/migrations/v2/json.go b/x/gov/migrations/v2/json.go deleted file mode 100644 index 5d44a0de0ff2..000000000000 --- a/x/gov/migrations/v2/json.go +++ /dev/null @@ -1,31 +0,0 @@ -package v2 - -import ( - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -// migrateJSONWeightedVotes migrates the ADR-037 weighted votes. -func migrateJSONWeightedVotes(oldVotes v1beta1.Votes) v1beta1.Votes { - newVotes := make(v1beta1.Votes, len(oldVotes)) - for i, oldVote := range oldVotes { - newVotes[i] = migrateVote(oldVote) - } - - return newVotes -} - -// MigrateJSON accepts exported v1 (v0.40) x/gov genesis state and migrates it to -// v2 (v0.43) x/gov genesis state. The migration includes: -// -// - Gov weighted votes. -func MigrateJSON(oldState *v1beta1.GenesisState) *v1beta1.GenesisState { - return &v1beta1.GenesisState{ - StartingProposalId: oldState.StartingProposalId, - Deposits: oldState.Deposits, - Votes: migrateJSONWeightedVotes(oldState.Votes), - Proposals: oldState.Proposals, - DepositParams: oldState.DepositParams, - VotingParams: oldState.VotingParams, - TallyParams: oldState.TallyParams, - } -} diff --git a/x/gov/migrations/v2/json_test.go b/x/gov/migrations/v2/json_test.go deleted file mode 100644 index 9203bf014943..000000000000 --- a/x/gov/migrations/v2/json_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package v2_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -func TestMigrateJSON(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig() - clientCtx := client.Context{}. - WithInterfaceRegistry(encodingConfig.InterfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). - WithCodec(encodingConfig.Codec) - - voter, err := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh") - require.NoError(t, err) - govGenState := &v1beta1.GenesisState{ - Votes: v1beta1.Votes{ - v1beta1.Vote{ProposalId: 1, Voter: voter.String(), Option: v1beta1.OptionAbstain}, - v1beta1.Vote{ProposalId: 2, Voter: voter.String(), Option: v1beta1.OptionEmpty}, - v1beta1.Vote{ProposalId: 3, Voter: voter.String(), Option: v1beta1.OptionNo}, - v1beta1.Vote{ProposalId: 4, Voter: voter.String(), Option: v1beta1.OptionNoWithVeto}, - v1beta1.Vote{ProposalId: 5, Voter: voter.String(), Option: v1beta1.OptionYes}, - }, - } - - migrated := v2.MigrateJSON(govGenState) - - bz, err := clientCtx.Codec.MarshalJSON(migrated) - require.NoError(t, err) - - // Indent the JSON bz correctly. - var jsonObj map[string]interface{} - err = json.Unmarshal(bz, &jsonObj) - require.NoError(t, err) - indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") - require.NoError(t, err) - - // Make sure about: - // - Votes are all ADR-037 weighted votes with weight 1. - expected := `{ - "deposit_params": { - "max_deposit_period": "0s", - "min_deposit": [] - }, - "deposits": [], - "proposals": [], - "starting_proposal_id": "0", - "tally_params": { - "quorum": "0", - "threshold": "0", - "veto_threshold": "0" - }, - "votes": [ - { - "option": "VOTE_OPTION_UNSPECIFIED", - "options": [ - { - "option": "VOTE_OPTION_ABSTAIN", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "1", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - }, - { - "option": "VOTE_OPTION_UNSPECIFIED", - "options": [ - { - "option": "VOTE_OPTION_UNSPECIFIED", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "2", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - }, - { - "option": "VOTE_OPTION_UNSPECIFIED", - "options": [ - { - "option": "VOTE_OPTION_NO", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "3", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - }, - { - "option": "VOTE_OPTION_UNSPECIFIED", - "options": [ - { - "option": "VOTE_OPTION_NO_WITH_VETO", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "4", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - }, - { - "option": "VOTE_OPTION_UNSPECIFIED", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "5", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - } - ], - "voting_params": { - "voting_period": "0s" - } -}` - - require.Equal(t, expected, string(indentedBz)) -} diff --git a/x/gov/migrations/v2/keys.go b/x/gov/migrations/v2/keys.go deleted file mode 100644 index fcedde0a5f46..000000000000 --- a/x/gov/migrations/v2/keys.go +++ /dev/null @@ -1,6 +0,0 @@ -package v2 - -const ( - // ModuleName is the name of the module - ModuleName = "gov" -) diff --git a/x/gov/migrations/v2/store.go b/x/gov/migrations/v2/store.go deleted file mode 100644 index 151df2f55bd4..000000000000 --- a/x/gov/migrations/v2/store.go +++ /dev/null @@ -1,102 +0,0 @@ -package v2 - -import ( - "fmt" - - corestoretypes "cosmossdk.io/core/store" - "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -const proposalIDLen = 8 - -// migratePrefixProposalAddress is a helper function that migrates all keys of format: -// -// into format: -// -func migratePrefixProposalAddress(store corestoretypes.KVStore, prefixBz []byte) error { - oldStore := prefix.NewStore(runtime.KVStoreAdapter(store), prefixBz) - - oldStoreIter := oldStore.Iterator(nil, nil) - defer oldStoreIter.Close() - - for ; oldStoreIter.Valid(); oldStoreIter.Next() { - proposalID := oldStoreIter.Key()[:proposalIDLen] - addr := oldStoreIter.Key()[proposalIDLen:] - newStoreKey := append(append(prefixBz, proposalID...), address.MustLengthPrefix(addr)...) - - // Set new key on store. Values don't change. - err := store.Set(newStoreKey, oldStoreIter.Value()) - if err != nil { - return err - } - oldStore.Delete(oldStoreIter.Key()) - } - return nil -} - -// migrateStoreWeightedVotes migrates a legacy vote to an ADR-037 weighted vote. -// Important: the `oldVote` has its `Option` field set, whereas the new weighted -// vote has its `Options` field set. -func migrateVote(oldVote v1beta1.Vote) v1beta1.Vote { - return v1beta1.Vote{ - ProposalId: oldVote.ProposalId, - Voter: oldVote.Voter, - Options: v1beta1.NewNonSplitVoteOption(oldVote.Option), - } -} - -// migrateStoreWeightedVotes migrates in-place all legacy votes to ADR-037 weighted votes. -func migrateStoreWeightedVotes(store corestoretypes.KVStore, cdc codec.BinaryCodec) error { - iterator := storetypes.KVStorePrefixIterator(runtime.KVStoreAdapter(store), types.VotesKeyPrefix) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - var oldVote v1beta1.Vote - err := cdc.Unmarshal(iterator.Value(), &oldVote) - if err != nil { - return err - } - - newVote := migrateVote(oldVote) - fmt.Println("migrateStoreWeightedVotes newVote=", newVote) - bz, err := cdc.Marshal(&newVote) - if err != nil { - return err - } - - err = store.Set(iterator.Key(), bz) - if err != nil { - return err - } - } - - return nil -} - -// MigrateStore performs in-place store migrations from v1 (v0.40) to v2 (v0.43). The -// migration includes: -// -// - Change addresses to be length-prefixed. -// - Change all legacy votes to ADR-037 weighted votes. -func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error { - store := storeService.OpenKVStore(ctx) - err := migratePrefixProposalAddress(store, types.DepositsKeyPrefix) - if err != nil { - return err - } - - err = migratePrefixProposalAddress(store, types.VotesKeyPrefix) - if err != nil { - return err - } - - return migrateStoreWeightedVotes(store, cdc) -} diff --git a/x/gov/migrations/v2/store_test.go b/x/gov/migrations/v2/store_test.go deleted file mode 100644 index a5c8cf9dc095..000000000000 --- a/x/gov/migrations/v2/store_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package v2_test - -import ( - "bytes" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" - v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2" - "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec - govKey := storetypes.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) - store := ctx.KVStore(govKey) - - _, _, addr1 := testdata.KeyTestPubAddr() - proposalID := uint64(6) - now := time.Now() - // Use dummy value for keys where we don't test values. - dummyValue := []byte("foo") - // Use real values for votes, as we're testing weighted votes. - oldVote := v1beta1.Vote{ProposalId: 1, Voter: "foobar", Option: v1beta1.OptionNoWithVeto} - oldVoteValue := cdc.MustMarshal(&oldVote) - newVote := v1beta1.Vote{ProposalId: 1, Voter: "foobar", Options: v1beta1.WeightedVoteOptions{{Option: v1beta1.OptionNoWithVeto, Weight: math.LegacyNewDec(1)}}} - newVoteValue := cdc.MustMarshal(&newVote) - - testCases := []struct { - name string - oldKey, oldValue, newKey, newValue []byte - }{ - { - "ProposalKey", - v1.ProposalKey(proposalID), dummyValue, - append(types.ProposalsKeyPrefix, sdk.Uint64ToBigEndian(proposalID)...), dummyValue, - }, - { - "ActiveProposalQueue", - v1.ActiveProposalQueueKey(proposalID, now), dummyValue, - activeProposalQueueKey(proposalID, now), dummyValue, - }, - { - "InactiveProposalQueue", - v1.InactiveProposalQueueKey(proposalID, now), dummyValue, - inactiveProposalQueueKey(proposalID, now), dummyValue, - }, - { - "ProposalIDKey", - v1.ProposalIDKey, dummyValue, - types.ProposalIDKey, dummyValue, - }, - { - "DepositKey", - v1.DepositKey(proposalID, addr1), dummyValue, - depositKey(proposalID, addr1), dummyValue, - }, - { - "VotesKeyPrefix", - v1.VoteKey(proposalID, addr1), oldVoteValue, - voteKey(proposalID, addr1), newVoteValue, - }, - } - - // Set all the old keys to the store - for _, tc := range testCases { - store.Set(tc.oldKey, tc.oldValue) - } - - // Run migratio - storeService := runtime.NewKVStoreService(govKey) - err := v2.MigrateStore(ctx, storeService, cdc) - require.NoError(t, err) - - // Make sure the new keys are set and old keys are deleted. - for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { - if !bytes.Equal(tc.oldKey, tc.newKey) { - require.Nil(t, store.Get(tc.oldKey)) - } - require.Equal(t, tc.newValue, store.Get(tc.newKey)) - }) - } -} - -// TODO(tip): remove all the functions below once we delete the migrations - -func depositKey(proposalID uint64, depositorAddr sdk.AccAddress) []byte { - return append(append(types.DepositsKeyPrefix, sdk.Uint64ToBigEndian(proposalID)...), address.MustLengthPrefix(depositorAddr.Bytes())...) -} - -func voteKey(proposalID uint64, addr sdk.AccAddress) []byte { - return append(append(types.VotesKeyPrefix, sdk.Uint64ToBigEndian(proposalID)...), address.MustLengthPrefix(addr.Bytes())...) -} - -func activeProposalQueueKey(proposalID uint64, endTime time.Time) []byte { - return append(append(types.ActiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...), sdk.Uint64ToBigEndian(proposalID)...) -} - -// InactiveProposalQueueKey returns the key for a proposalID in the inactiveProposalQueue -func inactiveProposalQueueKey(proposalID uint64, endTime time.Time) []byte { - return append(append(types.InactiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...), sdk.Uint64ToBigEndian(proposalID)...) -} diff --git a/x/gov/migrations/v3/convert.go b/x/gov/migrations/v3/convert.go index b9d18bd56984..551401b3fb58 100644 --- a/x/gov/migrations/v3/convert.go +++ b/x/gov/migrations/v3/convert.go @@ -13,6 +13,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) +const ( + // ModuleName is the name of the module + ModuleName = "gov" +) + // ConvertToLegacyProposal takes a new proposal and attempts to convert it to the // legacy proposal format. This conversion is best effort. New proposal types that // don't have a legacy message will return a "nil" content. diff --git a/x/gov/migrations/v3/json.go b/x/gov/migrations/v3/json.go deleted file mode 100644 index 06f1c82082ad..000000000000 --- a/x/gov/migrations/v3/json.go +++ /dev/null @@ -1,34 +0,0 @@ -package v3 - -import ( - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -// MigrateJSON accepts exported v2 (v0.43) x/gov genesis state and migrates it to -// v3 (V0.46) x/gov genesis state. The migration includes: -// -// - Updating everything to v1. -// - Migrating proposals to be Msg-based. -func MigrateJSON(oldState *v1beta1.GenesisState) (*v1.GenesisState, error) { - newProps, err := convertToNewProposals(oldState.Proposals) - if err != nil { - return nil, err - } - newVotes, err := convertToNewVotes(oldState.Votes) - if err != nil { - return nil, err - } - - depParams, votingParms, tallyParams := convertToNewDepParams(oldState.DepositParams), convertToNewVotingParams(oldState.VotingParams), convertToNewTallyParams(oldState.TallyParams) - - return &v1.GenesisState{ - StartingProposalId: oldState.StartingProposalId, - Deposits: convertToNewDeposits(oldState.Deposits), - Votes: newVotes, - Proposals: newProps, - DepositParams: &depParams, - VotingParams: &votingParms, - TallyParams: &tallyParams, - }, nil -} diff --git a/x/gov/migrations/v3/json_test.go b/x/gov/migrations/v3/json_test.go deleted file mode 100644 index a9089cf68626..000000000000 --- a/x/gov/migrations/v3/json_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package v3_test - -import ( - "encoding/json" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - "github.com/stretchr/testify/require" - - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/client" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/gov" - v3 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v3" - "github.com/cosmos/cosmos-sdk/x/gov/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -var voter = sdk.MustAccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh") - -func TestMigrateJSON(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) - clientCtx := client.Context{}. - WithInterfaceRegistry(encodingConfig.InterfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). - WithCodec(encodingConfig.Codec) - - govGenState := v1beta1.DefaultGenesisState() - propTime := time.Unix(1e9, 0) - contentAny, err := codectypes.NewAnyWithValue(v1beta1.NewTextProposal("my title", "my desc").(proto.Message)) - require.NoError(t, err) - govGenState.Proposals = v1beta1.Proposals{ - v1beta1.Proposal{ - ProposalId: 1, - Content: contentAny, - SubmitTime: propTime, - DepositEndTime: propTime, - VotingStartTime: propTime, - VotingEndTime: propTime, - Status: v1beta1.StatusDepositPeriod, - FinalTallyResult: v1beta1.EmptyTallyResult(), - TotalDeposit: sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(123))), - }, - } - govGenState.Votes = v1beta1.Votes{ - v1beta1.Vote{ProposalId: 1, Voter: voter.String(), Option: v1beta1.OptionAbstain}, - v1beta1.Vote{ProposalId: 2, Voter: voter.String(), Options: v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)}, - } - - migrated, err := v3.MigrateJSON(govGenState) - require.NoError(t, err) - - // Make sure the migrated proposal's Msg signer is the gov acct. - require.Equal(t, - authtypes.NewModuleAddress(types.ModuleName).String(), - migrated.Proposals[0].Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Authority, - ) - - bz, err := clientCtx.Codec.MarshalJSON(migrated) - require.NoError(t, err) - - // Indent the JSON bz correctly. - var jsonObj map[string]interface{} - err = json.Unmarshal(bz, &jsonObj) - require.NoError(t, err) - indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") - require.NoError(t, err) - - // Make sure about: - // - Proposals use MsgExecLegacyContent - expected := `{ - "constitution": "", - "deposit_params": { - "max_deposit_period": "172800s", - "min_deposit": [ - { - "amount": "10000000", - "denom": "stake" - } - ] - }, - "deposits": [], - "params": null, - "proposals": [ - { - "deposit_end_time": "2001-09-09T01:46:40Z", - "expedited": false, - "failed_reason": "", - "final_tally_result": { - "abstain_count": "0", - "no_count": "0", - "no_with_veto_count": "0", - "yes_count": "0" - }, - "id": "1", - "messages": [ - { - "@type": "/cosmos.gov.v1.MsgExecLegacyContent", - "authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - "content": { - "@type": "/cosmos.gov.v1beta1.TextProposal", - "description": "my desc", - "title": "my title" - } - } - ], - "metadata": "", - "proposer": "", - "status": "PROPOSAL_STATUS_DEPOSIT_PERIOD", - "submit_time": "2001-09-09T01:46:40Z", - "summary": "my desc", - "title": "my title", - "total_deposit": [ - { - "amount": "123", - "denom": "stake" - } - ], - "voting_end_time": "2001-09-09T01:46:40Z", - "voting_start_time": "2001-09-09T01:46:40Z" - } - ], - "starting_proposal_id": "1", - "tally_params": { - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000" - }, - "votes": [ - { - "metadata": "", - "options": [ - { - "option": "VOTE_OPTION_ABSTAIN", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "1", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - }, - { - "metadata": "", - "options": [ - { - "option": "VOTE_OPTION_NO", - "weight": "1.000000000000000000" - } - ], - "proposal_id": "2", - "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" - } - ], - "voting_params": { - "voting_period": "172800s" - } -}` - - require.Equal(t, expected, string(indentedBz)) -} diff --git a/x/gov/migrations/v3/keys.go b/x/gov/migrations/v3/keys.go deleted file mode 100644 index a4aa0fe28a70..000000000000 --- a/x/gov/migrations/v3/keys.go +++ /dev/null @@ -1,6 +0,0 @@ -package v3 - -const ( - // ModuleName is the name of the module - ModuleName = "gov" -) diff --git a/x/gov/migrations/v3/store.go b/x/gov/migrations/v3/store.go deleted file mode 100644 index b1a17b8ef202..000000000000 --- a/x/gov/migrations/v3/store.go +++ /dev/null @@ -1,98 +0,0 @@ -package v3 - -import ( - corestoretypes "cosmossdk.io/core/store" - "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -// migrateProposals migrates all legacy proposals into MsgExecLegacyContent -// proposals. -func migrateProposals(store storetypes.KVStore, cdc codec.BinaryCodec) error { - propStore := prefix.NewStore(store, v1.ProposalsKeyPrefix) - - iter := propStore.Iterator(nil, nil) - defer iter.Close() - - for ; iter.Valid(); iter.Next() { - var oldProp govv1beta1.Proposal - err := cdc.Unmarshal(iter.Value(), &oldProp) - if err != nil { - return err - } - - newProp, err := convertToNewProposal(oldProp) - if err != nil { - return err - } - bz, err := cdc.Marshal(&newProp) - if err != nil { - return err - } - - // Set new value on store. - propStore.Set(iter.Key(), bz) - } - - return nil -} - -// migrateVotes migrates all v1beta1 weighted votes (with sdk.Dec as weight) -// to v1 weighted votes (with string as weight) -func migrateVotes(store storetypes.KVStore, cdc codec.BinaryCodec) error { - votesStore := prefix.NewStore(store, v1.VotesKeyPrefix) - - iter := votesStore.Iterator(nil, nil) - defer iter.Close() - - for ; iter.Valid(); iter.Next() { - var oldVote govv1beta1.Vote - err := cdc.Unmarshal(iter.Value(), &oldVote) - if err != nil { - return err - } - - newVote := govv1.Vote{ - ProposalId: oldVote.ProposalId, - Voter: oldVote.Voter, - } - newOptions := make([]*govv1.WeightedVoteOption, len(oldVote.Options)) - for i, o := range oldVote.Options { - newOptions[i] = &govv1.WeightedVoteOption{ - Option: govv1.VoteOption(o.Option), - Weight: o.Weight.String(), // Convert to decimal string - } - } - newVote.Options = newOptions - bz, err := cdc.Marshal(&newVote) - if err != nil { - return err - } - - // Set new value on store. - votesStore.Set(iter.Key(), bz) - } - - return nil -} - -// MigrateStore performs in-place store migrations from v2 (v0.43) to v3 (v0.46). The -// migration includes: -// -// - Migrate proposals to be Msg-based. -func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error { - store := storeService.OpenKVStore(ctx) - - if err := migrateVotes(runtime.KVStoreAdapter(store), cdc); err != nil { - return err - } - - return migrateProposals(runtime.KVStoreAdapter(store), cdc) -} diff --git a/x/gov/migrations/v3/store_test.go b/x/gov/migrations/v3/store_test.go deleted file mode 100644 index 1937d5c37eb3..000000000000 --- a/x/gov/migrations/v3/store_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package v3_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/gov" - v1gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" - v3gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v3" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}).Codec - govKey := storetypes.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) - store := ctx.KVStore(govKey) - - propTime := time.Unix(1e9, 0) - - // Create 2 proposals - prop1, err := v1beta1.NewProposal(v1beta1.NewTextProposal("my title 1", "my desc 1"), 1, propTime, propTime) - require.NoError(t, err) - prop1Bz, err := cdc.Marshal(&prop1) - require.NoError(t, err) - prop2, err := v1beta1.NewProposal(v1beta1.NewTextProposal("my title 2", "my desc 2"), 2, propTime, propTime) - require.NoError(t, err) - require.NoError(t, err) - prop2Bz, err := cdc.Marshal(&prop2) - require.NoError(t, err) - - store.Set(v1gov.ProposalKey(prop1.ProposalId), prop1Bz) - store.Set(v1gov.ProposalKey(prop2.ProposalId), prop2Bz) - - // Vote on prop 1 - options := []v1beta1.WeightedVoteOption{ - {Option: v1beta1.OptionNo, Weight: math.LegacyMustNewDecFromStr("0.3")}, - {Option: v1beta1.OptionYes, Weight: math.LegacyMustNewDecFromStr("0.7")}, - } - vote1 := v1beta1.Vote{ProposalId: 1, Voter: voter.String(), Options: options} - vote1Bz := cdc.MustMarshal(&vote1) - store.Set(v1gov.VoteKey(1, voter), vote1Bz) - - // Run migrations. - storeService := runtime.NewKVStoreService(govKey) - err = v3gov.MigrateStore(ctx, storeService, cdc) - require.NoError(t, err) - - var newProp1 v1.Proposal - err = cdc.Unmarshal(store.Get(v1gov.ProposalKey(prop1.ProposalId)), &newProp1) - require.NoError(t, err) - compareProps(t, prop1, newProp1) - - var newProp2 v1.Proposal - err = cdc.Unmarshal(store.Get(v1gov.ProposalKey(prop2.ProposalId)), &newProp2) - require.NoError(t, err) - compareProps(t, prop2, newProp2) - - var newVote1 v1.Vote - err = cdc.Unmarshal(store.Get(v1gov.VoteKey(prop1.ProposalId, voter)), &newVote1) - require.NoError(t, err) - // Without the votes migration, we would have 300000000000000000 in state, - // because of how sdk.Dec stores itself in state. - require.Equal(t, "0.300000000000000000", newVote1.Options[0].Weight) - require.Equal(t, "0.700000000000000000", newVote1.Options[1].Weight) -} - -func compareProps(t *testing.T, oldProp v1beta1.Proposal, newProp v1.Proposal) { - t.Helper() - require.Equal(t, oldProp.ProposalId, newProp.Id) - require.Equal(t, oldProp.TotalDeposit.String(), sdk.Coins(newProp.TotalDeposit).String()) - require.Equal(t, oldProp.Status.String(), newProp.Status.String()) - require.Equal(t, oldProp.FinalTallyResult.Yes.String(), newProp.FinalTallyResult.YesCount) - require.Equal(t, oldProp.FinalTallyResult.No.String(), newProp.FinalTallyResult.NoCount) - require.Equal(t, oldProp.FinalTallyResult.NoWithVeto.String(), newProp.FinalTallyResult.NoWithVetoCount) - require.Equal(t, oldProp.FinalTallyResult.Abstain.String(), newProp.FinalTallyResult.AbstainCount) - - newContent := newProp.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content) - require.Equal(t, oldProp.Content.GetCachedValue().(v1beta1.Content), newContent) - - // Compare UNIX times, as a simple Equal gives difference between Local and - // UTC times. - // ref: https://github.com/golang/go/issues/19486#issuecomment-292968278 - require.Equal(t, oldProp.SubmitTime.Unix(), newProp.SubmitTime.Unix()) - require.Equal(t, oldProp.DepositEndTime.Unix(), newProp.DepositEndTime.Unix()) - require.Equal(t, oldProp.VotingStartTime.Unix(), newProp.VotingStartTime.Unix()) - require.Equal(t, oldProp.VotingEndTime.Unix(), newProp.VotingEndTime.Unix()) -} diff --git a/x/gov/migrations/v4/json.go b/x/gov/migrations/v4/json.go deleted file mode 100644 index 62d7ee9bd918..000000000000 --- a/x/gov/migrations/v4/json.go +++ /dev/null @@ -1,41 +0,0 @@ -package v4 - -import ( - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" -) - -// MigrateJSON accepts exported v3 (v0.46) x/gov genesis state and migrates it to -// v4 (v0.47) x/gov genesis state. The migration includes: -// -// Params migrations from x/params to gov -// Addition of the new min initial deposit ratio parameter that is set to 0 by default. -// Proposals in voting period are tracked in a separate index. -func MigrateJSON(oldState *v1.GenesisState) (*v1.GenesisState, error) { - defaultParams := v1.DefaultParams() - - params := v1.NewParams( - oldState.DepositParams.MinDeposit, - defaultParams.ExpeditedMinDeposit, - *oldState.DepositParams.MaxDepositPeriod, - *oldState.VotingParams.VotingPeriod, - *defaultParams.ExpeditedVotingPeriod, - oldState.TallyParams.Quorum, - oldState.TallyParams.Threshold, - defaultParams.ExpeditedThreshold, - oldState.TallyParams.VetoThreshold, - defaultParams.MinInitialDepositRatio, - defaultParams.ProposalCancelRatio, - defaultParams.ProposalCancelDest, - defaultParams.BurnProposalDepositPrevote, - defaultParams.BurnVoteQuorum, - defaultParams.BurnVoteVeto, - ) - - return &v1.GenesisState{ - StartingProposalId: oldState.StartingProposalId, - Deposits: oldState.Deposits, - Votes: oldState.Votes, - Proposals: oldState.Proposals, - Params: ¶ms, - }, nil -} diff --git a/x/gov/migrations/v4/json_test.go b/x/gov/migrations/v4/json_test.go deleted file mode 100644 index 4f85c284e3e9..000000000000 --- a/x/gov/migrations/v4/json_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package v4_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/client" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/gov" - v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" -) - -func TestMigrateJSON(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) - clientCtx := client.Context{}. - WithInterfaceRegistry(encodingConfig.InterfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). - WithCodec(encodingConfig.Codec) - - govGenState := v1.DefaultGenesisState() - oldGovState := &v1.GenesisState{ - StartingProposalId: govGenState.StartingProposalId, - Deposits: govGenState.Deposits, - Votes: govGenState.Votes, - Proposals: govGenState.Proposals, - DepositParams: &v1.DepositParams{ - MinDeposit: govGenState.Params.MinDeposit, - MaxDepositPeriod: govGenState.Params.MaxDepositPeriod, - }, - VotingParams: &v1.VotingParams{ - VotingPeriod: govGenState.Params.VotingPeriod, - }, - TallyParams: &v1.TallyParams{ - Quorum: govGenState.Params.Quorum, - Threshold: govGenState.Params.Threshold, - VetoThreshold: govGenState.Params.VetoThreshold, - }, - } - - migrated, err := v4.MigrateJSON(oldGovState) - require.NoError(t, err) - require.Equal(t, migrated, govGenState) - - bz, err := clientCtx.Codec.MarshalJSON(migrated) - require.NoError(t, err) - - // Indent the JSON bz correctly. - var jsonObj map[string]interface{} - err = json.Unmarshal(bz, &jsonObj) - require.NoError(t, err) - indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") - require.NoError(t, err) - - // Make sure about: - // - Proposals use MsgExecLegacyContent - expected := `{ - "constitution": "", - "deposit_params": null, - "deposits": [], - "params": { - "burn_proposal_deposit_prevote": false, - "burn_vote_quorum": false, - "burn_vote_veto": true, - "expedited_min_deposit": [ - { - "amount": "50000000", - "denom": "stake" - } - ], - "expedited_threshold": "0.667000000000000000", - "expedited_voting_period": "86400s", - "max_deposit_period": "172800s", - "min_deposit": [ - { - "amount": "10000000", - "denom": "stake" - } - ], - "min_initial_deposit_ratio": "0.000000000000000000", - "proposal_cancel_dest": "", - "proposal_cancel_ratio": "0.500000000000000000", - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000", - "voting_period": "172800s" - }, - "proposals": [], - "starting_proposal_id": "1", - "tally_params": null, - "votes": [], - "voting_params": null -}` - - require.Equal(t, expected, string(indentedBz)) -} diff --git a/x/gov/migrations/v4/keys.go b/x/gov/migrations/v4/keys.go deleted file mode 100644 index 7815a688d6e2..000000000000 --- a/x/gov/migrations/v4/keys.go +++ /dev/null @@ -1,28 +0,0 @@ -package v4 - -import "encoding/binary" - -const ( - // ModuleName is the name of the module - ModuleName = "gov" -) - -var ( - // ParamsKey is the key of x/gov params - ParamsKey = []byte{0x30} - - // - 0x04: ProposalContents - VotingPeriodProposalKeyPrefix = []byte{0x04} -) - -// VotingPeriodProposalKey gets if a proposal is in voting period. -func VotingPeriodProposalKey(proposalID uint64) []byte { - return append(VotingPeriodProposalKeyPrefix, GetProposalIDBytes(proposalID)...) -} - -// GetProposalIDBytes returns the byte representation of the proposalID -func GetProposalIDBytes(proposalID uint64) (proposalIDBz []byte) { - proposalIDBz = make([]byte, 8) - binary.BigEndian.PutUint64(proposalIDBz, proposalID) - return -} diff --git a/x/gov/migrations/v4/store.go b/x/gov/migrations/v4/store.go deleted file mode 100644 index cb41e5122231..000000000000 --- a/x/gov/migrations/v4/store.go +++ /dev/null @@ -1,138 +0,0 @@ -package v4 - -import ( - "fmt" - "sort" - - corestoretypes "cosmossdk.io/core/store" - "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/exported" - v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" -) - -func migrateParams(ctx sdk.Context, store storetypes.KVStore, legacySubspace exported.ParamSubspace, cdc codec.BinaryCodec) error { - dp := govv1.DepositParams{} - vp := govv1.VotingParams{} - tp := govv1.TallyParams{} - legacySubspace.Get(ctx, govv1.ParamStoreKeyDepositParams, &dp) - legacySubspace.Get(ctx, govv1.ParamStoreKeyVotingParams, &vp) - legacySubspace.Get(ctx, govv1.ParamStoreKeyTallyParams, &tp) - - defaultParams := govv1.DefaultParams() - params := govv1.NewParams( - dp.MinDeposit, - defaultParams.ExpeditedMinDeposit, - *dp.MaxDepositPeriod, - *vp.VotingPeriod, - *defaultParams.ExpeditedVotingPeriod, - tp.Quorum, - tp.Threshold, - defaultParams.ExpeditedThreshold, - tp.VetoThreshold, - defaultParams.MinInitialDepositRatio, - defaultParams.ProposalCancelRatio, - defaultParams.ProposalCancelDest, - defaultParams.BurnProposalDepositPrevote, - defaultParams.BurnVoteQuorum, - defaultParams.BurnVoteVeto, - ) - - bz, err := cdc.Marshal(¶ms) - if err != nil { - return err - } - - store.Set(ParamsKey, bz) - - return nil -} - -func migrateProposalVotingPeriod(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error { - propStore := prefix.NewStore(store, v1.ProposalsKeyPrefix) - - iter := propStore.Iterator(nil, nil) - defer iter.Close() - - for ; iter.Valid(); iter.Next() { - var prop govv1.Proposal - err := cdc.Unmarshal(iter.Value(), &prop) - if err != nil { - return err - } - - if prop.Status == govv1.StatusVotingPeriod { - store.Set(VotingPeriodProposalKey(prop.Id), []byte{1}) - } - } - - return nil -} - -// MigrateStore performs in-place store migrations from v3 (v0.46) to v4 (v0.47). The -// migration includes: -// -// Params migrations from x/params to gov -// Addition of the new min initial deposit ratio parameter that is set to 0 by default. -// Proposals in voting period are tracked in a separate index. -func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, legacySubspace exported.ParamSubspace, cdc codec.BinaryCodec) error { - store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx)) - if err := migrateProposalVotingPeriod(ctx, store, cdc); err != nil { - return err - } - - return migrateParams(ctx, store, legacySubspace, cdc) -} - -// AddProposerAddressToProposal will add proposer to proposal and set to the store. This function is optional. -func AddProposerAddressToProposal(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec, proposals map[uint64]string) error { - proposalIDs := make([]uint64, 0, len(proposals)) - - for proposalID := range proposals { - proposalIDs = append(proposalIDs, proposalID) - } - - // sort the proposalIDs - sort.Slice(proposalIDs, func(i, j int) bool { return proposalIDs[i] < proposalIDs[j] }) - - store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx)) - - for _, proposalID := range proposalIDs { - if len(proposals[proposalID]) == 0 { - return fmt.Errorf("found missing proposer for proposal ID: %d", proposalID) - } - - if _, err := sdk.AccAddressFromBech32(proposals[proposalID]); err != nil { - return fmt.Errorf("invalid proposer address : %s", proposals[proposalID]) - } - - bz := store.Get(append(types.ProposalsKeyPrefix, sdk.Uint64ToBigEndian(proposalID)...)) - var proposal govv1.Proposal - if err := cdc.Unmarshal(bz, &proposal); err != nil { - panic(err) - } - - // Check if proposal is active - if proposal.Status != govv1.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD && - proposal.Status != govv1.ProposalStatus_PROPOSAL_STATUS_DEPOSIT_PERIOD { - return fmt.Errorf("invalid proposal : %s, proposal not active", proposals[proposalID]) - } - - proposal.Proposer = proposals[proposalID] - - // set the new proposal with proposer - bz, err := cdc.Marshal(&proposal) - if err != nil { - panic(err) - } - store.Set(append(types.ProposalsKeyPrefix, sdk.Uint64ToBigEndian(proposalID)...), bz) - } - - return nil -} diff --git a/x/gov/migrations/v4/store_test.go b/x/gov/migrations/v4/store_test.go deleted file mode 100644 index 0704896ac4a7..000000000000 --- a/x/gov/migrations/v4/store_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package v4_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/gov" - v1gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" - v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" - "github.com/cosmos/cosmos-sdk/x/gov/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -var ( - _, _, addr = testdata.KeyTestPubAddr() - govAcct = authtypes.NewModuleAddress(types.ModuleName) - TestProposal = getTestProposal() -) - -type mockSubspace struct { - dp v1.DepositParams - vp v1.VotingParams - tp v1.TallyParams -} - -func newMockSubspace(p v1.Params) mockSubspace { - return mockSubspace{ - dp: v1.DepositParams{ - MinDeposit: p.MinDeposit, - MaxDepositPeriod: p.MaxDepositPeriod, - }, - vp: v1.VotingParams{ - VotingPeriod: p.VotingPeriod, - }, - tp: v1.TallyParams{ - Quorum: p.Quorum, - Threshold: p.Threshold, - VetoThreshold: p.VetoThreshold, - }, - } -} - -func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { - switch string(key) { - case string(v1.ParamStoreKeyDepositParams): - *ptr.(*v1.DepositParams) = ms.dp - case string(v1.ParamStoreKeyVotingParams): - *ptr.(*v1.VotingParams) = ms.vp - case string(v1.ParamStoreKeyTallyParams): - *ptr.(*v1.TallyParams) = ms.tp - } -} - -func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}, bank.AppModuleBasic{}).Codec - govKey := storetypes.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) - store := ctx.KVStore(govKey) - - legacySubspace := newMockSubspace(v1.DefaultParams()) - - propTime := time.Unix(1e9, 0) - - // Create 2 proposals - prop1Content, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), authtypes.NewModuleAddress("gov").String()) - require.NoError(t, err) - proposal1, err := v1.NewProposal([]sdk.Msg{prop1Content}, 1, propTime, propTime, "some metadata for the legacy content", "Test", "description", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false) - require.NoError(t, err) - prop1Bz, err := cdc.Marshal(&proposal1) - require.NoError(t, err) - store.Set(v1gov.ProposalKey(proposal1.Id), prop1Bz) - - proposal2, err := v1.NewProposal(getTestProposal(), 2, propTime, propTime, "some metadata for the legacy content", "Test", "description", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false) - proposal2.Status = v1.StatusVotingPeriod - require.NoError(t, err) - prop2Bz, err := cdc.Marshal(&proposal2) - require.NoError(t, err) - store.Set(v1gov.ProposalKey(proposal2.Id), prop2Bz) - - // Run migrations. - storeService := runtime.NewKVStoreService(govKey) - err = v4.MigrateStore(ctx, storeService, legacySubspace, cdc) - require.NoError(t, err) - - // Check params - var params v1.Params - bz := store.Get(v4.ParamsKey) - require.NoError(t, cdc.Unmarshal(bz, ¶ms)) - require.NotNil(t, params) - require.Equal(t, legacySubspace.dp.MinDeposit, params.MinDeposit) - require.Equal(t, legacySubspace.dp.MaxDepositPeriod, params.MaxDepositPeriod) - require.Equal(t, legacySubspace.vp.VotingPeriod, params.VotingPeriod) - require.Equal(t, legacySubspace.tp.Quorum, params.Quorum) - require.Equal(t, legacySubspace.tp.Threshold, params.Threshold) - require.Equal(t, legacySubspace.tp.VetoThreshold, params.VetoThreshold) - require.Equal(t, math.LegacyZeroDec().String(), params.MinInitialDepositRatio) - - // Check proposals' status - var migratedProp1 v1.Proposal - bz = store.Get(v1gov.ProposalKey(proposal1.Id)) - require.NoError(t, cdc.Unmarshal(bz, &migratedProp1)) - require.Equal(t, v1.StatusDepositPeriod, migratedProp1.Status) - - var migratedProp2 v1.Proposal - bz = store.Get(v1gov.ProposalKey(proposal2.Id)) - require.NoError(t, cdc.Unmarshal(bz, &migratedProp2)) - require.Equal(t, v1.StatusVotingPeriod, migratedProp2.Status) - - // Check if proposal 2 is in the new store but not proposal 1 - require.Nil(t, store.Get(v4.VotingPeriodProposalKey(proposal1.Id))) - require.Equal(t, []byte{0x1}, store.Get(v4.VotingPeriodProposalKey(proposal2.Id))) -} - -func getTestProposal() []sdk.Msg { - legacyProposalMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String()) - if err != nil { - panic(err) - } - - return []sdk.Msg{ - banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000)))), - legacyProposalMsg, - } -} diff --git a/x/gov/migrations/v5/store.go b/x/gov/migrations/v5/store.go index 018dfacb5a49..a55f93d9311c 100644 --- a/x/gov/migrations/v5/store.go +++ b/x/gov/migrations/v5/store.go @@ -5,17 +5,21 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) +var ( + // ParamsKey is the key of x/gov params + ParamsKey = []byte{0x30} +) + // MigrateStore performs in-place store migrations from v4 (v0.47) to v5 (v0.50). The // migration includes: // // Addition of the new proposal expedited parameters that are set to 0 by default. func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error { store := storeService.OpenKVStore(ctx) - paramsBz, err := store.Get(v4.ParamsKey) + paramsBz, err := store.Get(ParamsKey) if err != nil { return err } @@ -38,5 +42,5 @@ func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, c return err } - return store.Set(v4.ParamsKey, bz) + return store.Set(ParamsKey, bz) } diff --git a/x/gov/migrations/v5/store_test.go b/x/gov/migrations/v5/store_test.go index e4e4ba683266..41f13e510640 100644 --- a/x/gov/migrations/v5/store_test.go +++ b/x/gov/migrations/v5/store_test.go @@ -13,7 +13,6 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/gov" - v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" v5 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v5" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) @@ -25,7 +24,7 @@ func TestMigrateStore(t *testing.T) { store := ctx.KVStore(govKey) var params v1.Params - bz := store.Get(v4.ParamsKey) + bz := store.Get(v5.ParamsKey) require.NoError(t, cdc.Unmarshal(bz, ¶ms)) require.NotNil(t, params) require.Equal(t, "", params.ExpeditedThreshold) @@ -37,7 +36,7 @@ func TestMigrateStore(t *testing.T) { require.NoError(t, err) // Check params - bz = store.Get(v4.ParamsKey) + bz = store.Get(v5.ParamsKey) require.NoError(t, cdc.Unmarshal(bz, ¶ms)) require.NotNil(t, params) require.Equal(t, v1.DefaultParams().ExpeditedMinDeposit, params.ExpeditedMinDeposit) diff --git a/x/gov/module.go b/x/gov/module.go index a30b718ca1e2..4d0d525ba64f 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -134,22 +134,18 @@ type AppModule struct { keeper *keeper.Keeper accountKeeper govtypes.AccountKeeper bankKeeper govtypes.BankKeeper - - // legacySubspace is used solely for migration of x/params managed parameters - legacySubspace govtypes.ParamSubspace } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper *keeper.Keeper, - ak govtypes.AccountKeeper, bk govtypes.BankKeeper, ss govtypes.ParamSubspace, + ak govtypes.AccountKeeper, bk govtypes.BankKeeper, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak.AddressCodec()}, keeper: keeper, accountKeeper: ak, bankKeeper: bk, - legacySubspace: ss, } } @@ -179,9 +175,6 @@ type ModuleInputs struct { BankKeeper govtypes.BankKeeper StakingKeeper govtypes.StakingKeeper DistributionKeeper govtypes.DistributionKeeper - - // LegacySubspace is used solely for migration of x/params managed parameters - LegacySubspace govtypes.ParamSubspace `optional:"true"` } type ModuleOutputs struct { @@ -215,7 +208,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { defaultConfig, authority.String(), ) - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper) hr := v1beta1.HandlerRoute{Handler: v1beta1.ProposalHandler, RouteKey: govtypes.RouterKey} return ModuleOutputs{Module: m, Keeper: k, HandlerRoute: hr} @@ -282,7 +275,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { v1beta1.RegisterQueryServer(cfg.QueryServer(), legacyQueryServer) v1.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) - m := keeper.NewMigrator(am.keeper, am.legacySubspace) + m := keeper.NewMigrator(am.keeper) if err := cfg.RegisterMigration(govtypes.ModuleName, 1, m.Migrate1to2); err != nil { panic(fmt.Sprintf("failed to migrate x/gov from version 1 to 2: %v", err)) } diff --git a/x/gov/types/expected_keepers.go b/x/gov/types/expected_keepers.go index 7a2e9a9dc647..bd3c74a517f1 100644 --- a/x/gov/types/expected_keepers.go +++ b/x/gov/types/expected_keepers.go @@ -10,12 +10,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// ParamSubspace defines the expected Subspace interface for parameters (noalias) -type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) -} - // StakingKeeper expected staking keeper (Validator and Delegator sets) (noalias) type StakingKeeper interface { ValidatorAddressCodec() addresscodec.Codec diff --git a/x/mint/exported/exported.go b/x/mint/exported/exported.go deleted file mode 100644 index 000114e6194d..000000000000 --- a/x/mint/exported/exported.go +++ /dev/null @@ -1,18 +0,0 @@ -package exported - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -type ( - ParamSet = paramtypes.ParamSet - - // Subspace defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - Subspace interface { - GetParamSet(ctx sdk.Context, ps ParamSet) - } -) diff --git a/x/mint/keeper/migrator.go b/x/mint/keeper/migrator.go index 3e85e6edba08..f0161568dc5e 100644 --- a/x/mint/keeper/migrator.go +++ b/x/mint/keeper/migrator.go @@ -2,21 +2,17 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/exported" - v2 "github.com/cosmos/cosmos-sdk/x/mint/migrations/v2" ) // Migrator is a struct for handling in-place state migrations. type Migrator struct { - keeper Keeper - legacySubspace exported.Subspace + keeper Keeper } // NewMigrator returns Migrator instance for the state migration. -func NewMigrator(k Keeper, ss exported.Subspace) Migrator { +func NewMigrator(k Keeper) Migrator { return Migrator{ - keeper: k, - legacySubspace: ss, + keeper: k, } } @@ -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/mint // module state. func (m Migrator) Migrate1to2(ctx sdk.Context) error { - return v2.Migrate(ctx, m.keeper.storeService.OpenKVStore(ctx), m.legacySubspace, m.keeper.cdc) + return nil } diff --git a/x/mint/migrations/v2/migrate.go b/x/mint/migrations/v2/migrate.go deleted file mode 100644 index 82f267f3c704..000000000000 --- a/x/mint/migrations/v2/migrate.go +++ /dev/null @@ -1,37 +0,0 @@ -package v2 - -import ( - storetypes "cosmossdk.io/core/store" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/exported" - "github.com/cosmos/cosmos-sdk/x/mint/types" -) - -const ( - ModuleName = "mint" -) - -var ParamsKey = []byte{0x01} - -// Migrate migrates the x/mint module state from the consensus version 1 to -// version 2. Specifically, it takes the parameters that are currently stored -// and managed by the x/params modules and stores them directly into the x/mint -// module state. -func Migrate( - ctx sdk.Context, - store storetypes.KVStore, - legacySubspace exported.Subspace, - cdc codec.BinaryCodec, -) error { - var currParams types.Params - legacySubspace.GetParamSet(ctx, &currParams) - - if err := currParams.Validate(); err != nil { - return err - } - - bz := cdc.MustMarshal(&currParams) - return store.Set(ParamsKey, bz) -} diff --git a/x/mint/migrations/v2/migrator_test.go b/x/mint/migrations/v2/migrator_test.go deleted file mode 100644 index 70fd27084a45..000000000000 --- a/x/mint/migrations/v2/migrator_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package v2_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/mint/exported" - v2 "github.com/cosmos/cosmos-sdk/x/mint/migrations/v2" - "github.com/cosmos/cosmos-sdk/x/mint/types" -) - -type mockSubspace struct { - ps types.Params -} - -func newMockSubspace(ps types.Params) mockSubspace { - return mockSubspace{ps: ps} -} - -func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { - *ps.(*types.Params) = ms.ps -} - -func TestMigrate(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) - cdc := encCfg.Codec - - storeKey := storetypes.NewKVStoreKey(v2.ModuleName) - tKey := storetypes.NewTransientStoreKey("transient_test") - ctx := testutil.DefaultContext(storeKey, tKey) - kvStoreService := runtime.NewKVStoreService(storeKey) - store := kvStoreService.OpenKVStore(ctx) - - legacySubspace := newMockSubspace(types.DefaultParams()) - require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc)) - - var res types.Params - bz, err := store.Get(v2.ParamsKey) - require.NoError(t, err) - require.NoError(t, cdc.Unmarshal(bz, &res)) - require.Equal(t, legacySubspace.ps, res) -} diff --git a/x/mint/module.go b/x/mint/module.go index 5a90a517b1c3..8191d639ffa8 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/mint/exported" "github.com/cosmos/cosmos-sdk/x/mint/keeper" "github.com/cosmos/cosmos-sdk/x/mint/simulation" "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -88,9 +87,6 @@ type AppModule struct { keeper keeper.Keeper authKeeper types.AccountKeeper - // legacySubspace is used solely for migration of x/params managed parameters - legacySubspace exported.Subspace - // inflationCalculator is used to calculate the inflation rate during BeginBlock. // If inflationCalculator is nil, the default inflation calculation logic is used. inflationCalculator types.InflationCalculationFn @@ -103,7 +99,6 @@ func NewAppModule( keeper keeper.Keeper, ak types.AccountKeeper, ic types.InflationCalculationFn, - ss exported.Subspace, ) AppModule { if ic == nil { ic = types.DefaultInflationCalculationFn @@ -114,7 +109,6 @@ func NewAppModule( keeper: keeper, authKeeper: ak, inflationCalculator: ic, - legacySubspace: ss, } } @@ -130,7 +124,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(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)) @@ -202,9 +196,6 @@ type ModuleInputs struct { Cdc codec.Codec InflationCalculationFn types.InflationCalculationFn `optional:"true"` - // LegacySubspace is used solely for migration of x/params managed parameters - LegacySubspace exported.Subspace `optional:"true"` - AccountKeeper types.AccountKeeper BankKeeper types.BankKeeper StakingKeeper types.StakingKeeper @@ -245,7 +236,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { ) // when no inflation calculation function is provided it will use the default types.DefaultInflationCalculationFn - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.InflationCalculationFn, in.LegacySubspace) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.InflationCalculationFn) return ModuleOutputs{MintKeeper: k, Module: m} } From 0a08dd6a100f04622fcae03564bde53312f31b98 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 10:19:08 +0200 Subject: [PATCH 02/11] fix lint --- CHANGELOG.md | 1 + x/gov/migrations/v3/convert.go | 111 --------------------------------- x/gov/migrations/v5/store.go | 6 +- x/gov/module.go | 6 -- 4 files changed, 3 insertions(+), 121 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c0a4327afd9..aad319de529a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/gov/migrations/v3/convert.go b/x/gov/migrations/v3/convert.go index 551401b3fb58..f68c6382ac21 100644 --- a/x/gov/migrations/v3/convert.go +++ b/x/gov/migrations/v3/convert.go @@ -8,7 +8,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) @@ -136,113 +135,3 @@ func ConvertToLegacyDeposit(deposit *v1.Deposit) v1beta1.Deposit { Amount: types.NewCoins(deposit.Amount...), } } - -func convertToNewDeposits(oldDeps v1beta1.Deposits) v1.Deposits { - newDeps := make([]*v1.Deposit, len(oldDeps)) - for i, oldDep := range oldDeps { - newDeps[i] = &v1.Deposit{ - ProposalId: oldDep.ProposalId, - Depositor: oldDep.Depositor, - Amount: oldDep.Amount, - } - } - - return newDeps -} - -func convertToNewVotes(oldVotes v1beta1.Votes) (v1.Votes, error) { - newVotes := make([]*v1.Vote, len(oldVotes)) - for i, oldVote := range oldVotes { - var newWVOs []*v1.WeightedVoteOption - - // We deprecated Vote.Option in v043. However, it might still be set. - // - if only Options is set, or both Option & Options are set, we read from Options, - // - if Options is not set, and Option is set, we read from Option, - // - if none are set, we throw error. - switch { - case oldVote.Options != nil: - newWVOs = make([]*v1.WeightedVoteOption, len(oldVote.Options)) - for j, oldWVO := range oldVote.Options { - newWVOs[j] = v1.NewWeightedVoteOption(v1.VoteOption(oldWVO.Option), oldWVO.Weight) - } - - case oldVote.Option != v1beta1.OptionEmpty: - newWVOs = v1.NewNonSplitVoteOption(v1.VoteOption(oldVote.Option)) - default: - return nil, fmt.Errorf("vote does not have neither InterfaceRegistryOptions nor Option") - } - - newVotes[i] = &v1.Vote{ - ProposalId: oldVote.ProposalId, - Voter: oldVote.Voter, - Options: newWVOs, - } - } - - return newVotes, nil -} - -func convertToNewDepParams(oldDepParams v1beta1.DepositParams) v1.DepositParams { - return v1.DepositParams{ - MinDeposit: oldDepParams.MinDeposit, - MaxDepositPeriod: &oldDepParams.MaxDepositPeriod, - } -} - -func convertToNewVotingParams(oldVoteParams v1beta1.VotingParams) v1.VotingParams { - return v1.VotingParams{ - VotingPeriod: &oldVoteParams.VotingPeriod, - } -} - -func convertToNewTallyParams(oldTallyParams v1beta1.TallyParams) v1.TallyParams { - return v1.TallyParams{ - Quorum: oldTallyParams.Quorum.String(), - Threshold: oldTallyParams.Threshold.String(), - VetoThreshold: oldTallyParams.VetoThreshold.String(), - } -} - -func convertToNewProposal(oldProp v1beta1.Proposal) (v1.Proposal, error) { - msg, err := v1.NewLegacyContent(oldProp.GetContent(), authtypes.NewModuleAddress(ModuleName).String()) - if err != nil { - return v1.Proposal{}, err - } - msgAny, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return v1.Proposal{}, err - } - - return v1.Proposal{ - Id: oldProp.ProposalId, - Messages: []*codectypes.Any{msgAny}, - Status: v1.ProposalStatus(oldProp.Status), - FinalTallyResult: &v1.TallyResult{ - YesCount: oldProp.FinalTallyResult.Yes.String(), - NoCount: oldProp.FinalTallyResult.No.String(), - AbstainCount: oldProp.FinalTallyResult.Abstain.String(), - NoWithVetoCount: oldProp.FinalTallyResult.NoWithVeto.String(), - }, - SubmitTime: &oldProp.SubmitTime, - DepositEndTime: &oldProp.DepositEndTime, - TotalDeposit: oldProp.TotalDeposit, - VotingStartTime: &oldProp.VotingStartTime, - VotingEndTime: &oldProp.VotingEndTime, - Title: oldProp.GetContent().GetTitle(), - Summary: oldProp.GetContent().GetDescription(), - }, nil -} - -func convertToNewProposals(oldProps v1beta1.Proposals) (v1.Proposals, error) { - newProps := make([]*v1.Proposal, len(oldProps)) - for i, oldProp := range oldProps { - p, err := convertToNewProposal(oldProp) - if err != nil { - return nil, err - } - - newProps[i] = &p - } - - return newProps, nil -} diff --git a/x/gov/migrations/v5/store.go b/x/gov/migrations/v5/store.go index a55f93d9311c..701492955432 100644 --- a/x/gov/migrations/v5/store.go +++ b/x/gov/migrations/v5/store.go @@ -8,10 +8,8 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) -var ( - // ParamsKey is the key of x/gov params - ParamsKey = []byte{0x30} -) +// ParamsKey is the key of x/gov params +var ParamsKey = []byte{0x30} // MigrateStore performs in-place store migrations from v4 (v0.47) to v5 (v0.50). The // migration includes: diff --git a/x/gov/module.go b/x/gov/module.go index 4d0d525ba64f..f9461b49ec95 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -33,7 +33,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ConsensusVersion = 5 @@ -158,7 +157,6 @@ func (am AppModule) IsAppModule() {} func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(ProvideModule, ProvideKeyTable), appmodule.Invoke(InvokeAddRoutes, InvokeSetHooks)) } @@ -214,10 +212,6 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { return ModuleOutputs{Module: m, Keeper: k, HandlerRoute: hr} } -func ProvideKeyTable() paramtypes.KeyTable { - return v1.ParamKeyTable() //nolint:staticcheck // we still need this for upgrades -} - func InvokeAddRoutes(keeper *keeper.Keeper, routes []v1beta1.HandlerRoute) { if keeper == nil || routes == nil { return From beb51bc7dcf776370259fec641a4996bd446e6c7 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 10:39:18 +0200 Subject: [PATCH 03/11] remove params module enitrely --- baseapp/block_gas_test.go | 1 - scripts/mockgen.sh | 1 - simapp/app.go | 46 +------ simapp/app_config.go | 13 +- tests/integration/bank/app_test.go | 2 - tests/integration/gov/genesis_test.go | 2 - tests/integration/gov/module_test.go | 1 - tests/integration/runtime/query_test.go | 2 - tests/integration/tx/context_test.go | 2 - testutil/configurator/configurator.go | 11 -- testutil/network/network.go | 2 - types/query/pagination_test.go | 2 - x/auth/testutil/app_config.go | 2 - x/authz/testutil/app_config.go | 2 - x/bank/simulation/genesis.go | 7 +- x/bank/simulation/operations_test.go | 2 - x/bank/types/params_legacy.go | 23 ---- x/crisis/types/legacy_params.go | 31 ----- x/distribution/testutil/app_config.go | 2 - x/distribution/types/params_legacy.go | 22 ---- x/evidence/testutil/app_config.go | 2 - x/feegrant/simulation/operations_test.go | 2 - x/gov/common_test.go | 2 - x/gov/exported/exported.go | 18 --- x/gov/simulation/operations_test.go | 2 - x/group/testutil/app_config.go | 2 - x/mint/testutil/app_config.go | 2 - x/nft/testutil/app_config.go | 2 - x/params/proposal_handler_test.go | 116 ------------------ x/slashing/app_test.go | 1 - x/slashing/testutil/app_config.go | 2 - x/slashing/testutil/expected_keepers_mocks.go | 108 ++-------------- x/slashing/types/expected_keepers.go | 10 -- x/slashing/types/params_legacy.go | 35 ------ x/staking/testutil/app_config.go | 2 - x/staking/types/params_legacy.go | 32 ----- 36 files changed, 20 insertions(+), 494 deletions(-) delete mode 100644 x/bank/types/params_legacy.go delete mode 100644 x/crisis/types/legacy_params.go delete mode 100644 x/distribution/types/params_legacy.go delete mode 100644 x/gov/exported/exported.go delete mode 100644 x/params/proposal_handler_test.go delete mode 100644 x/slashing/types/params_legacy.go delete mode 100644 x/staking/types/params_legacy.go diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 09b9ffe045e5..7ae5cda888cc 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -86,7 +86,6 @@ func TestBaseApp_BlockGas(t *testing.T) { configurator.NewAppConfig( configurator.AuthModule(), configurator.TxModule(), - configurator.ParamsModule(), configurator.ConsensusModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index cda998093a19..294917e18dd5 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -13,7 +13,6 @@ $mockgen_cmd -source=orm/model/ormtable/hooks.go -package ormmocks -destination $mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/feegrant/expected_keepers.go -package testutil -destination x/feegrant/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/mint/types/expected_keepers.go -package testutil -destination x/mint/testutil/expected_keepers_mocks.go -$mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destination x/params/testutil/staking_keeper_mock.go $mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/auth/tx/config/expected_keepers.go -package testutil -destination x/auth/tx/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go diff --git a/simapp/app.go b/simapp/app.go index 68cee5a26e7a..eb414e1a4994 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -95,11 +95,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/params" - paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -155,7 +150,6 @@ type SimApp struct { GovKeeper govkeeper.Keeper CrisisKeeper *crisiskeeper.Keeper UpgradeKeeper *upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper @@ -253,7 +247,7 @@ func NewSimApp( keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + govtypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, circuittypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, ) @@ -263,7 +257,6 @@ func NewSimApp( panic(err) } - tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) app := &SimApp{ BaseApp: bApp, legacyAmino: legacyAmino, @@ -271,11 +264,8 @@ func NewSimApp( txConfig: txConfig, interfaceRegistry: interfaceRegistry, keys: keys, - tkeys: tkeys, } - app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) - // set the BaseApp's parameter store app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{}) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) @@ -340,8 +330,6 @@ func NewSimApp( // by granting the governance module the right to execute the message. // See: https://docs.cosmos.network/main/modules/gov#proposal-messages govRouter := govv1beta1.NewRouter() - govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)) govConfig := govtypes.DefaultConfig() /* Example of setting gov params: @@ -395,7 +383,6 @@ func NewSimApp( staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()), evidence.NewAppModule(app.EvidenceKeeper), - params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -412,9 +399,7 @@ func NewSimApp( map[string]module.AppModuleBasic{ genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), govtypes.ModuleName: gov.NewAppModuleBasic( - []govclient.ProposalHandler{ - paramsclient.ProposalHandler, - }, + []govclient.ProposalHandler{}, ), }) app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) @@ -453,7 +438,7 @@ func NewSimApp( authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, + feegrant.ModuleName, nft.ModuleName, group.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName, } app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) @@ -497,7 +482,6 @@ func NewSimApp( // initialize stores app.MountKVStores(keys) - app.MountTransientStores(tkeys) // initialize BaseApp app.SetInitChainer(app.InitChainer) @@ -678,14 +662,6 @@ func (app *SimApp) GetStoreKeys() []storetypes.StoreKey { return keys } -// GetSubspace returns a param subspace for a given module name. -// -// NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace { - subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) - return subspace -} - // SimulationManager implements the SimulationApp interface func (app *SimApp) SimulationManager() *module.SimulationManager { return app.sm @@ -757,19 +733,3 @@ func BlockedAddresses() map[string]bool { return modAccAddrs } - -// initParamsKeeper init params keeper and its subspaces -func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { - paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - - paramsKeeper.Subspace(authtypes.ModuleName) - paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(minttypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName) - paramsKeeper.Subspace(crisistypes.ModuleName) - - return paramsKeeper -} diff --git a/simapp/app_config.go b/simapp/app_config.go index 2b11313e60dd..776ae93732f3 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -21,7 +21,6 @@ import ( groupmodulev1 "cosmossdk.io/api/cosmos/group/module/v1" mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" nftmodulev1 "cosmossdk.io/api/cosmos/nft/module/v1" - paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" @@ -65,9 +64,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects - paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" _ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects @@ -152,7 +148,6 @@ var ( feegrant.ModuleName, nft.ModuleName, group.ModuleName, - paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, circuittypes.ModuleName, @@ -197,10 +192,6 @@ var ( Name: slashingtypes.ModuleName, Config: appconfig.WrapAny(&slashingmodulev1.Module{}), }, - { - Name: paramstypes.ModuleName, - Config: appconfig.WrapAny(¶msmodulev1.Module{}), - }, { Name: "tx", Config: appconfig.WrapAny(&txconfigv1.Config{}), @@ -267,9 +258,7 @@ var ( map[string]module.AppModuleBasic{ genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), govtypes.ModuleName: gov.NewAppModuleBasic( - []govclient.ProposalHandler{ - paramsclient.ProposalHandler, - }, + []govclient.ProposalHandler{}, ), }, )) diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index da860ca21e8b..8c9d42e81f02 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -31,7 +31,6 @@ import ( distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" _ "github.com/cosmos/cosmos-sdk/x/gov" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -117,7 +116,6 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.TxModule(), diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 0142949dbd30..50ef7e3d7b3b 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -31,7 +31,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -49,7 +48,6 @@ type suite struct { } var appConfig = configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/gov/module_test.go b/tests/integration/gov/module_test.go index 7853a51da6d3..2c758d40d308 100644 --- a/tests/integration/gov/module_test.go +++ b/tests/integration/gov/module_test.go @@ -22,7 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go index 3ae7a2835f59..ee524e05a28d 100644 --- a/tests/integration/runtime/query_test.go +++ b/tests/integration/runtime/query_test.go @@ -24,7 +24,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" _ "github.com/cosmos/cosmos-sdk/x/bank" _ "github.com/cosmos/cosmos-sdk/x/consensus" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -45,7 +44,6 @@ func initFixture(t assert.TestingT) *fixture { configurator.NewAppConfig( configurator.AuthModule(), configurator.TxModule(), - configurator.ParamsModule(), configurator.ConsensusModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/tx/context_test.go b/tests/integration/tx/context_test.go index 2210c9c934fd..7246a2c798d1 100644 --- a/tests/integration/tx/context_test.go +++ b/tests/integration/tx/context_test.go @@ -33,7 +33,6 @@ func TestDefineCustomGetSigners(t *testing.T) { _, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), @@ -61,7 +60,6 @@ func TestDefineCustomGetSigners(t *testing.T) { _, err = simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index d671b2d82884..adcce08f81ab 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -16,7 +16,6 @@ import ( groupmodulev1 "cosmossdk.io/api/cosmos/group/module/v1" mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" nftmodulev1 "cosmossdk.io/api/cosmos/nft/module/v1" - paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" @@ -56,7 +55,6 @@ func defaultConfig() *Config { "feegrant", "nft", "group", - "params", "consensus", "vesting", "circuit", @@ -162,15 +160,6 @@ func AuthModule() ModuleOption { } } -func ParamsModule() ModuleOption { - return func(config *Config) { - config.ModuleConfigs["params"] = &appv1alpha1.ModuleConfig{ - Name: "params", - Config: appconfig.WrapAny(¶msmodulev1.Module{}), - } - } -} - func TxModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["tx"] = &appv1alpha1.ModuleConfig{ diff --git a/testutil/network/network.go b/testutil/network/network.go index eb0c8ead0d7b..8fc1266045f8 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -59,7 +59,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" _ "github.com/cosmos/cosmos-sdk/x/consensus" // import consensus as a blank "github.com/cosmos/cosmos-sdk/x/genutil" - _ "github.com/cosmos/cosmos-sdk/x/params" // import params as a blank _ "github.com/cosmos/cosmos-sdk/x/staking" // import staking as a blank stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -175,7 +174,6 @@ func DefaultConfig(factory TestFixtureFactory) Config { func MinimumAppConfig() depinject.Config { return configurator.NewAppConfig( configurator.AuthModule(), - configurator.ParamsModule(), configurator.BankModule(), configurator.GenutilModule(), configurator.StakingModule(), diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 13fbe98efa8a..c561481dfb56 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -30,7 +30,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/bank/types" _ "github.com/cosmos/cosmos-sdk/x/consensus" - _ "github.com/cosmos/cosmos-sdk/x/params" ) const ( @@ -71,7 +70,6 @@ func (s *paginationTestSuite) SetupTest() { configurator.NewAppConfig( configurator.AuthModule(), configurator.BankModule(), - configurator.ParamsModule(), configurator.ConsensusModule(), configurator.OmitInitGenesis(), ), diff --git a/x/auth/testutil/app_config.go b/x/auth/testutil/app_config.go index c8e88f2bc6b2..c639c6905c60 100644 --- a/x/auth/testutil/app_config.go +++ b/x/auth/testutil/app_config.go @@ -8,7 +8,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -19,6 +18,5 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), ) diff --git a/x/authz/testutil/app_config.go b/x/authz/testutil/app_config.go index f1e61c100bbb..ff8be58fe3cb 100644 --- a/x/authz/testutil/app_config.go +++ b/x/authz/testutil/app_config.go @@ -10,7 +10,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/gov" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -20,7 +19,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.AuthzModule(), configurator.MintModule(), diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index 1dd6fd3dc8ad..b5c75e3726be 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -12,6 +12,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/types" ) +var ( + // KeyDefaultSendEnabled is store's key for the DefaultSendEnabled option + KeyDefaultSendEnabled = []byte("DefaultSendEnabled") +) + // RandomGenesisDefaultSendEnabledParam computes randomized allow all send transfers param for the bank module func RandomGenesisDefaultSendEnabledParam(r *rand.Rand) bool { // 90% chance of transfers being enabled or P(a) = 0.9 for success @@ -72,7 +77,7 @@ func RandomGenesisBalances(simState *module.SimulationState) []types.Balance { // RandomizedGenState generates a random GenesisState for bank func RandomizedGenState(simState *module.SimulationState) { var defaultSendEnabledParam bool - simState.AppParams.GetOrGenerate(string(types.KeyDefaultSendEnabled), &defaultSendEnabledParam, simState.Rand, func(r *rand.Rand) { defaultSendEnabledParam = RandomGenesisDefaultSendEnabledParam(r) }) + simState.AppParams.GetOrGenerate(string(KeyDefaultSendEnabled), &defaultSendEnabledParam, simState.Rand, func(r *rand.Rand) { defaultSendEnabledParam = RandomGenesisDefaultSendEnabledParam(r) }) sendEnabled := RandomGenesisSendEnabled(simState.Rand, simState.BondDenom) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index cae5cefcb22a..6e026ce0087d 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -26,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/bank/types" _ "github.com/cosmos/cosmos-sdk/x/consensus" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -50,7 +49,6 @@ func (suite *SimTestSuite) SetupTest() { depinject.Configs( configurator.NewAppConfig( configurator.AuthModule(), - configurator.ParamsModule(), configurator.BankModule(), configurator.StakingModule(), configurator.ConsensusModule(), diff --git a/x/bank/types/params_legacy.go b/x/bank/types/params_legacy.go deleted file mode 100644 index 668358b4df7a..000000000000 --- a/x/bank/types/params_legacy.go +++ /dev/null @@ -1,23 +0,0 @@ -package types - -import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - -var ( - // KeySendEnabled is store's key for SendEnabled Params - // Deprecated: Use the SendEnabled functionality in the keeper. - KeySendEnabled = []byte("SendEnabled") - // KeyDefaultSendEnabled is store's key for the DefaultSendEnabled option - KeyDefaultSendEnabled = []byte("DefaultSendEnabled") -) - -// Deprecated: ParamKeyTable for bank module. -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Deprecated: ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool), - } -} diff --git a/x/crisis/types/legacy_params.go b/x/crisis/types/legacy_params.go deleted file mode 100644 index bcb689a4fadd..000000000000 --- a/x/crisis/types/legacy_params.go +++ /dev/null @@ -1,31 +0,0 @@ -package types - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// ParamStoreKeyConstantFee is the constant fee parameter -var ParamStoreKeyConstantFee = []byte("ConstantFee") - -// Deprecated: Type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable( - paramtypes.NewParamSetPair(ParamStoreKeyConstantFee, sdk.Coin{}, validateConstantFee), - ) -} - -func validateConstantFee(i interface{}) error { - v, ok := i.(sdk.Coin) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if !v.IsValid() { - return fmt.Errorf("invalid constant fee: %s", v) - } - - return nil -} diff --git a/x/distribution/testutil/app_config.go b/x/distribution/testutil/app_config.go index c824f4dff45c..9bbf0910daa3 100644 --- a/x/distribution/testutil/app_config.go +++ b/x/distribution/testutil/app_config.go @@ -9,7 +9,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/distribution" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -19,7 +18,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.DistributionModule(), configurator.MintModule(), diff --git a/x/distribution/types/params_legacy.go b/x/distribution/types/params_legacy.go deleted file mode 100644 index 4805e8bd8c8c..000000000000 --- a/x/distribution/types/params_legacy.go +++ /dev/null @@ -1,22 +0,0 @@ -package types - -import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - -// Parameter keys -var ( - ParamStoreKeyCommunityTax = []byte("communitytax") - ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled") -) - -// Deprecated: ParamKeyTable returns the parameter key table. -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Deprecated: ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), - paramtypes.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled), - } -} diff --git a/x/evidence/testutil/app_config.go b/x/evidence/testutil/app_config.go index 30a0645b79f6..ee585bfb434e 100644 --- a/x/evidence/testutil/app_config.go +++ b/x/evidence/testutil/app_config.go @@ -9,7 +9,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/slashing" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -21,7 +20,6 @@ var AppConfig = configurator.NewAppConfig( configurator.SlashingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.EvidenceModule(), configurator.GenutilModule(), ) diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index f9bd1723e993..8c193a2a82b2 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -36,7 +36,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/consensus" _ "github.com/cosmos/cosmos-sdk/x/genutil" _ "github.com/cosmos/cosmos-sdk/x/mint" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -64,7 +63,6 @@ func (suite *SimTestSuite) SetupTest() { configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.FeegrantModule(), ), diff --git a/x/gov/common_test.go b/x/gov/common_test.go index fcca0590bc60..a688b78859f6 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -30,7 +30,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -120,7 +119,6 @@ func createTestSuite(t *testing.T) suite { app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/x/gov/exported/exported.go b/x/gov/exported/exported.go deleted file mode 100644 index 08a5d2594e90..000000000000 --- a/x/gov/exported/exported.go +++ /dev/null @@ -1,18 +0,0 @@ -package exported - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -type ( - ParamSet = paramtypes.ParamSet - - // Subspace defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - } -) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index a7b8c8751059..bbd1d0307e38 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -35,7 +35,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) @@ -424,7 +423,6 @@ func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { configurator.NewAppConfig( configurator.AuthModule(), configurator.TxModule(), - configurator.ParamsModule(), configurator.BankModule(), configurator.StakingModule(), configurator.ConsensusModule(), diff --git a/x/group/testutil/app_config.go b/x/group/testutil/app_config.go index a9dc1f950c37..14d5304e2bfd 100644 --- a/x/group/testutil/app_config.go +++ b/x/group/testutil/app_config.go @@ -10,7 +10,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/group/module" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -20,7 +19,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.GroupModule(), ) diff --git a/x/mint/testutil/app_config.go b/x/mint/testutil/app_config.go index 4f385518dcb8..ece7b9f08dd8 100644 --- a/x/mint/testutil/app_config.go +++ b/x/mint/testutil/app_config.go @@ -8,7 +8,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -18,7 +17,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.MintModule(), ) diff --git a/x/nft/testutil/app_config.go b/x/nft/testutil/app_config.go index 6e7d85f77539..11a5e72fea4d 100644 --- a/x/nft/testutil/app_config.go +++ b/x/nft/testutil/app_config.go @@ -10,7 +10,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -20,7 +19,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.MintModule(), configurator.NFTModule(), diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go deleted file mode 100644 index fb81c4daf91f..000000000000 --- a/x/params/proposal_handler_test.go +++ /dev/null @@ -1,116 +0,0 @@ -package params_test - -import ( - "context" - "testing" - - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/suite" - - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstestutil "github.com/cosmos/cosmos-sdk/x/params/testutil" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// StakingKeeper defines the expected staking keeper -type StakingKeeper interface { - MaxValidators(ctx context.Context) (res uint32, err error) -} - -type HandlerTestSuite struct { - suite.Suite - - ctx sdk.Context - govHandler govv1beta1.Handler - stakingKeeper StakingKeeper -} - -func (suite *HandlerTestSuite) SetupTest() { - encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{}) - key := storetypes.NewKVStoreKey(paramtypes.StoreKey) - tkey := storetypes.NewTransientStoreKey("params_transient_test") - - ctx := testutil.DefaultContext(key, tkey) - paramsKeeper := keeper.NewKeeper(encodingCfg.Codec, encodingCfg.Amino, key, tkey) - paramsKeeper.Subspace("staking").WithKeyTable(stakingtypes.ParamKeyTable()) //nolint:staticcheck // TODO: depreacte this test case - ctrl := gomock.NewController(suite.T()) - stakingKeeper := paramstestutil.NewMockStakingKeeper(ctrl) - stakingKeeper.EXPECT().MaxValidators(ctx).Return(uint32(1), nil) - - suite.govHandler = params.NewParamChangeProposalHandler(paramsKeeper) - suite.stakingKeeper = stakingKeeper - suite.ctx = ctx -} - -func TestHandlerTestSuite(t *testing.T) { - suite.Run(t, new(HandlerTestSuite)) -} - -func testProposal(changes ...proposal.ParamChange) *proposal.ParameterChangeProposal { - return proposal.NewParameterChangeProposal("title", "description", changes) -} - -func (suite *HandlerTestSuite) TestProposalHandler() { - testCases := []struct { - name string - proposal *proposal.ParameterChangeProposal - onHandle func() - expErr bool - }{ - { - "all fields", - testProposal(proposal.NewParamChange(stakingtypes.ModuleName, string(stakingtypes.KeyMaxValidators), "1")), - func() { - maxVals, err := suite.stakingKeeper.MaxValidators(suite.ctx) - suite.Require().NoError(err) - suite.Require().Equal(uint32(1), maxVals) - }, - false, - }, - { - "invalid type", - testProposal(proposal.NewParamChange(stakingtypes.ModuleName, string(stakingtypes.KeyMaxValidators), "-")), - func() {}, - true, - }, - //{ - // "omit empty fields", - // testProposal(proposal.ParamChange{ - // Subspace: govtypes.ModuleName, - // Key: string(govv1.ParamStoreKeyDepositParams), - // Value: `{"min_deposit": [{"denom": "uatom","amount": "64000000"}], "max_deposit_period": "172800000000000"}`, - // }), - // func() { - // depositParams := suite.app.GovKeeper.GetDepositParams(suite.ctx) - // defaultPeriod := govv1.DefaultPeriod - // suite.Require().Equal(govv1.DepositParams{ - // MinDeposit: sdk.NewCoins(sdk.NewCoin("uatom", sdkmath.NewInt(64000000))), - // MaxDepositPeriod: &defaultPeriod, - // }, depositParams) - // }, - // false, - // }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { - err := suite.govHandler(suite.ctx, tc.proposal) - if tc.expErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - tc.onHandle() - } - }) - } -} diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 1e1b36e0602e..9bb25eadf7c7 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -57,7 +57,6 @@ func TestSlashingMsgs(t *testing.T) { app, err := sims.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( - configurator.ParamsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.SlashingModule(), diff --git a/x/slashing/testutil/app_config.go b/x/slashing/testutil/app_config.go index f2fd2d14e061..8e2afcc3be72 100644 --- a/x/slashing/testutil/app_config.go +++ b/x/slashing/testutil/app_config.go @@ -9,7 +9,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/distribution" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/slashing" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -21,7 +20,6 @@ var AppConfig = configurator.NewAppConfig( configurator.SlashingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.MintModule(), configurator.DistributionModule(), diff --git a/x/slashing/testutil/expected_keepers_mocks.go b/x/slashing/testutil/expected_keepers_mocks.go index 08f615baf5d6..1c479da554cc 100644 --- a/x/slashing/testutil/expected_keepers_mocks.go +++ b/x/slashing/testutil/expected_keepers_mocks.go @@ -12,8 +12,7 @@ import ( address "cosmossdk.io/core/address" math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" - types0 "github.com/cosmos/cosmos-sdk/x/params/types" - types1 "github.com/cosmos/cosmos-sdk/x/staking/types" + types0 "github.com/cosmos/cosmos-sdk/x/staking/types" gomock "github.com/golang/mock/gomock" ) @@ -145,93 +144,6 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) } -// MockParamSubspace is a mock of ParamSubspace interface. -type MockParamSubspace struct { - ctrl *gomock.Controller - recorder *MockParamSubspaceMockRecorder -} - -// MockParamSubspaceMockRecorder is the mock recorder for MockParamSubspace. -type MockParamSubspaceMockRecorder struct { - mock *MockParamSubspace -} - -// NewMockParamSubspace creates a new mock instance. -func NewMockParamSubspace(ctrl *gomock.Controller) *MockParamSubspace { - mock := &MockParamSubspace{ctrl: ctrl} - mock.recorder = &MockParamSubspaceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockParamSubspace) EXPECT() *MockParamSubspaceMockRecorder { - return m.recorder -} - -// Get mocks base method. -func (m *MockParamSubspace) Get(ctx types.Context, key []byte, ptr interface{}) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Get", ctx, key, ptr) -} - -// Get indicates an expected call of Get. -func (mr *MockParamSubspaceMockRecorder) Get(ctx, key, ptr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockParamSubspace)(nil).Get), ctx, key, ptr) -} - -// GetParamSet mocks base method. -func (m *MockParamSubspace) GetParamSet(ctx types.Context, ps types0.ParamSet) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "GetParamSet", ctx, ps) -} - -// GetParamSet indicates an expected call of GetParamSet. -func (mr *MockParamSubspaceMockRecorder) GetParamSet(ctx, ps interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParamSet", reflect.TypeOf((*MockParamSubspace)(nil).GetParamSet), ctx, ps) -} - -// HasKeyTable mocks base method. -func (m *MockParamSubspace) HasKeyTable() bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HasKeyTable") - ret0, _ := ret[0].(bool) - return ret0 -} - -// HasKeyTable indicates an expected call of HasKeyTable. -func (mr *MockParamSubspaceMockRecorder) HasKeyTable() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasKeyTable", reflect.TypeOf((*MockParamSubspace)(nil).HasKeyTable)) -} - -// SetParamSet mocks base method. -func (m *MockParamSubspace) SetParamSet(ctx types.Context, ps types0.ParamSet) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetParamSet", ctx, ps) -} - -// SetParamSet indicates an expected call of SetParamSet. -func (mr *MockParamSubspaceMockRecorder) SetParamSet(ctx, ps interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetParamSet", reflect.TypeOf((*MockParamSubspace)(nil).SetParamSet), ctx, ps) -} - -// WithKeyTable mocks base method. -func (m *MockParamSubspace) WithKeyTable(table types0.KeyTable) types0.Subspace { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WithKeyTable", table) - ret0, _ := ret[0].(types0.Subspace) - return ret0 -} - -// WithKeyTable indicates an expected call of WithKeyTable. -func (mr *MockParamSubspaceMockRecorder) WithKeyTable(table interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithKeyTable", reflect.TypeOf((*MockParamSubspace)(nil).WithKeyTable), table) -} - // MockStakingKeeper is a mock of StakingKeeper interface. type MockStakingKeeper struct { ctrl *gomock.Controller @@ -270,10 +182,10 @@ func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call { } // Delegation mocks base method. -func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types.AccAddress, arg2 types.ValAddress) (types1.DelegationI, error) { +func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types.AccAddress, arg2 types.ValAddress) (types0.DelegationI, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2) - ret0, _ := ret[0].(types1.DelegationI) + ret0, _ := ret[0].(types0.DelegationI) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -285,10 +197,10 @@ func (mr *MockStakingKeeperMockRecorder) Delegation(arg0, arg1, arg2 interface{} } // GetAllValidators mocks base method. -func (m *MockStakingKeeper) GetAllValidators(ctx context.Context) ([]types1.Validator, error) { +func (m *MockStakingKeeper) GetAllValidators(ctx context.Context) ([]types0.Validator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAllValidators", ctx) - ret0, _ := ret[0].([]types1.Validator) + ret0, _ := ret[0].([]types0.Validator) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -315,7 +227,7 @@ func (mr *MockStakingKeeperMockRecorder) IsValidatorJailed(ctx, addr interface{} } // IterateValidators mocks base method. -func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types1.ValidatorI) bool) error { +func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types0.ValidatorI) bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "IterateValidators", arg0, arg1) ret0, _ := ret[0].(error) @@ -402,10 +314,10 @@ func (mr *MockStakingKeeperMockRecorder) Unjail(arg0, arg1 interface{}) *gomock. } // Validator mocks base method. -func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types.ValAddress) (types1.ValidatorI, error) { +func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types.ValAddress) (types0.ValidatorI, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Validator", arg0, arg1) - ret0, _ := ret[0].(types1.ValidatorI) + ret0, _ := ret[0].(types0.ValidatorI) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -431,10 +343,10 @@ func (mr *MockStakingKeeperMockRecorder) ValidatorAddressCodec() *gomock.Call { } // ValidatorByConsAddr mocks base method. -func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types.ConsAddress) (types1.ValidatorI, error) { +func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types.ConsAddress) (types0.ValidatorI, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1) - ret0, _ := ret[0].(types1.ValidatorI) + ret0, _ := ret[0].(types0.ValidatorI) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/x/slashing/types/expected_keepers.go b/x/slashing/types/expected_keepers.go index f653d009ccdd..2760c0639cf9 100644 --- a/x/slashing/types/expected_keepers.go +++ b/x/slashing/types/expected_keepers.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -26,15 +25,6 @@ type BankKeeper interface { SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins } -// ParamSubspace defines the expected Subspace interfacace -type ParamSubspace interface { - HasKeyTable() bool - WithKeyTable(table paramtypes.KeyTable) paramtypes.Subspace - Get(ctx sdk.Context, key []byte, ptr interface{}) - GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) - SetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) -} - // StakingKeeper expected staking keeper type StakingKeeper interface { ValidatorAddressCodec() address.Codec diff --git a/x/slashing/types/params_legacy.go b/x/slashing/types/params_legacy.go deleted file mode 100644 index f7ea30db0d55..000000000000 --- a/x/slashing/types/params_legacy.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov -controlled execution of MsgUpdateParams messages. These types remains solely -for migration purposes and will be removed in a future release. -*/ -package types - -import ( - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// Parameter store keys -var ( - KeySignedBlocksWindow = []byte("SignedBlocksWindow") - KeyMinSignedPerWindow = []byte("MinSignedPerWindow") - KeyDowntimeJailDuration = []byte("DowntimeJailDuration") - KeySlashFractionDoubleSign = []byte("SlashFractionDoubleSign") - KeySlashFractionDowntime = []byte("SlashFractionDowntime") -) - -// Deprecated: ParamKeyTable for slashing module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Deprecated: ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeySignedBlocksWindow, &p.SignedBlocksWindow, validateSignedBlocksWindow), - paramtypes.NewParamSetPair(KeyMinSignedPerWindow, &p.MinSignedPerWindow, validateMinSignedPerWindow), - paramtypes.NewParamSetPair(KeyDowntimeJailDuration, &p.DowntimeJailDuration, validateDowntimeJailDuration), - paramtypes.NewParamSetPair(KeySlashFractionDoubleSign, &p.SlashFractionDoubleSign, validateSlashFractionDoubleSign), - paramtypes.NewParamSetPair(KeySlashFractionDowntime, &p.SlashFractionDowntime, validateSlashFractionDowntime), - } -} diff --git a/x/staking/testutil/app_config.go b/x/staking/testutil/app_config.go index 4f9118e395ce..4bebab4a670a 100644 --- a/x/staking/testutil/app_config.go +++ b/x/staking/testutil/app_config.go @@ -9,7 +9,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/distribution" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/slashing" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) @@ -20,7 +19,6 @@ var AppConfig = configurator.NewAppConfig( configurator.StakingModule(), configurator.TxModule(), configurator.ConsensusModule(), - configurator.ParamsModule(), configurator.GenutilModule(), configurator.MintModule(), configurator.DistributionModule(), diff --git a/x/staking/types/params_legacy.go b/x/staking/types/params_legacy.go deleted file mode 100644 index f2ab55624976..000000000000 --- a/x/staking/types/params_legacy.go +++ /dev/null @@ -1,32 +0,0 @@ -package types - -import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - -var ( - KeyUnbondingTime = []byte("UnbondingTime") - KeyMaxValidators = []byte("MaxValidators") - KeyMaxEntries = []byte("MaxEntries") - KeyBondDenom = []byte("BondDenom") - KeyHistoricalEntries = []byte("HistoricalEntries") - KeyMinCommissionRate = []byte("MinCommissionRate") -) - -var _ paramtypes.ParamSet = (*Params)(nil) - -// Deprecated: now params can be accessed on key `0x51` on the staking store. -// ParamTable for staking module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Deprecated: Implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyUnbondingTime, &p.UnbondingTime, validateUnbondingTime), - paramtypes.NewParamSetPair(KeyMaxValidators, &p.MaxValidators, validateMaxValidators), - paramtypes.NewParamSetPair(KeyMaxEntries, &p.MaxEntries, validateMaxEntries), - paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries), - paramtypes.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom), - paramtypes.NewParamSetPair(KeyMinCommissionRate, &p.MinCommissionRate, validateMinCommissionRate), - } -} From c838a719012b263620fb24ce76cf303d16aab6ea Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 10:50:02 +0200 Subject: [PATCH 04/11] some more removal --- server/api/server_test.go | 1 - simapp/app_test.go | 4 +- simapp/app_v2.go | 12 --- simapp/simd/cmd/testnet_test.go | 2 - .../bank/keeper/deterministic_test.go | 1 - tests/integration/rapidgen/rapidgen.go | 5 - tests/integration/tx/decode_test.go | 3 +- x/auth/types/params_legacy.go | 38 ------- x/consensus/exported/exported.go | 9 -- x/distribution/exported/exported.go | 18 ---- x/gov/types/v1/params_legacy.go | 102 ------------------ x/mint/types/params_legacy.go | 39 ------- 12 files changed, 2 insertions(+), 232 deletions(-) delete mode 100644 x/auth/types/params_legacy.go delete mode 100644 x/distribution/exported/exported.go delete mode 100644 x/gov/types/v1/params_legacy.go delete mode 100644 x/mint/types/params_legacy.go diff --git a/server/api/server_test.go b/server/api/server_test.go index 0484277b800c..1066e1128ad7 100644 --- a/server/api/server_test.go +++ b/server/api/server_test.go @@ -27,7 +27,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" _ "github.com/cosmos/cosmos-sdk/x/genutil" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/simapp/app_test.go b/simapp/app_test.go index c25a02da91e0..0936d405ac7a 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -39,7 +39,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" group "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -206,7 +206,6 @@ func TestRunMigrations(t *testing.T) { "slashing": slashing.AppModule{}.ConsensusVersion(), "gov": gov.AppModule{}.ConsensusVersion(), "group": group.AppModule{}.ConsensusVersion(), - "params": params.AppModule{}.ConsensusVersion(), "upgrade": upgrade.AppModule{}.ConsensusVersion(), "vesting": vesting.AppModule{}.ConsensusVersion(), "feegrant": feegrantmodule.AppModule{}.ConsensusVersion(), @@ -255,7 +254,6 @@ func TestInitGenesisOnMigration(t *testing.T) { "distribution": distribution.AppModule{}.ConsensusVersion(), "slashing": slashing.AppModule{}.ConsensusVersion(), "gov": gov.AppModule{}.ConsensusVersion(), - "params": params.AppModule{}.ConsensusVersion(), "upgrade": upgrade.AppModule{}.ConsensusVersion(), "vesting": vesting.AppModule{}.ConsensusVersion(), "feegrant": feegrantmodule.AppModule{}.ConsensusVersion(), diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 38dc0b877cbe..14ef1da5538c 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -41,8 +41,6 @@ import ( govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) @@ -75,7 +73,6 @@ type SimApp struct { GovKeeper *govkeeper.Keeper CrisisKeeper *crisiskeeper.Keeper UpgradeKeeper *upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper @@ -177,7 +174,6 @@ func NewSimApp( &app.GovKeeper, &app.CrisisKeeper, &app.UpgradeKeeper, - &app.ParamsKeeper, &app.AuthzKeeper, &app.EvidenceKeeper, &app.FeeGrantKeeper, @@ -317,14 +313,6 @@ func (app *SimApp) kvStoreKeys() map[string]*storetypes.KVStoreKey { return keys } -// GetSubspace returns a param subspace for a given module name. -// -// NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace { - subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) - return subspace -} - // SimulationManager implements the SimulationApp interface func (app *SimApp) SimulationManager() *module.SimulationManager { return app.sm diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 8cc84047a640..6d697b0d0d12 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -24,7 +24,6 @@ import ( genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -36,7 +35,6 @@ func Test_TestnetCmd(t *testing.T) { staking.AppModuleBasic{}, mint.AppModuleBasic{}, distribution.AppModuleBasic{}, - params.AppModuleBasic{}, consensus.AppModuleBasic{}, ) diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 1cd35ba7d3c5..5f7a48199bd7 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -28,7 +28,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" _ "github.com/cosmos/cosmos-sdk/x/consensus" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/tests/integration/rapidgen/rapidgen.go b/tests/integration/rapidgen/rapidgen.go index 66eaee9a568f..f62ee394d724 100644 --- a/tests/integration/rapidgen/rapidgen.go +++ b/tests/integration/rapidgen/rapidgen.go @@ -25,7 +25,6 @@ import ( gov_v1beta1_api "cosmossdk.io/api/cosmos/gov/v1beta1" groupapi "cosmossdk.io/api/cosmos/group/v1" mintapi "cosmossdk.io/api/cosmos/mint/v1beta1" - paramsapi "cosmossdk.io/api/cosmos/params/v1beta1" slashingapi "cosmossdk.io/api/cosmos/slashing/v1beta1" stakingapi "cosmossdk.io/api/cosmos/staking/v1beta1" upgradeapi "cosmossdk.io/api/cosmos/upgrade/v1beta1" @@ -45,7 +44,6 @@ import ( gov_v1beta1_types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" grouptypes "github.com/cosmos/cosmos-sdk/x/group" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/params/types/proposal" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -267,9 +265,6 @@ var ( GenType(&minttypes.Params{}, &mintapi.Params{}, GenOpts), - // params - GenType(&proposal.ParameterChangeProposal{}, ¶msapi.ParameterChangeProposal{}, GenOpts), - GenType(&slashingtypes.Params{}, &slashingapi.Params{}, GenOpts.WithDisallowNil()), GenType(&stakingtypes.StakeAuthorization{}, &stakingapi.StakeAuthorization{}, GenOpts), diff --git a/tests/integration/tx/decode_test.go b/tests/integration/tx/decode_test.go index f22123e79732..bce4de221af7 100644 --- a/tests/integration/tx/decode_test.go +++ b/tests/integration/tx/decode_test.go @@ -35,7 +35,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -45,7 +44,7 @@ func TestDecode(t *testing.T) { encCfg := testutil.MakeTestEncodingConfig( auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}, consensus.AppModuleBasic{}, distribution.AppModuleBasic{}, evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, - gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{}, + gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, slashing.AppModuleBasic{}, staking.AppModuleBasic{}, upgrade.AppModuleBasic{}, vesting.AppModuleBasic{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino diff --git a/x/auth/types/params_legacy.go b/x/auth/types/params_legacy.go deleted file mode 100644 index 8800f5822283..000000000000 --- a/x/auth/types/params_legacy.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov -controlled execution of MsgUpdateParams messages. These types remains solely -for migration purposes and will be removed in a future release. -*/ -package types - -import ( - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// Parameter keys -var ( - KeyMaxMemoCharacters = []byte("MaxMemoCharacters") - KeyTxSigLimit = []byte("TxSigLimit") - KeyTxSizeCostPerByte = []byte("TxSizeCostPerByte") - KeySigVerifyCostED25519 = []byte("SigVerifyCostED25519") - KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1") -) - -var _ paramtypes.ParamSet = &Params{} - -// Deprecated: ParamKeyTable for auth module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs -// pairs of auth module's parameters. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyMaxMemoCharacters, &p.MaxMemoCharacters, validateMaxMemoCharacters), - paramtypes.NewParamSetPair(KeyTxSigLimit, &p.TxSigLimit, validateTxSigLimit), - paramtypes.NewParamSetPair(KeyTxSizeCostPerByte, &p.TxSizeCostPerByte, validateTxSizeCostPerByte), - paramtypes.NewParamSetPair(KeySigVerifyCostED25519, &p.SigVerifyCostED25519, validateSigVerifyCostED25519), - paramtypes.NewParamSetPair(KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1, validateSigVerifyCostSecp256k1), - } -} diff --git a/x/consensus/exported/exported.go b/x/consensus/exported/exported.go index 60dd19abb47a..ab6371156338 100644 --- a/x/consensus/exported/exported.go +++ b/x/consensus/exported/exported.go @@ -4,18 +4,9 @@ import ( "context" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - - sdk "github.com/cosmos/cosmos-sdk/types" ) type ( - // ParamStore defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - ParamStore interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - } // ConsensusParamSetter defines the interface fulfilled by BaseApp's // ParamStore which allows setting its appVersion field. diff --git a/x/distribution/exported/exported.go b/x/distribution/exported/exported.go deleted file mode 100644 index 000114e6194d..000000000000 --- a/x/distribution/exported/exported.go +++ /dev/null @@ -1,18 +0,0 @@ -package exported - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -type ( - ParamSet = paramtypes.ParamSet - - // Subspace defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - Subspace interface { - GetParamSet(ctx sdk.Context, ps ParamSet) - } -) diff --git a/x/gov/types/v1/params_legacy.go b/x/gov/types/v1/params_legacy.go deleted file mode 100644 index ceee66b23529..000000000000 --- a/x/gov/types/v1/params_legacy.go +++ /dev/null @@ -1,102 +0,0 @@ -package v1 - -import ( - "errors" - "fmt" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// Parameter store key -var ( - ParamStoreKeyDepositParams = []byte("depositparams") - ParamStoreKeyVotingParams = []byte("votingparams") - ParamStoreKeyTallyParams = []byte("tallyparams") -) - -// Deprecated: ParamKeyTable - Key declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable( - paramtypes.NewParamSetPair(ParamStoreKeyDepositParams, DepositParams{}, validateDepositParams), - paramtypes.NewParamSetPair(ParamStoreKeyVotingParams, VotingParams{}, validateVotingParams), - paramtypes.NewParamSetPair(ParamStoreKeyTallyParams, TallyParams{}, validateTallyParams), - ) -} - -func validateDepositParams(i interface{}) error { - v, ok := i.(DepositParams) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if !sdk.Coins(v.MinDeposit).IsValid() { - return fmt.Errorf("invalid minimum deposit: %s", v.MinDeposit) - } - if v.MaxDepositPeriod == nil || v.MaxDepositPeriod.Seconds() <= 0 { - return fmt.Errorf("maximum deposit period must be positive: %d", v.MaxDepositPeriod) - } - - return nil -} - -func validateTallyParams(i interface{}) error { - v, ok := i.(TallyParams) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - quorum, err := math.LegacyNewDecFromStr(v.Quorum) - if err != nil { - return fmt.Errorf("invalid quorum string: %w", err) - } - if quorum.IsNegative() { - return fmt.Errorf("quorom cannot be negative: %s", quorum) - } - if quorum.GT(math.LegacyOneDec()) { - return fmt.Errorf("quorom too large: %s", v) - } - - threshold, err := math.LegacyNewDecFromStr(v.Threshold) - if err != nil { - return fmt.Errorf("invalid threshold string: %w", err) - } - if !threshold.IsPositive() { - return fmt.Errorf("vote threshold must be positive: %s", threshold) - } - if threshold.GT(math.LegacyOneDec()) { - return fmt.Errorf("vote threshold too large: %s", v) - } - - vetoThreshold, err := math.LegacyNewDecFromStr(v.VetoThreshold) - if err != nil { - return fmt.Errorf("invalid vetoThreshold string: %w", err) - } - if !vetoThreshold.IsPositive() { - return fmt.Errorf("veto threshold must be positive: %s", vetoThreshold) - } - if vetoThreshold.GT(math.LegacyOneDec()) { - return fmt.Errorf("veto threshold too large: %s", v) - } - - return nil -} - -func validateVotingParams(i interface{}) error { - v, ok := i.(VotingParams) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.VotingPeriod == nil { - return errors.New("voting period must not be nil") - } - - if v.VotingPeriod.Seconds() <= 0 { - return fmt.Errorf("voting period must be positive: %s", v.VotingPeriod) - } - - return nil -} diff --git a/x/mint/types/params_legacy.go b/x/mint/types/params_legacy.go deleted file mode 100644 index 23354e2f89ea..000000000000 --- a/x/mint/types/params_legacy.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov -controlled execution of MsgUpdateParams messages. These types remains solely -for migration purposes and will be removed in a future release. -*/ -package types - -import ( - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// Parameter store keys -var ( - KeyMintDenom = []byte("MintDenom") - KeyInflationRateChange = []byte("InflationRateChange") - KeyInflationMax = []byte("InflationMax") - KeyInflationMin = []byte("InflationMin") - KeyGoalBonded = []byte("GoalBonded") - KeyBlocksPerYear = []byte("BlocksPerYear") -) - -// Deprecated: ParamTable for minting module. -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Implements params.ParamSet -// -// Deprecated. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom), - paramtypes.NewParamSetPair(KeyInflationRateChange, &p.InflationRateChange, validateInflationRateChange), - paramtypes.NewParamSetPair(KeyInflationMax, &p.InflationMax, validateInflationMax), - paramtypes.NewParamSetPair(KeyInflationMin, &p.InflationMin, validateInflationMin), - paramtypes.NewParamSetPair(KeyGoalBonded, &p.GoalBonded, validateGoalBonded), - paramtypes.NewParamSetPair(KeyBlocksPerYear, &p.BlocksPerYear, validateBlocksPerYear), - } -} From 891b0570c9642f93bee47cf3cedcd7cb7c2a1b64 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 11:50:03 +0200 Subject: [PATCH 05/11] still provide --- x/gov/module.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/x/gov/module.go b/x/gov/module.go index 98071fc834c1..f70139e041b7 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -157,11 +157,8 @@ func (am AppModule) IsAppModule() {} func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Invoke(InvokeAddRoutes, InvokeSetHooks)) -} - -func ProvideKeyTable() paramtypes.KeyTable { - return v1.ParamKeyTable() //nolint:staticcheck // we still need this for upgrades + appmodule.Invoke(InvokeAddRoutes, InvokeSetHooks), + appmodule.Provide(ProvideModule)) } type ModuleInputs struct { From 2f8f1c842130cda0ec4fefd913140ab325e2ea3e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 11:51:12 +0200 Subject: [PATCH 06/11] lint --- simapp/app_test.go | 1 - x/bank/simulation/genesis.go | 6 ++---- x/distribution/types/params.go | 9 --------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/simapp/app_test.go b/simapp/app_test.go index 0936d405ac7a..07aa456e1249 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -39,7 +39,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" group "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index b5c75e3726be..65fff19a7c12 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -12,10 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/types" ) -var ( - // KeyDefaultSendEnabled is store's key for the DefaultSendEnabled option - KeyDefaultSendEnabled = []byte("DefaultSendEnabled") -) +// KeyDefaultSendEnabled is store's key for the DefaultSendEnabled option +var KeyDefaultSendEnabled = []byte("DefaultSendEnabled") // RandomGenesisDefaultSendEnabledParam computes randomized allow all send transfers param for the bank module func RandomGenesisDefaultSendEnabledParam(r *rand.Rand) bool { diff --git a/x/distribution/types/params.go b/x/distribution/types/params.go index f7c980284175..b8438ca73812 100644 --- a/x/distribution/types/params.go +++ b/x/distribution/types/params.go @@ -39,12 +39,3 @@ func validateCommunityTax(i interface{}) error { return nil } - -func validateWithdrawAddrEnabled(i interface{}) error { - _, ok := i.(bool) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - return nil -} From 447e1dd0268697095e28b9fd92733c6efdabbf0a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 11:53:07 +0200 Subject: [PATCH 07/11] add back configurator --- testutil/configurator/configurator.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index adcce08f81ab..dea6a646486f 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -16,6 +16,7 @@ import ( groupmodulev1 "cosmossdk.io/api/cosmos/group/module/v1" mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" nftmodulev1 "cosmossdk.io/api/cosmos/nft/module/v1" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" @@ -56,6 +57,7 @@ func defaultConfig() *Config { "nft", "group", "consensus", + "params", "vesting", "circuit", }, @@ -159,7 +161,14 @@ func AuthModule() ModuleOption { } } } - +func ParamsModule() ModuleOption { + return func(config *Config) { + config.ModuleConfigs["params"] = &appv1alpha1.ModuleConfig{ + Name: "params", + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + } + } +} func TxModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["tx"] = &appv1alpha1.ModuleConfig{ From dce92fe614f4c4fa6809d0addd3d5149459ec899 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 11:57:45 +0200 Subject: [PATCH 08/11] add changelog --- CHANGELOG.md | 1 + testutil/configurator/configurator.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aad319de529a..7d3fe82356cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -261,6 +261,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (signing) [#14087](https://github.com/cosmos/cosmos-sdk/pull/14087) Add SignModeHandlerWithContext interface with a new `GetSignBytesWithContext` to get the sign bytes using `context.Context` as an argument to access state. * (server) [#14062](https://github.com/cosmos/cosmos-sdk/pull/14062) Remove rosetta from server start. * (crypto) [#3129](https://github.com/cosmos/cosmos-sdk/pull/3129) New armor and keyring key derivation uses aead and encryption uses chacha20poly. +* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo. The Cosmos SDK has migrated aay from using params, if youre app still uses it, then you can leave it plugged into your app ### State Machine Breaking diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index dea6a646486f..c3b8cfdbd881 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -76,7 +76,6 @@ func defaultConfig() *Config { "feegrant", "nft", "group", - "params", "consensus", "upgrade", "vesting", @@ -97,7 +96,6 @@ func defaultConfig() *Config { "feegrant", "nft", "group", - "params", "consensus", "upgrade", "vesting", From b13c902406fe9baeab57a409c65567d5d2a7c84f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 13:37:02 +0200 Subject: [PATCH 09/11] changelog and upgrading --- CHANGELOG.md | 3 ++- UPGRADING.md | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3fe82356cd..a8b7fb2afd87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -261,7 +261,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (signing) [#14087](https://github.com/cosmos/cosmos-sdk/pull/14087) Add SignModeHandlerWithContext interface with a new `GetSignBytesWithContext` to get the sign bytes using `context.Context` as an argument to access state. * (server) [#14062](https://github.com/cosmos/cosmos-sdk/pull/14062) Remove rosetta from server start. * (crypto) [#3129](https://github.com/cosmos/cosmos-sdk/pull/3129) New armor and keyring key derivation uses aead and encryption uses chacha20poly. -* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo. The Cosmos SDK has migrated aay from using params, if youre app still uses it, then you can leave it plugged into your app +* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo. + * The Cosmos SDK has migrated aay from using params, if you're app still uses it, then you can leave it plugged into your app ### State Machine Breaking diff --git a/UPGRADING.md b/UPGRADING.md index f1a4ce7a9a7a..792e7f826496 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -5,6 +5,10 @@ Note, always read the **SimApp** section for more information on application wir ## [Unreleased] +### Params + +Params Migrations were removed. It is required to migrate to 0.50 prior to upgrading to .51. + ### SimApp In this section we describe the changes made in Cosmos SDK' SimApp. From bdee21ae8cb2756f91787bf0e802a75aac11965a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 15:23:35 +0200 Subject: [PATCH 10/11] fix test --- tests/integration/runtime/query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go index ee524e05a28d..2c8b1e16ef7a 100644 --- a/tests/integration/runtime/query_test.go +++ b/tests/integration/runtime/query_test.go @@ -81,7 +81,7 @@ func TestQueryAppConfig(t *testing.T) { } // has all expected modules - for _, modName := range []string{"auth", "bank", "tx", "consensus", "runtime", "params", "staking"} { + for _, modName := range []string{"auth", "bank", "tx", "consensus", "runtime", "staking"} { modConfig := moduleConfigs[modName] if modConfig == nil { t.Fatalf("missing %s", modName) From 48856e1c449564547836a6ad5134549e80a26fb1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 22 Sep 2023 15:30:47 +0200 Subject: [PATCH 11/11] fix lint --- testutil/configurator/configurator.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index c3b8cfdbd881..4964cbf489a1 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -159,6 +159,7 @@ func AuthModule() ModuleOption { } } } + func ParamsModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["params"] = &appv1alpha1.ModuleConfig{ @@ -167,6 +168,7 @@ func ParamsModule() ModuleOption { } } } + func TxModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["tx"] = &appv1alpha1.ModuleConfig{