Skip to content

Commit

Permalink
addressed vishal PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Dec 18, 2023
1 parent 2324fbd commit 50ddeb7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions x/stakeibc/keeper/unbonding_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func (k Keeper) ConsolidateUnbondingMessages(
}

// This is to protect against a division by zero error, but this would technically be possible
// if the 32 validators with the most capacity were all 0 weight
// if the 32 validators with the most capacity were all 0 weight and we wanted to unbond more
// than their combined delegation
if totalRemainingDelegationsAcrossBatch.IsZero() {
return finalUnbondings, errors.New("no delegations to redistribute during consolidation")
}
Expand All @@ -304,15 +305,15 @@ func (k Keeper) ConsolidateUnbondingMessages(
excessRemaining := totalExcessAmount
for i := range unbondingsBatch {
unbonding := unbondingsBatch[i]
remainingDelegation, ok := remainingDelegationsInBatchByVal[unbonding.Validator]
if !ok {
return finalUnbondings, fmt.Errorf("validator %s not found in initial unbonding plan", unbonding.Validator)
}

var validatorUnbondIncrease sdkmath.Int
if i != len(unbondingsBatch)-1 {
// For all but the last validator, calculate their unbonding increase by
// splitting the excess proportionally in line with their remaining delegation
remainingDelegation, ok := remainingDelegationsInBatchByVal[unbonding.Validator]
if !ok {
return finalUnbondings, fmt.Errorf("validator %s not found in initial unbonding plan", unbonding.Validator)
}
unbondIncreaseProportion := remainingDelegation.Quo(totalRemainingDelegationsAcrossBatch)
validatorUnbondIncrease = sdk.NewDecFromInt(totalExcessAmount).Mul(unbondIncreaseProportion).TruncateInt()

Expand All @@ -321,16 +322,11 @@ func (k Keeper) ConsolidateUnbondingMessages(
} else {
// The last validator in the set should get any remainder from int truction
// First confirm the validator has sufficient remaining delegation to cover this
remainingDelegation, ok := remainingDelegationsInBatchByVal[unbonding.Validator]
if !ok {
return finalUnbondings, fmt.Errorf("validator %s not found in initial unbonding plan", unbonding.Validator)
}
if sdk.NewDecFromInt(excessRemaining).GT(remainingDelegation) {
return finalUnbondings,
fmt.Errorf("validator %s does not have enough remaining delegation (%v) to cover the excess (%v)",
unbonding.Validator, remainingDelegation, excessRemaining)
}

validatorUnbondIncrease = excessRemaining
}

Expand Down

0 comments on commit 50ddeb7

Please sign in to comment.