Skip to content

Commit 57f80fb

Browse files
committed
restored original wait_for_block_status
1 parent 420f861 commit 57f80fb

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,22 @@ impl SignerCoordinator {
331331
// Based on the amount of rejections, eventually modify the timeout.
332332
let block_status = match self.stackerdb_comms.wait_for_block_status(
333333
block_signer_sighash,
334-
&mut block_status_tracker,
335-
rejections_timer,
336-
*rejections_timeout,
337334
EVENT_RECEIVER_POLL,
335+
|status| {
336+
if rejections_timer.elapsed() > *rejections_timeout {
337+
return false;
338+
}
339+
if *status != block_status_tracker {
340+
return false;
341+
}
342+
return true;
343+
},
338344
)? {
339-
Some(status) => status,
345+
Some(status) => {
346+
// keep track of the last status
347+
block_status_tracker = status.clone();
348+
status
349+
}
340350
None => {
341351
// If we just received a timeout, we should check if the burnchain
342352
// tip has changed or if we received this signed block already in

testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -480,32 +480,30 @@ impl StackerDBListenerComms {
480480

481481
/// Get the status for `block` from the Stacker DB listener.
482482
/// 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.
484488
/// If the timeout is reached, return `Ok(None)`.
485-
pub fn wait_for_block_status(
489+
pub fn wait_for_block_status<F>(
486490
&self,
487491
block_signer_sighash: &Sha512Trunc256Sum,
488-
block_status_tracker: &mut BlockStatus,
489-
rejections_timer: std::time::Instant,
490-
rejections_timeout: Duration,
491492
timeout: Duration,
492-
) -> Result<Option<BlockStatus>, NakamotoNodeError> {
493+
condition: F,
494+
) -> Result<Option<BlockStatus>, NakamotoNodeError>
495+
where
496+
F: Fn(&BlockStatus) -> bool,
497+
{
493498
let (lock, cvar) = &*self.blocks;
494499
let blocks = lock.lock().expect("FATAL: failed to lock block status");
495500

496501
let (guard, timeout_result) = cvar
497502
.wait_timeout_while(blocks, timeout, |map| {
498-
if rejections_timer.elapsed() > rejections_timeout {
499-
return true;
500-
}
501503
let Some(status) = map.get(block_signer_sighash) else {
502504
return true;
503505
};
504-
if status != block_status_tracker {
505-
*block_status_tracker = status.clone();
506-
return false;
507-
}
508-
return true;
506+
condition(status)
509507
})
510508
.expect("FATAL: failed to wait on block status cond var");
511509

0 commit comments

Comments
 (0)