Skip to content

Commit

Permalink
Change condition to sort voters
Browse files Browse the repository at this point in the history
  • Loading branch information
kukugi committed Oct 6, 2020
1 parent 418de04 commit 4d77aab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions types/voter_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4d77aab

Please sign in to comment.