Skip to content

Commit

Permalink
fix: throttle message events when the node is syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdesu committed Nov 11, 2024
1 parent 830cab5 commit dada041
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/controller/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ class Server extends EventEmitter {
this.logger.debug(`Received new block[${BigInt(result.number)}]`)

const status = this.eventStatus

const now = Date.now()
if (status.history.length > 0 &&now - status.history[status.history.length - 1].receivedAt < 5000) {
// Ignore the message if it is received too frequently, this is a common case when the node is syncing.
return;
}
status.history.push({ receivedAt: now })
if (status.history.length > 10) {
status.history.shift()
}

clearTimeout(status.checkTipHeight_notify)
clearTimeout(status.checkTipHeight_warn)

Expand Down

0 comments on commit dada041

Please sign in to comment.