Skip to content
This repository was archived by the owner on Jul 18, 2021. It is now read-only.

Commit 2821b96

Browse files
committed
Prevent block info spam on errors
1 parent bc7a85b commit 2821b96

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/services/round-populator.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
const moment = require('moment');
2+
13
const cache = require('./cache');
24
const database = require('../../models');
35
const eventBus = require('./event-bus');
46

57
class RoundPopulator {
8+
constructor() {
9+
this.blockInfoUnavailable = new Map();
10+
}
11+
612
async populateRound(upstream, height) {
13+
const lastUnavailable = this.blockInfoUnavailable.get(upstream.fullUpstreamName);
14+
if (lastUnavailable && moment().diff(lastUnavailable, 'minutes') < 5) {
15+
return;
16+
}
17+
718
eventBus.publish('log/debug', `Round-Populator | ${upstream.fullUpstreamNameLogs} | Populating round ${height}`);
819
const blockInfo = await upstream.getBlockInfo(height);
20+
if (!blockInfo) {
21+
this.blockInfoUnavailable.set(upstream.fullUpstreamName, new Date());
22+
}
923
if (!blockInfo || !blockInfo.hash || !blockInfo.plotterId) {
1024
return;
1125
}
26+
if (this.blockInfoUnavailable.has(upstream.fullUpstreamName)) {
27+
this.blockInfoUnavailable.delete(upstream.fullUpstreamName);
28+
}
1229
const round = await cache.ensureRoundIsCached(upstream, height);
1330
round.blockHash = blockInfo.hash;
1431
const activePlotter = await upstream.getActivePlotter(round.blockHeight);
@@ -18,6 +35,11 @@ class RoundPopulator {
1835
}
1936

2037
async populateUnpopulatedRounds(upstream, maxHeight) {
38+
const lastUnavailable = this.blockInfoUnavailable.get(upstream.fullUpstreamName);
39+
if (lastUnavailable && moment().diff(lastUnavailable, 'minutes') < 5) {
40+
return;
41+
}
42+
2143
const unpopulatedRounds = await database().round.findAll({
2244
where: {
2345
upstream: upstream.fullUpstreamName,

0 commit comments

Comments
 (0)