Skip to content

Commit

Permalink
fix(x/bank): miss keypair of SendEnabled to restore legacy param set …
Browse files Browse the repository at this point in the history
…before migration

this change was introduced in https://github.com/cosmos/cosmos-sdk/pull/11977/files,
but accidently get removed in https://github.com/cosmos/cosmos-sdk/pull/12630/files,
since bank send_enabled refactor before params migration
  • Loading branch information
mmsqe committed Oct 13, 2023
1 parent d24d469 commit 68c0f8c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (x/gov) [#17910](https://github.com/cosmos/cosmos-sdk/pull/17910) Remove telemetry for counting votes and proposals. It was incorrectly counting votes. Use alternatives, such as state streaming.

### State Machine Breaking

* (x/bank) [#18107](https://github.com/cosmos/cosmos-sdk/pull/18107) Add missing keypair of SendEnabled to restore legacy param set before migration.

## [v0.47.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.5) - 2023-09-01

### Features
Expand Down
1 change: 1 addition & 0 deletions x/bank/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
)
4 changes: 4 additions & 0 deletions x/bank/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,5 +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 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)
}
3 changes: 3 additions & 0 deletions x/bank/migrations/v4/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions x/bank/migrations/v4/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 TestMigrate(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(bank.AppModuleBasic{})
cdc := encCfg.Codec
Expand Down
38 changes: 37 additions & 1 deletion x/bank/types/params_legacy.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

0 comments on commit 68c0f8c

Please sign in to comment.