Skip to content

Commit 795b4a7

Browse files
committed
Revert "fix: dont rely on node burn block to be processed"
This reverts commit c6ca6b9.
1 parent c6ca6b9 commit 795b4a7

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

stacks-signer/src/v0/signer_state.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,9 @@ impl LocalStateMachine {
580580
}
581581
};
582582

583-
let (next_burn_block_height, next_burn_block_hash) = match expected_burn_block.clone() {
584-
Some(expected_burn_block) => (
585-
expected_burn_block.burn_block_height,
586-
expected_burn_block.consensus_hash,
587-
),
588-
None => {
589-
let peer_info = client.get_peer_info()?;
590-
(peer_info.burn_block_height, peer_info.pox_consensus)
591-
}
592-
};
583+
let peer_info = client.get_peer_info()?;
584+
let next_burn_block_height = peer_info.burn_block_height;
585+
let next_burn_block_hash = peer_info.pox_consensus;
593586
let mut tx_replay_set = prior_state_machine.tx_replay_set.clone();
594587

595588
if let Some(expected_burn_block) = expected_burn_block {
@@ -1004,8 +997,41 @@ impl LocalStateMachine {
1004997
replay_state: &ReplayState,
1005998
) -> Result<Option<ReplayState>, SignerChainstateError> {
1006999
if expected_burn_block.burn_block_height > prior_state_machine.burn_block_height {
1007-
// no bitcoin fork, because we're higher than the previous tip
1008-
return Ok(None);
1000+
// prevent too large of a loop
1001+
if expected_burn_block
1002+
.burn_block_height
1003+
.saturating_sub(prior_state_machine.burn_block_height)
1004+
> 10
1005+
{
1006+
return Ok(None);
1007+
}
1008+
// are we building on top of this prior tip?
1009+
let mut parent_burn_block_info =
1010+
db.get_burn_block_by_ch(&expected_burn_block.consensus_hash)?;
1011+
1012+
while parent_burn_block_info.block_height > prior_state_machine.burn_block_height {
1013+
let Ok(parent_info) =
1014+
db.get_burn_block_by_hash(&parent_burn_block_info.parent_burn_block_hash)
1015+
else {
1016+
warn!(
1017+
"Failed to get parent burn block info for {}",
1018+
parent_burn_block_info.parent_burn_block_hash
1019+
);
1020+
return Ok(None);
1021+
};
1022+
parent_burn_block_info = parent_info;
1023+
}
1024+
if parent_burn_block_info.consensus_hash == prior_state_machine.burn_block {
1025+
// no bitcoin fork, because we're building on the parent
1026+
return Ok(None);
1027+
} else {
1028+
info!("Detected bitcoin fork - prior tip is not parent of new tip.";
1029+
"new_tip.burn_block_height" => expected_burn_block.burn_block_height,
1030+
"new_tip.consensus_hash" => %expected_burn_block.consensus_hash,
1031+
"prior_tip.burn_block_height" => prior_state_machine.burn_block_height,
1032+
"prior_tip.consensus_hash" => %prior_state_machine.burn_block,
1033+
);
1034+
}
10091035
}
10101036
if expected_burn_block.consensus_hash == prior_state_machine.burn_block {
10111037
// no bitcoin fork, because we're at the same burn block hash as before

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,6 +3982,13 @@ fn tx_replay_simple() {
39823982
let _http_origin = format!("http://{}", &conf.node.rpc_bind);
39833983
let btc_controller = &signer_test.running_nodes.btc_regtest_controller;
39843984

3985+
let miner_pk = btc_controller
3986+
.get_mining_pubkey()
3987+
.as_deref()
3988+
.map(Secp256k1PublicKey::from_hex)
3989+
.unwrap()
3990+
.unwrap();
3991+
39853992
if signer_test.bootstrap_snapshot() {
39863993
signer_test.shutdown_and_snapshot();
39873994
return;

0 commit comments

Comments
 (0)