39
39
type
40
40
BlockVerifierFn* =
41
41
proc (signedBlock: ForkedSignedBeaconBlock, maybeFinalized: bool ):
42
- Future[Result[void , VerifierError]] {.async: ( raises: [CancelledError] ) .}
42
+ Future[Result[void , VerifierError]] {.gcsafe, raises: [] .}
43
43
InhibitFn* = proc : bool {.gcsafe, raises:[].}
44
44
45
45
RequestManager* = object
49
49
quarantine: ref Quarantine
50
50
blobQuarantine: ref BlobQuarantine
51
51
blockVerifier: BlockVerifierFn
52
- blockLoopFuture: Future[void ].Raising([CancelledError] )
53
- blobLoopFuture: Future[void ].Raising([CancelledError] )
52
+ blockLoopFuture: Future[void ]
53
+ blobLoopFuture: Future[void ]
54
54
55
55
func shortLog* (x: seq [Eth2Digest]) : string =
56
56
" [" & x.mapIt(shortLog(it)).join(" , " ) & " ]"
@@ -104,7 +104,7 @@ proc checkResponse(idList: seq[BlobIdentifier],
104
104
return false
105
105
true
106
106
107
- proc requestBlocksByRoot(rman: RequestManager, items: seq [Eth2Digest]) {.async: (raises: [CancelledError] ) .} =
107
+ proc requestBlocksByRoot(rman: RequestManager, items: seq [Eth2Digest]) {.async.} =
108
108
var peer: Peer
109
109
try :
110
110
peer = await rman.network.peerPool.acquire()
@@ -171,21 +171,27 @@ proc requestBlocksByRoot(rman: RequestManager, items: seq[Eth2Digest]) {.async:
171
171
peer = peer, blocks = shortLog(items), err = blocks.error()
172
172
peer.updateScore(PeerScoreNoValues)
173
173
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
174
181
finally :
175
182
if not (isNil(peer)):
176
183
rman.network.peerPool.release(peer)
177
184
178
185
proc fetchBlobsFromNetwork(self: RequestManager,
179
- idList: seq [BlobIdentifier])
180
- {.async: (raises: [CancelledError]) .} =
186
+ idList: seq [BlobIdentifier]) {.async.} =
181
187
var peer: Peer
182
188
183
189
try :
184
190
peer = await self.network.peerPool.acquire()
185
191
debug " Requesting blobs by root" , peer = peer, blobs = shortLog(idList),
186
192
peer_score = peer.getScore()
187
193
188
- let blobs = await blobSidecarsByRoot(peer, BlobIdentifierList idList)
194
+ let blobs = ( await blobSidecarsByRoot(peer, BlobIdentifierList idList) )
189
195
190
196
if blobs.isOk:
191
197
let ublobs = blobs.get()
@@ -213,11 +219,18 @@ proc fetchBlobsFromNetwork(self: RequestManager,
213
219
peer = peer, blobs = shortLog(idList), err = blobs.error()
214
220
peer.updateScore(PeerScoreNoValues)
215
221
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
216
229
finally :
217
230
if not (isNil(peer)):
218
231
self.network.peerPool.release(peer)
219
232
220
- proc requestManagerBlockLoop(rman: RequestManager) {.async: (raises: [CancelledError] ) .} =
233
+ proc requestManagerBlockLoop(rman: RequestManager) {.async.} =
221
234
while true :
222
235
# TODO This polling could be replaced with an AsyncEvent that is fired
223
236
# from the quarantine when there's work to do
@@ -232,19 +245,33 @@ proc requestManagerBlockLoop(rman: RequestManager) {.async: (raises: [CancelledE
232
245
continue
233
246
234
247
debug " Requesting detected missing blocks" , blocks = shortLog(blocks)
235
- let start = SyncMoment.now(0 )
248
+ try :
249
+ let start = SyncMoment.now(0 )
236
250
237
- var workers: array [PARALLEL_REQUESTS, Future[void ].Raising([CancelledError] ) ]
251
+ var workers: array [PARALLEL_REQUESTS, Future[void ]]
238
252
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)
241
255
242
- await allFutures(workers)
256
+ await allFutures(workers)
243
257
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
245
274
246
- debug " Request manager block tick" , blocks = shortLog(blocks),
247
- sync_speed = speed(start, finish)
248
275
249
276
proc getMissingBlobs(rman: RequestManager): seq [BlobIdentifier] =
250
277
let
@@ -281,28 +308,42 @@ proc getMissingBlobs(rman: RequestManager): seq[BlobIdentifier] =
281
308
rman.quarantine[].removeBlobless(blobless)
282
309
fetches
283
310
284
- proc requestManagerBlobLoop(rman: RequestManager) {.async: (raises: [CancelledError]) .} =
311
+
312
+ proc requestManagerBlobLoop(rman: RequestManager) {.async.} =
285
313
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
288
316
await sleepAsync(POLL_INTERVAL)
289
317
if rman.inhibit():
290
318
continue
291
319
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
306
347
307
348
proc start* (rman: var RequestManager) =
308
349
# # Start Request Manager's loops.
0 commit comments