Skip to content

fix(dash-spv): slow-peer swap on refactor/network-mod adds a peer without emitting PeerConnected #1218

Closed

Description

@xdustinface

Problem

On refactor/network-mod (#902), the peer supervisor's slow-peer swap adds the incoming peer to the connected set without sending NetworkEvent::PeerConnected. Only the displaced peer gets its PeerDisconnected. The other two accept paths (free slot, last-resort) both send PeerConnected.

dash-spv/src/network/manager.rs at 748816fe, the else if let Some(pos) = slow branch:

let new_addr = peer.addr();
let old = peers.swap_remove(pos);
peers.push(peer);
replaced = Some(new_addr);
Some(old)

Impact

Everything keyed on PeerConnected never learns about a swapped-in peer:

  • BlockHeadersManager never announces our tip to it (the GetHeaders sent to new peers once synced), so it keeps sending inv instead of header announcements.
  • MempoolManager never activates it, so its mempool transactions are missed.
  • The FFI on_peer_connected callback never fires, so apps under-count peers.
  • When that peer later disconnects, PeerDisconnected arrives for an address consumers never saw connect.

Evidence

Testnet full sync, run 2 of a dev vs refactor/network-mod benchmark (2026-10-26):

10:41:58.985086 DEBUG dash_spv::network: peer connected: 68.67.122.71:19999 | lag=495ms height=1579699
10:41:58.985100 INFO  dash_spv::network: peer supervisor: swapped out slow 68.67.122.8:19999 for 68.67.122.71:19999
10:44:18.527923 WARN  dash_spv::network: request timeout: kicked 1 peer(s) {PeerId { addr: 68.67.122.71:19999, connection: 12 }}, retried 26 request(s)
10:44:18.528066 INFO  dash_spv::client::event_handler: NetworkEvent: PeerDisconnected(68.67.122.71:19999)

That peer delivered 62.5 MB over 140s with no NetworkEvent: PeerConnected(68.67.122.71:19999) anywhere in the log.

Fix

Send NetworkEvent::PeerConnected(new_addr) in the swap branch, next to the PeerDisconnected(old_addr) that follows it. A test that drives a swap and asserts both events would pin it down.

Related

The same runs show PeerDisconnected for addresses not connected at the time: 49 disconnect events against 16 connections in one run, 35 of them for peers that were not connected. Consumers counting disconnects as dropped connections are misled. That may deserve its own fix.

Activity

  1. added a commit that references this issue on Oct 27, 2026
    ca9e568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions