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

fix: remove initialising peer-exchange while creating a node #1158

Merged
merged 7 commits into from
Feb 17, 2023

Conversation

danisharora099
Copy link
Collaborator

@danisharora099 danisharora099 commented Feb 8, 2023

Problem

PeerExchange is being initialised when a node was created, similar to other protocols like Filter and LightPush. This is however incorrect as PeerExchange is a discovery protocol and is to be initialised through libp2p's peerDiscovery or manually.

Solution

Remove initialising PeerExchange by default while creating nodes

Notes

@github-actions
Copy link

github-actions bot commented Feb 8, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 114.94 KB (-0.06% 🔽) 2.3 s (-0.06% 🔽) 2.4 s (+29.16% 🔺) 4.7 s
Waku default setup 386.13 KB (-0.18% 🔽) 7.8 s (-0.18% 🔽) 4.2 s (-4.27% 🔽) 11.9 s
ECIES encryption 27.88 KB (0%) 558 ms (0%) 953 ms (-27.72% 🔽) 1.6 s
Symmetric encryption 27.88 KB (0%) 558 ms (0%) 1.1 s (-14.08% 🔽) 1.6 s
DNS discovery 108.79 KB (0%) 2.2 s (0%) 2.1 s (-15.53% 🔽) 4.2 s
Privacy preserving protocols 114.01 KB (-0.01% 🔽) 2.3 s (-0.01% 🔽) 1.5 s (-6.87% 🔽) 3.8 s
Light protocols 116.07 KB (-0.01% 🔽) 2.4 s (-0.01% 🔽) 1.6 s (-2.21% 🔽) 4 s
History retrieval protocols 115.91 KB (-0.01% 🔽) 2.4 s (-0.01% 🔽) 1.4 s (-2.72% 🔽) 3.7 s

@fryorcraken
Copy link
Collaborator

Wow, I actually have been thinking of doing this PR because it creates conflict with the new libp2p API so it's great to see that it also makes sense from your POV.

However, you only updated the create package here and I think the change needs an update on interfaces, core and tests too where peerExchange should be removed from the node interfaces.

@danisharora099
Copy link
Collaborator Author

Wow, I actually have been thinking of doing this PR because it creates conflict with the new libp2p API so it's great to see that it also makes sense from your POV.

However, you only updated the create package here and I think the change needs an update on interfaces, core and tests too where peerExchange should be removed from the node interfaces.

based on your reply, im confused now as it makes sense.

it's a protocol that we need to mount to our node to be able to dial relevant px nodes
however, the discovery should only start if specified through libp2p's peerDiscovery
the discovery class in itself creates another instance of the PeerExchange class, while it should ideally reuse the already initialised instance (which can't be accessed as the node creation and peerDiscovery setup happens in the same line
eg:

    waku = await createLightNode({
      libp2p: {
        peerDiscovery: [
          bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }),
          wakuPeerExchangeDiscovery(),
        ],
      },
    });

i might be missing something but thought it might be better to get a fresh perspective on this

@danisharora099 danisharora099 marked this pull request as draft February 9, 2023 07:33
@fryorcraken
Copy link
Collaborator

it's a protocol that we need to mount to our node to be able to dial relevant px nodes

That's the thing, we don't need the waku node to expose the peer exchange API. We just need peer exchange to access the right libp2p components to operate.
Hence, I would remove it from the waku node interface and just build it as a normal libp2p peer discovery module that can be passed to libp2p.

Copy link
Collaborator

@fryorcraken fryorcraken left a comment

Choose a reason for hiding this comment

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

Did not do a full review as there is a fundamental show stopper.

@@ -61,11 +62,11 @@ export async function waitForRemotePeer(
}

if (protocols.includes(Protocols.PeerExchange)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We do not expect users to use peer exchange directly but only as a libp2p peer discovery protocol. Hence peer exchange support can be dropped from waitForRemotePeer and also potentially from the Protocols enum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

based on this comment, #1160 (comment) and libp2p/js-libp2p-interfaces#338 should no longer be a problem for us at this moment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

based on this comment, #1160 (comment) and libp2p/js-libp2p-interfaces#338 should no longer be a problem for us at this moment.

Yep I agree.

- also removes the manual test for peer-exchange (assumption is that the
only way to initialise peer-exchange is through libp2p's peerDiscovery and
not manually) (ref:
#1158 (comment))

 # Please enter the commit message for your changes. Lines
starting
@danisharora099 danisharora099 marked this pull request as ready for review February 16, 2023 06:34
@danisharora099
Copy link
Collaborator Author

@fryorcraken it's ready for review again.
the best way to review is by going to "files changed" instead of per commit

);

expect(receivedCallback).to.be.true;
const pxPeers = waku.libp2p
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

might help to abstract this into a generic helper like getPeersForProtocols


expect(receivedCallback).to.be.true;
const pxPeers = waku.libp2p
.getConnections()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This strategies makes the test slow to run every time.

Instead of waiting 40s and then checking connection do this: listen on new connection events on libp2p. for each new connection, check tag. As soon as one with a peer exchange tag is found, test can stop.

You can also wrap that in a timeout so it does not wait forever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

great idea!

i saw a flaw while i revisited this: we assume that a peer exchange node will definitely connect but as we know (ref: waku-org/nwaku#1521), it's very probable that no connections are made. thus, i have refactored this to listen for discovery instead of connections

@danisharora099 danisharora099 merged commit 1b41569 into master Feb 17, 2023
@danisharora099 danisharora099 deleted the danisharora/fix-px branch February 17, 2023 07:57
@github-actions github-actions bot mentioned this pull request Feb 17, 2023
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.

2 participants