@@ -580,16 +580,9 @@ impl LocalStateMachine {
580
580
}
581
581
} ;
582
582
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 ;
593
586
let mut tx_replay_set = prior_state_machine. tx_replay_set . clone ( ) ;
594
587
595
588
if let Some ( expected_burn_block) = expected_burn_block {
@@ -1004,8 +997,41 @@ impl LocalStateMachine {
1004
997
replay_state : & ReplayState ,
1005
998
) -> Result < Option < ReplayState > , SignerChainstateError > {
1006
999
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
+ }
1009
1035
}
1010
1036
if expected_burn_block. consensus_hash == prior_state_machine. burn_block {
1011
1037
// no bitcoin fork, because we're at the same burn block hash as before
0 commit comments