Skip to content

Commit

Permalink
Additional Undelegation Logging (#390)
Browse files Browse the repository at this point in the history
Co-authored-by: Aidan Salzmann <aidan@stridelabs.co>
  • Loading branch information
sampocs and asalzmann authored Nov 27, 2022
1 parent 9d5e1f6 commit e74c34d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 4 additions & 5 deletions x/stakeibc/keeper/unbonding_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions x/stakeibc/keeper/validator_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit e74c34d

Please sign in to comment.