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

Discv5 POC integration #748

Merged
merged 12 commits into from
Nov 1, 2021
Merged

Discv5 POC integration #748

merged 12 commits into from
Nov 1, 2021

Conversation

jm-clius
Copy link
Contributor

@jm-clius jm-clius commented Oct 15, 2021

This PR relates to vacp2p/research#75

It adds POC integration of discv5 in nim-waku.

Background

Discovery v5 provides the first "true" ambient peer discovery mechanism for nim-waku. In combination with DNS discovery this provides nim-waku clients the option to bootstrap connection to the network and gradually discover other peers.

Clients may choose not to enable discv5 for many reasons, including:

  • it may not be useful for discovering a very specific peer with very specific capabilities (needle-in-a-haystack)
  • it requires a fair amount of resources, specifically bandwidth

We try to mitigate the latter by providing external API calls to start and stop discv5. The needle-in-a-haystack problem is an ongoing investigation, together with capability discovery.

For now Discovery v5 is disabled by default.

Why is this POC?

It shows that discovery v5 works for nim-waku. What still needs to be proven/tested is:

  • if we can find interesting nodes to connect to, even if discv5 is only enabled for short periods of time (using the start and stop API calls)
  • what the measurable impact is on bandwidth usage

Next steps for discv5 in nim-waku

  • fine-grained bandwidth metrics (in general we don't have good stats for overall bandwidth usage or what we use bandwidth for)
  • real world tests

Next steps for peer discovery in nim-waku

  • reasonable design and task breakdown for the problem of capability discovery
  • peer exchange (should be a fairly easy add to nim-libp2p, with a lot to gain from it)

Also see discussion re desktop requirements

@jm-clius jm-clius changed the title Discv5 proof of concept integration Discv5 POC integration Oct 15, 2021
@status-im-auto
Copy link
Collaborator

status-im-auto commented Oct 15, 2021

Jenkins Builds

Click to see older builds (29)
Commit #️⃣ Finished (UTC) Duration Platform Result
03c83ac #1 2021-10-15 14:16:46 ~2 min linux 📄log
✔️ 03c83ac #1 2021-10-15 14:30:29 ~15 min macos 📦bin
✔️ 03c83ac #1 2021-10-15 14:59:33 ~44 min windows 📦exe
7e1298b #2 2021-10-26 10:07:21 ~2 min linux 📄log
✔️ 7e1298b #2 2021-10-26 10:16:38 ~11 min macos 📦bin
✔️ 7e1298b #2 2021-10-26 10:42:43 ~37 min windows 📦exe
61afcea #3 2021-10-26 15:35:14 ~2 min linux 📄log
✔️ 61afcea #3 2021-10-26 15:44:42 ~11 min macos 📦bin
✔️ 61afcea #3 2021-10-26 16:14:49 ~41 min windows 📦exe
✔️ 5961be1 #5 2021-10-27 15:47:02 ~12 min macos 📦bin
5961be1 #5 2021-10-27 15:54:14 ~19 min linux 📄log
✔️ 5961be1 #5 2021-10-27 16:51:23 ~1 hr 17 min windows 📦exe
✔️ c024047 #4 2021-10-27 15:48:15 ~14 min macos 📦bin
✔️ c024047 #4 2021-10-27 16:02:10 ~28 min linux 📦bin
✔️ c024047 #4 2021-10-27 16:39:56 ~1 hr 6 min windows 📦exe
✔️ c2c2faf #6 2021-10-27 16:37:50 ~11 min macos 📦bin
✔️ c2c2faf #6 2021-10-27 16:44:13 ~18 min linux 📦bin
✔️ c2c2faf #6 2021-10-27 17:23:31 ~57 min windows 📦exe
✔️ e0e591f #7 2021-10-28 11:18:25 ~12 min macos 📦bin
✔️ e0e591f #7 2021-10-28 11:23:57 ~18 min linux 📦bin
✔️ e0e591f #7 2021-10-28 12:17:30 ~1 hr 11 min windows 📦exe
5c42d38 #8 2021-11-01 14:26:03 ~11 min macos 📄log
✔️ 5c42d38 #8 2021-11-01 14:29:33 ~15 min linux 📦bin
✔️ 5c42d38 #8 2021-11-01 14:58:46 ~44 min windows 📦exe
5c42d38 #9 2021-11-01 15:02:33 ~13 min macos 📄log
3563e21 #9 2021-11-01 15:12:02 ~1 min linux 📄log
✔️ 3563e21 #10 2021-11-01 15:22:05 ~11 min macos 📦bin
3563e21 #10 2021-11-01 15:33:05 ~2 min linux 📄log
✔️ 3563e21 #9 2021-11-01 15:58:46 ~48 min windows 📦exe
Commit #️⃣ Finished (UTC) Duration Platform Result
8ce7040 #11 2021-11-01 15:41:15 ~1 min linux 📄log
✔️ 8ce7040 #11 2021-11-01 15:50:52 ~11 min macos 📦bin
✔️ 8ce7040 #10 2021-11-01 16:28:34 ~49 min windows 📦exe
4ee4337 #12 2021-11-01 15:45:42 ~1 min linux 📄log
✔️ 4ee4337 #12 2021-11-01 15:55:39 ~11 min macos 📦bin
4ee4337 #13 2021-11-01 16:08:53 ~1 min linux 📄log
✔️ 4ee4337 #11 2021-11-01 16:35:41 ~51 min windows 📦exe

@jm-clius jm-clius marked this pull request as ready for review October 27, 2021 15:46
waku/v2/node/discv5/waku_discv5.nim Show resolved Hide resolved
@@ -53,6 +57,15 @@ proc initAddress(T: type MultiAddress, str: string): T {.raises: [Defect, ValueE
raise newException(ValueError,
"Invalid bootstrap node multi-address")

func getTransportProtocol(typedR: TypedRecord): Option[IpTransportProtocol] =
if typedR.tcp6.isSome or typedR.tcp.isSome:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this as a separate function and call it here, as for new transport we need to add the functionality in getTransportProtocol rather than modifying it.

if typedR.tcp6.isSome or typedR.tcp.isSome:
return some(IpTransportProtocol.tcpProtocol)

if typedR.udp6.isSome or typedR.udp.isSome:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for udp transport.

let ip = ipv4(typedR.ip.get)
addrs.add MultiAddress.init(ip, tcpProtocol, Port typedR.tcp.get)

if typedR.ip6.isSome:
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems we are reusing the code for tcp and udp .

Copy link
Contributor Author

@jm-clius jm-clius Oct 28, 2021

Choose a reason for hiding this comment

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

True, except that we read different transport addresses for each, of course. It's not pretty, but in this instance I prefer having it typed out as readable as possible, rather than having, say, a template where the construction of the addresses can become a bit obscure. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is tradeoff, and i get what you mean, my reasoning was that if we start supporting more transport then we have to add in this section again with redundant code, however for only 2 transports it is readable in current format.

@jm-clius
Copy link
Contributor Author

UPDATE: not sure why CI is failing for Github CI (it's passing on Jenkins for all three platforms). It may be related to subtle differences in localhost addressing. Will investigate in the morning.


var discoveredPeers: seq[RemotePeerInfo]

for node in discoveredNodes:
Copy link
Contributor

@rshiv rshiv Oct 29, 2021

Choose a reason for hiding this comment

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

queryRandom does not have a size guard , do we accept all the discovered nodes anyway. A limit over the discovered nodes might be useful for certain topologies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quite right! I think we do not yet have a clear idea how quickly our own "discovered" peer store will grow and we may have to implement stricter limits at some point.
In practice, note that we have the following limits already:

  • for libp2p connections, the maxConnections setting
  • the discv5 routing table, and query results like this one, are limited by k-buckets and bucket size. You can see how the underlying query is limited here

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

Thanks Hanno! LGTM!

# Discovery v5 API #
####################

proc findRandomPeers*(wakuDiscv5: WakuDiscoveryV5): Future[Result[seq[RemotePeerInfo], cstring]] {.async.} =
Copy link
Contributor

Choose a reason for hiding this comment

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

As a suggestion, I'd define a type for Result[seq[RemotePeerInfo], cstring]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally agree, but for a Result being used only once I think we may have some unnecessary indirection? For example, this module elsewhere returns Result[enr.Record, cstring] which is not reused either, but would then also require its own type for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

As it is wrapped inside a Future type, I thought it is prettier to be defined as a separate type, though not necessary.


if newPeers.len > 0:
debug "Connecting to newly discovered peers", count=newPeers.len()
await connectToNodes(node, newPeers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any limit on the number of connected Peers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The underlying libp2p max connections which is now configurable. Though we may indeed want to implement something more sophisticated for our own peer connection management (e.g. prioritising peers we discovered ourselves above incoming connections, etc.)

Copy link
Contributor

@oskarth oskarth left a comment

Choose a reason for hiding this comment

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

Exciting to see Disc v5 support coming along :)

waku/v2/node/wakunode2.nim Show resolved Hide resolved
@jm-clius
Copy link
Contributor Author

jm-clius commented Nov 1, 2021

Merging this PR in order to get some traction on the release from a stable codebase. Happy to address any further comments in subsequent PRs, if there are any. :)

@jm-clius jm-clius merged commit f85434e into master Nov 1, 2021
@jm-clius jm-clius deleted the feat/discv5 branch November 1, 2021 18:02
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.

5 participants