3939type
4040 BlockVerifierFn * =
4141 proc (signedBlock: ForkedSignedBeaconBlock , maybeFinalized: bool ):
42- Future [Result [void , VerifierError ]] {.async : ( raises: [CancelledError ]) .}
42+ Future [Result [void , VerifierError ]] {.gcsafe , raises : [] .}
4343 InhibitFn * = proc : bool {.gcsafe , raises :[].}
4444
4545 RequestManager * = object
4949 quarantine: ref Quarantine
5050 blobQuarantine: ref BlobQuarantine
5151 blockVerifier: BlockVerifierFn
52- blockLoopFuture: Future [void ]. Raising ([ CancelledError ])
53- blobLoopFuture: Future [void ]. Raising ([ CancelledError ])
52+ blockLoopFuture: Future [void ]
53+ blobLoopFuture: Future [void ]
5454
5555func shortLog * (x: seq [Eth2Digest ]): string =
5656 " [" & x.mapIt (shortLog (it)).join (" , " ) & " ]"
@@ -104,7 +104,7 @@ proc checkResponse(idList: seq[BlobIdentifier],
104104 return false
105105 true
106106
107- proc requestBlocksByRoot (rman: RequestManager , items: seq [Eth2Digest ]) {.async : (raises: [ CancelledError ]) .} =
107+ proc requestBlocksByRoot (rman: RequestManager , items: seq [Eth2Digest ]) {.async .} =
108108 var peer: Peer
109109 try :
110110 peer = await rman.network.peerPool.acquire ()
@@ -171,21 +171,27 @@ proc requestBlocksByRoot(rman: RequestManager, items: seq[Eth2Digest]) {.async:
171171 peer = peer, blocks = shortLog (items), err = blocks.error ()
172172 peer.updateScore (PeerScoreNoValues )
173173
174+ except CancelledError as exc:
175+ raise exc
176+ except CatchableError as exc:
177+ peer.updateScore (PeerScoreNoValues )
178+ debug " Error while fetching blocks by root" , exc = exc.msg,
179+ items = shortLog (items), peer = peer, peer_score = peer.getScore ()
180+ raise exc
174181 finally :
175182 if not (isNil (peer)):
176183 rman.network.peerPool.release (peer)
177184
178185proc fetchBlobsFromNetwork (self: RequestManager ,
179- idList: seq [BlobIdentifier ])
180- {.async : (raises: [CancelledError ]).} =
186+ idList: seq [BlobIdentifier ]) {.async .} =
181187 var peer: Peer
182188
183189 try :
184190 peer = await self.network.peerPool.acquire ()
185191 debug " Requesting blobs by root" , peer = peer, blobs = shortLog (idList),
186192 peer_score = peer.getScore ()
187193
188- let blobs = await blobSidecarsByRoot (peer, BlobIdentifierList idList)
194+ let blobs = ( await blobSidecarsByRoot (peer, BlobIdentifierList idList) )
189195
190196 if blobs.isOk:
191197 let ublobs = blobs.get ()
@@ -213,11 +219,18 @@ proc fetchBlobsFromNetwork(self: RequestManager,
213219 peer = peer, blobs = shortLog (idList), err = blobs.error ()
214220 peer.updateScore (PeerScoreNoValues )
215221
222+ except CancelledError as exc:
223+ raise exc
224+ except CatchableError as exc:
225+ peer.updateScore (PeerScoreNoValues )
226+ debug " Error while fetching blobs by root" , exc = exc.msg,
227+ idList = shortLog (idList), peer = peer, peer_score = peer.getScore ()
228+ raise exc
216229 finally :
217230 if not (isNil (peer)):
218231 self.network.peerPool.release (peer)
219232
220- proc requestManagerBlockLoop (rman: RequestManager ) {.async : (raises: [ CancelledError ]) .} =
233+ proc requestManagerBlockLoop (rman: RequestManager ) {.async .} =
221234 while true :
222235 # TODO This polling could be replaced with an AsyncEvent that is fired
223236 # from the quarantine when there's work to do
@@ -232,19 +245,33 @@ proc requestManagerBlockLoop(rman: RequestManager) {.async: (raises: [CancelledE
232245 continue
233246
234247 debug " Requesting detected missing blocks" , blocks = shortLog (blocks)
235- let start = SyncMoment .now (0 )
248+ try :
249+ let start = SyncMoment .now (0 )
236250
237- var workers: array [PARALLEL_REQUESTS , Future [void ]. Raising ([ CancelledError ]) ]
251+ var workers: array [PARALLEL_REQUESTS , Future [void ]]
238252
239- for i in 0 ..< PARALLEL_REQUESTS :
240- workers[i] = rman.requestBlocksByRoot (blocks)
253+ for i in 0 ..< PARALLEL_REQUESTS :
254+ workers[i] = rman.requestBlocksByRoot (blocks)
241255
242- await allFutures (workers)
256+ await allFutures (workers)
243257
244- let finish = SyncMoment .now (uint64 (len (blocks)))
258+ let finish = SyncMoment .now (uint64 (len (blocks)))
259+
260+ var succeed = 0
261+ for worker in workers:
262+ if worker.completed ():
263+ inc (succeed)
264+
265+ debug " Request manager block tick" , blocks = shortLog (blocks),
266+ succeed = succeed,
267+ failed = (len (workers) - succeed),
268+ sync_speed = speed (start, finish)
269+
270+ except CancelledError :
271+ break
272+ except CatchableError as exc:
273+ warn " Unexpected error in request manager block loop" , exc = exc.msg
245274
246- debug " Request manager block tick" , blocks = shortLog (blocks),
247- sync_speed = speed (start, finish)
248275
249276proc getMissingBlobs (rman: RequestManager ): seq [BlobIdentifier ] =
250277 let
@@ -281,28 +308,42 @@ proc getMissingBlobs(rman: RequestManager): seq[BlobIdentifier] =
281308 rman.quarantine[].removeBlobless (blobless)
282309 fetches
283310
284- proc requestManagerBlobLoop (rman: RequestManager ) {.async : (raises: [CancelledError ]).} =
311+
312+ proc requestManagerBlobLoop (rman: RequestManager ) {.async .} =
285313 while true :
286- # TODO This polling could be replaced with an AsyncEvent that is fired
287- # from the quarantine when there's work to do
314+ # TODO This polling could be replaced with an AsyncEvent that is fired
315+ # from the quarantine when there's work to do
288316 await sleepAsync (POLL_INTERVAL )
289317 if rman.inhibit ():
290318 continue
291319
292- let fetches = rman.getMissingBlobs ()
293- if fetches.len > 0 :
294- debug " Requesting detected missing blobs" , blobs = shortLog (fetches)
295- let start = SyncMoment .now (0 )
296- var workers: array [PARALLEL_REQUESTS , Future [void ].Raising ([CancelledError ])]
297- for i in 0 ..< PARALLEL_REQUESTS :
298- workers[i] = rman.fetchBlobsFromNetwork (fetches)
299-
300- await allFutures (workers)
301- let finish = SyncMoment .now (uint64 (len (fetches)))
302-
303- debug " Request manager blob tick" ,
304- blobs_count = len (fetches),
305- sync_speed = speed (start, finish)
320+ let fetches = rman.getMissingBlobs ()
321+ if fetches.len > 0 :
322+ debug " Requesting detected missing blobs" , blobs = shortLog (fetches)
323+ try :
324+ let start = SyncMoment .now (0 )
325+ var workers: array [PARALLEL_REQUESTS , Future [void ]]
326+ for i in 0 ..< PARALLEL_REQUESTS :
327+ workers[i] = rman.fetchBlobsFromNetwork (fetches)
328+
329+ await allFutures (workers)
330+ let finish = SyncMoment .now (uint64 (len (fetches)))
331+
332+ var succeed = 0
333+ for worker in workers:
334+ if worker.finished () and not (worker.failed ()):
335+ inc (succeed)
336+
337+ debug " Request manager blob tick" ,
338+ blobs_count = len (fetches),
339+ succeed = succeed,
340+ failed = (len (workers) - succeed),
341+ sync_speed = speed (start, finish)
342+
343+ except CancelledError :
344+ break
345+ except CatchableError as exc:
346+ warn " Unexpected error in request manager blob loop" , exc = exc.msg
306347
307348proc start * (rman: var RequestManager ) =
308349 # # Start Request Manager's loops.
0 commit comments