Check exceptional case of leader votes
Even if it has enough votes, it may not be majority of votes to EOA.
It confirms that there is no EOA having more votes than current leader.
@@ -158,6 +158,7 @@ func (s *LeaderVoteList) checkVoted(quorum int, leader module.Address) bool {
}
var vEmpty int
var vCount int
+ voted := make(map[string]int)
for _, vote := range s.votes {
if vote == nil {
continue
@@ -166,13 +167,20 @@ func (s *LeaderVoteList) checkVoted(quorum int, leader module.Address) bool {
vEmpty += 1
} else if vote.NewLeader.Equal(leader) {
vCount += 1
+ } else {
+ voted[vote.NewLeader.String()] += 1
}
- if vEmpty + vCount > quorum {
- return true
}
+ if vEmpty + vCount <= quorum {
+ return false
}
+ for _, cnt := range voted {
+ if cnt > vCount {
return false
}
+ }
+ return true
+}
func (s *LeaderVoteList) Verify(reps *RepsList) error {
if s == nil || len(s.votes) == 0 {
