From 6049e6d53da68c0f3d14e2e07484da14857bcb37 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 21 Nov 2023 21:38:33 +0100 Subject: [PATCH] retry sync request when receiving invalid response range Inform `sync_queue` about inconsistent responses to sync requests so that the affected requests are retried with a different peer. --- beacon_chain/sync/sync_manager.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index 4200bc9bca..4692abafde 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -417,6 +417,7 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} = let slots = mapIt(blockData, it[].slot) if not(checkResponse(req, slots)): peer.updateScore(PeerScoreBadResponse) + man.queue.push(req) warn "Received blocks sequence is not in requested range", blocks_count = len(blockData), blocks_map = blockSmap, request = req @@ -446,12 +447,15 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} = let uniqueSlots = foldl(slots, combine(a, b), @[slots[0]]) if not(checkResponse(req, uniqueSlots)): peer.updateScore(PeerScoreBadResponse) + man.queue.push(req) warn "Received blobs sequence is not in requested range", blobs_count = len(blobData), blobs_map = getShortMap(req, blobData), request = req return let groupedBlobs = groupBlobs(req, blockData, blobData) if groupedBlobs.isErr(): + peer.updateScore(PeerScoreBadResponse) + man.queue.push(req) warn "Received blobs sequence is invalid", blobs_map = getShortMap(req, blobData), request = req, msg=groupedBlobs.error() return @@ -462,9 +466,9 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} = if blobData.isSome: let blobs = blobData.get() if len(blobs) != len(blockData): - info "block and blobs have different lengths", blobs=len(blobs), blocks=len(blockData) peer.updateScore(PeerScoreNoValues) man.queue.push(req) + info "block and blobs have different lengths", blobs=len(blobs), blocks=len(blockData) return for i, blk in blockData: if len(blobs[i]) > 0 and blk[].slot != @@ -502,6 +506,7 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} = man.workers[index].status = SyncWorkerStatus.Processing) except CatchableError as exc: + man.queue.push(req) debug "Unexpected exception while receiving blocks", request = req, errName = exc.name, errMsg = exc.msg return