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: track mcache not validated count #351

Merged
merged 1 commit into from
Oct 3, 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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements Initiali
private onScrapeMetrics(metrics: Metrics): void {
/* Data structure sizes */
metrics.mcacheSize.set(this.mcache.size)
metrics.mcacheNotValidatedCount.set(this.mcache.notValidatedCount)
// Arbitrary size
metrics.cacheSize.set({ cache: 'direct' }, this.direct.size)
metrics.cacheSize.set({ cache: 'seenCache' }, this.seenCache.size)
Expand Down
23 changes: 20 additions & 3 deletions src/message-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class MessageCache {

history: CacheEntry[][] = []

/** Track with accounting of messages in the mcache that are not yet validated */
notValidatedCount = 0

/**
* Holds history of messages in timebounded history arrays
*/
Expand Down Expand Up @@ -71,6 +74,10 @@ export class MessageCache {

this.history[0].push({ ...messageId, topic: msg.topic })

if (!validated) {
this.notValidatedCount++
}

return true
}

Expand Down Expand Up @@ -143,6 +150,10 @@ export class MessageCache {
return null
}

if (!entry.validated) {
this.notValidatedCount--
}

const { message, originatingPeers } = entry
entry.validated = true
// Clear the known peers list (after a message is validated, it is forwarded and we no
Expand All @@ -155,9 +166,15 @@ export class MessageCache {
* Shifts the current window, discarding messages older than this.history.length of the cache
*/
shift(): void {
const last = this.history[this.history.length - 1]
last.forEach((entry) => {
this.msgs.delete(entry.msgIdStr)
const lastCacheEntries = this.history[this.history.length - 1]
lastCacheEntries.forEach((cacheEntry) => {
const entry = this.msgs.get(cacheEntry.msgIdStr)
if (entry) {
this.msgs.delete(cacheEntry.msgIdStr)
if (!entry.validated) {
this.notValidatedCount--
}
}
})

this.history.pop()
Expand Down
4 changes: 4 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ export function getMetrics(
name: 'gossipsub_mcache_size',
help: 'Current mcache msg count'
}),
mcacheNotValidatedCount: register.gauge({
name: 'gossipsub_mcache_not_validated_count',
help: 'Current mcache msg count not validated'
}),

topicStrToLabel: topicStrToLabel,

Expand Down