diff --git a/.changeset/twelve-eggs-bathe.md b/.changeset/twelve-eggs-bathe.md new file mode 100644 index 0000000000..ba04f829ac --- /dev/null +++ b/.changeset/twelve-eggs-bathe.md @@ -0,0 +1,5 @@ +--- +"@farcaster/hubble": patch +--- + +fix: Fix gossip worker spending too much time iterating peer store diff --git a/apps/hubble/src/hubble.ts b/apps/hubble/src/hubble.ts index d087e575cd..97b27b3046 100644 --- a/apps/hubble/src/hubble.ts +++ b/apps/hubble/src/hubble.ts @@ -1251,6 +1251,7 @@ export class Hub implements HubInterface { ); await this.gossipNode.gossipContactInfo(contactInfo); + statsd().gauge("peer_store.count", await this.gossipNode.peerStoreCount()); return Promise.resolve(ok(undefined)); } } @@ -1397,8 +1398,6 @@ export class Hub implements HubInterface { } private async handleContactInfo(peerId: PeerId, content: ContactInfoContent): Promise { - statsd().gauge("peer_store.count", await this.gossipNode.peerStoreCount()); - let message: ContactInfoContentBody = content.body ? content.body : ContactInfoContentBody.create({ diff --git a/apps/hubble/src/network/p2p/gossipNodeWorker.ts b/apps/hubble/src/network/p2p/gossipNodeWorker.ts index 72a01397f0..482830b713 100644 --- a/apps/hubble/src/network/p2p/gossipNodeWorker.ts +++ b/apps/hubble/src/network/p2p/gossipNodeWorker.ts @@ -363,6 +363,7 @@ export class LibP2PNode { } async peerStoreCount() { + // Note this is performance intensive and blocks the event loop if there are many peers const peers = await this._node?.peerStore.all(); return peers?.length ?? 0; }