Skip to content

Conversation

SuchitraSwain
Copy link

issue: #905

### What was wrong?

  • After bootstrap, peers were added to the peerstore but not yet in the routing table.
  • DHT queries called find_local_closest_peers(), which returned an empty list.
  • This blocked random walks, provider lookups, and peer discovery.
  • As a result, nodes remained isolated and couldn’t progress beyond initial bootstrap peers.

### How was it fixed?
A fallback mechanism was implemented in the DHT query logic:

  • Configurable threshold: Uses connected peers from the peerstore when the routing table has fewer than MIN_PEERS_THRESHOLD = 5 entries.
  • Distance-based sorting: Connected peers are sorted by XOR distance to the target key.
  • Integration points: Added across peer_routing.py and kad_dht.py for FIND_NODE, GET_VALUE, PUT_VALUE, and provider lookups.
  • Graceful handling: Falls back only when necessary; no impact when routing table is sufficiently populated.
  • Tech requirements / highlights
  • No breaking changes to existing DHT APIs.
  • Threshold is configurable for different network environments.
  • Fully covered with 3 new unit tests ensuring fallback correctness.
  • All existing peer routing and DHT tests updated and passing (28/28 total).

✅ Benefits

  • Eliminates bootstrap deadlock.
  • Ensures peer discovery works immediately after startup.
  • Improves resilience and connectivity in sparse networks.
  • Maintains Kademlia’s routing efficiency by preferring routing table peers when available.

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

put a cute animal picture link inside the parentheses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants