11import { BrowserWindow } from 'electron' ;
22import fs from 'fs' ;
3+ import moment , { Moment } from 'moment' ;
34import readline from 'readline' ;
45import path from 'path' ;
56import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress' ;
67import type { GetBlockSyncProgressType } from '../../common/ipc/api' ;
78import { BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL } from '../config' ;
9+ import { BlockSyncType } from '../../common/types/cardano-node.types' ;
10+ import { isItFreshLog } from './blockSyncProgressHelpers' ;
811
912const blockKeyword = 'Replayed block' ;
1013const validatingChunkKeyword = 'Validating chunk' ;
@@ -18,15 +21,11 @@ const progressKeywords = [
1821 ledgerKeyword ,
1922] ;
2023
21- type KeywordTypeMap = {
22- [ name : string ] : GetBlockSyncProgressType ;
23- } ;
24-
25- const keywordTypeMap : KeywordTypeMap = {
26- [ blockKeyword ] : 'replayedBlock' ,
27- [ validatingChunkKeyword ] : 'validatingChunk' ,
28- [ validatedChunkKeyword ] : 'validatingChunk' ,
29- [ ledgerKeyword ] : 'pushingLedger' ,
24+ const keywordTypeMap : Record < string , GetBlockSyncProgressType > = {
25+ [ blockKeyword ] : BlockSyncType . replayedBlock ,
26+ [ validatingChunkKeyword ] : BlockSyncType . validatingChunk ,
27+ [ validatedChunkKeyword ] : BlockSyncType . validatingChunk ,
28+ [ ledgerKeyword ] : BlockSyncType . pushingLedger ,
3029} ;
3130
3231function containProgressKeywords ( line : string ) {
@@ -43,6 +42,8 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4342 return keywordTypeMap [ key ] ;
4443}
4544
45+ const applicationStartDate = moment . utc ( ) ;
46+
4647export const handleCheckBlockReplayProgress = (
4748 mainWindow : BrowserWindow ,
4849 logsDirectoryPath : string
@@ -59,7 +60,10 @@ export const handleCheckBlockReplayProgress = (
5960 const progress = [ ] ;
6061
6162 for await ( const line of rl ) {
62- if ( containProgressKeywords ( line ) ) {
63+ if (
64+ containProgressKeywords ( line ) &&
65+ isItFreshLog ( applicationStartDate , line )
66+ ) {
6367 progress . push ( line ) ;
6468 }
6569 }
0 commit comments