Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubSub Not Working on Relayed Connections without Relay Subscription in [email protected] #2349

Closed
vaibhavmuchandi opened this issue Jan 9, 2024 · 3 comments

Comments

@vaibhavmuchandi
Copy link

vaibhavmuchandi commented Jan 9, 2024

  • 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:

  1. Set up a libp2p relay server and two libp2p nodes using the provided script.
  2. Make the nodes subscribe to a pubsub topic and establish a relayed connection.
  3. Observe that pubsub messages are not relayed unless the relay server itself subscribes to the same topic.

https://gist.github.com/vaibhavmuchandi/7cc3d28161ceff68de9bb036bf03a24d

  1. The script initializes a relay server and two libp2p nodes.

  2. Node1 subscribes to a topic named "test-topic" and listens for messages.

  3. Once Node2 connects to Node1, it publishes a message to the "test-topic".

  4. In the current setup, you should see the published message logged in the console by Node1.

  5. Now, comment out the line node.services.pubsub.subscribe("test-topic") in the createRelayServer function. This simulates the
    relay not subscribing to the topic.

  6. Rerun the script

  7. 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.

@vaibhavmuchandi vaibhavmuchandi added the need/triage Needs initial labeling and prioritization label Jan 9, 2024
@vaibhavmuchandi
Copy link
Author

bumping this

@achingbrain
Copy link
Member

Relayed connections are time/data limited which means they can be closed at any time so data-heavy protocols don't run over them by default.

This is normally overridable with a runOnTransientConnection option but it looks like GossipSub doesn't have one of these - this will add it: ChainSafe/js-libp2p-gossipsub#485

Once that's been merged & released you should be able to configure it as:

import { createLibp2p } from 'libp2p'
import { gossipsub } from '@libp2p/gossipsub'

const node = await createLibp2({
  // other config
  services: {
    pubsub: gossipsub({
      runOnTransientConnection: true
    })
  }
})

What's happening in your example is the pubsub message is being sent from node2 to the relay over the direct websocket connection, then from the relay to node1.

What you want is for the message to got from node2 to node1 over the relayed connection between them instead.

With the runOnTransientConnection option you can remove gossipsub from the relay entirely.

@achingbrain achingbrain removed the need/triage Needs initial labeling and prioritization label Feb 5, 2024
@achingbrain
Copy link
Member

@chainsafe/[email protected] contains the fix for runOnTransientConnection - please try that and the suggestions on https://gist.github.com/vaibhavmuchandi/7cc3d28161ceff68de9bb036bf03a24d

This should resolve the issue, please re-open this issue if you're still having trouble getting it working.

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

No branches or pull requests

2 participants