Skip to content

Commit

Permalink
Cleanup related to #296
Browse files Browse the repository at this point in the history
- rewrote comment
- added "found" booleans to getter methods to clarify logic
  • Loading branch information
jtremback committed Aug 29, 2022
1 parent 84c24b3 commit e05edd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,13 @@ func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, bloc
}

// GetValsetUpdateBlockHeight gets the block height for a given valset update id
func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) uint64 {
func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) (uint64, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId))
if bz == nil {
return 0
return 0, false
}
return binary.BigEndian.Uint64(bz)
return binary.BigEndian.Uint64(bz), true
}

// DeleteValsetUpdateBlockHeight deletes the block height value for a given vaset update id
Expand Down Expand Up @@ -661,14 +661,14 @@ func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint6
}

// GetInitChainHeight returns the provider block height when the given consumer chain was initiated
func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) uint64 {
func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.InitChainHeightKey(chainID))
if bz == nil {
return 0
return 0, false
}

return binary.BigEndian.Uint64(bz)
return binary.BigEndian.Uint64(bz), true
}

// DeleteInitChainHeight deletes the block height value for which the given consumer chain's channel was established
Expand Down
9 changes: 5 additions & 4 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ func (k Keeper) OnRecvSlashPacket(ctx sdk.Context, packet channeltypes.Packet, d
func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.SlashPacketData) (success bool, err error) {
// map VSC ID to infraction height for the given chain ID
var infractionHeight uint64
var found bool
if data.ValsetUpdateId == 0 {
infractionHeight = k.GetInitChainHeight(ctx, chainID)
infractionHeight, found = k.GetInitChainHeight(ctx, chainID)
} else {
infractionHeight = k.GetValsetUpdateBlockHeight(ctx, data.ValsetUpdateId)
infractionHeight, found = k.GetValsetUpdateBlockHeight(ctx, data.ValsetUpdateId)
}

// return if there isn't any initial chain height for the consumer chain
if infractionHeight == 0 {
// return error if we cannot find infraction height matching the validator update id
if !found {
return false, fmt.Errorf("cannot find infraction height matching the validator update id %d for chain %s", data.ValsetUpdateId, chainID)
}

Expand Down

0 comments on commit e05edd7

Please sign in to comment.