From e74c34d12a462e2d23463d717abfe01db9490d8f Mon Sep 17 00:00:00 2001 From: sampocs Date: Sun, 27 Nov 2022 00:01:54 -0600 Subject: [PATCH] Additional Undelegation Logging (#390) Co-authored-by: Aidan Salzmann --- x/stakeibc/keeper/unbonding_records.go | 9 ++++----- x/stakeibc/keeper/validator_selection.go | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x/stakeibc/keeper/unbonding_records.go b/x/stakeibc/keeper/unbonding_records.go index 2ffbde5cac..c91cb6a46f 100644 --- a/x/stakeibc/keeper/unbonding_records.go +++ b/x/stakeibc/keeper/unbonding_records.go @@ -83,11 +83,8 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon valAddr := validator.GetAddress() valUnbondAmt := newUnbondingToValidator[valAddr] currentAmtStaked := validator.GetDelegationAmt() - if err != nil { - errMsg := fmt.Sprintf("Error fetching validator staked amount %d: %s", currentAmtStaked, err.Error()) - k.Logger(ctx).Error(errMsg) - return nil, 0, nil, nil, sdkerrors.Wrap(types.ErrNoValidatorAmts, errMsg) - } + k.Logger(ctx).Info(fmt.Sprintf("Validator %s - Weight: %d, Expected Unbond Amount: %d, Current Delegations: %d", valAddr, validator.Weight, valUnbondAmt, currentAmtStaked)) + if valUnbondAmt > currentAmtStaked { // if we don't have enough assets to unbond overflowAmt += valUnbondAmt - currentAmtStaked valUnbondAmt = currentAmtStaked @@ -101,6 +98,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon valAddrToUnbondAmt[valAddr] = valUnbondAmtInt64 } if overflowAmt > 0 { // if we need to reallocate any weights + k.Logger(ctx).Info(fmt.Sprintf("Expected validator undelegation amount on %s is greater than it's current delegations. Redistributing undelegations accordingly.", hostZone.ChainId)) for _, validator := range validators { valAddr := validator.GetAddress() valUnbondAmt, err := cast.ToUint64E(valAddrToUnbondAmt[valAddr]) @@ -223,6 +221,7 @@ func (k Keeper) InitiateAllHostZoneUnbondings(ctx sdk.Context, dayNumber uint64) failedUnbondings = append(failedUnbondings, hostZone.ChainId) continue } + k.Logger(ctx).Info(fmt.Sprintf("Total unbonded amount for %s: %d%s", hostZone.ChainId, totalAmtToUnbond, hostZone.HostDenom)) err = k.SubmitHostZoneUnbondingMsg(ctx, msgs, totalAmtToUnbond, marshalledCallbackArgs, hostZone) if err != nil { errMsg := fmt.Sprintf("Error submitting unbonding tx for host zone %s: %s", hostZone.ChainId, err.Error()) diff --git a/x/stakeibc/keeper/validator_selection.go b/x/stakeibc/keeper/validator_selection.go index 4b50526926..54aa7fc1c7 100644 --- a/x/stakeibc/keeper/validator_selection.go +++ b/x/stakeibc/keeper/validator_selection.go @@ -52,6 +52,8 @@ func (k Keeper) GetTargetValAmtsForHostZone(ctx sdk.Context, hostZone types.Host k.Logger(ctx).Error(fmt.Sprintf("No non-zero validators found for host zone %s", hostZone.ChainId)) return nil, types.ErrNoValidatorWeights } + k.Logger(ctx).Info(fmt.Sprintf("Total Validator Weight for %s: %d", hostZone.ChainId, totalWeight)) + if finalDelegation == 0 { k.Logger(ctx).Error(fmt.Sprintf("Cannot calculate target delegation if final amount is 0 %s", hostZone.ChainId)) return nil, types.ErrNoValidatorWeights @@ -71,8 +73,8 @@ func (k Keeper) GetTargetValAmtsForHostZone(ctx sdk.Context, hostZone types.Host return validators[i].Weight < validators[j].Weight }) - for i, validator := range hostZone.Validators { - if i == len(hostZone.Validators)-1 { + for i, validator := range validators { + if i == len(validators)-1 { // for the last element, we need to make sure that the allocatedAmt is equal to the finalDelegation targetAmount[validator.GetAddress()] = finalDelegation - allocatedAmt } else {