Skip to content

Commit

Permalink
fix!: fix migration issue (#2214)
Browse files Browse the repository at this point in the history
* init commit

* took into account comments
  • Loading branch information
insumity authored Sep 4, 2024
1 parent 68f0ab4 commit f85677c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions x/ccv/provider/migrations/v8/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ func MigrateLaunchedConsumerChains(ctx sdk.Context, store storetypes.KVStore, pk
rekeyChainIdAndConsAddrKey(store, providertypes.ConsumerCommissionRateKeyPrefix(), chainId, consumerId)

// chainId -> MinimumPowerInTopN
rekeyFromChainIdToConsumerId(store, MinimumPowerInTopNKeyPrefix, chainId, consumerId)
oldKey := providertypes.StringIdWithLenKey(MinimumPowerInTopNKeyPrefix, chainId)
value := store.Get(oldKey)
if value != nil {
newKey := providertypes.StringIdWithLenKey(MinimumPowerInTopNKeyPrefix, consumerId)
store.Set(newKey, value)
store.Delete(oldKey)
}

// chainId -> ConsumerAddrsToPruneV2
rekeyChainIdAndTsKey(store, providertypes.ConsumerAddrsToPruneV2KeyPrefix(), chainId, consumerId)
Expand All @@ -211,21 +217,21 @@ func MigrateLaunchedConsumerChains(ctx sdk.Context, store storetypes.KVStore, pk
// Note: InitializationParameters is not needed since the chain is already launched

// migrate power shaping params
topNKey := append([]byte{LegacyTopNKeyPrefix}, []byte(chainId)...)
topNKey := providertypes.StringIdWithLenKey(LegacyTopNKeyPrefix, chainId)
var topN uint32 = 0
buf := store.Get(topNKey)
if buf != nil {
topN = binary.BigEndian.Uint32(buf)
}

validatorsPowerCapKey := append([]byte{LegacyValidatorsPowerCapKeyPrefix}, []byte(chainId)...)
validatorsPowerCapKey := providertypes.StringIdWithLenKey(LegacyValidatorsPowerCapKeyPrefix, chainId)
var validatorsPowerCap uint32 = 0
buf = store.Get(validatorsPowerCapKey)
if buf != nil {
validatorsPowerCap = binary.BigEndian.Uint32(buf)
}

validatorSetCapKey := append([]byte{LegacyValidatorSetCapKeyPrefix}, []byte(chainId)...)
validatorSetCapKey := providertypes.StringIdWithLenKey(LegacyValidatorSetCapKeyPrefix, chainId)
var validatorSetCap uint32 = 0
buf = store.Get(validatorSetCapKey)
if buf != nil {
Expand All @@ -235,14 +241,14 @@ func MigrateLaunchedConsumerChains(ctx sdk.Context, store storetypes.KVStore, pk
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix()
var allowlist []string
for _, addr := range pk.GetAllowList(ctx, consumerId) {
foo, _ := bech32.ConvertAndEncode(bech32PrefixConsAddr, addr.ToSdkConsAddr().Bytes())
allowlist = append(allowlist, foo)
bech32Addr, _ := bech32.ConvertAndEncode(bech32PrefixConsAddr, addr.ToSdkConsAddr().Bytes())
allowlist = append(allowlist, bech32Addr)
}

var denylist []string
for _, addr := range pk.GetDenyList(ctx, consumerId) {
foo, _ := bech32.ConvertAndEncode(bech32PrefixConsAddr, addr.ToSdkConsAddr().Bytes())
allowlist = append(allowlist, foo)
bech32Addr, _ := bech32.ConvertAndEncode(bech32PrefixConsAddr, addr.ToSdkConsAddr().Bytes())
allowlist = append(allowlist, bech32Addr)
}

powerShapingParameters := providertypes.PowerShapingParameters{
Expand Down

0 comments on commit f85677c

Please sign in to comment.