Avoid bothering to prep for broadcast if we aren't gonna broadcast
What changed, and why it matters
This is a small internal cleanup in the code that handles Lightning channel closure broadcasts. It moves an early-exit check earlier in a function so that, in a special 'manual broadcast' mode, the code skips unnecessary setup work when it already knows it will not actually broadcast anything yet. The change does not alter the final return values or the conditions under which broadcasting happens; it only avoids doing some now-pointless work. There is no direct security fix here, but it reduces the chance of future logic mistakes by making the intent clearer.
No immediate action required. Treat as a normal code-quality/refactor commit. If auditing this area, verify that the early return still correctly preserves all state set before it (notably `holder_tx_signed = true`) and that downstream callers handle the empty return consistently with the prior behavior.
Security signals we found
Behavior-preserving refactor of broadcast-deferral logic
Manual-broadcast mode early return moved earlier in function
No change to conditions that trigger broadcast or deferral
No new input validation, cryptographic, or trust-boundary changes
Evidence from the diff
In ChannelMonitorImpl::generate_claimable_outpoints_and_watch_outputs, the existing guard that returns empty vectors when require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain was moved from the end of the function to immediately after self.holder_tx_signed = true. This means the function no longer allocates watch_outputs or iterates over onchain_events_awaiting_threshold_conf when it will ultimately return empty results. The observable behavior is unchanged; the patch is purely a refactor to avoid unnecessary work and clarify control flow.
Changed components
lightning/src/chain/channelmonitor.rsChannelMonitorImpl::generate_claimable_outpoints_and_watch_outputsInspect captured patch +8 / −7
diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs
index 5182679..ebb331b 100644
--- a/lightning/src/chain/channelmonitor.rs
+++ b/lightning/src/chain/channelmonitor.rs
@@ -3961,6 +3961,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// in the claim that is queued to OnchainTxHandler. We set holder_tx_signed here to reject
// new channel updates.
self.holder_tx_signed = true;
+
+ // In manual-broadcast mode, if we have not yet observed the funding transaction on-chain,
+ // return empty vectors rather than triggering a broadcast.
+ if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
+ return (Vec::new(), Vec::new());
+ }
+
let mut watch_outputs = Vec::new();
// In CSV anchor channels, we can't broadcast our HTLC transactions while the commitment transaction is
// unconfirmed.
@@ -3986,13 +3993,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
}
claimable_outpoints.append(&mut new_outpoints);
}
- // In manual-broadcast mode, if we have not yet observed the funding transaction on-chain,
- // return empty vectors.
- if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
- return (Vec::new(), Vec::new());
- } else {
- (claimable_outpoints, watch_outputs)
- }
+ (claimable_outpoints, watch_outputs)
}
#[rustfmt::skip]
Why this scored 24/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.