Skip to content

Commit

Permalink
Fix the stake percentage rounding error in nonsigning api (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored May 31, 2024
1 parent a4ff5bf commit 4082841
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions disperser/dataapi/nonsigner_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4082841

Please sign in to comment.