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

refactor: start moving discovery modules to waku/discovery #2587

Merged
merged 6 commits into from
Apr 17, 2024

Conversation

Ivansete-status
Copy link
Collaborator

@Ivansete-status Ivansete-status commented Apr 15, 2024

Description

We need to allow nwaku features to be accessible from both wakunode2 and libwaku. In this PR, we start moving discovery logic from wakunode2 app to a more generic location, waku/node/discovery_manager.

In future PRs, is likely that we will perform the following movements:

  1. wakuDiscv5 and dynamicBootstrapNodes, see this, will get controlled only by DiscoveryManager.
  2. The WakuNode object will contain a reference to discoveryManager, similarly to how it now contains a reference to peerManager. See:
    WakuNode* = ref object
    peerManager*: PeerManager

Notice that the discoveryManager module is aimed to contain the logic to handle the discovery of other peers plus the logic to make the "self" node discoverable by others.

Issue

migrate DiscV5 and DNS Discovery from app.nim to waku_node.nim: #2452

Copy link

github-actions bot commented Apr 15, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2587-rln-v2-false

Built from 8163a49

@Ivansete-status Ivansete-status self-assigned this Apr 15, 2024
@Ivansete-status Ivansete-status marked this pull request as ready for review April 15, 2024 11:59
@gabrielmer
Copy link
Contributor

I wonder if discovery should enter at the node layer, or if it belongs to the "middleware" layer we talked about when creating the factory.

Definitely love the idea of having a discovery manager :) Having the discovery logic in its own module is a great step 🤩

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is a good step for restructure.
The only thing if sthg was changed in formatting as seemingly there are changes related only for that purpose without any meaningful change?
But it's ok, manageable.

@Ivansete-status
Copy link
Collaborator Author

I wonder if discovery should enter at the node layer, or if it belongs to the "middleware" layer we talked about when creating the factory.

Definitely love the idea of having a discovery manager :) Having the discovery logic in its own module is a great step 🤩

Very good point!
I think the DiscoveryManager component can be at the same level as PeerManager because both imply some management and interaction with other peers. Another option, to fulfill with your suggestion, would be to move the "discovery" logic one folder up, and then have waku/discovery_manager/ instead of waku/node/discovery_manager.

How do you feel about having the following? Does it sound correct?

 WakuNode* = ref object 
   peerManager*: PeerManager
   discManager*: DiscoveryManager   <------ 

@gabrielmer
Copy link
Contributor

Very good point! I think the DiscoveryManager component can be at the same level as PeerManager because both imply some management and interaction with other peers. Another option, to fulfill with your suggestion, would be to move the "discovery" logic one folder up, and then have waku/discovery_manager/ instead of waku/node/discovery_manager.

How do you feel about having the following? Does it sound correct?

 WakuNode* = ref object 
   peerManager*: PeerManager
   discManager*: DiscoveryManager   <------ 

It's true that both the PeerManager and the DiscoveryManager imply some management/interaction with other peers, but what I'm not sure about is if they are at the same layer of abstraction.

There's a chance that the DiscoveryManager is actually some kind of upper level logic intended for the PeerManager to get populated, which in that case they shouldn't be together. But I do lack some background, so not sure if what I'm saying makes sense at all haha, but I think it's important to have that clear before adding it to the waku_node module.

@jm-clius what's your take on it?

@jm-clius
Copy link
Contributor

jm-clius commented Apr 16, 2024

While having a Discovery Manager makes sense from a code org POV, I wouldn't compose it into the node object. In fact, we've specifically moved discovery elements out of the node as we realised more and more that we needed the separate layer of abstraction (side note: we've also seriously considered moving peer management outside of the node object, even though it is indeed at a lower abstraction than the discovery manager). In general:

  • a node is an object wrapping a libp2p switch, mounts libp2p protocols and manages the APIs to these protocols
  • a peer manager is an object that manages a store of possible peers for the node and ensures that the node has the kind of connectivity it needs for every type of protocol.
  • a discovery protocol may be any protocol/external provider of peers to the peer manager. These protocols may be discv5, DHTs, rendezvous, supplied lists, DNS lookups, etc. that have very little to do with libp2p transports and communications (in other words, it operates completely separately from the node and simply supplies the outcome of discovered peers to the peer manager).

The composition of the above is what makes a Waku application. Afaics the role of the node factory is exactly to assist with the composition of all these elements, so this is where the DiscoverManager would belong. IMO it would be a mistake to blur the lines of separation here.

@Ivansete-status Ivansete-status changed the title refactor: start moving discovery modules to waku/node/discovery_manager/ refactor: start moving discovery modules to waku/discovery Apr 17, 2024
Copy link
Contributor

@gabrielmer gabrielmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing! Thanks so much! 😍

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! The code organisation makes sense - also to include discovery functions in the factory from where it can be encapsulated by the bindings. Not sure yet I see the advantage why somewhat disparate objects would be composed into a single object, DiscoveryManager, though. Approving, as I assume it will make more sense in a future PR. :D

@Ivansete-status Ivansete-status merged commit 828583a into master Apr 17, 2024
13 of 15 checks passed
@Ivansete-status Ivansete-status deleted the discovery-in-libwaku branch April 17, 2024 19:48
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

Successfully merging this pull request may close these issues.

4 participants