Skip to content

Commit 5a51d63

Browse files
committed
Fix candidate votes serialization order
1 parent 5e7fe38 commit 5a51d63

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

systemcontractindex/stakingindex/candidate_votes.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stakingindex
22

33
import (
44
"math/big"
5+
"sort"
56

67
"github.com/pkg/errors"
78
"google.golang.org/protobuf/proto"
@@ -98,7 +99,17 @@ func (cv *candidateVotes) Add(cand string, amount *big.Int, votes *big.Int) {
9899

99100
func (cv *candidateVotes) Serialize() ([]byte, error) {
100101
cl := stakingpb.CandidateList{}
101-
for cand, c := range cv.cands {
102+
103+
// Create a slice of candidate addresses and sort them for consistent ordering
104+
addresses := make([]string, 0, len(cv.cands))
105+
for cand := range cv.cands {
106+
addresses = append(addresses, cand)
107+
}
108+
sort.Strings(addresses)
109+
110+
// Add candidates in sorted order
111+
for _, cand := range addresses {
112+
c := cv.cands[cand]
102113
cl.Candidates = append(cl.Candidates, &stakingpb.Candidate{
103114
Address: cand,
104115
Votes: c.votes.String(),

0 commit comments

Comments
 (0)