diff --git a/.golangci.yml b/.golangci.yml index f6b2dd23f..d0364c2c4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -72,4 +72,4 @@ linters-settings: # options for analysis running run: # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m + timeout: 10m diff --git a/types/voter_set.go b/types/voter_set.go index 79989320f..640dc4db2 100644 --- a/types/voter_set.go +++ b/types/voter_set.go @@ -782,11 +782,15 @@ func sortVoters(candidates []voter) []voter { temp := make([]voter, len(candidates)) copy(temp, candidates) sort.Slice(temp, func(i, j int) bool { - a := new(big.Int).Mul(big.NewInt(temp[i].val.VotingPower), big.NewInt(precisionForSelection)) - a.Div(a, big.NewInt(temp[i].val.StakingPower)) - b := new(big.Int).Mul(big.NewInt(temp[j].val.VotingPower), big.NewInt(precisionForSelection)) - b.Div(b, big.NewInt(temp[j].val.StakingPower)) - return a.Cmp(b) == 1 + a, overflow1 := safeMul(temp[i].val.VotingPower, temp[j].val.StakingPower) + b, overflow2 := safeMul(temp[j].val.VotingPower, temp[i].val.StakingPower) + if !overflow1 && !overflow2 { + return a > b + } else { + bigA := new(big.Int).Mul(big.NewInt(temp[i].val.VotingPower), big.NewInt(temp[j].val.StakingPower)) + bigB := new(big.Int).Mul(big.NewInt(temp[j].val.VotingPower), big.NewInt(temp[i].val.StakingPower)) + return bigA.Cmp(bigB) == 1 + } }) return temp }