discv5 stage1 beta test (#862)

* update vendor/nim-eth submodule

point to the selectable `protocol-id` feature branch

* use d5waku as protocol-id

Use compiletime flag to change the discv5 protocol-id to "d5waku" allowing
nim-waku to span a separate discv5 network

* waku discv5 first beta stage

  - start discv5 during node start
  - added config options for discv5

* fix: pass to tcp port also when specifying ext ip

* bump nim-eth

Co-authored-by: ksr <kaiserd@users.noreply.github.com>
This commit is contained in:
Daniel Kaiser 2022-03-01 15:11:56 +01:00 committed by GitHub
parent 6be0fb233a
commit dbe76d29ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 14 deletions

4
.gitmodules vendored
View File

@ -1,8 +1,8 @@
[submodule "vendor/nim-eth"]
path = vendor/nim-eth
url = https://github.com/status-im/nim-eth.git
url = https://github.com/kaiserd/nim-eth.git
ignore = dirty
branch = master
branch = add-selectable-protocol-id-static
[submodule "vendor/nim-secp256k1"]
path = vendor/nim-secp256k1
url = https://github.com/status-im/nim-secp256k1.git

View File

@ -96,6 +96,9 @@ endif
endif
endif
# use a separate waku discv5 network with `protocol-id="d5waku"`
NIM_PARAMS := $(NIM_PARAMS) -d:discv5_protocol_id:d5waku
deps: | deps-common nat-libs waku.nims rlnlib
ifneq ($(USE_LIBBACKTRACE), 0)
deps: | libbacktrace

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 4e2b340af659d959b76160d4e6b39a3c395e9a9a
Subproject commit d442d84d221655ea25271b41bd2de546bafe4914

View File

@ -265,6 +265,24 @@ type
defaultValue: false
name: "discv5-enr-auto-update" .}: bool
discv5TableIpLimit* {.
hidden
desc: "Maximum amount of nodes with the same IP in discv5 routing tables"
defaultValue: 10
name: "discv5-table-ip-limit" .}: uint
discv5BucketIpLimit* {.
hidden
desc: "Maximum amount of nodes with the same IP in discv5 routing table buckets"
defaultValue: 2
name: "discv5-bucket-ip-limit" .}: uint
discv5BitsPerHop* {.
hidden
desc: "Kademlia's b variable, increase for less hops per lookup"
defaultValue: 1
name: "discv5-bits-per-hop" .}: int
## websocket config
websocketSupport* {.
desc: "Enable websocket: true|false",
@ -324,4 +342,4 @@ proc completeCmdArg*(T: type Port, val: TaintedString): seq[string] =
func defaultListenAddress*(conf: WakuNodeConf): ValidIpAddress =
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
(static ValidIpAddress.init("0.0.0.0"))
(static ValidIpAddress.init("0.0.0.0"))

View File

@ -77,11 +77,12 @@ proc findRandomPeers*(wakuDiscv5: WakuDiscoveryV5): Future[Result[seq[RemotePeer
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
## Filter based on our needs
let filteredNodes = discoveredNodes.filter(isWakuNode) # Currently only a single predicate
# let filteredNodes = discoveredNodes.filter(isWakuNode) # Currently only a single predicate
# TODO: consider node filtering based on ENR; we do not filter based on ENR in the first waku discv5 beta stage
var discoveredPeers: seq[RemotePeerInfo]
for node in filteredNodes:
for node in discoveredNodes:
# Convert discovered ENR to RemotePeerInfo and add to discovered nodes
let res = node.record.toRemotePeerInfo()
@ -107,7 +108,8 @@ proc new*(T: type WakuDiscoveryV5,
privateKey: keys.PrivateKey,
flags: WakuEnrBitfield,
enrFields: openArray[(string, seq[byte])],
rng: ref BrHmacDrbgContext): T =
rng: ref BrHmacDrbgContext,
discv5Config: protocol.DiscoveryConfig = protocol.defaultDiscoveryConfig): T =
var bootstrapEnrs: seq[enr.Record]
for node in bootstrapNodes:
@ -127,6 +129,7 @@ proc new*(T: type WakuDiscoveryV5,
bindPort = discv5UdpPort,
bindIp = bindIP,
enrAutoUpdate = enrAutoUpdate,
config = discv5Config,
rng = rng)
return WakuDiscoveryV5(protocol: protocol, listening: false)

View File

@ -1076,10 +1076,13 @@ when isMainModule:
)
if conf.discv5Discovery:
let discv5UdpPort = Port(uint16(conf.discv5UdpPort) + conf.portsShift)
let
discv5UdpPort = Port(uint16(conf.discv5UdpPort) + conf.portsShift)
discoveryConfig = DiscoveryConfig.init(
conf.discv5TableIpLimit, conf.discv5BucketIpLimit, conf.discv5BitsPerHop)
node.wakuDiscv5 = WakuDiscoveryV5.new(
extIP, extTcpPort, some(discv5UdpPort),
extIP, extPort, some(discv5UdpPort),
conf.listenAddress,
discv5UdpPort,
conf.discv5BootstrapNodes,
@ -1087,7 +1090,8 @@ when isMainModule:
keys.PrivateKey(conf.nodekey.skkey),
wakuFlags,
[], # Empty enr fields, for now
node.rng
node.rng,
discoveryConfig
)
ok(node)
@ -1168,9 +1172,14 @@ when isMainModule:
## Start a configured node and all mounted protocols.
## Resume history, connect to static nodes and start
## keep-alive, if configured.
# Start Waku v2 node
# Start Waku v2 node
waitFor node.start()
# start discv5 and connect to discovered nodes
if conf.discv5Discovery:
if not waitFor node.startDiscv5():
error "could not start Discovery v5"
# Resume historical messages, this has to be called after the node has been started
if conf.store and conf.persistMessages:
@ -1238,9 +1247,9 @@ when isMainModule:
##############
# Node setup #
##############
debug "1/6 Setting up storage"
var
pStorage: WakuPeerStorage
mStorage: WakuMessageStore