diff --git a/packages/go-kosu/abci/rebalance.go b/packages/go-kosu/abci/rebalance.go index f309fa92..1de9317b 100644 --- a/packages/go-kosu/abci/rebalance.go +++ b/packages/go-kosu/abci/rebalance.go @@ -79,15 +79,15 @@ func posterIterator(app *App, totalBalance *big.Int) func(string, *types.Poster) // calculates a poster's period limit based on their balance and the total poster balance func posterLimit(periodLimit uint64, posterBalance, totalBalance *big.Int) uint64 { // copy periodLimit (pl), posterBalance (pb), totalBalance (tb) - var pl, pb, tb big.Int + pl, pb, tb := &big.Int{}, &big.Int{}, &big.Int{} pl.SetUint64(periodLimit) pb.Set(posterBalance) tb.Set(totalBalance) // limit = (posterBalance / totalBalance) * periodLimit limit := big.NewInt(0) - limit.Mul(&pl, &pb) - limit.Div(limit, &tb) + limit.Mul(pl, pb) + limit.Div(limit, tb) if !limit.IsUint64() { return math.MaxUint64 diff --git a/packages/go-kosu/abci/witness.go b/packages/go-kosu/abci/witness.go index 516054c3..9cacd837 100644 --- a/packages/go-kosu/abci/witness.go +++ b/packages/go-kosu/abci/witness.go @@ -102,15 +102,18 @@ func scaleBalance(balance *big.Int) int64 { return int64(0) } - scaled := &big.Rat{} - divisor := &big.Int{} + scaled := &big.Int{} + ether := &big.Int{} + scaled.Set(balance) // scale balance by 10**18 (base units for KOSU) + // linter disabled for outdated gosec rule // nolint:gosec - divisor = divisor.Exp(big.NewInt(10), big.NewInt(18), nil) - scaled.SetFrac(balance, divisor) + ether.Exp(big.NewInt(10), big.NewInt(18), big.NewInt(0)) + scaled.Div(balance, ether) - res, _ := scaled.Float64() - power := math.Floor(res) - return int64(power) + if !scaled.IsInt64() { + return math.MaxInt64 + } + return scaled.Int64() }