Drop excess `Transaction` `clone` in LSPS2 service
What changed, and why it matters
This commit is a minor code cleanup in the LSPS2 liquidity service. It removes an unnecessary copy (clone) of a Bitcoin transaction when retrieving and broadcasting a funding transaction. The change returns a reference to the existing transaction instead of duplicating it. There is no security issue here—only a small performance improvement and cleaner code.
No security action required. This is a routine refactoring/optimization commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch changes get_funding_tx() to return Option<&Transaction> instead of Option<Transaction>, replacing funding_tx.clone() with funding_tx.as_ref(). The caller in handle_open_channel now passes funding_tx directly to broadcast_transactions rather than &funding_tx (since it is already a reference). This eliminates an unnecessary clone of a Transaction struct. No logic, authorization, validation, or cryptographic behavior is altered.
Changed components
lightning-liquidity/src/lsps2/service.rsInspect captured patch +4 / −4
diff --git a/lightning-liquidity/src/lsps2/service.rs b/lightning-liquidity/src/lsps2/service.rs
index 4fd747a..9bb3ded 100644
--- a/lightning-liquidity/src/lsps2/service.rs
+++ b/lightning-liquidity/src/lsps2/service.rs
@@ -166,9 +166,9 @@ impl TrustModel {
}
}
- fn get_funding_tx(&self) -> Option<Transaction> {
+ fn get_funding_tx(&self) -> Option<&Transaction> {
match self {
- TrustModel::ClientTrustsLsp { funding_tx, .. } => funding_tx.clone(),
+ TrustModel::ClientTrustsLsp { funding_tx, .. } => funding_tx.as_ref(),
_ => None,
}
}
@@ -581,7 +581,7 @@ impl OutboundJITChannel {
}
}
- fn get_funding_tx(&self) -> Option<Transaction> {
+ fn get_funding_tx(&self) -> Option<&Transaction> {
self.trust_model.get_funding_tx()
}
@@ -2028,7 +2028,7 @@ where
}
if let Some(funding_tx) = jit_channel.get_funding_tx() {
- self.tx_broadcaster.broadcast_transactions(&[&funding_tx]);
+ self.tx_broadcaster.broadcast_transactions(&[funding_tx]);
}
}
}
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.