libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.io
Other
2.3k stars 440 forks source link

PubSub not recognizing subscribers/peers, when peers are subscribed to same topic. #2568

Closed 0xCourtney closed 4 months ago

0xCourtney commented 4 months ago

Severity: High

Description:

I've configured a node to connect to a known bootstrapped peer and broadcast messages using floodsub. Both nodes are running locally on my machine. It seems like the node can connect to the peer just fine (and vice versa) however pubsub does not seem to recognize that a peer is connected despite both nodes subscribing to the same topic. As a result, I cannot exchange messages between nodes. I was having this issue using gossipsub originally, and was only able to get gossipsub to work when I set the directPeers. I would expect that I could exchange messages between peers as long as they both subscribe to the same topic.

Looking into this a bit further it seems the issue may be with the connection managers onConnect method. I tried debugging the _onPeerConnected function but it was not being called. For reference, this may be related to https://github.com/ChainSafe/js-libp2p-gossipsub/issues/481.

Logs
# Node 1 is started and subscribed to 'test-topic'
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - node instance has started
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - node is subscribed to test-topic

# Node 2 is started and subscribed to 'test-topic'
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - node instance has started
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - node is subscribed to test-topic

# Node 1 discovers Node 2
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - peer found: QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm

# Node 2 discovers Node 1
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - peer found: Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP

# Node 1 connects with Node 2
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - connected to: zQma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP

# Node 2 connects with Node 1
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - connected to: zQmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - node peers QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm

# Node 1 does not have pubsub peers or subscribers
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - node connections 2
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - pubsub subscribers: 0
Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP - pubsub peers: 0

# Node 2 does not have pubsub peers or subscribers
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - node connections 2
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - pubsub subscribers: 0
QmcrQZ6RJdpYuGvZqD5QEHAv6qX4BrQLJLQPQUrTrzdcgm - pubsub peers: 0

Steps to reproduce the error:

Minimally reproducible example: https://gist.github.com/0xCourtney/c59b786d8609ebcba7747658f3b7b6d3

achingbrain commented 4 months ago

Can you please configure the @libp2p/identify service and try again?

import { identify } from '@libp2p/identify'

const n = await createLibp2p({
  // ... other config
  services: {
    // ... other services
    identify: identify()
  }
})
0xCourtney commented 4 months ago

Can you please configure the @libp2p/identify service and try again?

import { identify } from '@libp2p/identify'

const n = await createLibp2p({
  // ... other config
  services: {
    // ... other services
    identify: identify()
  }
})

That did it, thanks.