Skip to content

Commit

Permalink
added additional safety check
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Dec 13, 2023
1 parent 031afe1 commit e388120
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion x/stakeibc/keeper/unbonding_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (k Keeper) ConsolidateUnbondingMessages(
// splitting the excess proportionally in line with their remaining delegation
remainingDelegation, ok := remainingDelegationsInBatchByVal[unbonding.Validator]
if !ok {
return finalUnbondings, fmt.Errorf("validator not found in initial unbonding plan")
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 @@ -320,6 +320,17 @@ func (k Keeper) ConsolidateUnbondingMessages(
excessRemaining = excessRemaining.Sub(validatorUnbondIncrease)
} 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 e388120

Please sign in to comment.