mirror of https://github.com/waku-org/nwaku.git
chore: adding discv5 logs (#2811)
This commit is contained in:
parent
a05fa06919
commit
974b8a39ac
4
Makefile
4
Makefile
|
@ -130,6 +130,10 @@ ifeq ($(POSTGRES), 1)
|
||||||
NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
|
NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DEBUG_DISCV5), 1)
|
||||||
|
NIM_PARAMS := $(NIM_PARAMS) -d:debugDiscv5
|
||||||
|
endif
|
||||||
|
|
||||||
clean: | clean-libbacktrace
|
clean: | clean-libbacktrace
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,31 @@ proc updateENRShards(
|
||||||
|
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
|
proc logDiscv5FoundPeers(discoveredRecords: seq[waku_enr.Record]) =
|
||||||
|
for record in discoveredRecords:
|
||||||
|
let recordUri = record.toURI()
|
||||||
|
let capabilities = record.getCapabilities()
|
||||||
|
|
||||||
|
let typedRecord = record.toTyped().valueOr:
|
||||||
|
warn "Could not parse to typed record", error = error, enr = recordUri
|
||||||
|
continue
|
||||||
|
|
||||||
|
let peerInfo = record.toRemotePeerInfo().valueOr:
|
||||||
|
warn "Could not generate remote peer info", error = error, enr = recordUri
|
||||||
|
continue
|
||||||
|
|
||||||
|
let addrs = peerInfo.constructMultiaddrStr()
|
||||||
|
|
||||||
|
let rs = typedRecord.relaySharding()
|
||||||
|
let shardsStr =
|
||||||
|
if rs.isSome():
|
||||||
|
$rs.get()
|
||||||
|
else:
|
||||||
|
"no shards found"
|
||||||
|
|
||||||
|
notice "Received discv5 node",
|
||||||
|
addrs = addrs, enr = recordUri, capabilities = capabilities, shards = shardsStr
|
||||||
|
|
||||||
proc findRandomPeers*(
|
proc findRandomPeers*(
|
||||||
wd: WakuDiscoveryV5, overridePred = none(WakuDiscv5Predicate)
|
wd: WakuDiscoveryV5, overridePred = none(WakuDiscv5Predicate)
|
||||||
): Future[seq[waku_enr.Record]] {.async.} =
|
): Future[seq[waku_enr.Record]] {.async.} =
|
||||||
|
@ -180,6 +205,9 @@ proc findRandomPeers*(
|
||||||
|
|
||||||
var discoveredRecords = discoveredNodes.mapIt(it.record)
|
var discoveredRecords = discoveredNodes.mapIt(it.record)
|
||||||
|
|
||||||
|
when defined(debugDiscv5):
|
||||||
|
logDiscv5FoundPeers(discoveredRecords)
|
||||||
|
|
||||||
# Filter out nodes that do not match the predicate
|
# Filter out nodes that do not match the predicate
|
||||||
if overridePred.isSome():
|
if overridePred.isSome():
|
||||||
discoveredRecords = discoveredRecords.filter(overridePred.get())
|
discoveredRecords = discoveredRecords.filter(overridePred.get())
|
||||||
|
|
|
@ -649,18 +649,29 @@ proc connectToNodes*(
|
||||||
info "Dialing multiple peers", numOfPeers = nodes.len
|
info "Dialing multiple peers", numOfPeers = nodes.len
|
||||||
|
|
||||||
var futConns: seq[Future[bool]]
|
var futConns: seq[Future[bool]]
|
||||||
|
var connectedPeers: seq[RemotePeerInfo]
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
let node = parsePeerInfo(node)
|
let node = parsePeerInfo(node)
|
||||||
if node.isOk():
|
if node.isOk():
|
||||||
futConns.add(pm.connectRelay(node.value))
|
futConns.add(pm.connectRelay(node.value))
|
||||||
|
connectedPeers.add(node.value)
|
||||||
else:
|
else:
|
||||||
error "Couldn't parse node info", error = node.error
|
error "Couldn't parse node info", error = node.error
|
||||||
|
|
||||||
await allFutures(futConns)
|
await allFutures(futConns)
|
||||||
let successfulConns = futConns.mapIt(it.read()).countIt(it == true)
|
|
||||||
|
# Filtering successful connectedPeers based on futConns
|
||||||
|
let combined = zip(connectedPeers, futConns)
|
||||||
|
connectedPeers = combined.filterIt(it[1].read() == true).mapIt(it[0])
|
||||||
|
|
||||||
|
when defined(debugDiscv5):
|
||||||
|
let peerIds = connectedPeers.mapIt(it.peerId)
|
||||||
|
let origin = connectedPeers.mapIt(it.origin)
|
||||||
|
notice "established connections with found peers",
|
||||||
|
peerIds = peerIds, origin = origin
|
||||||
|
|
||||||
info "Finished dialing multiple peers",
|
info "Finished dialing multiple peers",
|
||||||
successfulConns = successfulConns, attempted = nodes.len
|
successfulConns = connectedPeers.len, attempted = nodes.len
|
||||||
|
|
||||||
# The issue seems to be around peers not being fully connected when
|
# The issue seems to be around peers not being fully connected when
|
||||||
# trying to subscribe. So what we do is sleep to guarantee nodes are
|
# trying to subscribe. So what we do is sleep to guarantee nodes are
|
||||||
|
@ -726,8 +737,7 @@ proc connectToRelayPeers*(pm: PeerManager) {.async.} =
|
||||||
if outRelayPeers.len >= pm.outRelayPeersTarget:
|
if outRelayPeers.len >= pm.outRelayPeersTarget:
|
||||||
return
|
return
|
||||||
|
|
||||||
let notConnectedPeers =
|
let notConnectedPeers = pm.peerStore.getNotConnectedPeers()
|
||||||
pm.peerStore.getNotConnectedPeers().mapIt(RemotePeerInfo.init(it.peerId, it.addrs))
|
|
||||||
|
|
||||||
var outsideBackoffPeers = notConnectedPeers.filterIt(pm.canBeConnected(it.peerId))
|
var outsideBackoffPeers = notConnectedPeers.filterIt(pm.canBeConnected(it.peerId))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue