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

feat: curate peers shared over px protocol #1671

Merged
merged 3 commits into from
Apr 19, 2023
Merged

Conversation

alrevuelta
Copy link
Contributor

@alrevuelta alrevuelta commented Apr 12, 2023

closes #1521

  • Remove the peer exchange discv5 loop and reuse the peers discovered via discv5 by the peer manager. ref
  • Curate peers shared over peer exchange, sharing only reachable peers feat: curate peers shared over peerexchange #1521 (peers that are connected (or were connected in the past) and come from discv5). This helps the requester to not waste time with unreachable peers.
  • Fix issue were duplicated peers were returned by peer exchange protocol within the same rpc call. (eg if 2 peers were requested, both could be the same)
  • Update px cache every x time, to avoid attacks such as graph learning. With this, a peer requesting peers via px will get at max MaxPeersCacheSize peers (see this).

Beyond unit tests, can be tested with:

./build/wakunode2 --dns-discovery=true --dns-discovery-url=enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.nodes.status.im --discv5-discovery=true --discv5-enr-auto-update=True --nodekey=161c2836197e8918d7eb1039758423795f0dc697a018ed55d5931aa9b0e5efb3 --peer-exchange
./build/wakunode2 \
--tcp-port=30305 \
--ports-shift=1 \
--peer-exchange-node=/ip4/127.0.0.1/tcp/60000/p2p/16Uiu2HAm2ZuRHGZUzG6JGJeY1nGKHXLGrQYnZ7mZToymHtFfYFFf

@alrevuelta alrevuelta force-pushed the curate-px-peers branch 6 times, most recently from 8574e79 to 456f486 Compare April 14, 2023 06:32
@alrevuelta alrevuelta marked this pull request as ready for review April 14, 2023 06:48
@@ -113,6 +113,10 @@ proc addPeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo) =

pm.peerStore[AddressBook][remotePeerInfo.peerId] = remotePeerInfo.addrs
pm.peerStore[KeyBook][remotePeerInfo.peerId] = publicKey
pm.peerStore[SourceBook][remotePeerInfo.peerId] = origin

if remotePeerInfo.enr.isSome:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we use () as it is a verb?

Suggested change
if remotePeerInfo.enr.isSome:
if remotePeerInfo.enr.isSome():

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! 🥇

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.

Approach looks good, though I have a question about race conditions.

Comment on lines 130 to 131
wpx.cleanCache()
wpx.populateEnrCache()
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this cause a race condition between when someone is querying the cache and the heartbeat is cleaning the cache in order to populate it again? I would suggest that the cache being populated and the one queried be different with an atomic swap between the two after the former is populated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, totally missed that

should be fixed here: 910afc5

require (await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo()))

# Give disv5 some time to discover each other
await sleepAsync(5000.millis)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to limit these "arbitrary" sleeps in our tests and rather check for the state (e.g. in a loop with some smaller sleep duration) or would that be an overkill? IMO that could potentially speed up some test runs and at the same time make them more resilient in case the node is slower.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, totally agree that in some tests we should follow this pattern, waitFor instead of arbitrary sleep. we would still need a timeout but ofc tests would finish before, and we can cut some time.

perhaps not for this specific test, but will take it into account for further tests/refactors thanks!

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! LGTM now.

@alrevuelta alrevuelta merged commit 14305c6 into master Apr 19, 2023
12 checks passed
@alrevuelta alrevuelta deleted the curate-px-peers branch April 19, 2023 14:12
@vpavlin vpavlin mentioned this pull request May 16, 2023
1 task
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.

feat: curate peers shared over peerexchange
4 participants