Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
likhita-809 committed Dec 8, 2023
1 parent c1ac1d2 commit b7bd994
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ func (k Keeper) CalculateDelegationRewards(ctx context.Context, val sdk.Validato
if stake.LTE(currentStake.Add(marginOfErr)) {
stake = currentStake
} else {
panic(fmt.Sprintf("calculated final stake for delegator %s greater than current stake"+
return sdk.DecCoins{}, fmt.Errorf("calculated final stake for delegator %s greater than current stake"+
"\n\tfinal stake:\t%s"+
"\n\tcurrent stake:\t%s",
del.GetDelegatorAddr(), stake, currentStake))
del.GetDelegatorAddr(), stake, currentStake)
}
}

Expand Down
5 changes: 3 additions & 2 deletions x/slashing/keeper/signing_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"fmt"
"time"

"github.com/bits-and-blooms/bitset"
Expand All @@ -26,7 +27,7 @@ func (k Keeper) HasValidatorSigningInfo(ctx context.Context, consAddr sdk.ConsAd
func (k Keeper) JailUntil(ctx context.Context, consAddr sdk.ConsAddress, jailTime time.Time) error {
signInfo, err := k.ValidatorSigningInfo.Get(ctx, consAddr)
if err != nil {
return errorsmod.Wrap(err, "cannot jail validator that does not have any signing information")
return errorsmod.Wrap(err, fmt.Sprintf("cannot jail validator with consensus address %s that does not have any signing information", consAddr.String()))
}

signInfo.JailedUntil = jailTime
Expand All @@ -37,7 +38,7 @@ func (k Keeper) JailUntil(ctx context.Context, consAddr sdk.ConsAddress, jailTim
func (k Keeper) Tombstone(ctx context.Context, consAddr sdk.ConsAddress) error {
signInfo, err := k.ValidatorSigningInfo.Get(ctx, consAddr)
if err != nil {
return types.ErrNoSigningInfoFound.Wrap("cannot tombstone validator that does not have any signing information")
return types.ErrNoSigningInfoFound.Wrap(fmt.Sprintf("cannot tombstone validator with consensus address %s that does not have any signing information", consAddr.String()))
}

if signInfo.Tombstoned {
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/alias_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(inde
address := iterator.Value()
validator, err := k.GetValidator(ctx, address)
if err != nil {
return fmt.Errorf("validator record not found for address: %X", address)
return fmt.Errorf("validator record not found for address: %s", sdk.ValAddress(address).String())
}
if validator.IsBonded() {
stop := fn(i, validator) // XXX is this safe will the validator unexposed fields be able to get written to?
Expand Down
13 changes: 9 additions & 4 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ func (k Keeper) GetDelegatorUnbonding(ctx context.Context, delegator sdk.AccAddr
func (k Keeper) GetDelegatorBonded(ctx context.Context, delegator sdk.AccAddress) (math.Int, error) {
bonded := math.LegacyZeroDec()

var iterErr error
err := k.IterateDelegatorDelegations(ctx, delegator, func(delegation types.Delegation) bool {
validatorAddr, err := k.validatorAddressCodec.StringToBytes(delegation.ValidatorAddress)
if err != nil {
iterErr = err
return true
}
validator, err := k.GetValidator(ctx, validatorAddr)
Expand All @@ -229,6 +231,9 @@ func (k Keeper) GetDelegatorBonded(ctx context.Context, delegator sdk.AccAddress
}
return false
})
if iterErr != nil {
return bonded.RoundInt(), iterErr
}
return bonded.RoundInt(), err
}

Expand Down Expand Up @@ -728,7 +733,7 @@ func (k Keeper) Delegate(
case validator.IsUnbonding(), validator.IsUnbonded():
sendName = types.NotBondedPoolName
default:
return math.LegacyZeroDec(), fmt.Errorf("invalid validator status")
return math.LegacyZeroDec(), fmt.Errorf("invalid validator status: %v", validator.Status)
}

bondDenom, err := k.BondDenom(ctx)
Expand Down Expand Up @@ -760,7 +765,7 @@ func (k Keeper) Delegate(
return math.LegacyDec{}, err
}
default:
return math.LegacyZeroDec(), fmt.Errorf("unknown token source bond status")
return math.LegacyZeroDec(), fmt.Errorf("unknown token source bond status: %v", tokenSrc)
}
}

Expand Down Expand Up @@ -832,7 +837,7 @@ func (k Keeper) Unbond(
validator.TokensFromShares(delegation.Shares).TruncateInt().LT(validator.MinSelfDelegation) {
err = k.jailValidator(ctx, validator)
if err != nil {
return amount, err
return amount, fmt.Errorf("failed to get updated validator after jailing: %v", err)
}
validator, err = k.GetValidator(ctx, valbz)
if err != nil {
Expand Down Expand Up @@ -909,7 +914,7 @@ func (k Keeper) getBeginInfo(
return validator.UnbondingTime, validator.UnbondingHeight, false, nil

default:
return completionTime, height, false, fmt.Errorf("unknown validator status: %s", validator.Status)
return completionTime, height, false, fmt.Errorf("unknown validator status: %v", validator.Status)
}
}

Expand Down

0 comments on commit b7bd994

Please sign in to comment.