diff --git a/fluffy/network/wire/portal_protocol.nim b/fluffy/network/wire/portal_protocol.nim index 5f88b1f5d..03d8728ec 100644 --- a/fluffy/network/wire/portal_protocol.nim +++ b/fluffy/network/wire/portal_protocol.nim @@ -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,18 +393,22 @@ 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. - let node = p.baseProtocol.getNode(srcId) + # 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()) portal_message_requests_incoming.inc( labelValues = [$p.protocolId, $message.kind]) diff --git a/fluffy/tests/test_portal_wire_protocol.nim b/fluffy/tests/test_portal_wire_protocol.nim index bb6077b19..933033480 100644 --- a/fluffy/tests/test_portal_wire_protocol.nim +++ b/fluffy/tests/test_portal_wire_protocol.nim @@ -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 diff --git a/vendor/nim-eth b/vendor/nim-eth index 074edff1b..0d7e7448c 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 074edff1b4cdbc9989e2ee9f996437a28a3ba182 +Subproject commit 0d7e7448c4a2a50136e726be7d4e4a38e094e8e3