Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gossipFactor parameter to GossipsubOpts #502

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading