@@ -148,10 +148,16 @@ class SyncStateSchedulerActor(
148
148
log.info(s " Waiting for target block to start the state sync " )
149
149
}
150
150
151
- private def finalizeSync (state : SchedulerState , targetBlock : BigInt , syncInitiator : ActorRef ): Unit = {
151
+ private def finalizeSync (
152
+ state : SchedulerState ,
153
+ currentStats : ProcessingStatistics ,
154
+ targetBlock : BigInt ,
155
+ syncInitiator : ActorRef
156
+ ): Unit = {
152
157
if (state.memBatch.nonEmpty) {
153
158
log.debug(s " Persisting ${state.memBatch.size} elements to blockchain and finalizing the state sync " )
154
- sync.persistBatch(state, targetBlock)
159
+ val finalState = sync.persistBatch(state, targetBlock)
160
+ reportStats(syncInitiator, currentStats, finalState)
155
161
syncInitiator ! StateSyncFinished
156
162
context.become(idle(ProcessingStatistics ()))
157
163
} else {
@@ -191,6 +197,7 @@ class SyncStateSchedulerActor(
191
197
}
192
198
}
193
199
case RequestFailed (from, reason) =>
200
+ log.debug(" Processing failed request from {}. Failure reason {}" , from, reason)
194
201
val newDownloaderState = currentDownloaderState.handleRequestFailure(from)
195
202
ProcessingResult (Left (DownloaderError (newDownloaderState, from, reason, critical = true )))
196
203
}
@@ -326,7 +333,7 @@ class SyncStateSchedulerActor(
326
333
handleRestart(currentState, currentStats, targetBlock, restartRequested.get)
327
334
328
335
case Sync if currentState.numberOfPendingRequests == 0 =>
329
- finalizeSync(currentState, targetBlock, syncInitiator)
336
+ finalizeSync(currentState, currentStats, targetBlock, syncInitiator)
330
337
331
338
case result : RequestResult =>
332
339
if (processing) {
@@ -414,13 +421,15 @@ class SyncStateSchedulerActor(
414
421
self ! Sync
415
422
416
423
case ProcessingResult (Left (err)) =>
424
+ log.debug(" Received error result" )
417
425
err match {
418
426
case Critical (er) =>
419
427
log.error(s " Critical error while state syncing ${er}, stopping state sync " )
420
428
// TODO we should probably start sync again from new target block, as current trie is malformed or declare
421
429
// fast sync as failure and start normal sync from scratch
422
430
context.stop(self)
423
431
case DownloaderError (newDownloaderState, peer, description, critical) =>
432
+ log.debug(" Downloader error by peer {}" , peer)
424
433
if (critical && handshakedPeers.contains(peer)) {
425
434
blacklist(peer.id, syncConfig.blacklistDuration, description)
426
435
}
@@ -563,12 +572,16 @@ object SyncStateSchedulerActor {
563
572
}
564
573
565
574
def handleRequestFailure (from : Peer ): DownloaderState = {
566
- val requestedNodes = activeRequests(from.id)
567
- val newNodesToGet = requestedNodes.foldLeft(nodesToGet) { case (map, node) =>
568
- map + (node -> None )
569
- }
575
+ activeRequests
576
+ .get(from.id)
577
+ .map { requestedNodes =>
578
+ val newNodesToGet = requestedNodes.foldLeft(nodesToGet) { case (map, node) =>
579
+ map + (node -> None )
580
+ }
570
581
571
- copy(activeRequests = activeRequests - from.id, nodesToGet = newNodesToGet)
582
+ copy(activeRequests = activeRequests - from.id, nodesToGet = newNodesToGet)
583
+ }
584
+ .getOrElse(this )
572
585
}
573
586
574
587
/**
0 commit comments