Skip to content

Commit

Permalink
fix: track promise only after a successful sendRpc() (#415)
Browse files Browse the repository at this point in the history
* fix: track promise only after a successful sendRpc()

* feat: add iwant_promise_untracked metric

* Update src/index.ts

---------

Co-authored-by: Cayman <caymannava@gmail.com>
  • Loading branch information
twoeths and wemeetagain authored Mar 23, 2023
1 parent 5b3aee9 commit a959b09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,15 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
return
}

this.sendRpc(id, { messages: ihave, control: { iwant, prune } })
const sent = this.sendRpc(id, { messages: ihave, control: { iwant, prune } })
const iwantMessageIds = iwant[0]?.messageIDs
if (iwantMessageIds) {
if (sent) {
this.gossipTracer.addPromise(id, iwantMessageIds)
} else {
this.metrics?.iwantPromiseUntracked.inc(1)
}
}
}

/**
Expand Down Expand Up @@ -1385,7 +1393,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
iwantList = iwantList.slice(0, iask)
this.iasked.set(id, iasked + iask)

this.gossipTracer.addPromise(id, iwantList)
// do not add gossipTracer promise here until a successful sendRpc()

return [
{
Expand Down
4 changes: 4 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ export function getMetrics(
4 * opts.gossipPromiseExpireSec
]
}),
iwantPromiseUntracked: register.gauge({
name: 'gossip_iwant_promise_untracked',
help: 'Total count of untracked IWANT promise'
}),

/* Data structure sizes */
/** Unbounded cache sizes */
Expand Down

0 comments on commit a959b09

Please sign in to comment.