Skip to content

Commit 3d7f634

Browse files
authored
unrevert more of #5765 (#5834)
1 parent 225ef5e commit 3d7f634

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

beacon_chain/gossip_processing/block_processor.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type
6161
blobs*: Opt[BlobSidecars]
6262
maybeFinalized*: bool
6363
## The block source claims the block has been finalized already
64-
resfut*: Future[Result[void, VerifierError]]
64+
resfut*: Future[Result[void, VerifierError]].Raising([CancelledError])
6565
queueTick*: Moment # Moment when block was enqueued
6666
validationDur*: Duration # Time it took to perform gossip validation
6767
src*: MsgSource
@@ -385,7 +385,7 @@ proc checkBloblessSignature(self: BlockProcessor,
385385
proc enqueueBlock*(
386386
self: var BlockProcessor, src: MsgSource, blck: ForkedSignedBeaconBlock,
387387
blobs: Opt[BlobSidecars],
388-
resfut: Future[Result[void, VerifierError]] = nil,
388+
resfut: Future[Result[void, VerifierError]].Raising([CancelledError]) = nil,
389389
maybeFinalized = false,
390390
validationDur = Duration()) =
391391
withBlck(blck):
@@ -756,7 +756,7 @@ proc storeBlock(
756756
proc addBlock*(
757757
self: var BlockProcessor, src: MsgSource, blck: ForkedSignedBeaconBlock,
758758
blobs: Opt[BlobSidecars], maybeFinalized = false,
759-
validationDur = Duration()): Future[Result[void, VerifierError]] =
759+
validationDur = Duration()): Future[Result[void, VerifierError]] {.async: (raises: [CancelledError], raw: true).} =
760760
## Enqueue a Gossip-validated block for consensus verification
761761
# Backpressure:
762762
# There is no backpressure here - producers must wait for `resfut` to

beacon_chain/networking/peer_pool.nim

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ template outgoingEvent(eventType: EventType): AsyncEvent =
108108
pool.outNotFullEvent
109109
110110
proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
111-
filter: set[PeerType]) {.async.} =
111+
filter: set[PeerType]) {.async: (raises: [CancelledError]).} =
112112
if filter == {PeerType.Incoming, PeerType.Outgoing} or filter == {}:
113113
var fut1 = incomingEvent(eventType).wait()
114114
var fut2 = outgoingEvent(eventType).wait()
115115
try:
116-
discard await one(fut1, fut2)
116+
try:
117+
discard await one(fut1, fut2)
118+
except ValueError:
119+
raiseAssert "one precondition satisfied"
117120
if fut1.finished():
118121
if not(fut2.finished()):
119122
await fut2.cancelAndWait()
@@ -138,11 +141,11 @@ proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
138141
outgoingEvent(eventType).clear()
139142
140143
proc waitNotEmptyEvent[A, B](pool: PeerPool[A, B],
141-
filter: set[PeerType]): Future[void] =
144+
filter: set[PeerType]) {.async: (raises: [CancelledError], raw: true).} =
142145
pool.waitForEvent(EventType.NotEmptyEvent, filter)
143146
144147
proc waitNotFullEvent[A, B](pool: PeerPool[A, B],
145-
filter: set[PeerType]): Future[void] =
148+
filter: set[PeerType]){.async: (raises: [CancelledError], raw: true).} =
146149
pool.waitForEvent(EventType.NotFullEvent, filter)
147150
148151
proc newPeerPool*[A, B](maxPeers = -1, maxIncomingPeers = -1,
@@ -451,15 +454,15 @@ proc getPeerSpaceMask[A, B](pool: PeerPool[A, B],
451454
{PeerType.Outgoing}
452455
453456
proc waitForEmptySpace*[A, B](pool: PeerPool[A, B],
454-
peerType: PeerType) {.async.} =
457+
peerType: PeerType) {.async: (raises: [CancelledError]).} =
455458
## This procedure will block until ``pool`` will have an empty space for peer
456459
## of type ``peerType``.
457460
let mask = pool.getPeerSpaceMask(peerType)
458461
while pool.lenSpace({peerType}) == 0:
459462
await pool.waitNotFullEvent(mask)
460463
461464
proc addPeer*[A, B](pool: PeerPool[A, B],
462-
peer: A, peerType: PeerType): Future[PeerStatus] {.async.} =
465+
peer: A, peerType: PeerType): Future[PeerStatus] {.async: (raises: [CancelledError]).} =
463466
## Add peer ``peer`` of type ``peerType`` to PeerPool ``pool``.
464467
##
465468
## This procedure will wait for an empty space in PeerPool ``pool``, if
@@ -533,7 +536,7 @@ proc acquireItemImpl[A, B](pool: PeerPool[A, B],
533536

534537
proc acquire*[A, B](pool: PeerPool[A, B],
535538
filter = {PeerType.Incoming,
536-
PeerType.Outgoing}): Future[A] {.async.} =
539+
PeerType.Outgoing}): Future[A] {.async: (raises: [CancelledError]).} =
537540
## Acquire peer from PeerPool ``pool``, which match the filter ``filter``.
538541
mixin getKey
539542
doAssert(filter != {}, "Filter must not be empty")
@@ -586,7 +589,7 @@ proc release*[A, B](pool: PeerPool[A, B], peers: openArray[A]) {.inline.} =
586589
proc acquire*[A, B](pool: PeerPool[A, B],
587590
number: int,
588591
filter = {PeerType.Incoming,
589-
PeerType.Outgoing}): Future[seq[A]] {.async.} =
592+
PeerType.Outgoing}): Future[seq[A]] {.async: (raises: [CancelledError]).} =
590593
## Acquire ``number`` number of peers from PeerPool ``pool``, which match the
591594
## filter ``filter``.
592595
doAssert(filter != {}, "Filter must not be empty")
@@ -735,7 +738,7 @@ proc clear*[A, B](pool: PeerPool[A, B]) =
735738
pool.acqIncPeersCount = 0
736739
pool.acqOutPeersCount = 0
737740
738-
proc clearSafe*[A, B](pool: PeerPool[A, B]) {.async.} =
741+
proc clearSafe*[A, B](pool: PeerPool[A, B]) {.async: (raises: [CancelledError]).} =
739742
## Performs "safe" clear. Safe means that it first acquires all the peers
740743
## in PeerPool, and only after that it will reset storage.
741744
var acquired = newSeq[A]()

0 commit comments

Comments
 (0)