From 14a6c32af2dd4fb6f56bff3fb37b465e2465bbd4 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 27 Mar 2024 16:11:17 +0700 Subject: [PATCH 1/2] feat: publish at least mesh_n peers --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 9bc059a6..6162a13d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2036,6 +2036,18 @@ export class GossipSub extends TypedEventEmitter implements Pub tosend.add(peer) tosendCount.mesh++ }) + + if (meshPeers.size < this.opts.D) { + // pick additional topic peers above the publishThreshold + const topicPeers = this.getRandomGossipPeers(topic, this.opts.D - meshPeers.size, (id) => { + return !meshPeers.has(id) && !this.direct.has(id) && !this.floodsubPeers.has(id) && this.score.score(id) >= this.opts.scoreThresholds.publishThreshold + }) + + topicPeers.forEach((peer) => { + tosend.add(peer) + tosendCount.mesh++ + }) + } // eslint-disable-next-line @typescript-eslint/brace-style } From e43f074bee8875e917ef7fda812e0a9af8b31f65 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Thu, 18 Apr 2024 08:20:07 +0700 Subject: [PATCH 2/2] chore: add more comments --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 6162a13d..a4457b02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2037,6 +2037,8 @@ export class GossipSub extends TypedEventEmitter implements Pub tosendCount.mesh++ }) + // We want to publish to at least `D` peers. + // If there are insufficient peers in the mesh, publish to other topic peers if (meshPeers.size < this.opts.D) { // pick additional topic peers above the publishThreshold const topicPeers = this.getRandomGossipPeers(topic, this.opts.D - meshPeers.size, (id) => {