@@ -106,27 +106,31 @@ pub enum ReplayState {
106
106
Unset ,
107
107
/// A replay is currently in progress, with an associated transaction set and scope.
108
108
InProgress ( ReplayTransactionSet , ReplayScope ) ,
109
- /// An invalid state where a replay set was provided without a valid scope.
110
- /// Possibly caused by the scope being a local state in the `Signer` struct.
111
- Invalid ,
112
109
}
113
110
114
111
impl ReplayState {
115
- /// Constructs a `ReplayState` from a given replay transaction set and an optional scope.
112
+ /// Infers the appropriate `ReplayState` based on the contents of the replay transaction set
113
+ /// and the optional scope.
114
+ ///
115
+ /// # Arguments
116
+ ///
117
+ /// * `replay_set` - A reference to a set of transactions intended for replay.
118
+ /// * `scope_opt` - An optional scope defining the boundaries or context for the replay.
116
119
///
117
120
/// # Returns
118
121
///
119
- /// - `Unset` if the replay set is empty.
120
- /// - `Invalid` if the replay set exists but the scope is missing.
121
- /// - `InProgress` if both a non-empty replay set and a valid scope are provided.
122
- fn infer_state ( replay_set : & ReplayTransactionSet , scope_opt : & ReplayScopeOpt ) -> Self {
122
+ /// * `Some(ReplayState::Unset)` if the `replay_set` is empty.
123
+ /// * `Some(ReplayState::InProgress)` if the `replay_set` is non-empty and a `scope` is provided.
124
+ /// * `None` if the `replay_set` is non-empty but no `scope` is provided.
125
+ /// - Possibly caused by the scope being a local state in the `Signer` struct, which is not persisted.
126
+ fn infer_state ( replay_set : & ReplayTransactionSet , scope_opt : & ReplayScopeOpt ) -> Option < Self > {
123
127
if replay_set. is_empty ( ) {
124
- return Self :: Unset ;
128
+ return Some ( Self :: Unset ) ;
125
129
}
126
130
127
131
match scope_opt {
128
- None => Self :: Invalid ,
129
- Some ( scope ) => Self :: InProgress ( replay_set . clone ( ) , scope . clone ( ) ) ,
132
+ Some ( scope ) => Some ( Self :: InProgress ( replay_set . clone ( ) , scope . clone ( ) ) ) ,
133
+ None => None ,
130
134
}
131
135
}
132
136
}
@@ -602,7 +606,16 @@ impl LocalStateMachine {
602
606
return Err ( ClientError :: InvalidResponse ( err_msg) . into ( ) ) ;
603
607
}
604
608
605
- let replay_state = ReplayState :: infer_state ( & tx_replay_set, tx_replay_scope) ;
609
+ let replay_state = match ReplayState :: infer_state ( & tx_replay_set, tx_replay_scope) {
610
+ Some ( valid_state) => valid_state,
611
+ None => {
612
+ warn ! (
613
+ "Tx Replay: Invalid state due to scope being not set while in replay mode!"
614
+ ) ;
615
+ return Err ( SignerChainstateError :: LocalStateMachineNotReady ) ;
616
+ }
617
+ } ;
618
+
606
619
if let Some ( new_replay_state) = self . handle_possible_bitcoin_fork (
607
620
db,
608
621
client,
@@ -619,10 +632,6 @@ impl LocalStateMachine {
619
632
tx_replay_set = new_txs_set;
620
633
* tx_replay_scope = Some ( new_scope) ;
621
634
}
622
- ReplayState :: Invalid => {
623
- warn ! ( "Tx Replay: Invalid state due to scope being not set while in replay mode!" ) ;
624
- return Err ( SignerChainstateError :: LocalStateMachineNotReady ) ;
625
- }
626
635
}
627
636
}
628
637
}
@@ -998,7 +1007,6 @@ impl LocalStateMachine {
998
1007
prior_state_machine,
999
1008
scope,
1000
1009
) ,
1001
- ReplayState :: Invalid => Ok ( Some ( ReplayState :: Invalid ) ) ,
1002
1010
}
1003
1011
}
1004
1012
0 commit comments