Skip to content

Commit a420939

Browse files
committed
fix: Stacks tip check only checks parent tenure
This is needed for the case where the miner is knowingly reorging the previous tenure, which is the canonical tip, but this reorg is allowed because of the bad timing of blocks.
1 parent 07b39fb commit a420939

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ impl SignerCoordinator {
321321
)
322322
})?;
323323

324+
let parent_tenure_header =
325+
NakamotoChainState::get_block_header(chain_state.db(), &parent_block_id)?
326+
.ok_or(NakamotoNodeError::UnexpectedChainState)?;
327+
324328
// this is used to track the start of the waiting cycle
325329
let rejections_timer = Instant::now();
326330
loop {
@@ -386,12 +390,14 @@ impl SignerCoordinator {
386390
));
387391
}
388392

389-
// Check if a new Stacks block has arrived
390-
let (canonical_stacks_tip_ch, canonical_stacks_tip_bh) =
391-
SortitionDB::get_canonical_stacks_chain_tip_hash(sortdb.conn()).unwrap();
392-
let canonical_stacks_tip =
393-
StacksBlockId::new(&canonical_stacks_tip_ch, &canonical_stacks_tip_bh);
394-
if canonical_stacks_tip != parent_block_id {
393+
// Check if a new Stacks block has arrived in the parent tenure
394+
let highest_in_tenure =
395+
NakamotoChainState::get_highest_known_block_header_in_tenure(
396+
&mut chain_state.index_conn(),
397+
&parent_tenure_header.consensus_hash,
398+
)?
399+
.ok_or(NakamotoNodeError::UnexpectedChainState)?;
400+
if highest_in_tenure.index_block_hash() != parent_block_id {
395401
debug!("SignCoordinator: Exiting due to new stacks tip");
396402
return Err(NakamotoNodeError::StacksTipChanged);
397403
}

0 commit comments

Comments
 (0)