Skip to content

Conversation

@sanity
Copy link
Collaborator

@sanity sanity commented Oct 3, 2025

Problem

When handling FindOptimalPeer requests in small networks, the gateway was only skipping the joiner peer when recommending connections:

HashSet::from([joiner.peer.clone()])

This caused the gateway to repeatedly recommend itself or peers that the joiner was already connected to, preventing proper peer-to-peer mesh formation.

Example failure scenario:

  1. Peer1 connects to Gateway (1 connection)
  2. Peer1 wants more connections, sends FindOptimalPeer to Gateway
  3. Gateway looks for peers near random location, skipping only Peer1
  4. Gateway recommends itself (Gateway) back to Peer1
  5. Peer1 tries to connect to Gateway again (already connected)
  6. No mesh formation occurs

Solution

Use the full skip_connections set that includes all peers the joiner is already connected to:

skip_connections.iter().cloned().collect()

Location: crates/core/src/operations/connect.rs:199

This ensures the gateway only recommends NEW peers that the joiner isn't already connected to.

Background

This fix was originally implemented in commit 24a6b7c (branch fix/connection-maintenance-skip-list) but was never merged to main. This PR reapplies that critical fix.

Testing

✅ All existing connectivity tests pass:

  • test_gateway_reconnection
  • test_basic_gateway_connectivity

The fix enables proper peer discovery in multi-peer networks by ensuring gateways provide useful peer recommendations.

Related Issues

🤖 Generated with Claude Code

[AI-assisted debugging and comment]

## Problem

When handling FindOptimalPeer requests, the gateway was only skipping
the joiner peer when recommending connections:

  HashSet::from([joiner.peer.clone()])

This caused the gateway to recommend itself or peers that the joiner
was already connected to, preventing proper peer-to-peer mesh formation
in small networks.

## Fix

Use the full skip_connections set that includes all peers the joiner
is already connected to:

  skip_connections.iter().cloned().collect()

This ensures the gateway only recommends NEW peers that the joiner
isn't already connected to.

## Background

This fix was originally implemented in commit 24a6b7c (branch
fix/connection-maintenance-skip-list) but was never merged to main.
This represents a regression that prevented small network mesh formation.

## Testing

- All existing connectivity tests pass
- Fix enables proper peer discovery in multi-peer networks

Related: #1905, #1904, #1889

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sanity sanity added this pull request to the merge queue Oct 3, 2025
Merged via the queue into main with commit f1269e5 Oct 3, 2025
8 checks passed
@sanity sanity deleted the fix/peer-recommendation-skip-list branch October 3, 2025 19:27
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.

3 participants