Skip to content

Commit 686894a

Browse files
committed
crc: remove ReplayState::Invalid variant, #5971
1 parent 4874e7f commit 686894a

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

stacks-signer/src/v0/signer_state.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,31 @@ pub enum ReplayState {
106106
Unset,
107107
/// A replay is currently in progress, with an associated transaction set and scope.
108108
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,
112109
}
113110

114111
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.
116119
///
117120
/// # Returns
118121
///
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> {
123127
if replay_set.is_empty() {
124-
return Self::Unset;
128+
return Some(Self::Unset);
125129
}
126130

127131
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,
130134
}
131135
}
132136
}
@@ -602,7 +606,16 @@ impl LocalStateMachine {
602606
return Err(ClientError::InvalidResponse(err_msg).into());
603607
}
604608

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+
606619
if let Some(new_replay_state) = self.handle_possible_bitcoin_fork(
607620
db,
608621
client,
@@ -619,10 +632,6 @@ impl LocalStateMachine {
619632
tx_replay_set = new_txs_set;
620633
*tx_replay_scope = Some(new_scope);
621634
}
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-
}
626635
}
627636
}
628637
}
@@ -998,7 +1007,6 @@ impl LocalStateMachine {
9981007
prior_state_machine,
9991008
scope,
10001009
),
1001-
ReplayState::Invalid => Ok(Some(ReplayState::Invalid)),
10021010
}
10031011
}
10041012

0 commit comments

Comments
 (0)