From a7d8082fc7b8ea61b005136fe4f90e633c323ed7 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 23 Feb 2022 20:54:11 +0100 Subject: [PATCH] transport.sendMessage: avoid passing address twice Node already has the address, so it does not make sense to pass it as a separate parameter. --- eth/p2p/discoveryv5/protocol.nim | 3 +-- eth/p2p/discoveryv5/transport.nim | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 583d6a0..0afc7f0 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -383,14 +383,13 @@ proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T): RequestId = doAssert(toNode.address.isSome()) let - address = toNode.address.get() reqId = RequestId.init(d.rng[]) message = encodeMessage(m, reqId) trace "Send message packet", dstId = toNode.id, address, kind = messageKind(T) discovery_message_requests_outgoing.inc() - d.transport.sendMessage(toNode, address, message) + d.transport.sendMessage(toNode, message) return reqId proc ping*(d: Protocol, toNode: Node): diff --git a/eth/p2p/discoveryv5/transport.nim b/eth/p2p/discoveryv5/transport.nim index 7965fa2..c24d412 100644 --- a/eth/p2p/discoveryv5/transport.nim +++ b/eth/p2p/discoveryv5/transport.nim @@ -68,9 +68,11 @@ proc registerRequest(t: Transport, n: Node, message: seq[byte], t.pendingRequests.del(nonce) ##Todo: remove dependence on message. This should be higher -proc sendMessage*(t: Transport, toNode: Node, address: Address, message: seq[byte]) = - let (data, nonce) = encodeMessagePacket(t.rng[], t.codec, toNode.id, - address, message) +proc sendMessage*(t: Transport, toNode: Node, message: seq[byte]) = + doAssert(toNode.address.isSome()) + let address = toNode.address.get() + let (data, nonce) = encodeMessagePacket(t.rng[], t.codec, + toNode.id, address, message) t.registerRequest(toNode, message, nonce) t.send(toNode, data)