Skip to content

Commit

Permalink
feat: add gossipFactor parameter to GossipsubOpts (#502)
Browse files Browse the repository at this point in the history
* fix: add missing `GossipFactor` parameter to `GossipsubOpts`

Based on the spec, `GossipFactor` is a parameter other than a constant,
and can be configured.

* fix: fix eslint errors
  • Loading branch information
mkermani144 authored Aug 19, 2024
1 parent a1f58ca commit 07b995c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export interface GossipsubOptsSpec {
Dscore: number
/** Dout sets the quota for the number of outbound connections to maintain in a topic mesh. */
Dout: number
/** Dlazy affects how many peers we will emit gossip to at each heartbeat. */
/**
* Dlazy affects the minimum number of peers we will emit gossip to at each
* heartbeat.
*/
Dlazy: number
/** heartbeatInterval is the time between heartbeats in milliseconds */
heartbeatInterval: number
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit {
* If true, will utilize the libp2p connection manager tagging system to prune/graft connections to peers, defaults to true
*/
tagMeshPeers: boolean

/**
* Specify what percent of peers to send gossip to. If the percent results in
* a number smaller than `Dlazy`, `Dlazy` will be used instead.
*
* It should be a number between 0 and 1, with a reasonable default of 0.25
*/
gossipFactor: number
}

export interface GossipsubMessage {
Expand Down Expand Up @@ -450,6 +458,7 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
opportunisticGraftPeers: constants.GossipsubOpportunisticGraftPeers,
opportunisticGraftTicks: constants.GossipsubOpportunisticGraftTicks,
directConnectTicks: constants.GossipsubDirectConnectTicks,
gossipFactor: constants.GossipsubGossipFactor,
...options,
scoreParams: createPeerScoreParams(options.scoreParams),
scoreThresholds: createPeerScoreThresholds(options.scoreThresholds)
Expand Down Expand Up @@ -2498,7 +2507,8 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub

if (candidateToGossip.size === 0) return
let target = this.opts.Dlazy
const factor = constants.GossipsubGossipFactor * candidateToGossip.size
const gossipFactor = this.opts.gossipFactor
const factor = gossipFactor * candidateToGossip.size
let peersToGossip: Set<PeerIdStr> | PeerIdStr[] = candidateToGossip
if (factor > target) {
target = factor
Expand Down

0 comments on commit 07b995c

Please sign in to comment.