4747 discv5: DiscV5
4848 compatibleForkId: CompatibleForkIdProc
4949
50+ declareCounter disc_incoming_packets, " Number of incoming packets on discovery port" , labels = [" type" ]
51+ declareCounter discv5_nodes_discovered, " Number of nodes discovered via discv5" , labels = [" type" ]
52+ declareCounter discv4_nodes_discovered, " Number of nodes discovered via discv4"
53+
5054# ------------------------------------------------------------------------------
5155# Private functions
5256# ------------------------------------------------------------------------------
@@ -65,6 +69,7 @@ func to(node: NodeV5, _: type NodeV4): ENodeResult[NodeV4] =
6569 let v4 = NodeV4 (
6670 id: node.id,
6771 node: ? ENode .fromEnr (node.record),
72+ fromDiscv5: true ,
6873 )
6974 ok (v4)
7075
@@ -90,8 +95,15 @@ proc processClient(
9095 if discv4.isErr:
9196 # unhandled buf will be handled by discv5
9297 let addrv5 = raddr.to (AddressV5 )
93- proto.discv5.receiveV5 (addrv5, buf).isOkOr:
94- debug " Discovery receive error" , discv4= discv4.error, discv5= error
98+ let res = proto.discv5.receiveV5 (addrv5, buf)
99+ if res.isErr:
100+ debug " Discovery receive error" , discv4= discv4.error, discv5= res.error, address= addrv5
101+ disc_incoming_packets.inc (labelValues = [" spam" ])
102+ else :
103+ disc_incoming_packets.inc (labelValues = [" discv5" ])
104+
105+ else :
106+ disc_incoming_packets.inc (labelValues = [" discv4" ])
95107
96108func eligibleNode (proto: Eth1Discovery , rec: Record ): bool =
97109 # Filter out non `eth` node
@@ -198,15 +210,18 @@ proc lookupRandomNode*(proto: Eth1Discovery, queue: AsyncQueue[NodeV4]) {.async:
198210 if proto.discv4.isNil.not :
199211 let nodes = await proto.discv4.lookupRandom ()
200212 for node in nodes:
213+ discv4_nodes_discovered.inc ()
201214 await queue.addLast (node)
202215
203216 if proto.discv5.isNil.not :
204217 let nodes = await proto.discv5.queryRandom ()
205218 for node in nodes:
219+ discv5_nodes_discovered.inc ()
206220 if not proto.eligibleNode (node.record):
207221 continue
208222 let v4 = node.to (NodeV4 ).valueOr:
209223 continue
224+ discv5_nodes_discovered.inc (labelValues = [" eligible" ])
210225 await queue.addLast (v4)
211226
212227proc getRandomBootnode * (proto: Eth1Discovery ): Opt [NodeV4 ] =
0 commit comments