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

GossipsubIWantFollowupTime as a param #216

Merged
merged 1 commit into from
Mar 24, 2022
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
4 changes: 2 additions & 2 deletions test/tracer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('IWantTracer', () => {
it('should track broken promises', async function () {
// tests that unfullfilled promises are tracked correctly
this.timeout(6000)
const t = new IWantTracer(null)
const t = new IWantTracer(constants.GossipsubIWantFollowupTime, null)
const peerA = 'A'
const peerB = 'B'

Expand Down Expand Up @@ -36,7 +36,7 @@ describe('IWantTracer', () => {
it('should track unbroken promises', async function () {
// like above, but this time we deliver messages to fullfil the promises
this.timeout(6000)
const t = new IWantTracer(null)
const t = new IWantTracer(constants.GossipsubIWantFollowupTime, null)
const peerA = 'A'
const peerB = 'B'

Expand Down
5 changes: 4 additions & 1 deletion ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export type GossipsubOpts = GossipsubOptsSpec & {
scoreParams: Partial<PeerScoreParams>
/** peer score thresholds */
scoreThresholds: Partial<PeerScoreThresholds>
/** customize GossipsubIWantFollowupTime in order not to apply IWANT penalties */
gossipsubIWantFollowupTime: number

dataTransform?: DataTransform
metricsRegister?: MetricsRegister | null
Expand Down Expand Up @@ -330,6 +332,7 @@ export default class Gossipsub extends EventEmitter {
mcacheLength: constants.GossipsubHistoryLength,
mcacheGossip: constants.GossipsubHistoryGossip,
seenTTL: constants.GossipsubSeenTTL,
gossipsubIWantFollowupTime: constants.GossipsubIWantFollowupTime,
...options,
scoreParams: createPeerScoreParams(options.scoreParams),
scoreThresholds: createPeerScoreThresholds(options.scoreThresholds)
Expand Down Expand Up @@ -414,7 +417,7 @@ export default class Gossipsub extends EventEmitter {
this.metrics = null
}

this.gossipTracer = new IWantTracer(this.metrics)
this.gossipTracer = new IWantTracer(this.opts.gossipsubIWantFollowupTime, this.metrics)

/**
* libp2p
Expand Down
10 changes: 5 additions & 5 deletions ts/tracer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GossipsubIWantFollowupTime } from './constants'
import { messageIdToString } from './utils'
import { MsgIdStr, PeerIdStr, RejectReason } from './types'
import { Metrics } from './metrics'
Expand All @@ -22,10 +21,11 @@ export class IWantTracer {
* Necessary to know if peers are actually breaking promises or simply sending them a bit later
*/
private readonly requestMsByMsg = new Map<MsgIdStr, number>()
private readonly requestMsByMsgExpire = 10 * GossipsubIWantFollowupTime
private readonly requestMsByMsgExpire: number

// eslint-disable-next-line no-useless-constructor
constructor(private readonly metrics: Metrics | null) {}
constructor(private readonly gossipsubIWantFollowupTime: number, private readonly metrics: Metrics | null) {
this.requestMsByMsgExpire = 10 * gossipsubIWantFollowupTime
}

get size(): number {
return this.promises.size
Expand Down Expand Up @@ -54,7 +54,7 @@ export class IWantTracer {

// If a promise for this message id and peer already exists we don't update the expiry
if (!expireByPeer.has(from)) {
expireByPeer.set(from, now + GossipsubIWantFollowupTime)
expireByPeer.set(from, now + this.gossipsubIWantFollowupTime)

if (this.metrics) {
this.metrics.iwantPromiseStarted.inc(1)
Expand Down