Skip to content

Commit d2eb51a

Browse files
committed
fix: add missing GossipFactor parameter to GossipsubOpts
Based on the spec, `GossipFactor` is a parameter other than a constant, and can be configured.
1 parent a1f58ca commit d2eb51a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export interface GossipsubOptsSpec {
99
Dscore: number
1010
/** Dout sets the quota for the number of outbound connections to maintain in a topic mesh. */
1111
Dout: number
12-
/** Dlazy affects how many peers we will emit gossip to at each heartbeat. */
12+
/**
13+
* Dlazy affects the minimum number of peers we will emit gossip to at each
14+
* heartbeat.
15+
*/
1316
Dlazy: number
1417
/** heartbeatInterval is the time between heartbeats in milliseconds */
1518
heartbeatInterval: number

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit {
201201
* If true, will utilize the libp2p connection manager tagging system to prune/graft connections to peers, defaults to true
202202
*/
203203
tagMeshPeers: boolean
204+
205+
/**
206+
* Specify what percent of peers to send gossip to. If the percent results in
207+
* a number smaller than `Dlazy`, `Dlazy` will be used instead.
208+
*
209+
* It should be a number between 0 and 1, with a reasonable default of 0.25
210+
*/
211+
gossipFactor: number;
204212
}
205213

206214
export interface GossipsubMessage {
@@ -450,6 +458,7 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
450458
opportunisticGraftPeers: constants.GossipsubOpportunisticGraftPeers,
451459
opportunisticGraftTicks: constants.GossipsubOpportunisticGraftTicks,
452460
directConnectTicks: constants.GossipsubDirectConnectTicks,
461+
gossipFactor: constants.GossipsubGossipFactor,
453462
...options,
454463
scoreParams: createPeerScoreParams(options.scoreParams),
455464
scoreThresholds: createPeerScoreThresholds(options.scoreThresholds)
@@ -2498,7 +2507,8 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
24982507

24992508
if (candidateToGossip.size === 0) return
25002509
let target = this.opts.Dlazy
2501-
const factor = constants.GossipsubGossipFactor * candidateToGossip.size
2510+
const gossipFactor = this.opts.gossipFactor;
2511+
const factor = gossipFactor * candidateToGossip.size
25022512
let peersToGossip: Set<PeerIdStr> | PeerIdStr[] = candidateToGossip
25032513
if (factor > target) {
25042514
target = factor

0 commit comments

Comments
 (0)