This commit is contained in:
Dobromir Popov
2026-07-08 18:48:50 +02:00
parent 29db25108f
commit e44abc910d
7 changed files with 191 additions and 19 deletions

View File

@@ -159,6 +159,18 @@ DEFAULT_CALLER_CREDIT_USDT = 1.0
DEFAULT_DEVNET_TOPUP_USDT = 1.0
def _endpoint_key(url: str) -> str:
"""Normalize http(s) endpoints for host:port comparison."""
parsed = urllib.parse.urlparse(url.rstrip("/"))
host = (parsed.hostname or "").lower()
if not host:
return url.rstrip("/").lower()
port = parsed.port
if port is None:
port = 443 if parsed.scheme == "https" else 80
return f"{host}:{port}"
def _model_aliases(model: str | None) -> set[str]:
"""Return stable lookup aliases for a model repo or display name."""
if not model:
@@ -3168,7 +3180,10 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
node_work.append((rn.wallet_address, max(0, effective_end - covered_up_to)))
covered_up_to = effective_end
# Strip the first-shard node we're about to proxy to — it's already handling the request.
downstream_hops = [h for h in route_hops if h["endpoint"].rstrip("/") != node.endpoint.rstrip("/")]
downstream_hops = [
h for h in route_hops
if _endpoint_key(h["endpoint"]) != _endpoint_key(node.endpoint)
]
downstream_urls = json.dumps(downstream_hops)
route_debug = " -> ".join(
f"{n.node_id}@{n.endpoint}[{n.shard_start}-{n.shard_end}]"
@@ -5447,7 +5462,25 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
if not node.wallet_address or not server.contracts.registry.get_wallet(node.wallet_address).banned
]
route, error = _select_route(alive, required_start, required_end, contracts=server.contracts)
route_model = resolved_name or model
candidates = _enumerate_routes(
alive,
required_start,
required_end,
model=route_model,
contracts=server.contracts,
max_candidates=server.route_stats.config.max_candidate_routes,
)
if candidates:
# Prefer a distributed multi-hop route when available. Greedy
# _select_route alone would pick a single full-shard node and omit
# partial head shards that share the same port on another host.
route = max(candidates, key=lambda cand: len(cand.nodes)).nodes
error = ""
else:
route, error = _select_route(
alive, required_start, required_end, contracts=server.contracts,
)
if error:
_tracker_log(
server,