From 408284107530609f2fbd91be2fc031900d0d72d9 Mon Sep 17 00:00:00 2001 From: Jian Xiao <99709935+jianoaix@users.noreply.github.com> Date: Fri, 31 May 2024 15:31:02 -0700 Subject: [PATCH] Fix the stake percentage rounding error in nonsigning api (#591) --- disperser/dataapi/nonsigner_handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/disperser/dataapi/nonsigner_handler.go b/disperser/dataapi/nonsigner_handler.go index a23ebf763a..bcb42c1848 100644 --- a/disperser/dataapi/nonsigner_handler.go +++ b/disperser/dataapi/nonsigner_handler.go @@ -96,11 +96,12 @@ func (s *server) getOperatorNonsigningRate(ctx context.Context, startTime, endTi return nil, err } - const multipler = 10000 stakePercentage := float64(0) if stake, ok := state.Operators[q][opID]; ok { - p, _ := new(big.Int).Div(new(big.Int).Mul(stake.Stake, big.NewInt(multipler)), state.Totals[q].Stake).Float64() - stakePercentage = p / multipler + totalStake := new(big.Float).SetInt(state.Totals[q].Stake) + stakePercentage, _ = new(big.Float).Quo( + new(big.Float).SetInt(stake.Stake), + totalStake).Float64() } else if liveOnly { // Operator "opID" isn't live at "endBlock", skip it. continue