From 7c86924a75ff681acdda9adbb4b2e4d66eedcefd Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 08:39:21 +0800 Subject: [PATCH 01/12] Problem: miss keypair of SendEnabled to restore legacy param set before migration --- CHANGELOG.md | 1 + x/bank/keeper/migrations.go | 8 +++++++- x/bank/migrations/v4/store.go | 7 +------ x/bank/types/params_legacy.go | 38 ++++++++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c71eb8612fd0..6ccd3e7c4ec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (x/gov) [#17780](https://github.com/cosmos/cosmos-sdk/pull/17780) Recover panics and turn them into errors when executing x/gov proposals. +* (x/bank) [#](https://github.com/crypto-org-chain/cosmos-sdk/pull/) Add miss keypair of SendEnabled to restore legacy param set before migration. ### Bug Fixes diff --git a/x/bank/keeper/migrations.go b/x/bank/keeper/migrations.go index 2e2d0ee7ad7a..0139556953a3 100644 --- a/x/bank/keeper/migrations.go +++ b/x/bank/keeper/migrations.go @@ -6,6 +6,7 @@ import ( v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" v3 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v3" v4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // Migrator is a struct for handling in-place store migrations. @@ -31,5 +32,10 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { // Migrate3to4 migrates x/bank storage from version 3 to 4. func (m Migrator) Migrate3to4(ctx sdk.Context) error { - return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) + var oldParams types.Params + m.legacySubspace.GetParamSet(ctx, &oldParams) + m.keeper.SetAllSendEnabled(ctx, oldParams.GetSendEnabled()) + currParams := types.NewParams(oldParams.DefaultSendEnabled) + m.keeper.SetParams(ctx, currParams) + return v4.MigrateStore(ctx, m.keeper.storeKey, currParams, m.keeper.cdc) } diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index 03c5b02f43bc..61c66ca73af6 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -16,11 +15,8 @@ var ParamsKey = []byte{0x05} // version 4. Specifically, it takes the parameters that are currently stored // and managed by the x/params module and stores them directly into the x/bank // module state. -func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, currParams types.Params, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) - var currParams types.Params - legacySubspace.GetParamSet(ctx, &currParams) - if err := currParams.Validate(); err != nil { return err } @@ -29,7 +25,6 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace if err != nil { return err } - store.Set(ParamsKey, bz) return nil diff --git a/x/bank/types/params_legacy.go b/x/bank/types/params_legacy.go index 668358b4df7a..d88d15218938 100644 --- a/x/bank/types/params_legacy.go +++ b/x/bank/types/params_legacy.go @@ -1,6 +1,11 @@ package types -import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) var ( // KeySendEnabled is store's key for SendEnabled Params @@ -18,6 +23,37 @@ func ParamKeyTable() paramtypes.KeyTable { // Deprecated: ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeySendEnabled, &p.SendEnabled, validateSendEnabledParams), paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool), } } + +// SendEnabledParams is a collection of parameters indicating if a coin denom is enabled for sending +type SendEnabledParams []*SendEnabled + +func validateSendEnabledParams(i interface{}) error { + params, ok := i.([]*SendEnabled) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + // ensure each denom is only registered one time. + registered := make(map[string]bool) + for _, p := range params { + if _, exists := registered[p.Denom]; exists { + return fmt.Errorf("duplicate send enabled parameter found: '%s'", p.Denom) + } + if err := validateSendEnabled(*p); err != nil { + return err + } + registered[p.Denom] = true + } + return nil +} + +func validateSendEnabled(i interface{}) error { + param, ok := i.(SendEnabled) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return sdk.ValidateDenom(param.Denom) +} From 773bde0a3a9fced9d5c305616524e737614ab290 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 08:40:53 +0800 Subject: [PATCH 02/12] Update CHANGELOG.md Signed-off-by: mmsqe --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ccd3e7c4ec4..71c0e2affa5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (x/gov) [#17780](https://github.com/cosmos/cosmos-sdk/pull/17780) Recover panics and turn them into errors when executing x/gov proposals. -* (x/bank) [#](https://github.com/crypto-org-chain/cosmos-sdk/pull/) Add miss keypair of SendEnabled to restore legacy param set before migration. +* (x/bank) [#194](https://github.com/crypto-org-chain/cosmos-sdk/pull/194) Add miss keypair of SendEnabled to restore legacy param set before migration. ### Bug Fixes From 43b2ca5c15e9eac2f9de4932f48425bcfffcdccb Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 10:14:52 +0800 Subject: [PATCH 03/12] fix test --- x/bank/migrations/v4/store_test.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/x/bank/migrations/v4/store_test.go b/x/bank/migrations/v4/store_test.go index b9d2c035c25b..25d6f07d9f84 100644 --- a/x/bank/migrations/v4/store_test.go +++ b/x/bank/migrations/v4/store_test.go @@ -7,24 +7,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/bank/exported" v4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4" "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" ) -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(bank.AppModuleBasic{}) cdc := encCfg.Codec @@ -34,11 +21,10 @@ func TestMigrate(t *testing.T) { ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) - legacySubspace := newMockSubspace(types.DefaultParams()) - require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc)) + require.NoError(t, v4.MigrateStore(ctx, storeKey, types.DefaultParams(), cdc)) var res types.Params bz := store.Get(v4.ParamsKey) require.NoError(t, cdc.Unmarshal(bz, &res)) - require.Equal(t, legacySubspace.ps, res) + require.Equal(t, types.DefaultParams(), res) } From dcbb61e9b5f99dce3de93cb1b0e54523f8f34c00 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 10:50:34 +0800 Subject: [PATCH 04/12] Apply suggestions from code review --- x/bank/exported/exported.go | 1 + x/bank/keeper/migrations.go | 10 ++++------ x/bank/migrations/v4/store.go | 9 +++++---- x/bank/migrations/v4/store_test.go | 20 ++++++++++++++++++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 7ab9136e896d..9a518025968c 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -21,5 +21,6 @@ type ( // NOTE: This is used solely for migration of x/params managed parameters. Subspace interface { GetParamSet(ctx sdk.Context, ps ParamSet) + Get(ctx sdk.Context, key []byte, ptr interface{}) } ) diff --git a/x/bank/keeper/migrations.go b/x/bank/keeper/migrations.go index 0139556953a3..32880532c7f4 100644 --- a/x/bank/keeper/migrations.go +++ b/x/bank/keeper/migrations.go @@ -32,10 +32,8 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { // Migrate3to4 migrates x/bank storage from version 3 to 4. func (m Migrator) Migrate3to4(ctx sdk.Context) error { - var oldParams types.Params - m.legacySubspace.GetParamSet(ctx, &oldParams) - m.keeper.SetAllSendEnabled(ctx, oldParams.GetSendEnabled()) - currParams := types.NewParams(oldParams.DefaultSendEnabled) - m.keeper.SetParams(ctx, currParams) - return v4.MigrateStore(ctx, m.keeper.storeKey, currParams, m.keeper.cdc) + var sendEnabled []*types.SendEnabled + m.legacySubspace.Get(ctx, types.KeySendEnabled, &sendEnabled) + m.keeper.SetAllSendEnabled(ctx, sendEnabled) + return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) } diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index 61c66ca73af6..5bd10c8dd34c 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -15,16 +16,16 @@ var ParamsKey = []byte{0x05} // version 4. Specifically, it takes the parameters that are currently stored // and managed by the x/params module and stores them directly into the x/bank // module state. -func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, currParams types.Params, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) - if err := currParams.Validate(); err != nil { - return err - } + var currParams types.Params + legacySubspace.GetParamSet(ctx, &currParams) bz, err := cdc.Marshal(&currParams) if err != nil { return err } + store.Set(ParamsKey, bz) return nil diff --git a/x/bank/migrations/v4/store_test.go b/x/bank/migrations/v4/store_test.go index 25d6f07d9f84..537d2a39c854 100644 --- a/x/bank/migrations/v4/store_test.go +++ b/x/bank/migrations/v4/store_test.go @@ -7,11 +7,26 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/bank/exported" v4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4" "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" ) +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 (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) {} + func TestMigrate(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(bank.AppModuleBasic{}) cdc := encCfg.Codec @@ -21,10 +36,11 @@ func TestMigrate(t *testing.T) { ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) - require.NoError(t, v4.MigrateStore(ctx, storeKey, types.DefaultParams(), cdc)) + legacySubspace := newMockSubspace(types.DefaultParams()) + require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc)) var res types.Params bz := store.Get(v4.ParamsKey) require.NoError(t, cdc.Unmarshal(bz, &res)) - require.Equal(t, types.DefaultParams(), res) + require.Equal(t, legacySubspace.ps, res) } From cffd5bbcfa8006059328b82677177d74fdc7c005 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 11:03:01 +0800 Subject: [PATCH 05/12] keep currParams validate --- x/bank/migrations/v4/store.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index 5bd10c8dd34c..03c5b02f43bc 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -21,6 +21,10 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) + if err := currParams.Validate(); err != nil { + return err + } + bz, err := cdc.Marshal(&currParams) if err != nil { return err From fab5d3e297fc7622c01a80455e94d2d689d1b5af Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 13 Oct 2023 11:22:21 +0800 Subject: [PATCH 06/12] cleanup --- x/bank/exported/exported.go | 2 +- x/bank/keeper/migrations.go | 7 ++++++- x/bank/types/params_legacy.go | 34 ---------------------------------- 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 9a518025968c..dbe3cb741cd7 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -21,6 +21,6 @@ type ( // NOTE: This is used solely for migration of x/params managed parameters. Subspace interface { GetParamSet(ctx sdk.Context, ps ParamSet) - Get(ctx sdk.Context, key []byte, ptr interface{}) + GetRaw(ctx sdk.Context, key []byte) []byte } ) diff --git a/x/bank/keeper/migrations.go b/x/bank/keeper/migrations.go index 32880532c7f4..31cb3dea0a36 100644 --- a/x/bank/keeper/migrations.go +++ b/x/bank/keeper/migrations.go @@ -1,6 +1,7 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" @@ -13,6 +14,7 @@ import ( type Migrator struct { keeper BaseKeeper legacySubspace exported.Subspace + legacyAmino *codec.LegacyAmino } // NewMigrator returns a new Migrator. @@ -33,7 +35,10 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { // Migrate3to4 migrates x/bank storage from version 3 to 4. func (m Migrator) Migrate3to4(ctx sdk.Context) error { var sendEnabled []*types.SendEnabled - m.legacySubspace.Get(ctx, types.KeySendEnabled, &sendEnabled) + bz := m.legacySubspace.GetRaw(ctx, types.KeySendEnabled) + if err := m.legacyAmino.UnmarshalJSON(bz, &sendEnabled); err != nil { + return err + } m.keeper.SetAllSendEnabled(ctx, sendEnabled) return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) } diff --git a/x/bank/types/params_legacy.go b/x/bank/types/params_legacy.go index d88d15218938..2b4a2142a522 100644 --- a/x/bank/types/params_legacy.go +++ b/x/bank/types/params_legacy.go @@ -1,9 +1,6 @@ package types import ( - fmt "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -23,37 +20,6 @@ func ParamKeyTable() paramtypes.KeyTable { // Deprecated: ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeySendEnabled, &p.SendEnabled, validateSendEnabledParams), paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool), } } - -// SendEnabledParams is a collection of parameters indicating if a coin denom is enabled for sending -type SendEnabledParams []*SendEnabled - -func validateSendEnabledParams(i interface{}) error { - params, ok := i.([]*SendEnabled) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - // ensure each denom is only registered one time. - registered := make(map[string]bool) - for _, p := range params { - if _, exists := registered[p.Denom]; exists { - return fmt.Errorf("duplicate send enabled parameter found: '%s'", p.Denom) - } - if err := validateSendEnabled(*p); err != nil { - return err - } - registered[p.Denom] = true - } - return nil -} - -func validateSendEnabled(i interface{}) error { - param, ok := i.(SendEnabled) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - return sdk.ValidateDenom(param.Denom) -} From 482394d6d41351ef57c810c0c5511fe1c3de3fa1 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 13 Oct 2023 11:26:27 +0800 Subject: [PATCH 07/12] Revert "cleanup" This reverts commit fab5d3e297fc7622c01a80455e94d2d689d1b5af. --- x/bank/exported/exported.go | 2 +- x/bank/keeper/migrations.go | 7 +------ x/bank/types/params_legacy.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index dbe3cb741cd7..9a518025968c 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -21,6 +21,6 @@ type ( // NOTE: This is used solely for migration of x/params managed parameters. Subspace interface { GetParamSet(ctx sdk.Context, ps ParamSet) - GetRaw(ctx sdk.Context, key []byte) []byte + Get(ctx sdk.Context, key []byte, ptr interface{}) } ) diff --git a/x/bank/keeper/migrations.go b/x/bank/keeper/migrations.go index 31cb3dea0a36..32880532c7f4 100644 --- a/x/bank/keeper/migrations.go +++ b/x/bank/keeper/migrations.go @@ -1,7 +1,6 @@ package keeper import ( - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" @@ -14,7 +13,6 @@ import ( type Migrator struct { keeper BaseKeeper legacySubspace exported.Subspace - legacyAmino *codec.LegacyAmino } // NewMigrator returns a new Migrator. @@ -35,10 +33,7 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { // Migrate3to4 migrates x/bank storage from version 3 to 4. func (m Migrator) Migrate3to4(ctx sdk.Context) error { var sendEnabled []*types.SendEnabled - bz := m.legacySubspace.GetRaw(ctx, types.KeySendEnabled) - if err := m.legacyAmino.UnmarshalJSON(bz, &sendEnabled); err != nil { - return err - } + m.legacySubspace.Get(ctx, types.KeySendEnabled, &sendEnabled) m.keeper.SetAllSendEnabled(ctx, sendEnabled) return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) } diff --git a/x/bank/types/params_legacy.go b/x/bank/types/params_legacy.go index 2b4a2142a522..d88d15218938 100644 --- a/x/bank/types/params_legacy.go +++ b/x/bank/types/params_legacy.go @@ -1,6 +1,9 @@ package types import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -20,6 +23,37 @@ func ParamKeyTable() paramtypes.KeyTable { // Deprecated: ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeySendEnabled, &p.SendEnabled, validateSendEnabledParams), paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool), } } + +// SendEnabledParams is a collection of parameters indicating if a coin denom is enabled for sending +type SendEnabledParams []*SendEnabled + +func validateSendEnabledParams(i interface{}) error { + params, ok := i.([]*SendEnabled) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + // ensure each denom is only registered one time. + registered := make(map[string]bool) + for _, p := range params { + if _, exists := registered[p.Denom]; exists { + return fmt.Errorf("duplicate send enabled parameter found: '%s'", p.Denom) + } + if err := validateSendEnabled(*p); err != nil { + return err + } + registered[p.Denom] = true + } + return nil +} + +func validateSendEnabled(i interface{}) error { + param, ok := i.(SendEnabled) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return sdk.ValidateDenom(param.Denom) +} From ab1e521986cdcdcd7eb7bd1a10e4334c608e2f23 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 13 Oct 2023 11:27:27 +0800 Subject: [PATCH 08/12] clear SendEnabled from params --- x/bank/migrations/v4/store.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index 03c5b02f43bc..2a0482838fa0 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -21,6 +21,9 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) + // it's migrated to the x/bank module store, so delete from the params + currParams.SendEnabled = nil + if err := currParams.Validate(); err != nil { return err } From 8e32e57156759517415097eacb1b7d41bcd5e6f0 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 11:52:43 +0800 Subject: [PATCH 09/12] fix test --- tests/integration/bank/keeper/keeper_test.go | 2 ++ x/bank/keeper/keeper_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/integration/bank/keeper/keeper_test.go b/tests/integration/bank/keeper/keeper_test.go index 7b37a19be0b2..493103ef3ea2 100644 --- a/tests/integration/bank/keeper/keeper_test.go +++ b/tests/integration/bank/keeper/keeper_test.go @@ -1642,6 +1642,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { *ps.(*types.Params) = ms.ps } +func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) {} + func (suite *IntegrationTestSuite) TestMigrator_Migrate3to4() { ctx, bankKeeper := suite.ctx, suite.bankKeeper diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 9cb428322b82..cd1daabe086c 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1697,6 +1697,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { *ps.(*banktypes.Params) = ms.ps } +func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) {} + func (suite *KeeperTestSuite) TestMigrator_Migrate3to4() { ctx, bankKeeper := suite.ctx, suite.bankKeeper require := suite.Require() From b1a82bd6e5a4983470da34664f391a66c633df14 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 13 Oct 2023 12:09:13 +0800 Subject: [PATCH 10/12] fix doc --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c0e2affa5c..ad5540def3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (x/gov) [#17780](https://github.com/cosmos/cosmos-sdk/pull/17780) Recover panics and turn them into errors when executing x/gov proposals. -* (x/bank) [#194](https://github.com/crypto-org-chain/cosmos-sdk/pull/194) Add miss keypair of SendEnabled to restore legacy param set before migration. ### Bug Fixes @@ -48,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (config) [#17649](https://github.com/cosmos/cosmos-sdk/pull/17649) Fix `mempool.max-txs` configuration is invalid in `app.config`. * (mempool) [#17668](https://github.com/cosmos/cosmos-sdk/pull/17668) Fix `PriorityNonceIterator.Next()` nil pointer ref for min priority at the end of iteration. * (x/auth) [#17902](https://github.com/cosmos/cosmos-sdk/pull/17902) Remove tip posthandler. +* (x/bank) [#194](https://github.com/crypto-org-chain/cosmos-sdk/pull/194) Add miss keypair of SendEnabled to restore legacy param set before migration. ### Client Breaking Changes From 74c53fe6e2a735ead1cf1e2b8744ad6831775bcc Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 13 Oct 2023 15:22:34 +0800 Subject: [PATCH 11/12] Update x/bank/migrations/v4/store.go Co-authored-by: mmsqe Signed-off-by: yihuang --- x/bank/migrations/v4/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index 2a0482838fa0..f96357d1d3e7 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -22,7 +22,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace legacySubspace.GetParamSet(ctx, &currParams) // it's migrated to the x/bank module store, so delete from the params - currParams.SendEnabled = nil + currParams = types.NewParams(currParams.DefaultSendEnabled) if err := currParams.Validate(); err != nil { return err From 6f09c0035644a385d3497bb4f3a1856d3ea5b268 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 13 Oct 2023 15:23:10 +0800 Subject: [PATCH 12/12] Update x/bank/migrations/v4/store.go Signed-off-by: yihuang --- x/bank/migrations/v4/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/migrations/v4/store.go b/x/bank/migrations/v4/store.go index f96357d1d3e7..9d8eb41289f3 100644 --- a/x/bank/migrations/v4/store.go +++ b/x/bank/migrations/v4/store.go @@ -21,7 +21,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) - // it's migrated to the x/bank module store, so delete from the params + // SendEnabled is migrated to the x/bank module store, so delete from the params currParams = types.NewParams(currParams.DefaultSendEnabled) if err := currParams.Validate(); err != nil {