@@ -21,10 +21,6 @@ export class FullSynchronizer extends Synchronizer {
21
21
private stopSyncing : boolean
22
22
private vmPromise ?: Promise < void >
23
23
24
- // Tracking vars for log msg condensation on zero tx blocks
25
- private NUM_ZERO_TXS_PER_LOG_MSG = 50
26
- public zeroTxsBlockLogMsgCounter : number = 0
27
-
28
24
constructor ( options : SynchronizerOptions ) {
29
25
super ( options )
30
26
this . blockFetcher = null
@@ -68,9 +64,15 @@ export class FullSynchronizer extends Synchronizer {
68
64
return
69
65
}
70
66
this . runningBlocks = true
67
+ let blockCounter = 0
68
+ let txCounter = 0
69
+ const NUM_BLOCKS_PER_LOG_MSG = 50
71
70
try {
72
71
let oldHead = Buffer . alloc ( 0 )
73
- let newHead = ( await this . vm . blockchain . getHead ( ) ) . hash ( )
72
+ const newHeadBlock = await this . vm . blockchain . getHead ( )
73
+ let newHead = newHeadBlock . hash ( )
74
+ const firstHeadBlock = newHeadBlock
75
+ let lastHeadBlock = newHeadBlock
74
76
while ( ! newHead . equals ( oldHead ) && ! this . stopSyncing ) {
75
77
oldHead = newHead
76
78
this . vmPromise = this . vm . runBlockchain ( this . vm . blockchain , 1 )
@@ -79,27 +81,29 @@ export class FullSynchronizer extends Synchronizer {
79
81
newHead = headBlock . hash ( )
80
82
// check if we did run a new block:
81
83
if ( ! newHead . equals ( oldHead ) ) {
82
- const number = headBlock . header . number . toNumber ( )
83
- const hash = short ( newHead )
84
- const numTxs = headBlock . transactions . length
85
- if ( numTxs === 0 ) {
86
- this . zeroTxsBlockLogMsgCounter += 1
87
- }
88
- if (
89
- ( numTxs > 0 && this . zeroTxsBlockLogMsgCounter > 0 ) ||
90
- ( numTxs === 0 && this . zeroTxsBlockLogMsgCounter >= this . NUM_ZERO_TXS_PER_LOG_MSG )
91
- ) {
92
- this . config . logger . info ( `Processed ${ this . zeroTxsBlockLogMsgCounter } blocks with 0 txs` )
93
- this . zeroTxsBlockLogMsgCounter = 0
94
- }
95
- if ( numTxs > 0 ) {
96
- this . config . logger . info ( `Executed block number=${ number } hash=${ hash } txs=${ numTxs } ` )
84
+ blockCounter += 1
85
+ txCounter += headBlock . transactions . length
86
+ lastHeadBlock = headBlock
87
+
88
+ if ( blockCounter >= NUM_BLOCKS_PER_LOG_MSG ) {
89
+ const firstNumber = firstHeadBlock . header . number . toNumber ( )
90
+ const firstHash = short ( firstHeadBlock . hash ( ) )
91
+ const lastNumber = lastHeadBlock . header . number . toNumber ( )
92
+ const lastHash = short ( lastHeadBlock . hash ( ) )
93
+ this . config . logger . info (
94
+ `Executed blocks count=${ blockCounter } first=${ firstNumber } hash=${ firstHash } last=${ lastNumber } hash=${ lastHash } with txs=${ txCounter } `
95
+ )
96
+ blockCounter = 0
97
+ txCounter = 0
97
98
}
98
99
}
99
100
}
101
+ } catch ( error ) {
102
+ this . emit ( 'error' , error )
100
103
} finally {
101
104
this . runningBlocks = false
102
105
}
106
+ return blockCounter
103
107
}
104
108
105
109
/**
0 commit comments