Skip to content

feat(retrieval): connect to known peers on-demand when peers are exhausted#5387

Draft
gacevicljubisa wants to merge 2 commits intomasterfrom
feat/on-demand-peer-connect-retrieval
Draft

feat(retrieval): connect to known peers on-demand when peers are exhausted#5387
gacevicljubisa wants to merge 2 commits intomasterfrom
feat/on-demand-peer-connect-retrieval

Conversation

@gacevicljubisa
Copy link
Member

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

When a node has few connected peers, retrieval fails fast because forwarding peers exhaust their sparse connected topology. This PR adds a fallback: when all connected peers are exhausted, the retrieval service calls ConnectClosest to find the closest known-but-disconnected peer to the chunk address, connects on demand, and retries retrieval through it. Up to 3 connection attempts are made before giving up.

Key changes:

  • New OnDemandConnecter interface in topology with ConnectClosest(ctx, addr, skipPeers...)
  • (*Kad).ConnectClosest implementation: filters disconnected/non-blocklisted/non-backoff peers from knownPeers, sorts by XOR proximity, attempts connection with parent-context-bounded timeout
  • retrieval.Service accepts the connecter as an optional dependency (nil-safe), wired with kad in node.go
  • 4 unit tests covering: success path, exhausted attempts, no-op when peers are available, nil-safe behavior

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant