Skip to content

Commit a673576

Browse files
committed
fix: wait for block to be processed, not to be tip
It is not certain that the last block we mined will become the canonical tip, so it is better to just wait for it to be processed.
1 parent 799f347 commit a673576

File tree

1 file changed

+10
-12
lines changed
  • testnet/stacks-node/src/nakamoto_node

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -669,20 +669,18 @@ impl BlockMinerThread {
669669
return Ok(());
670670
};
671671

672-
// Wait for the last block to be processed before proceeding
673672
if let Some(last_block_mined) = &self.last_block_mined {
673+
// Wait until the last block mined has been processed
674674
loop {
675-
let (stacks_tip_ch, stacks_tip_bh) =
676-
SortitionDB::get_canonical_stacks_chain_tip_hash(sortdb.conn()).map_err(
677-
|e| {
678-
error!("Failed to load canonical Stacks tip: {e:?}");
679-
NakamotoNodeError::ParentNotFound
680-
},
681-
)?;
682-
683-
if last_block_mined.header.consensus_hash == stacks_tip_ch
684-
&& last_block_mined.header.block_hash() == stacks_tip_bh
685-
{
675+
let (_, processed, _, _) = chain_state
676+
.nakamoto_blocks_db()
677+
.get_block_processed_and_signed_weight(
678+
&last_block_mined.header.consensus_hash,
679+
&last_block_mined.header.block_hash(),
680+
)?
681+
.ok_or_else(|| NakamotoNodeError::UnexpectedChainState)?;
682+
683+
if processed {
686684
break;
687685
}
688686

0 commit comments

Comments
 (0)