Replace `StateMachine::default` use with `core::mem::replace`
What changed, and why it matters
This is a small code cleanup change. It removes a manually-written 'default' value for an internal state-machine type and replaces one use of a standard-library helper (core::mem::take) with a slightly more explicit one (core::mem::swap). The behavior is functionally identical: the state machine is still briefly put into a placeholder 'Indeterminate' state while a transition runs. There is no security fix here.
No security action required. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes the manual Default implementation for StateMachine, whose default() returned StateMachine::Indeterminate. The only caller, the do_state_transition! macro, previously used core::mem::take to move the current state out and leave StateMachine::default() in its place. The patch instead creates a local StateMachine::Indeterminate and core::mem::swaps it with $self.state_machine. The resulting state transitions and error paths are unchanged; the diff is purely stylistic/clippy-driven.
Changed components
lightning/src/ln/interactivetxs.rsInspect captured patch +2 / −7
diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs
index 7fc63d7..97047eb 100644
--- a/lightning/src/ln/interactivetxs.rs
+++ b/lightning/src/ln/interactivetxs.rs
@@ -1492,12 +1492,6 @@ enum StateMachine {
NegotiationAborted(NegotiationAborted),
}
-impl Default for StateMachine {
- fn default() -> Self {
- Self::Indeterminate
- }
-}
-
// The `StateMachine` internally executes the actual transition between two states and keeps
// track of the current state. This macro defines _how_ those state transitions happen to
// update the internal state.
@@ -1932,7 +1926,8 @@ impl InteractiveTxMessageSend {
// This macro executes a state machine transition based on a provided action.
macro_rules! do_state_transition {
($self: ident, $transition: ident, $msg: expr) => {{
- let state_machine = core::mem::take(&mut $self.state_machine);
+ let mut state_machine = StateMachine::Indeterminate;
+ core::mem::swap(&mut state_machine, &mut $self.state_machine);
$self.state_machine = state_machine.$transition($msg);
match &$self.state_machine {
StateMachine::NegotiationAborted(state) => Err(state.0.clone()),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.