From 0066781f11464a9880b178495d29fe8f18b78849 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Thu, 25 May 2023 11:40:05 -0700 Subject: [PATCH] use bytes in place where possible --- x/ccv/provider/keeper/key_assignment.go | 21 +++------------------ x/ccv/provider/keeper/throttle.go | 13 ++----------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index de4cbace7c..b4d07e5776 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -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 } @@ -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) } @@ -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, diff --git a/x/ccv/provider/keeper/throttle.go b/x/ccv/provider/keeper/throttle.go index 4a3a9f8303..c381ff9676 100644 --- a/x/ccv/provider/keeper/throttle.go +++ b/x/ccv/provider/keeper/throttle.go @@ -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) } @@ -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) }