File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ type Storage interface {
54
54
55
55
type Communication interface {
56
56
57
- // Nodes returns all nodes known to the application .
57
+ // Nodes returns all nodes that participate in the epoch .
58
58
Nodes () []NodeID
59
59
60
60
// Send sends a message to the given destination node
Original file line number Diff line number Diff line change @@ -174,6 +174,8 @@ func (e *Epoch) init() error {
174
174
e .cancelWaitForBlockNotarization = func () {}
175
175
e .finishCtx , e .finishFn = context .WithCancel (context .Background ())
176
176
e .nodes = e .Comm .Nodes ()
177
+ sortNodes (e .nodes )
178
+
177
179
e .quorumSize = Quorum (len (e .nodes ))
178
180
e .rounds = make (map [uint64 ]* Round )
179
181
e .maxRoundWindow = DefaultMaxRoundWindow
@@ -2685,6 +2687,13 @@ func (e *Epoch) isWithinMaxRoundWindow(round uint64) bool {
2685
2687
return e .round < round && round - e .round < e .maxRoundWindow
2686
2688
}
2687
2689
2690
+ // sortNodes sorts the nodes in place by their byte representations.
2691
+ func sortNodes (nodes []NodeID ) {
2692
+ slices .SortFunc (nodes , func (a , b NodeID ) int {
2693
+ return bytes .Compare (a [:], b [:])
2694
+ })
2695
+ }
2696
+
2688
2697
func LeaderForRound (nodes []NodeID , r uint64 ) NodeID {
2689
2698
n := len (nodes )
2690
2699
return nodes [r % uint64 (n )]
You can’t perform that action at this time.
0 commit comments