From 99f5f270b9e7b69e4ef543c1ff1c019815af58cb Mon Sep 17 00:00:00 2001 From: dozyio <37986489+dozyio@users.noreply.github.com> Date: Sat, 30 Nov 2024 11:51:41 +0000 Subject: [PATCH] fix: do not add peers to routing table during RPC handling (#2866) This can cause a race condition where two peers try to bootstrap to each other, then fail to add the other to the routing table because they wait for the other to respond to a ping first. It also fixes a smaller bug whereby we'd try to add a peer to the routing table after they send us an RPC message but they are a DHT client - they'd not respond to the ping we send before adding them so it's a waste of resources. --- packages/kad-dht/src/rpc/index.ts | 6 ------ packages/kad-dht/test/rpc/handlers/ping.spec.ts | 2 -- 2 files changed, 8 deletions(-) diff --git a/packages/kad-dht/src/rpc/index.ts b/packages/kad-dht/src/rpc/index.ts index bfd88659bf..4a0c70aff4 100644 --- a/packages/kad-dht/src/rpc/index.ts +++ b/packages/kad-dht/src/rpc/index.ts @@ -95,12 +95,6 @@ export class RPC { const { stream, connection } = data const peerId = connection.remotePeer - try { - await this.routingTable.add(peerId) - } catch (err: any) { - this.log.error(err) - } - const self = this // eslint-disable-line @typescript-eslint/no-this-alias await pipe( diff --git a/packages/kad-dht/test/rpc/handlers/ping.spec.ts b/packages/kad-dht/test/rpc/handlers/ping.spec.ts index 1deef99c8e..1ee8552981 100644 --- a/packages/kad-dht/test/rpc/handlers/ping.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/ping.spec.ts @@ -2,7 +2,6 @@ import { defaultLogger } from '@libp2p/logger' import { expect } from 'aegir/chai' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { type Message, MessageType } from '../../../src/message/dht.js' import { PingHandler } from '../../../src/rpc/handlers/ping.js' import { createPeerId } from '../../utils/create-peer-id.js' @@ -30,7 +29,6 @@ describe('rpc - handlers - Ping', () => { it('replies with the same message', async () => { const msg: Message = { type: T, - key: uint8ArrayFromString('hello'), closer: [], providers: [] }