Skip to content

Commit 9ee535e

Browse files
committed
[ETCM-313] Integrate branch resolver actor with fast sync
1 parent a4110e9 commit 9ee535e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/FastSync.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,26 @@ class FastSync(
284284
if (batchFailuresCount > fastSyncMaxBatchRetries) {
285285
log.info("Max skeleton batch failures reached. Master peer must be wrong.")
286286
handleRewind(header, masterPeer.get, fastSyncBlockValidationN, blacklistDuration)
287+
288+
// Start branch resolution and wait for response from the FastSyncBranchResolver actor.
289+
context become waitingForBranchResolution
287290
branchResolver ! FastSyncBranchResolver.StartBranchResolver
288-
// TODO: Become waiting for a branch resolution
289291
currentSkeleton = None
290292
}
291293
}
292294

295+
private def waitingForBranchResolution: Receive = handleCommonMessages orElse handleStatus orElse {
296+
case FastSyncBranchResolver.BranchResolvedSuccessful(firstCommonBlockNumber, resolvedPeer) =>
297+
// Reset the batch failures count
298+
batchFailuresCount = 0
299+
300+
// Restart syncing from the valid block available in state.
301+
syncState = syncState.copy(bestBlockHeaderNumber = firstCommonBlockNumber)
302+
masterPeer = Some(resolvedPeer)
303+
context become receive
304+
processSyncing()
305+
}
306+
293307
private def blockHeadersError(peer: Peer) = {
294308
blacklist(peer.id, blacklistDuration, "error in block headers response")
295309
processSyncing()

0 commit comments

Comments
 (0)