Extract helper + logger for failing HTLC intercepts
What changed, and why it matters
This commit is a pure code cleanup: it moves an existing block of code that fails an intercepted HTLC into a small helper function and creates a logger earlier so the next commit in the series is easier to read. No behavior changes, no security fixes, and no new logic is introduced.
No security action needed; review the follow-up commit referenced in the message ('Makes the next commit cleaner') for any actual security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff in lightning/src/ln/channelmanager.rs refactors HTLC intercept failure handling. It hoists creation of a WithContext logger and extracts a closure (fail_intercepted_htlc) that builds the HTLCSource, HTLCFailReason, and HTLCHandlingFailureType and pushes them into failed_intercept_forwards. The existing Occupied hash-map branch is then replaced by a log line plus a call to that closure. The logic, failure codes, and data flow are identical before and after; only code structure changed.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +23 / −21
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 8013168..396cc78 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -10687,6 +10687,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
let payment_hash = forward_info.payment_hash;
+ let logger = WithContext::from(
+ &self.logger,
+ None,
+ Some(prev_channel_id),
+ Some(payment_hash),
+ );
let pending_add = PendingAddHTLCInfo {
prev_short_channel_id,
prev_counterparty_node_id,
@@ -10696,6 +10702,22 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
prev_user_channel_id,
forward_info,
};
+ let mut fail_intercepted_htlc = |pending_add: PendingAddHTLCInfo| {
+ let htlc_source =
+ HTLCSource::PreviousHopData(pending_add.htlc_previous_hop_data());
+ let reason = HTLCFailReason::from_failure_code(
+ LocalHTLCFailureReason::UnknownNextPeer,
+ );
+ let failure_type = HTLCHandlingFailureType::InvalidForward {
+ requested_forward_scid: scid,
+ };
+ failed_intercept_forwards.push((
+ htlc_source,
+ payment_hash,
+ reason,
+ failure_type,
+ ));
+ };
if !is_our_scid
&& pending_add.forward_info.incoming_amt_msat.is_some()
@@ -10729,32 +10751,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
entry.insert(pending_add);
},
hash_map::Entry::Occupied(_) => {
- let logger = WithContext::from(
- &self.logger,
- None,
- Some(prev_channel_id),
- Some(payment_hash),
- );
log_info!(
logger,
"Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}",
scid
);
- let htlc_source = HTLCSource::PreviousHopData(
- pending_add.htlc_previous_hop_data(),
- );
- let reason = HTLCFailReason::from_failure_code(
- LocalHTLCFailureReason::UnknownNextPeer,
- );
- let failure_type = HTLCHandlingFailureType::InvalidForward {
- requested_forward_scid: scid,
- };
- failed_intercept_forwards.push((
- htlc_source,
- payment_hash,
- reason,
- failure_type,
- ));
+ fail_intercepted_htlc(pending_add);
},
}
} else {
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.