1+ const moment = require ( 'moment' ) ;
2+
13const cache = require ( './cache' ) ;
24const database = require ( '../../models' ) ;
35const eventBus = require ( './event-bus' ) ;
46
57class 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