Skip to content

Commit

Permalink
retry sync request when receiving invalid response range (#5615)
Browse files Browse the repository at this point in the history
Inform `sync_queue` about inconsistent responses to sync requests
so that the affected requests are retried with a different peer.
  • Loading branch information
etan-status authored Nov 22, 2023
1 parent c33dd2c commit 7554ca2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion beacon_chain/sync/sync_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 !=
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7554ca2

Please sign in to comment.