Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions execution_chain/networking/discoveryv4/kademlia.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type
Node* = ref object
node*: ENode
id*: NodeId
fromDiscv5*: bool

RoutingTable = object
thisNode: Node
Expand Down
19 changes: 17 additions & 2 deletions execution_chain/networking/eth1_discovery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type
discv5: DiscV5
compatibleForkId: CompatibleForkIdProc

declareCounter disc_incoming_packets, "Number of incoming packets on discovery port", labels = ["type"]
declareCounter discv5_nodes_discovered, "Number of nodes discovered via discv5", labels = ["type"]
declareCounter discv4_nodes_discovered, "Number of nodes discovered via discv4"

#------------------------------------------------------------------------------
# Private functions
#------------------------------------------------------------------------------
Expand All @@ -65,6 +69,7 @@ func to(node: NodeV5, _: type NodeV4): ENodeResult[NodeV4] =
let v4 = NodeV4(
id: node.id,
node: ?ENode.fromEnr(node.record),
fromDiscv5: true,
)
ok(v4)

Expand All @@ -90,8 +95,15 @@ proc processClient(
if discv4.isErr:
# unhandled buf will be handled by discv5
let addrv5 = raddr.to(AddressV5)
proto.discv5.receiveV5(addrv5, buf).isOkOr:
debug "Discovery receive error", discv4=discv4.error, discv5=error
let res = proto.discv5.receiveV5(addrv5, buf)
if res.isErr:
debug "Discovery receive error", discv4=discv4.error, discv5=res.error, address=addrv5
disc_incoming_packets.inc(labelValues = ["spam"])
else:
disc_incoming_packets.inc(labelValues = ["discv5"])

else:
disc_incoming_packets.inc(labelValues = ["discv4"])

func eligibleNode(proto: Eth1Discovery, rec: Record): bool =
# Filter out non `eth` node
Expand Down Expand Up @@ -198,15 +210,18 @@ proc lookupRandomNode*(proto: Eth1Discovery, queue: AsyncQueue[NodeV4]) {.async:
if proto.discv4.isNil.not:
let nodes = await proto.discv4.lookupRandom()
for node in nodes:
discv4_nodes_discovered.inc()
await queue.addLast(node)

if proto.discv5.isNil.not:
let nodes = await proto.discv5.queryRandom()
for node in nodes:
discv5_nodes_discovered.inc()
if not proto.eligibleNode(node.record):
continue
let v4 = node.to(NodeV4).valueOr:
continue
discv5_nodes_discovered.inc(labelValues = ["eligible"])
await queue.addLast(v4)

proc getRandomBootnode*(proto: Eth1Discovery): Opt[NodeV4] =
Expand Down
4 changes: 2 additions & 2 deletions execution_chain/networking/p2p_metrics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export

declarePublicGauge rlpx_connected_peers, "Number of connected peers in the pool"

declarePublicCounter rlpx_connect_success, "Number of successfull rlpx connects"
declarePublicCounter rlpx_connect_success, "Number of successfull rlpx connects", labels = ["discversion"]

declarePublicCounter rlpx_connect_failure,
"Number of rlpx connects that failed", labels = ["reason"]
"Number of rlpx connects that failed", labels = ["reason", "discversion"]

declarePublicCounter rlpx_accept_success, "Number of successful rlpx accepted peers"

Expand Down
9 changes: 8 additions & 1 deletion execution_chain/networking/peer_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,17 @@ proc connect[Network](p: PeerPoolRef[Network], remote: Node): Future[PeerRef[Net
# TODO: Probably should move all this logic to rlpx.nim
if res.isOk():
rlpx_connect_success.inc()
if remote.fromDiscv5:
rlpx_connect_success.inc(labelValues = ["discv5"])
else:
rlpx_connect_success.inc(labelValues = ["discv4"])
return res.get()
else:
rlpx_connect_failure.inc()
rlpx_connect_failure.inc(labelValues = [$res.error])
if remote.fromDiscv5:
rlpx_connect_failure.inc(labelValues = [$res.error, "discv5"])
else:
rlpx_connect_failure.inc(labelValues = [$res.error, "discv4"])
case res.error():
of UselessRlpxPeerError:
p.addSeen(remote.id, SeenTableTimeUselessPeer)
Expand Down