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
@@ -201,15 +213,18 @@ proc lookupRandomNode*(proto: Eth1Discovery, queue: AsyncQueue[NodeV4]) {.async:
201213 if proto.discv4.isNil.not :
202214 let nodes = await proto.discv4.lookupRandom ()
203215 for node in nodes:
216+ discv4_nodes_discovered.inc ()
204217 await queue.addLast (node)
205218
206219 if proto.discv5.isNil.not :
207220 let nodes = await proto.discv5.queryRandom ()
208221 for node in nodes:
222+ discv5_nodes_discovered.inc ()
209223 if not proto.eligibleNode (node.record):
210224 continue
211225 let v4 = node.to (NodeV4 ).valueOr:
212226 continue
227+ discv5_nodes_discovered.inc (labelValues = [" eligible" ])
213228 await queue.addLast (v4)
214229
215230proc getRandomBootnode * (proto: Eth1Discovery ): Opt [NodeV4 ] =
0 commit comments