From 7c0e1ac7a1459dbcfc00d8b3d6a6fc22b884c832 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Wed, 11 Dec 2024 19:29:26 -0700 Subject: [PATCH] cleanup --- packages/portalnetwork/src/client/client.ts | 3 ++- .../portalnetwork/src/networks/contentLookup.ts | 16 ++++++++-------- .../portalnetwork/src/networks/history/gossip.ts | 2 +- packages/portalnetwork/src/networks/network.ts | 8 -------- .../portalnetwork/src/networks/nodeLookup.ts | 4 ++-- packages/portalnetwork/src/util/util.ts | 1 - 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/portalnetwork/src/client/client.ts b/packages/portalnetwork/src/client/client.ts index cf2717636..3d06fd749 100644 --- a/packages/portalnetwork/src/client/client.ts +++ b/packages/portalnetwork/src/client/client.ts @@ -373,10 +373,11 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent await this.handleUTP(nodeAddress, message, message.request) return } - const network = this.networks.get(bytesToHex(message.protocol) as NetworkId) if (!network) { + this.logger(`Received TALKREQ message on unsupported network ${bytesToHex(message.protocol)}`) await this.sendPortalNetworkResponse(nodeAddress, message.id, new Uint8Array()) + return } diff --git a/packages/portalnetwork/src/networks/contentLookup.ts b/packages/portalnetwork/src/networks/contentLookup.ts index 3c5b21b06..da33c243c 100644 --- a/packages/portalnetwork/src/networks/contentLookup.ts +++ b/packages/portalnetwork/src/networks/contentLookup.ts @@ -73,10 +73,10 @@ export class ContentLookup { // Sort known peers by distance to the content const nearest = this.network.routingTable.values() for (const enr of nearest) { - // Skip if the node has an active uTP request - if (this.network.portal.uTP.hasRequests(enr.nodeId)) { - continue - } + // // Skip if the node has an active uTP request + // if (this.network.portal.uTP.hasRequests(enr.nodeId) === true) { + // continue + // } const dist = distance(enr.nodeId, this.contentId) this.lookupPeers.push({ enr, distance: Number(dist) }) this.meta.set(enr.nodeId, { enr: enr.encodeTxt(), distance: bigIntToHex(dist) }) @@ -196,10 +196,10 @@ export class ContentLookup { this.logger(`received ${res.enrs.length} ENRs for closer nodes`) for (const enr of res.enrs) { const decodedEnr = ENR.decode(enr as Uint8Array) - // Skip if the node has an active uTP request - if (this.network.portal.uTP.hasRequests(decodedEnr.nodeId)) { - continue - } + // // Skip if the node has an active uTP request + // if (this.network.portal.uTP.hasRequests(decodedEnr.nodeId) === true) { + // continue + // } if (!this.meta.has(decodedEnr.nodeId)) { const dist = distance(decodedEnr.nodeId, this.contentId) this.lookupPeers.push({ enr: decodedEnr, distance: Number(dist) }) diff --git a/packages/portalnetwork/src/networks/history/gossip.ts b/packages/portalnetwork/src/networks/history/gossip.ts index ffe2ddf98..89ece6fcf 100644 --- a/packages/portalnetwork/src/networks/history/gossip.ts +++ b/packages/portalnetwork/src/networks/history/gossip.ts @@ -50,7 +50,7 @@ export class GossipManager { */ private gossip(peer: ENR) { // Skip if the node has an active uTP request - if (this.history.portal.uTP.hasRequests(peer.nodeId)) { + if (this.history.portal.uTP.hasRequests(peer.nodeId) === true) { return } const queue = this.gossipQueues[peer.nodeId] diff --git a/packages/portalnetwork/src/networks/network.ts b/packages/portalnetwork/src/networks/network.ts index 61a028315..1a23cc47c 100644 --- a/packages/portalnetwork/src/networks/network.ts +++ b/packages/portalnetwork/src/networks/network.ts @@ -118,15 +118,11 @@ export abstract class BaseNetwork extends EventEmitter { networkId: NetworkId, utpMessage?: boolean, ): Promise { - if (this.routingTable.isIgnored(enr.nodeId)) { - return new Uint8Array() - } try { const res = await this.portal.sendPortalNetworkMessage(enr, payload, networkId, utpMessage) return res } catch (err: any) { this.logger.extend('error')(`${err.message}`) - this.routingTable['ignoreNode'](enr.nodeId) return new Uint8Array() } } @@ -322,10 +318,6 @@ export abstract class BaseNetwork extends EventEmitter { value: findNodesMsg, }) const res = await this.sendMessage(enr, payload, this.networkId) - if (res.length === 0) { - this.routingTable['ignoreNode'](enr.nodeId) - return - } if (bytesToInt(res.slice(0, 1)) === MessageCodes.NODES) { this.portal.metrics?.nodesMessagesReceived.inc() const decoded = PortalWireMessageType.deserialize(res).value as NodesMessage diff --git a/packages/portalnetwork/src/networks/nodeLookup.ts b/packages/portalnetwork/src/networks/nodeLookup.ts index a9e827b6e..ae833f834 100644 --- a/packages/portalnetwork/src/networks/nodeLookup.ts +++ b/packages/portalnetwork/src/networks/nodeLookup.ts @@ -92,7 +92,7 @@ export class NodeLookup { } // Skip if the node has an active uTP request - if (this.network.portal.uTP.hasRequests(nodeId)) { + if (this.network.portal.uTP.hasRequests(nodeId) === true) { continue } @@ -130,7 +130,7 @@ export class NodeLookup { // Query selected nodes in parallel with timeout const lookupPromises = currentBatch - .filter((peer) => !this.network.portal.uTP.hasRequests(peer.nodeId)) + .filter((peer) => this.network.portal.uTP.hasRequests(peer.nodeId) === false) .map((peer) => this.queryPeer(peer)) try { diff --git a/packages/portalnetwork/src/util/util.ts b/packages/portalnetwork/src/util/util.ts index 896733b4b..b6af962f9 100644 --- a/packages/portalnetwork/src/util/util.ts +++ b/packages/portalnetwork/src/util/util.ts @@ -6,7 +6,6 @@ import { bigIntToBytes, bytesToBigInt, bytesToUnprefixedHex, - bytesToUtf8, unprefixedHexToBytes, } from '@ethereumjs/util'