mirror of https://github.com/waku-org/nwaku.git
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:
parent
6be0fb233a
commit
dbe76d29ce
|
@ -1,8 +1,8 @@
|
||||||
[submodule "vendor/nim-eth"]
|
[submodule "vendor/nim-eth"]
|
||||||
path = 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
|
ignore = dirty
|
||||||
branch = master
|
branch = add-selectable-protocol-id-static
|
||||||
[submodule "vendor/nim-secp256k1"]
|
[submodule "vendor/nim-secp256k1"]
|
||||||
path = vendor/nim-secp256k1
|
path = vendor/nim-secp256k1
|
||||||
url = https://github.com/status-im/nim-secp256k1.git
|
url = https://github.com/status-im/nim-secp256k1.git
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -96,6 +96,9 @@ endif
|
||||||
endif
|
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
|
deps: | deps-common nat-libs waku.nims rlnlib
|
||||||
ifneq ($(USE_LIBBACKTRACE), 0)
|
ifneq ($(USE_LIBBACKTRACE), 0)
|
||||||
deps: | libbacktrace
|
deps: | libbacktrace
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e2b340af659d959b76160d4e6b39a3c395e9a9a
|
Subproject commit d442d84d221655ea25271b41bd2de546bafe4914
|
|
@ -265,6 +265,24 @@ type
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "discv5-enr-auto-update" .}: bool
|
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
|
## websocket config
|
||||||
websocketSupport* {.
|
websocketSupport* {.
|
||||||
desc: "Enable websocket: true|false",
|
desc: "Enable websocket: true|false",
|
||||||
|
|
|
@ -77,11 +77,12 @@ proc findRandomPeers*(wakuDiscv5: WakuDiscoveryV5): Future[Result[seq[RemotePeer
|
||||||
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
|
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
|
||||||
|
|
||||||
## Filter based on our needs
|
## 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]
|
var discoveredPeers: seq[RemotePeerInfo]
|
||||||
|
|
||||||
for node in filteredNodes:
|
for node in discoveredNodes:
|
||||||
# Convert discovered ENR to RemotePeerInfo and add to discovered nodes
|
# Convert discovered ENR to RemotePeerInfo and add to discovered nodes
|
||||||
let res = node.record.toRemotePeerInfo()
|
let res = node.record.toRemotePeerInfo()
|
||||||
|
|
||||||
|
@ -107,7 +108,8 @@ proc new*(T: type WakuDiscoveryV5,
|
||||||
privateKey: keys.PrivateKey,
|
privateKey: keys.PrivateKey,
|
||||||
flags: WakuEnrBitfield,
|
flags: WakuEnrBitfield,
|
||||||
enrFields: openArray[(string, seq[byte])],
|
enrFields: openArray[(string, seq[byte])],
|
||||||
rng: ref BrHmacDrbgContext): T =
|
rng: ref BrHmacDrbgContext,
|
||||||
|
discv5Config: protocol.DiscoveryConfig = protocol.defaultDiscoveryConfig): T =
|
||||||
|
|
||||||
var bootstrapEnrs: seq[enr.Record]
|
var bootstrapEnrs: seq[enr.Record]
|
||||||
for node in bootstrapNodes:
|
for node in bootstrapNodes:
|
||||||
|
@ -127,6 +129,7 @@ proc new*(T: type WakuDiscoveryV5,
|
||||||
bindPort = discv5UdpPort,
|
bindPort = discv5UdpPort,
|
||||||
bindIp = bindIP,
|
bindIp = bindIP,
|
||||||
enrAutoUpdate = enrAutoUpdate,
|
enrAutoUpdate = enrAutoUpdate,
|
||||||
|
config = discv5Config,
|
||||||
rng = rng)
|
rng = rng)
|
||||||
|
|
||||||
return WakuDiscoveryV5(protocol: protocol, listening: false)
|
return WakuDiscoveryV5(protocol: protocol, listening: false)
|
||||||
|
|
|
@ -1076,10 +1076,13 @@ when isMainModule:
|
||||||
)
|
)
|
||||||
|
|
||||||
if conf.discv5Discovery:
|
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(
|
node.wakuDiscv5 = WakuDiscoveryV5.new(
|
||||||
extIP, extTcpPort, some(discv5UdpPort),
|
extIP, extPort, some(discv5UdpPort),
|
||||||
conf.listenAddress,
|
conf.listenAddress,
|
||||||
discv5UdpPort,
|
discv5UdpPort,
|
||||||
conf.discv5BootstrapNodes,
|
conf.discv5BootstrapNodes,
|
||||||
|
@ -1087,7 +1090,8 @@ when isMainModule:
|
||||||
keys.PrivateKey(conf.nodekey.skkey),
|
keys.PrivateKey(conf.nodekey.skkey),
|
||||||
wakuFlags,
|
wakuFlags,
|
||||||
[], # Empty enr fields, for now
|
[], # Empty enr fields, for now
|
||||||
node.rng
|
node.rng,
|
||||||
|
discoveryConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
ok(node)
|
ok(node)
|
||||||
|
@ -1172,6 +1176,11 @@ when isMainModule:
|
||||||
# Start Waku v2 node
|
# Start Waku v2 node
|
||||||
waitFor node.start()
|
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
|
# Resume historical messages, this has to be called after the node has been started
|
||||||
if conf.store and conf.persistMessages:
|
if conf.store and conf.persistMessages:
|
||||||
waitFor node.resume()
|
waitFor node.resume()
|
||||||
|
|
Loading…
Reference in New Issue