fix(x/bank): miss keypair of SendEnabled to restore legacy param set before migration (#18113)
This commit is contained in:
parent
753dd912f5
commit
9c2c424a1e
@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* (x/gov) [#17873](https://github.com/cosmos/cosmos-sdk/pull/17873) Fail any inactive and active proposals that cannot be decoded.
|
||||
* (x/slashing) [#18016](https://github.com/cosmos/cosmos-sdk/pull/18016) Fixed builder function for missed blocks key (`validatorMissedBlockBitArrayPrefixKey`) in slashing/migration/v4
|
||||
* (x/bank) [#18107](https://github.com/cosmos/cosmos-sdk/pull/18107) Add missing keypair of SendEnabled to restore legacy param set before migration.
|
||||
|
||||
### Client Breaking Changes
|
||||
|
||||
|
||||
@ -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 any)
|
||||
}
|
||||
)
|
||||
|
||||
@ -2376,6 +2376,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() {
|
||||
bankKeeper := suite.bankKeeper
|
||||
ctx := sdk.UnwrapSDKContext(suite.ctx)
|
||||
|
||||
@ -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,12 @@ 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 {
|
||||
m.MigrateSendEnabledParams(ctx)
|
||||
return v4.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
|
||||
}
|
||||
|
||||
// MigrateSendEnabledParams get params from x/params and update the bank params.
|
||||
func (m Migrator) MigrateSendEnabledParams(ctx sdk.Context) {
|
||||
sendEnabled := types.GetSendEnabledParams(ctx, m.legacySubspace)
|
||||
m.keeper.SetAllSendEnabled(ctx, sendEnabled)
|
||||
}
|
||||
|
||||
@ -156,6 +156,6 @@ func TestMigrateGenState(t *testing.T) {
|
||||
},
|
||||
}
|
||||
_ = v4.MigrateGenState(&origState)
|
||||
assert.Len(t, origState.Params.SendEnabled, 2)
|
||||
assert.Len(t, origState.Params.SendEnabled, 2) //nolint:staticcheck // SA1019: keep for test
|
||||
})
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@ func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, legacySubs
|
||||
var currParams types.Params
|
||||
legacySubspace.GetParamSet(ctx, &currParams)
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -29,6 +29,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
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
package types
|
||||
|
||||
import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
import (
|
||||
fmt "fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/exported"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// KeySendEnabled is store's key for SendEnabled Params
|
||||
@ -18,6 +24,44 @@ 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
|
||||
|
||||
// GetSendEnabledParams retrieves the send enabled parameters from the provided context and legacy subspace.
|
||||
func GetSendEnabledParams(ctx sdk.Context, legacySubspace exported.Subspace) []*SendEnabled {
|
||||
var sendEnabled []*SendEnabled
|
||||
legacySubspace.Get(ctx, KeySendEnabled, &sendEnabled)
|
||||
return 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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user