Skip to content

fix(peermanager): prefer connected peers in selection#1309

Merged
igor-sirotin merged 1 commit into
masterfrom
fix/filter-prefer-connected-peers
Jun 9, 2026
Merged

fix(peermanager): prefer connected peers in selection#1309
igor-sirotin merged 1 commit into
masterfrom
fix/filter-prefer-connected-peers

Conversation

@igor-sirotin

Copy link
Copy Markdown
Collaborator

Problem

Filter/lightpush peer selection (AutomaticSelectRandom, and the
service-slot pubsub-topic path in selectServicePeer) picks uniformly at
random among all peers that support the protocol + pubsub topic, with no
regard for connectedness.

A light node that has learned many peers via discv5 / peer-exchange — some of
them stale or unreachable (e.g. torn-down nodes whose ENRs a bootstrap node is
still advertising) — therefore keeps selecting dead peers for its filter
subscriptions. It churns on failed dials (all dials failed) and the
subscription for a content topic can stay down long enough to miss messages,
even while an already-connected, reachable service node is available.

This is the proximate cause of the flaky status-go light-client functional
tests (status-im/status-go#7513): in CI a failing light node was observed
re-dialing ~18 dead peer-exchange peers 30–70× each over 70s while a perfectly
good connected fleet node sat unused.

Change

Add preferConnectedPeers: bias selection toward peers we are currently
connected to, falling back to the full candidate set when none are
connected
(so behavior is unchanged when there is no connected candidate).
Applied in both SelectRandom and the selectServicePeer pubsub-topic path.

Notes

  • Backward-compatible: existing peermanager selection tests pass unchanged
    (they don't connect the candidate peers, so the fallback returns the full
    set as before).
  • A connected-preference unit test that actually dials a peer is awkward here
    because libp2p identify overwrites the manually-added supported protocols
    after connection (the existing SelectPeerWithLowestRTT test is ordered last
    for the same reason); happy to add one if you have a preferred harness.
  • Complements the nwaku-side fix fix(discovery): prune stale discv5 peers from peer store so PX stops serving dead ENRs (#3933) logos-delivery#3939 (stop the
    bootstrap node from serving stale ENRs); this PR makes the client resilient
    regardless of what it is served.

🤖 Generated with Claude Code

Filter/lightpush peer selection (Automatic -> SelectRandom, and the
service-slot pubsub path) chose uniformly at random among all peers that
support the protocol+pubsub topic, with no regard for connectedness. A
light node that has learned many peers via discv5/peer-exchange — some of
them stale/unreachable (e.g. torn-down nodes whose ENRs a bootstrap node
still advertised) — would therefore keep picking dead peers, churning on
failed dials and missing messages, even while a perfectly good already-
connected service node (e.g. the static fleet node) was available.

Add preferConnectedPeers: bias selection toward peers we are currently
connected to, falling back to the full candidate set when none are
connected (so behavior is unchanged when there is no connected candidate).

Relates to status-im/status-go#7513.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@igor-sirotin
igor-sirotin marked this pull request as ready for review June 9, 2026 12:58
@status-im-auto

Copy link
Copy Markdown

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ bca1267 1 2026-06-09 15:30:47 ~9 min unknown 📄log

@Ivansete-status Ivansete-status left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great idea

Comment on lines +95 to +96
// Prefer peers we are already connected to, so we don't churn on dialing
// stale/unreachable peers learned via discovery or peer-exchange.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The func name is pretty self-explanatory

Suggested change
// Prefer peers we are already connected to, so we don't churn on dialing
// stale/unreachable peers learned via discovery or peer-exchange.

@igor-sirotin
igor-sirotin merged commit 9a10629 into master Jun 9, 2026
11 of 13 checks passed
@igor-sirotin
igor-sirotin deleted the fix/filter-prefer-connected-peers branch June 9, 2026 15:41
igor-sirotin added a commit to status-im/status-go that referenced this pull request Jun 9, 2026
Release tag including the prefer-connected-peers selection fix
(logos-messaging/logos-delivery-go#1309), which keeps light-client
filter/lightpush off stale/unreachable peers and fixes the flaky
light-client message tests (#7513). Supersedes the temporary branch pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
igor-sirotin added a commit to status-im/status-go that referenced this pull request Jun 9, 2026
Release tag including the prefer-connected-peers selection fix
(logos-messaging/logos-delivery-go#1309), which keeps light-client
filter/lightpush off stale/unreachable peers and fixes the flaky
light-client message tests (#7513). Supersedes the temporary branch pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
igor-sirotin added a commit to status-im/status-go that referenced this pull request Jun 9, 2026
Release tag including the prefer-connected-peers selection fix
(logos-messaging/logos-delivery-go#1309), which keeps light-client
filter/lightpush off stale/unreachable peers and fixes the flaky
light-client message tests (#7513). Supersedes the temporary branch pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
igor-sirotin added a commit to status-im/status-go that referenced this pull request Jun 9, 2026
* test: discovery mix full and light clients

* docs: known issue wakufleetconfig.json not found

* test: enable bridge network by default to prevent discovery

* fix: logs

* test(waku): use nwaku PR #3939 fleet image + num-shards-in-network=65

quay.io/wakuorg/nwaku-pr:3939 is the build of logos-messaging/logos-delivery#3939, the candidate fix for the light-client PX stale-ENR flake (#7513). Also enables store peer-exchange.

* test: allow finding more peers

* chore(deps): bump go-waku with filter prefer-connected-peers fix

Pulls waku-org/go-waku fix/filter-prefer-connected-peers, which makes
peer selection prefer already-connected peers. This stops light-client
filter/lightpush from churning on stale/unreachable peers learned via
peer-exchange, which was causing the flaky light-client message tests
(#7513).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(waku): use released nwaku v0.38.1 fleet (drop #3939)

Test the go-waku prefer-connected-peers fix in isolation: the status-go
image already carries it (go.mod -> go-waku fix branch), so point the
fleet at the released wakuorg/nwaku:v0.38.1 instead of the #3939 build.
The client-side fix should keep light clients off stale peers regardless
of fleet-side stale-ENR pruning.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(deps): bump go-waku to v0.10.2

Release tag including the prefer-connected-peers selection fix
(logos-messaging/logos-delivery-go#1309), which keeps light-client
filter/lightpush off stale/unreachable peers and fixes the flaky
light-client message tests (#7513). Supersedes the temporary branch pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: go mod tidy

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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