Skip to content

Commit

Permalink
[KS-427] Launcher: process DONs in a deterministic order (#14153)
Browse files Browse the repository at this point in the history
Sort by IDs to avoid iterating over a map, which could yield different results on different nodes.
  • Loading branch information
bolekk authored Aug 20, 2024
1 parent 80c60c4 commit 910dd8d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/capabilities/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -130,14 +131,21 @@ func (w *launcher) Name() string {
func (w *launcher) Launch(ctx context.Context, state *registrysyncer.LocalRegistry) error {
w.registry.SetLocalRegistry(state)

allDONIDs := []registrysyncer.DonID{}
for id := range state.IDsToDONs {
allDONIDs = append(allDONIDs, id)
}
slices.Sort(allDONIDs) // ensure deterministic order

// Let's start by updating the list of Peers
// We do this by creating a new entry for each node belonging
// to a public DON.
// We also add the hardcoded peers determined by the NetworkSetup.
allPeers := make(map[ragetypes.PeerID]p2ptypes.StreamConfig)

publicDONs := []registrysyncer.DON{}
for _, d := range state.IDsToDONs {
for _, id := range allDONIDs {
d := state.IDsToDONs[id]
if !d.DON.IsPublic {
continue
}
Expand Down Expand Up @@ -167,7 +175,8 @@ func (w *launcher) Launch(ctx context.Context, state *registrysyncer.LocalRegist
myWorkflowDONs := []registrysyncer.DON{}
remoteWorkflowDONs := []registrysyncer.DON{}
myDONs := map[uint32]bool{}
for _, d := range state.IDsToDONs {
for _, id := range allDONIDs {
d := state.IDsToDONs[id]
for _, peerID := range d.Members {
if peerID == myID {
myDONs[d.ID] = true
Expand Down

0 comments on commit 910dd8d

Please sign in to comment.