Skip to content

Commit

Permalink
use bytes in place where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed May 25, 2023
1 parent 9466b86 commit 0066781
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
21 changes: 3 additions & 18 deletions x/ccv/provider/keeper/key_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ func (k Keeper) GetValidatorByConsumerAddr(
if bz == nil {
return providerAddr, false
}
err := providerAddr.Unmarshal(bz)
if err != nil {
// An error here would indicate something is very wrong,
// the provider address is assumed to be correctly serialized in SetValidatorByConsumerAddr.
panic(fmt.Sprintf("failed to unmarshal provider address: %v", err))
}
providerAddr = types.NewProviderConsAddress(bz)
return providerAddr, true
}

Expand All @@ -135,11 +130,7 @@ func (k Keeper) SetValidatorByConsumerAddr(
) {
store := ctx.KVStore(k.storeKey)
// Cons address is a type alias for a byte string, no marshaling needed
bz, err := providerAddr.Marshal()
if err != nil {
// An error here would indicate something is very wrong,
panic(fmt.Sprintf("failed to marshal provider address: %v", err))
}
bz := providerAddr.ToSdkConsAddr()
store.Set(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr), bz)
}

Expand Down Expand Up @@ -173,13 +164,7 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string)
panic(fmt.Sprintf("failed to parse chainID and consumer address: %v", err))
}
consumerAddr := types.NewConsumerConsAddress(consumerAddrTmp)
var providerAddr types.ProviderConsAddress
err = providerAddr.Unmarshal(iterator.Value())
if err != nil {
// An error here would indicate something is very wrong,
// the provider address is assumed to be correctly serialized in SetValidatorByConsumerAddr.
panic(fmt.Sprintf("failed to unmarshal provider address: %v", err))
}
providerAddr := types.NewProviderConsAddress(iterator.Value())

validatorConsumerAddrs = append(validatorConsumerAddrs, types.ValidatorByConsumerAddr{
ConsumerAddr: &consumerAddr,
Expand Down
13 changes: 2 additions & 11 deletions x/ccv/provider/keeper/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ func (k Keeper) GetSlashMeterAllowance(ctx sdktypes.Context) sdktypes.Int {
func (k Keeper) QueueGlobalSlashEntry(ctx sdktypes.Context, entry providertypes.GlobalSlashEntry) {
store := ctx.KVStore(k.storeKey)
key := providertypes.GlobalSlashEntryKey(entry)
bz, err := entry.ProviderValConsAddr.Marshal()
if err != nil {
// This should never happen, since the provider val cons addr should be a valid sdk address
panic(fmt.Sprintf("failed to marshal validator consensus address: %s", err.Error()))
}
bz := entry.ProviderValConsAddr.ToSdkConsAddr()
store.Set(key, bz)
}

Expand Down Expand Up @@ -228,12 +224,7 @@ func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.G
// MustParseGlobalSlashEntryKey should not panic, since we should be iterating over keys that're
// assumed to be correctly serialized in QueueGlobalSlashEntry.
recvTime, chainID, ibcSeqNum := providertypes.MustParseGlobalSlashEntryKey(iterator.Key())
valAddr := providertypes.ProviderConsAddress{}
err := valAddr.Unmarshal(iterator.Value())
if err != nil {
// This should never happen, provider cons address is assumed to be correctly serialized in QueueGlobalSlashEntry
panic(fmt.Sprintf("failed to unmarshal validator consensus address: %s", err.Error()))
}
valAddr := providertypes.NewProviderConsAddress(iterator.Value())
entry := providertypes.NewGlobalSlashEntry(recvTime, chainID, ibcSeqNum, valAddr)
entries = append(entries, entry)
}
Expand Down

0 comments on commit 0066781

Please sign in to comment.