Skip to content

Attachment selection — scoring algorithm and periodic reassessment #67

@TickTockBent

Description

@TickTockBent

Phase 3 — Discovery Protocol v2

Context

Phase 2 gives every substrate node a cluster of attached transient nodes. Attachment selection lets transient nodes find better substrate nodes over time — closer, same enclave, less loaded.

This only applies to transient nodes. Substrate nodes don't have attachments to optimize — they're the mesh. They gossip with each other over HTTP and accept WebSocket attachments. Attachment selection is a transient-node optimization: "which substrate node am I attached to, and is there a better one?"

With the substrate/transient model, this is simpler than tree-based parent selection would be. There's no tree depth to optimize, no subtree reorganization, no cascading rebalancing. A transient node just evaluates available substrate nodes and swaps if one is meaningfully better.

Task

Scoring algorithm:

A transient node scores potential substrate attachments on three weighted factors (priority order):

  1. Enclave match (highest weight): same enclave substrate node means data flows directly without cross-enclave hops. Also means the substrate node's own store counts as a quorum vote — first ACK is instant.
  2. Latency: measured via topology response time and periodic probes
  3. Capacity: prefer substrate nodes with fewer attached transient nodes (attachment count included in topology)

Exact weights TBD empirically, but the priority order is fixed.

Periodic reassessment:

  • Every REPRAM_REATTACH_INTERVAL (default 300s), evaluate known topology for better substrate attachment
  • Compare best candidate score against current attachment score
  • If candidate is significantly better, trigger migration (Attachment migration — overlap, switch, hysteresis #68)
  • Only runs on transient nodes — substrate nodes skip this entirely

Configuration:

Variable Default Description
REPRAM_REATTACH_INTERVAL 300 Seconds between attachment reassessment cycles

Acceptance Criteria

  • Scoring function implemented with 3 factors
  • Periodic evaluation timer (transient nodes only)
  • Substrate nodes do not run attachment evaluation
  • Node identifies better substrate attachment candidates from topology
  • Scoring is deterministic and testable

Depends on Phase 2 (#61-#66).
Part of Discovery Protocol v2 — see docs/internal/REPRAM-Discovery-Protocol-v2.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    discovery-v2Discovery Protocol v2 — tree topology and NAT traversalenhancementNew feature or requestjavascriptPull requests that update javascript code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions