mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-05 03:25:04 +00:00
discv5 stage1 testnet (#863)
This commit is contained in:
parent
dbe76d29ce
commit
2972a50035
@ -99,3 +99,4 @@ task chat2bridge, "Build chat2-matterbridge":
|
|||||||
let name = "chat2bridge"
|
let name = "chat2bridge"
|
||||||
|
|
||||||
buildBinary name, "examples/v2/matterbridge/", "-d:chronicles_log_level=DEBUG"
|
buildBinary name, "examples/v2/matterbridge/", "-d:chronicles_log_level=DEBUG"
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import
|
import
|
||||||
strformat, os, osproc, net, strformat, chronicles, confutils, json,
|
strformat, os, osproc, net, strformat, chronicles, confutils, json,
|
||||||
|
eth/p2p/discoveryv5/enr,
|
||||||
|
eth/keys,
|
||||||
|
stew/shims/net as stewNet,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
@ -9,10 +12,14 @@ import
|
|||||||
import strutils except fromHex
|
import strutils except fromHex
|
||||||
|
|
||||||
const
|
const
|
||||||
defaults ="--log-level:TRACE --metrics-logging --metrics-server --rpc"
|
# Scenarios without discv5
|
||||||
|
# defaults ="--log-level:TRACE --metrics-logging --metrics-server --rpc"
|
||||||
|
# # Scenarios using discv5
|
||||||
|
defaults ="--log-level:TRACE --metrics-logging --metrics-server --rpc --discv5-discovery --discv5-table-ip-limit=1024 --discv5-bucket-ip-limit=16 --discv5-bits-per-hop=1"
|
||||||
wakuNodeBin = "build" / "wakunode2"
|
wakuNodeBin = "build" / "wakunode2"
|
||||||
metricsDir = "metrics"
|
metricsDir = "metrics"
|
||||||
portOffset = 2
|
portOffset = 2
|
||||||
|
discv5ExtIpAddr = "127.0.0.1" # Scenarios using discv5
|
||||||
|
|
||||||
type
|
type
|
||||||
NodeInfo* = object
|
NodeInfo* = object
|
||||||
@ -21,10 +28,12 @@ type
|
|||||||
address: string
|
address: string
|
||||||
shift: int
|
shift: int
|
||||||
label: string
|
label: string
|
||||||
|
enrUri: string # Scenarios using discv5
|
||||||
|
|
||||||
Topology = enum
|
Topology = enum
|
||||||
Star,
|
Star,
|
||||||
FullMesh
|
FullMesh,
|
||||||
|
BootstrapFleet # comprising one full-mesh core (fleet) and satellites (full nodes) using the fleet as bootstrap nodes
|
||||||
|
|
||||||
WakuNetworkConf* = object
|
WakuNetworkConf* = object
|
||||||
topology* {.
|
topology* {.
|
||||||
@ -37,19 +46,32 @@ type
|
|||||||
defaultValue: 16
|
defaultValue: 16
|
||||||
name: "amount" .}: int
|
name: "amount" .}: int
|
||||||
|
|
||||||
|
numFleetNodes* {.
|
||||||
|
desc: "Number of Fleetnodes."
|
||||||
|
defaultValue: 3
|
||||||
|
name: "numFleetNodes" .}: int
|
||||||
|
|
||||||
|
|
||||||
|
proc debugPrintEnrURI(enrUri: string) =
|
||||||
|
var r: Record
|
||||||
|
if not fromURI(r, enrUri):
|
||||||
|
echo "could not read ENR URI"
|
||||||
|
echo "ENR content: ", r
|
||||||
|
|
||||||
# NOTE: Don't distinguish between node types here a la full node, light node etc
|
# NOTE: Don't distinguish between node types here a la full node, light node etc
|
||||||
proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, label: string): NodeInfo =
|
proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, label: string, discv5BootStrapEnrs: seq[string] = @[]): NodeInfo =
|
||||||
let
|
let
|
||||||
rng = crypto.newRng()
|
rng = crypto.newRng()
|
||||||
key = SkPrivateKey.random(rng[])
|
key = SkPrivateKey.random(rng[])
|
||||||
hkey = key.getBytes().toHex()
|
hkey = key.getBytes().toHex()
|
||||||
rkey = SkPrivateKey.init(fromHex(hkey))[] #assumes ok
|
rkey = SkPrivateKey.init(fromHex(hkey))[] #assumes ok
|
||||||
privKey = PrivateKey(scheme: Secp256k1, skkey: rkey)
|
privKey = crypto.PrivateKey(scheme: Secp256k1, skkey: rkey)
|
||||||
#privKey = PrivateKey.random(Secp256k1)
|
#privKey = PrivateKey.random(Secp256k1)
|
||||||
pubkey = privKey.getPublicKey()[] #assumes ok
|
pubkey = privKey.getPublicKey()[] #assumes ok
|
||||||
keys = KeyPair(seckey: privKey, pubkey: pubkey)
|
keyPair = crypto.KeyPair(seckey: privKey, pubkey: pubkey)
|
||||||
peerInfo = PeerInfo.new(privKey)
|
peerInfo = PeerInfo.new(privKey)
|
||||||
port = 60000 + shift
|
port = 60000 + shift
|
||||||
|
discv5Port = 9000 + shift
|
||||||
#DefaultAddr = "/ip4/127.0.0.1/tcp/55505"
|
#DefaultAddr = "/ip4/127.0.0.1/tcp/55505"
|
||||||
address = "/ip4/127.0.0.1/tcp/" & $port
|
address = "/ip4/127.0.0.1/tcp/" & $port
|
||||||
hostAddress = MultiAddress.init(address).tryGet()
|
hostAddress = MultiAddress.init(address).tryGet()
|
||||||
@ -68,19 +90,68 @@ proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, lab
|
|||||||
if staticNodes.len > 0:
|
if staticNodes.len > 0:
|
||||||
for staticNode in staticNodes:
|
for staticNode in staticNodes:
|
||||||
result.cmd &= "--staticnode:" & staticNode & " "
|
result.cmd &= "--staticnode:" & staticNode & " "
|
||||||
|
|
||||||
|
# Scenarios using discv5
|
||||||
|
result.cmd &= "--nat:extip:" & discv5ExtIpAddr & " "
|
||||||
|
if discv5BootStrapEnrs.len > 0:
|
||||||
|
for enr in discv5BootStrapEnrs:
|
||||||
|
result.cmd &= "--discv5-bootstrap-node:" & enr & " "
|
||||||
|
|
||||||
result.shift = shift
|
result.shift = shift
|
||||||
result.label = label
|
result.label = label
|
||||||
result.master = master
|
result.master = master
|
||||||
result.address = listenStr
|
result.address = listenStr
|
||||||
|
|
||||||
|
# Scenarios using discv5
|
||||||
|
# We have to manually build the ENR which the node ran with the currently build node command will generate,
|
||||||
|
# because we need to know it before the node starts in order to be able to provide it as bootstrap information.
|
||||||
|
# Note: the ENR built here is not exactly the same as we don't integrate the waku2 key in this test scenario.
|
||||||
|
let enr = enr.Record.init(1,
|
||||||
|
keys.PrivateKey.fromHex(hkey).expect("could not convert priv key from hex"),
|
||||||
|
some(stewNet.ValidIpAddress.init(discv5ExtIpAddr)),
|
||||||
|
some(Port(discv5Port)), # tcp-port
|
||||||
|
some(Port(discv5Port))) # udp-port
|
||||||
|
.expect("Record within size limits")
|
||||||
|
result.enrUri = "enr:" & enr.toBase64
|
||||||
|
|
||||||
info "Node command created.", cmd=result.cmd, address = result.address
|
info "Node command created.", cmd=result.cmd, address = result.address
|
||||||
|
|
||||||
|
|
||||||
|
# # Scenarios without discv5
|
||||||
|
# proc starNetwork(amount: int): seq[NodeInfo] =
|
||||||
|
# let masterNode = initNodeCmd(portOffset, master = true, label = "master node")
|
||||||
|
# result.add(masterNode)
|
||||||
|
# for i in 1..<amount:
|
||||||
|
# result.add(initNodeCmd(portOffset + i, @[masterNode.address], label = "full node"))
|
||||||
|
|
||||||
|
# Scenarios using discv5
|
||||||
proc starNetwork(amount: int): seq[NodeInfo] =
|
proc starNetwork(amount: int): seq[NodeInfo] =
|
||||||
let masterNode = initNodeCmd(portOffset, master = true, label = "master node")
|
let masterNode = initNodeCmd(portOffset, master = true, label = "master node")
|
||||||
|
let bootstrapEnrList = @[masterNode.enrUri]
|
||||||
result.add(masterNode)
|
result.add(masterNode)
|
||||||
for i in 1..<amount:
|
for i in 1..<amount:
|
||||||
result.add(initNodeCmd(portOffset + i, @[masterNode.address], label = "full node"))
|
result.add(initNodeCmd(portOffset + i, label = "full node", discv5BootStrapEnrs = bootstrapEnrList)) # no waku bootstrap nodes; get bootstrap waku nodes via discv5
|
||||||
|
|
||||||
|
|
||||||
|
# Scenarios using discv5
|
||||||
|
proc bootstrapFleetNetwork(amount: int, numFleetNodes: int): seq[NodeInfo] =
|
||||||
|
debug "number of fleet nodes", numFleetNodes
|
||||||
|
debug "number of satellite nodes", amount
|
||||||
|
|
||||||
|
var bootstrapEnrList: seq[string] = @[] # bootstrap for discv5
|
||||||
|
var bootstrapNodeList: seq[string] = @[] # bootstrap for waku relay
|
||||||
|
|
||||||
|
for i in 0..<numFleetNodes:
|
||||||
|
for fleetNode in result:
|
||||||
|
bootstrapEnrList.add(fleetNode.enrUri)
|
||||||
|
bootstrapNodeList.add(fleetNode.address)
|
||||||
|
result.add(initNodeCmd(portOffset + i, staticNodes = bootstrapNodeList, label = "fleet node", discv5BootStrapEnrs = bootstrapEnrList))
|
||||||
|
|
||||||
|
for i in 0..<amount:
|
||||||
|
result.add(initNodeCmd(portOffset + numFleetNodes + i, label = "full node", discv5BootStrapEnrs = bootstrapEnrList)) # no waku bootstrap nodes; get bootstrap waku nodes via discv5
|
||||||
|
|
||||||
|
|
||||||
|
# Scenarios without discv5
|
||||||
proc fullMeshNetwork(amount: int): seq[NodeInfo] =
|
proc fullMeshNetwork(amount: int): seq[NodeInfo] =
|
||||||
debug "amount", amount
|
debug "amount", amount
|
||||||
for i in 0..<amount:
|
for i in 0..<amount:
|
||||||
@ -144,6 +215,9 @@ proc proccessGrafanaDashboard(nodes: int, inputFile: string,
|
|||||||
outputData["title"] = %* (outputData["title"].getStr() & " (all nodes)")
|
outputData["title"] = %* (outputData["title"].getStr() & " (all nodes)")
|
||||||
writeFile(outputFile, pretty(outputData))
|
writeFile(outputFile, pretty(outputData))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let conf = WakuNetworkConf.load()
|
let conf = WakuNetworkConf.load()
|
||||||
|
|
||||||
@ -153,12 +227,15 @@ when isMainModule:
|
|||||||
|
|
||||||
# Scenario xx2 14
|
# Scenario xx2 14
|
||||||
let amount = conf.amount
|
let amount = conf.amount
|
||||||
|
let numFleetNodes = conf.numFleetNodes
|
||||||
|
|
||||||
case topology:
|
case topology:
|
||||||
of Star:
|
of Star:
|
||||||
nodes = starNetwork(amount)
|
nodes = starNetwork(amount)
|
||||||
of FullMesh:
|
of FullMesh:
|
||||||
nodes = fullMeshNetwork(amount)
|
nodes = fullMeshNetwork(amount)
|
||||||
|
of BootstrapFleet:
|
||||||
|
nodes = bootstrapFleetNetwork(amount, numFleetNodes)
|
||||||
|
|
||||||
# var staticnodes: seq[string]
|
# var staticnodes: seq[string]
|
||||||
# for i in 0..<amount:
|
# for i in 0..<amount:
|
||||||
@ -189,6 +266,7 @@ when isMainModule:
|
|||||||
sleepDuration += 1
|
sleepDuration += 1
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
generatePrometheusConfig(nodes, metricsDir / "prometheus" / "prometheus.yml")
|
generatePrometheusConfig(nodes, metricsDir / "prometheus" / "prometheus.yml")
|
||||||
proccessGrafanaDashboard(nodes.len,
|
proccessGrafanaDashboard(nodes.len,
|
||||||
metricsDir / "waku-grafana-dashboard.json",
|
metricsDir / "waku-grafana-dashboard.json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user