Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions p2p/kademlia/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type Node struct {
// port of the node
Port uint16 `json:"port,omitempty"`

// Version of the supernode binary (advertised to peers; may be used by min-version gating)
Version string `json:"version,omitempty"`
// Version of the supernode binary (advertised to peers; may be used by min-version gating)
Version string `json:"version,omitempty"`

HashedID []byte
}
Expand Down
17 changes: 10 additions & 7 deletions sdk/task/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ func (t *CascadeTask) Run(ctx context.Context) error {
return err
}

// 1 - Fetch the supernodes (single-pass probe: sanitize + load snapshot)
supernodes, loads, err := t.fetchSupernodesWithLoads(ctx, t.Action.Height)
// 1 - Fetch the supernodes
supernodes, err := t.fetchSupernodes(ctx, t.Action.Height)

if err != nil {
t.LogEvent(ctx, event.SDKSupernodesUnavailable, "Supernodes unavailable", event.EventData{event.KeyError: err.Error()})
t.LogEvent(ctx, event.SDKTaskFailed, "Task failed", event.EventData{event.KeyError: err.Error()})
return err
}

// Rank by current load snapshot (fewest first), tie-break deterministically
supernodes = t.orderByLoadSnapshotThenDeterministic(supernodes, loads)
// Initial concurrent balance filter (one-time)
supernodes = t.filterByMinBalance(ctx, supernodes)

// Rank by available free RAM (descending). Unknown RAM stays after known.
supernodes = t.orderByFreeRAM(ctx, supernodes)
t.LogEvent(ctx, event.SDKSupernodesFound, "Supernodes found.", event.EventData{event.KeyCount: len(supernodes)})

// 2 - Register with the supernodes
Expand Down Expand Up @@ -76,11 +79,11 @@ func (t *CascadeTask) registerWithSupernodes(ctx context.Context, supernodes lum

var lastErr error
attempted := 0
// Work on a copy and re-rank between attempts to avoid stale ordering
// Work on a copy; re-rank by free RAM between attempts
remaining := append(lumera.Supernodes(nil), supernodes...)
for len(remaining) > 0 {
// Refresh load-aware ordering for remaining candidates
remaining = t.orderByLoadThenDeterministic(ctx, remaining)
// Re-rank remaining nodes by available RAM (descending)
remaining = t.orderByFreeRAM(ctx, remaining)
sn := remaining[0]
iteration := attempted + 1

Expand Down
14 changes: 9 additions & 5 deletions sdk/task/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ func NewCascadeDownloadTask(base BaseTask, actionId string, outputPath string, s
func (t *CascadeDownloadTask) Run(ctx context.Context) error {
t.LogEvent(ctx, event.SDKTaskStarted, "Running cascade download task", nil)

// 1 – fetch super-nodes (single-pass probe: sanitize + load snapshot)
supernodes, loads, err := t.fetchSupernodesWithLoads(ctx, t.Action.Height)
// 1 – fetch super-nodes (plain)
supernodes, err := t.fetchSupernodes(ctx, t.Action.Height)
if err != nil {
t.LogEvent(ctx, event.SDKSupernodesUnavailable, "super-nodes unavailable", event.EventData{event.KeyError: err.Error()})
t.LogEvent(ctx, event.SDKTaskFailed, "task failed", event.EventData{event.KeyError: err.Error()})
return err
}
// Rank by current load snapshot (fewest first), tie-break deterministically
supernodes = t.orderByLoadSnapshotThenDeterministic(supernodes, loads)
// Initial concurrent balance filter (one-time)
supernodes = t.filterByMinBalance(ctx, supernodes)

// Rank by available free RAM (descending). Unknown RAM stays after known.
supernodes = t.orderByFreeRAM(ctx, supernodes)
t.LogEvent(ctx, event.SDKSupernodesFound, "super-nodes found", event.EventData{event.KeyCount: len(supernodes)})

// 2 – download from super-nodes
Expand Down Expand Up @@ -83,7 +86,8 @@ func (t *CascadeDownloadTask) downloadFromSupernodes(ctx context.Context, supern
remaining := append(lumera.Supernodes(nil), supernodes...)
attempted := 0
for len(remaining) > 0 {
remaining = t.orderByLoadThenDeterministic(ctx, remaining)
// Re-rank remaining nodes by available RAM (descending)
remaining = t.orderByFreeRAM(ctx, remaining)
sn := remaining[0]
iteration := attempted + 1

Expand Down
Loading