PubSub Not Working on Relayed Connections without Relay Subscription in [email protected] #2349
Description
-
Version:
- "@chainsafe/libp2p-gossipsub": "^11.0.1"
- "@chainsafe/libp2p-noise": "^14.0.0"
- "@chainsafe/libp2p-yamux": "^6.0.1"
- "@libp2p/bootstrap": "^10.0.7"
- "@libp2p/circuit-relay-v2": "^1.0.10"
- "@libp2p/identify": "^1.0.6"
- "@libp2p/mplex": "10.0.9"
- "@libp2p/websockets": "^8.0.7"
- "libp2p": "^1.0.10"
-
Platform:
- Node.js version 20.10.0
-
Subsystem:
- Pubsub, Relay
Severity:
- High
Description:
After migrating from [email protected] to [email protected], I encountered an issue with pubsub on circuit-relayed connections. Previously, pubsub worked seamlessly on relayed connections, but in the newer version, pubsub on relayed connections fails unless the relay node itself subscribes to the same topic. This issue was not present in the earlier versions of libp2p.
Steps to reproduce the error:
- Set up a libp2p relay server and two libp2p nodes using the provided script.
- Make the nodes subscribe to a pubsub topic and establish a relayed connection.
- Observe that pubsub messages are not relayed unless the relay server itself subscribes to the same topic.
https://gist.github.com/vaibhavmuchandi/7cc3d28161ceff68de9bb036bf03a24d
-
The script initializes a relay server and two libp2p nodes.
-
Node1 subscribes to a topic named "test-topic" and listens for messages.
-
Once Node2 connects to Node1, it publishes a message to the "test-topic".
-
In the current setup, you should see the published message logged in the console by Node1.
-
Now, comment out the line node.services.pubsub.subscribe("test-topic") in the createRelayServer function. This simulates the
relay not subscribing to the topic. -
Rerun the script
-
Observe that Node1 no longer receives the published message from Node2, demonstrating the issue.
Expected Behavior:
Pubsub should work on relayed connections without the relay needing to subscribe to the topic, as it did in previous versions of libp2p.
Actual Behavior:
Pubsub on relayed connections only works if the relay server also subscribes to the pubsub topic.