type consensusNodeSlice []*consensusNode
+func (c consensusNodeSlice) Less(i, j int) bool {
+ if c[i].voteNum == c[j].voteNum {
+ return c[i].pubkey < c[j].pubkey
+ }
+ return c[i].voteNum > c[j].voteNum
+}
+
func (c consensusNodeSlice) Len() int { return len(c) }
-func (c consensusNodeSlice) Less(i, j int) bool { return c[i].voteNum > c[j].voteNum }
func (c consensusNodeSlice) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
type consensusNodeManager struct {
}
// In principle, there is no need to sort all voting nodes.
// if there is a performance problem, consider the optimization later.
- // TODO not consider the same number of votes
sort.Sort(consensusNodeSlice(nodes))
result := make(map[string]*consensusNode)