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

Compatibility with services in libp2p v0.45.0 #98

Closed
joeltg opened this issue May 16, 2023 · 7 comments · Fixed by #111
Closed

Compatibility with services in libp2p v0.45.0 #98

joeltg opened this issue May 16, 2023 · 7 comments · Fixed by #111

Comments

@joeltg
Copy link

joeltg commented May 16, 2023

libp2p v0.45.0 moved pubsub/DHT/fetch/identify/ping etc. into a separate "services" object, and as far as I can tell they are no longer available in the initial Components object, making it impossible (???) to make composable services that depend on e.g. pubsub to provide peer discovery. Can anyone confirm if this is true? What's the best approach to something like pubsub-peer-discovery in a post-v0.45.0 world? cc @achingbrain

@joeltg
Copy link
Author

joeltg commented May 16, 2023

(@TimDaub fyi this will affect you if you try to upgrade)

@achingbrain
Copy link
Member

This module still works for me if I declare a pubsub service that is an instance of gossipsub. It's not terribly obvious though.

I think what's missing is a way for services and other libp2p components to express their dependencies in a way that the user can discover a compile time - I've opened a PR which I think will fix this here: libp2p/js-libp2p#1762 - I'd love some input on it if you've got the time.

The change to this module after that PR is merged would be to change these lines to add & { pubsub: PubSub } like:

import type { PubSub } from '@libp2p/interface-pubsub'

//... whole file here

export function pubsubPeerDiscovery (init: PubsubPeerDiscoveryInit = {}): (components: PubSubPeerDiscoveryComponents & { pubsub: PubSub }) => PeerDiscovery {
  return (components: PubSubPeerDiscoveryComponents) => new PubSubPeerDiscovery(components, init)
}

@joeltg
Copy link
Author

joeltg commented May 18, 2023

Yeah, I was trying to develop a service similar to this one that depends on pubsub and I resorted to just casting const { pubsub } = components as Components & { pubsub?: PubSub } and asserting that it exists at runtime. Works for now!

Maybe I'm forgetting something (crazy how fast context gets garbage collected in my head) but why say PubSubPeerDiscoveryComponents & { pubsub: PubSub } and not just have pubsub: PubSub in the PubSubPeerDiscoveryComponents definition itself?

@achingbrain
Copy link
Member

but why say PubSubPeerDiscoveryComponents & { pubsub: PubSub } and not just have pubsub: PubSub in the PubSubPeerDiscoveryComponents definition itself?

No, you're right - I was thinking of the circuit relay server updates in libp2p/js-libp2p#1762 where the component has an implicit dependency on another component but doesn't actually interact with it in the code.

@p-shahi p-shahi added this to js-libp2p Jun 6, 2023
@p-shahi p-shahi moved this to 🥞Weekly Candidates/Discuss🎙 in js-libp2p Jun 6, 2023
@Hmac512
Copy link

Hmac512 commented Aug 5, 2023

I have a dirty patch that makes peer discovery work via gossipsub for 0.46.2 here: https://github.com/Hmac512/fix-libp2p-peer-discover-046/blob/9aadfdc80332e2bbde0ce78b91f9183799fba32d/src/gossipNode.ts#L169

Need to clean up the code. It tests forming a mesh with 10 nodes, and it runs successfully.

I left some extra stuff in the patches I added while debugging. Will simplify it later.

The fix is too dirty to be merged into the official packages, but posting here if anyone needs it.

What’s the status on exposing the services in the main js-libp2p?

@maschad
Copy link
Member

maschad commented Sep 5, 2023

We should probably update the README to outline how to configure these services with pubsub peer discovery.

@Hmac512
Copy link

Hmac512 commented Sep 7, 2023

Would be helpful

@maschad maschad moved this from 🥞Weekly Candidates/Discuss🎙 to 🛠️ Todo in js-libp2p Sep 12, 2023
achingbrain added a commit that referenced this issue Sep 18, 2023
Update to the consolidated libp2p interface deps.

Adds a note to the readme about configuring a pubsub service.

Closes #98
achingbrain added a commit that referenced this issue Sep 18, 2023
Update to the consolidated libp2p interface deps.

Adds a note to the readme about configuring a pubsub service.

Closes #98
@github-project-automation github-project-automation bot moved this from 🛠️ Todo to 🎉Done in js-libp2p Sep 18, 2023
github-actions bot pushed a commit that referenced this issue Sep 18, 2023
## [9.0.0](v8.0.6...v9.0.0) (2023-09-18)

### ⚠ BREAKING CHANGES

* update to latest [email protected] deps (#111)

### Dependencies

* update to latest [email protected] deps ([#111](#111)) ([d54009b](d54009b)), closes [#98](#98)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants