Skip to content

Commit

Permalink
fix store.set nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Aug 29, 2024
1 parent 1c63e3e commit dcda6ae
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions x/ccv/provider/migrations/v8/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ func rekeyFromChainIdToConsumerId(
) {
oldKey := append([]byte{keyPrefix}, []byte(chainId)...)
value := store.Get(oldKey)
newKey := append([]byte{keyPrefix}, []byte(consumerId)...)
store.Set(newKey, value)
store.Delete(oldKey)
if value != nil {
newKey := append([]byte{keyPrefix}, []byte(consumerId)...)
store.Set(newKey, value)
store.Delete(oldKey)
}
}

// rekeyChainIdAndConsAddrKey migrates store keys
Expand Down Expand Up @@ -321,6 +323,10 @@ func rekeyChainIdAndConsAddrKey(
for _, addr := range addrs {
oldKey := providertypes.StringIdAndConsAddrKey(keyPrefix, chainId, addr)
value := store.Get(oldKey)
if value == nil {
// this should not happen, but just in case as Set will fail if value is nil
continue
}
newKey := providertypes.StringIdAndConsAddrKey(keyPrefix, consumerId, addr)
store.Set(newKey, value)
store.Delete(oldKey)
Expand Down Expand Up @@ -356,6 +362,10 @@ func rekeyChainIdAndTsKey(
for _, ts := range timestamps {
oldKey := providertypes.StringIdAndTsKey(keyPrefix, chainId, ts)
value := store.Get(oldKey)
if value == nil {
// this should not happen, but just in case as Set will fail if value is nil
continue
}
newKey := providertypes.StringIdAndTsKey(keyPrefix, consumerId, ts)
store.Set(newKey, value)
store.Delete(oldKey)
Expand Down

0 comments on commit dcda6ae

Please sign in to comment.