1
+ const moment = require ( 'moment' ) ;
2
+
1
3
const cache = require ( './cache' ) ;
2
4
const database = require ( '../../models' ) ;
3
5
const eventBus = require ( './event-bus' ) ;
4
6
5
7
class RoundPopulator {
8
+ constructor ( ) {
9
+ this . blockInfoUnavailable = new Map ( ) ;
10
+ }
11
+
6
12
async populateRound ( upstream , height ) {
13
+ const lastUnavailable = this . blockInfoUnavailable . get ( upstream . fullUpstreamName ) ;
14
+ if ( lastUnavailable && moment ( ) . diff ( lastUnavailable , 'minutes' ) < 5 ) {
15
+ return ;
16
+ }
17
+
7
18
eventBus . publish ( 'log/debug' , `Round-Populator | ${ upstream . fullUpstreamNameLogs } | Populating round ${ height } ` ) ;
8
19
const blockInfo = await upstream . getBlockInfo ( height ) ;
20
+ if ( ! blockInfo ) {
21
+ this . blockInfoUnavailable . set ( upstream . fullUpstreamName , new Date ( ) ) ;
22
+ }
9
23
if ( ! blockInfo || ! blockInfo . hash || ! blockInfo . plotterId ) {
10
24
return ;
11
25
}
26
+ if ( this . blockInfoUnavailable . has ( upstream . fullUpstreamName ) ) {
27
+ this . blockInfoUnavailable . delete ( upstream . fullUpstreamName ) ;
28
+ }
12
29
const round = await cache . ensureRoundIsCached ( upstream , height ) ;
13
30
round . blockHash = blockInfo . hash ;
14
31
const activePlotter = await upstream . getActivePlotter ( round . blockHeight ) ;
@@ -18,6 +35,11 @@ class RoundPopulator {
18
35
}
19
36
20
37
async populateUnpopulatedRounds ( upstream , maxHeight ) {
38
+ const lastUnavailable = this . blockInfoUnavailable . get ( upstream . fullUpstreamName ) ;
39
+ if ( lastUnavailable && moment ( ) . diff ( lastUnavailable , 'minutes' ) < 5 ) {
40
+ return ;
41
+ }
42
+
21
43
const unpopulatedRounds = await database ( ) . round . findAll ( {
22
44
where : {
23
45
upstream : upstream . fullUpstreamName ,
0 commit comments