Add discv5 provided ENR directly to Portal protocol routing table (#1714)

* Add discv5 provided ENR directly to Portal protocol routing table

Previous version of getting the ENR from the discv5 routing table
would not work due to the order of first calling the talk protocol
handler and only after that the addEnr to the disc5 routing table.

Instead of changing this order, pass along the ENR directly to
avoid this additional getNode call.

* Still request ENR from discv5 if it wasn't passed via handshake
This commit is contained in:
Kim De Mey 2023-08-30 20:38:15 +02:00 committed by GitHub
parent f177f5bf11
commit 7ae333ac8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

View File

@ -381,7 +381,7 @@ proc handleOffer(p: PortalProtocol, o: OfferMessage, srcId: NodeId): seq[byte] =
AcceptMessage(connectionId: connectionId, contentKeys: contentKeysBitList))
proc messageHandler(protocol: TalkProtocol, request: seq[byte],
srcId: NodeId, srcUdpAddress: Address): seq[byte] =
srcId: NodeId, srcUdpAddress: Address, node: Opt[Node]): seq[byte] =
doAssert(protocol of PortalProtocol)
logScope:
@ -393,15 +393,19 @@ proc messageHandler(protocol: TalkProtocol, request: seq[byte],
if decoded.isOk():
let message = decoded.get()
trace "Received message request", srcId, srcUdpAddress, kind = message.kind
# Received a proper Portal message, check if this node exists in the base
# routing table and add if so.
# When the node exists in the base discv5 routing table it is likely that
# it will/would end up in the portal routing tables too but that is not
# certain as more nodes might exists on the base layer, and it will depend
# on the distance, order of lookups, etc.
# Note: Could add a findNodes with distance 0 call when not, and perhaps,
# optionally pass ENRs if the message was a discv5 handshake containing the
# ENR.
# Received a proper Portal message, check first if an ENR is provided by
# the discovery v5 layer and add it to the portal network routing table.
# If not provided through the handshake, try to get it from the discovery v5
# routing table.
# When the node would be eligable for the portal network routing table, it
# is possible that it exists in the base discv5 routing table as the same
# node ids are used. It is not certain at all however as more nodes might
# exists on the base layer, and it will also depend on the distance,
# order of lookups, etc.
# Note: As third measure, could run a findNodes request with distance 0.
if node.isSome():
discard p.routingTable.addNode(node.get())
else:
let node = p.baseProtocol.getNode(srcId)
if node.isSome():
discard p.routingTable.addNode(node.get())

View File

@ -131,10 +131,6 @@ procSuite "Portal Wire Protocol Tests":
check (await proto1.baseProtocol.ping(proto2.localNode)).isOk()
check (await proto2.baseProtocol.ping(proto1.localNode)).isOk()
# Start the portal protocol to seed nodes from the discoveryv5 routing
# table.
proto2.start()
let contentKey = ByteList.init(@[1'u8])
# content does not exist so this should provide us with the closest nodes

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 074edff1b4cdbc9989e2ee9f996437a28a3ba182
Subproject commit 0d7e7448c4a2a50136e726be7d4e4a38e094e8e3