@@ -558,7 +558,7 @@ impl LocalStateMachine {
558
558
} ;
559
559
return Err ( ClientError :: InvalidResponse ( err_msg) . into ( ) ) ;
560
560
}
561
- if let Some ( new_replay_set) = self . handle_possible_bitcoin_fork (
561
+ if let Some ( ( new_replay_set, new_replay_scope ) ) = self . handle_possible_bitcoin_fork (
562
562
db,
563
563
client,
564
564
& expected_burn_block,
@@ -567,6 +567,7 @@ impl LocalStateMachine {
567
567
tx_replay_scope,
568
568
) ? {
569
569
tx_replay_set = ReplayTransactionSet :: new ( new_replay_set) ;
570
+ * tx_replay_scope = new_replay_scope;
570
571
}
571
572
}
572
573
@@ -912,8 +913,11 @@ impl LocalStateMachine {
912
913
expected_burn_block : & NewBurnBlock ,
913
914
prior_state_machine : & SignerStateMachine ,
914
915
is_in_tx_replay_mode : bool ,
915
- tx_replay_scope : & mut Option < ( NewBurnBlock , NewBurnBlock ) > ,
916
- ) -> Result < Option < Vec < StacksTransaction > > , SignerChainstateError > {
916
+ tx_replay_scope : & Option < ( NewBurnBlock , NewBurnBlock ) > ,
917
+ ) -> Result <
918
+ Option < ( Vec < StacksTransaction > , Option < ( NewBurnBlock , NewBurnBlock ) > ) > ,
919
+ SignerChainstateError ,
920
+ > {
917
921
if expected_burn_block. burn_block_height > prior_state_machine. burn_block_height {
918
922
// no bitcoin fork, because we're advancing the burn block height
919
923
return Ok ( None ) ;
@@ -930,11 +934,14 @@ impl LocalStateMachine {
930
934
"prior_state_machine.burn_block" => %prior_state_machine. burn_block,
931
935
) ;
932
936
933
- //TODO: Remove unwrap once decided the final tx_replay_scope structure format
934
- // and if to handle them as part of State machine update
935
- let curr_scope = tx_replay_scope. clone ( ) . unwrap ( ) ;
937
+ let ( fork_origin, past_tip) = match tx_replay_scope {
938
+ Some ( scope) => scope,
939
+ None => {
940
+ warn ! ( "Tx Replay: BUG! Scope cannot be None while in replay mode!" ) ;
941
+ return Err ( SignerChainstateError :: LocalStateMachineNotReady ) ;
942
+ }
943
+ } ;
936
944
937
- let ( fork_origin, past_tip) = & curr_scope;
938
945
let is_deepest_fork =
939
946
expected_burn_block. burn_block_height < fork_origin. burn_block_height ;
940
947
if !is_deepest_fork {
@@ -944,22 +951,23 @@ impl LocalStateMachine {
944
951
}
945
952
946
953
let updated_replay_set;
954
+ let updated_scope_opt;
947
955
if let Some ( replay_set) =
948
956
self . compute_forked_txs_set ( db, client, expected_burn_block, & past_tip) ?
949
957
{
950
- let updated_scope = ( expected_burn_block. clone ( ) , past_tip. clone ( ) ) ;
958
+ let scope = ( expected_burn_block. clone ( ) , past_tip. clone ( ) ) ;
951
959
952
960
info ! ( "Tx Replay: replay set updated with {} tx(s)" , replay_set. len( ) ;
953
961
"tx_replay_set" => ?replay_set,
954
- "tx_replay_scope" => ?updated_scope ) ;
962
+ "tx_replay_scope" => ?scope ) ;
955
963
updated_replay_set = replay_set;
956
- * tx_replay_scope = Some ( updated_scope ) ;
964
+ updated_scope_opt = Some ( scope ) ;
957
965
} else {
958
966
info ! ( "Tx Replay: replay set will be cleared, because the fork involves the previous reward cycle." ) ;
959
967
updated_replay_set = vec ! [ ] ;
960
- * tx_replay_scope = None ;
968
+ updated_scope_opt = None ;
961
969
}
962
- return Ok ( Some ( updated_replay_set) ) ;
970
+ return Ok ( Some ( ( updated_replay_set, updated_scope_opt ) ) ) ;
963
971
}
964
972
965
973
info ! ( "Signer State: fork detected" ;
@@ -1040,17 +1048,18 @@ impl LocalStateMachine {
1040
1048
) )
1041
1049
. cloned ( )
1042
1050
. collect :: < Vec < _ > > ( ) ;
1051
+ let scope_opt;
1043
1052
if forked_txs. len ( ) > 0 {
1044
- let updated_scope = ( expected_burn_block. clone ( ) , potential_replay_tip) ;
1053
+ let scope = ( expected_burn_block. clone ( ) , potential_replay_tip) ;
1045
1054
info ! ( "Tx Replay: replay set updated with {} tx(s)" , forked_txs. len( ) ;
1046
1055
"tx_replay_set" => ?forked_txs,
1047
- "tx_replay_scope" => ?updated_scope ) ;
1048
- * tx_replay_scope = Some ( updated_scope ) ;
1056
+ "tx_replay_scope" => ?scope ) ;
1057
+ scope_opt = Some ( scope ) ;
1049
1058
} else {
1050
1059
info ! ( "Tx Replay: no transactions to be replayed." ) ;
1051
- * tx_replay_scope = None ;
1060
+ scope_opt = None ;
1052
1061
}
1053
- Ok ( Some ( forked_txs) )
1062
+ Ok ( Some ( ( forked_txs, scope_opt ) ) )
1054
1063
}
1055
1064
1056
1065
///TODO: This method can be used to remove dublication in 'handle_possible_bitcoin_fork'
0 commit comments