@@ -480,32 +480,30 @@ impl StackerDBListenerComms {
480
480
481
481
/// Get the status for `block` from the Stacker DB listener.
482
482
/// If the block is not found in the map, return an error.
483
- /// If the block is found, return it.
483
+ /// If the block is found, call `condition` to check if the block status
484
+ /// satisfies the condition.
485
+ /// If the condition is satisfied, return the block status as
486
+ /// `Ok(Some(status))`.
487
+ /// If the condition is not satisfied, wait for it to be satisfied.
484
488
/// If the timeout is reached, return `Ok(None)`.
485
- pub fn wait_for_block_status (
489
+ pub fn wait_for_block_status < F > (
486
490
& self ,
487
491
block_signer_sighash : & Sha512Trunc256Sum ,
488
- block_status_tracker : & mut BlockStatus ,
489
- rejections_timer : std:: time:: Instant ,
490
- rejections_timeout : Duration ,
491
492
timeout : Duration ,
492
- ) -> Result < Option < BlockStatus > , NakamotoNodeError > {
493
+ condition : F ,
494
+ ) -> Result < Option < BlockStatus > , NakamotoNodeError >
495
+ where
496
+ F : Fn ( & BlockStatus ) -> bool ,
497
+ {
493
498
let ( lock, cvar) = & * self . blocks ;
494
499
let blocks = lock. lock ( ) . expect ( "FATAL: failed to lock block status" ) ;
495
500
496
501
let ( guard, timeout_result) = cvar
497
502
. wait_timeout_while ( blocks, timeout, |map| {
498
- if rejections_timer. elapsed ( ) > rejections_timeout {
499
- return true ;
500
- }
501
503
let Some ( status) = map. get ( block_signer_sighash) else {
502
504
return true ;
503
505
} ;
504
- if status != block_status_tracker {
505
- * block_status_tracker = status. clone ( ) ;
506
- return false ;
507
- }
508
- return true ;
506
+ condition ( status)
509
507
} )
510
508
. expect ( "FATAL: failed to wait on block status cond var" ) ;
511
509
0 commit comments