From da8968003d8cd31dfb65dd00a7c4460afbf06a00 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 20 Sep 2024 14:23:37 -0600 Subject: [PATCH] portalnetwork: filter ENR responses by "closer than self" --- packages/portalnetwork/src/networks/network.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/portalnetwork/src/networks/network.ts b/packages/portalnetwork/src/networks/network.ts index 968a4f918..d0e51e658 100644 --- a/packages/portalnetwork/src/networks/network.ts +++ b/packages/portalnetwork/src/networks/network.ts @@ -626,7 +626,12 @@ export abstract class BaseNetwork extends EventEmitter { // Discv5 calls for maximum of 16 nodes per NODES message const ENRs = this.routingTable.nearest(lookupKey, 16) - const encodedEnrs = ENRs.filter((enr) => enr.nodeId !== src.nodeId).map((enr) => { + const encodedEnrs = ENRs.filter((enr) => { + // exclude requesting node's own ENR + enr.nodeId !== src.nodeId && + // exclude ENRs that are further from content than us + distance(enr.nodeId, lookupKey) < distance(this.enr.nodeId, lookupKey) + }).map((enr) => { return enr.encode() }) if (encodedEnrs.length > 0) {