@@ -161,11 +161,10 @@ setupPraosThreads tracer cfg queue st0 followers peers = do
161
161
(ts, f) <- BlockFetch. setupValidatorThreads cfg st0. blockFetchControllerState queue
162
162
let valHeader h = assert (blockInvariant h) $ do
163
163
let ! delay = cfg. headerValidationDelay h
164
- atomically $
165
- curry
166
- queue
167
- (CPUTask delay $ T. pack $ " ValidateHeader " ++ show (coerce @ _ @ Int $ blockHash h))
168
- (return () )
164
+ curry
165
+ (queueAndWait (atomically . queue))
166
+ (CPUTask delay $ T. pack $ " ValidateHeader " ++ show (coerce @ _ @ Int $ blockHash h))
167
+ (return () )
169
168
(map Concurrently ts ++ ) <$> setupPraosThreads' tracer cfg valHeader f st0 followers peers
170
169
171
170
setupPraosThreads' ::
@@ -208,7 +207,7 @@ praosNode ::
208
207
m [m () ]
209
208
praosNode tracer cfg followers peers = do
210
209
st0 <- PraosNodeState <$> newBlockFetchControllerState cfg. chain <*> pure Map. empty
211
- taskQueue <- atomically $ newTaskMultiQueue @ () 100
210
+ taskQueue <- atomically $ newTaskMultiQueue @ () (defaultQueueBound cfg . processingCores)
212
211
let queue = writeTMQueue taskQueue ()
213
212
praosThreads <- setupPraosThreads tracer cfg. praosConfig queue st0 followers peers
214
213
let cpuTasksProcessors = processCPUTasks cfg. processingCores (contramap PraosNodeEventCPU tracer) taskQueue
@@ -221,5 +220,17 @@ praosNode tracer cfg followers peers = do
221
220
cfg. blockMarker
222
221
st0. blockFetchControllerState. cpsVar
223
222
(BlockFetch. addProducedBlock st0. blockFetchControllerState)
224
- (atomically . queue)
223
+ (queueAndWait ( atomically . queue) )
225
224
return $ cpuTasksProcessors : generationThread : map runConcurrently praosThreads
225
+
226
+ queueAndWait ::
227
+ MonadSTM m =>
228
+ ((a , m () ) -> m () ) ->
229
+ (a , m () ) ->
230
+ m ()
231
+ queueAndWait queue (d, m) = do
232
+ sem <- newEmptyTMVarIO
233
+ curry queue d $ do
234
+ m
235
+ atomically $ putTMVar sem ()
236
+ atomically $ takeTMVar sem
0 commit comments