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 e0d3185
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 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
2 changes: 1 addition & 1 deletion types/validator_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ func TestValidatorSet_VerifyCommitLightTrusting(t *testing.T) {
require.NoError(t, err)

testCases := []struct {
//valSet *ValidatorSet
// valSet *ValidatorSet
voterSet *VoterSet
err bool
}{
Expand Down
13 changes: 8 additions & 5 deletions types/voter_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,14 @@ 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
}
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 e0d3185

Please sign in to comment.