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

Integration Issue with Helia: Custom Service Configuration Disables Peer Discovery in Browser Environment #1181

Closed
orwithout opened this issue May 9, 2024 · 3 comments

Comments

@orwithout
Copy link

orwithout commented May 9, 2024

Description:
I am encountering a significant issue in a pure browser environment when initializing IPFS nodes with Helia, which affects the functionality of OrbitDB. Even a minimal custom services configuration in Helia (e.g., libp2p: { services: {} }) seems to disable the node's ability to automatically discover peer nodes. However, removing the services option entirely restores this functionality. Given OrbitDB's reliance on specific libp2p configurations involving the services option (especially for pubsub with gossipsub), it is crucial to enable services without hindering peer discovery?

This issue has already been documented in Helia's repository (see issue #532), but I am raising it here as well because of the dependency OrbitDB has on this functionality. This problem could potentially affect many other OrbitDB users.

Steps to Reproduce:

  1. Initialize a Helia-based IPFS node in a clean browser environment with the following configuration:
// index.js
import { IDBBlockstore } from 'blockstore-idb';
import { IDBDatastore } from 'datastore-idb';
import { createHelia } from 'helia';

const instantiateHeliaNode = async () => {
  const datastore = new IDBDatastore('/datastore2');
  const blockstore = new IDBBlockstore('/blockstore2');
  await datastore.open();
  await blockstore.open();
  const heliaInstance = await createHelia({
    libp2p: {
      services: {}
    },
    peerStore: {
      persistence: false,
      threshold: 5
    },
    keychain: { pass: 'very-strong-password' },
    datastore: datastore,
    blockstore: blockstore
  });

  return heliaInstance;
};

document.addEventListener("DOMContentLoaded", async () => {
  const helia = window.helia = await instantiateHeliaNode();

  // monitor
  console.log('Helia node created with ID:', helia.libp2p.peerId.toString())
  setInterval(async () => {
      const peers = await helia.libp2p.peerStore.all();
      console.log(`Total number of store peers: ${peers.length}`);
      console.log('Connected peers count:', helia.libp2p.getPeers().length);
  }, 3000);
});
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script type="module" crossorigin src="./index.js"></script>
</head>
<body>
  <h1>IPFS in the Browser via Helia</h1>
</body>
</html>
  1. Observe the node's inability to discover peers (It may take several minutes or more).
  2. Remove or delete the services configuration and reinitialize the node in a clean browser environment (e.g., a new incognito window):
// In the index.js file: 

  const heliaInstance = await createHelia({
    // libp2p: {
    //   services: {}
    // },
    peerStore: {
      persistence: false,
      threshold: 5
    },
    keychain: {
      pass: 'very-strong-password'
    },
    datastore: datastore,
    blockstore: blockstore
  });
  1. Observe that the node can now discover peers.

Expected Behavior:
The node should be able to discover peers automatically, even when the services option is used, provided it is configured correctly or even if it is empty.

Actual Behavior:
The node fails to discover peers when the services option is included in the configuration. Removing this option restores peer discovery functionality.

Environment:

  • Browser Version: Google Chrome 123.0.6312, Microsoft Edge 123.2420
  • Operating System: Windows 2022
  • Helia Version: 4.2.1
  • Libp2p Version: 1.3.3

Additional Information:
Despite reviewing the documentation on service-related configurations (libp2p interface documentation and source code), I am still unsure how to resolve this issue.

Use the Service option to start Helia:

image

Start Helia without using the Service option:

image

@haydenyoung
Copy link
Member

I would definitely recommend reaching out to Helia/Libp2p via their various channels. I think that the more information they have to work with the easier they can make out-of-the-box connectivity and "iron out" many of these issues. The browser has always been difficult to work with especially due to its networking limitations. Hopefully, this will be resolved as more decentralized apps are built within the browser environment.

OrbitDB is working closely with Libp2p to improve connectivity, but, with limited resources, it is not always possible to address every connection issue.

Please feel free to share any more information you discover either within this issue or via the other OrbitDB channels.

@orwithout
Copy link
Author

Thank you for the prompt response and your suggestions.

I appreciate the insight into the challenges of working with browser environments and the limitations they impose on networking.

Based on your advice, I will reach out to the Helia and Libp2p teams through their respective channels to provide them with as much information as possible.

I will keep this issue updated with any new information or progress from my discussions with Helia and Libp2p.

@haydenyoung
Copy link
Member

Closing for now but feel free to re-open if you have any more information you would like to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants