Skip to content

Commit

Permalink
Update show.go
Browse files Browse the repository at this point in the history
fix divide by zero errors like the one below
```Oct 14 14:14:50.283 DBG allocations/show.go:87 Allocatable magnitude for strategy 0x..... : 0
panic: division of zero by zero or infinity by infinity```
  • Loading branch information
antojoseph authored Oct 14, 2024
1 parent 51715fd commit aae8491
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/operator/allocations/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ func getSharesFromMagnitude(totalScaledShare *big.Int, magnitude uint64) (*big.I
* shares = totalScaledShare * magnitude / PrecisionFactor
* percentageShares = (shares / totalScaledShare) * 100
*/

// Check for zero magnitude or totalScaledShare to avoid divide-by-zero errors
if magnitude == 0 || totalScaledShare.Cmp(big.NewInt(0)) == 0 {
return big.NewInt(0), big.NewFloat(0)
}

slashableMagBigInt := big.NewInt(1)
slashableMagBigInt = slashableMagBigInt.SetUint64(magnitude)

Expand Down

0 comments on commit aae8491

Please sign in to comment.