Skip to content

Commit 266871a

Browse files
Extract helper + logger for failing HTLC intercepts
Makes the next commit cleaner.
1 parent 8513341 commit 266871a

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10687,6 +10687,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1068710687

1068810688
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
1068910689
let payment_hash = forward_info.payment_hash;
10690+
let logger = WithContext::from(
10691+
&self.logger,
10692+
None,
10693+
Some(prev_channel_id),
10694+
Some(payment_hash),
10695+
);
1069010696
let pending_add = PendingAddHTLCInfo {
1069110697
prev_short_channel_id,
1069210698
prev_counterparty_node_id,
@@ -10696,6 +10702,22 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1069610702
prev_user_channel_id,
1069710703
forward_info,
1069810704
};
10705+
let mut fail_intercepted_htlc = |pending_add: PendingAddHTLCInfo| {
10706+
let htlc_source =
10707+
HTLCSource::PreviousHopData(pending_add.htlc_previous_hop_data());
10708+
let reason = HTLCFailReason::from_failure_code(
10709+
LocalHTLCFailureReason::UnknownNextPeer,
10710+
);
10711+
let failure_type = HTLCHandlingFailureType::InvalidForward {
10712+
requested_forward_scid: scid,
10713+
};
10714+
failed_intercept_forwards.push((
10715+
htlc_source,
10716+
payment_hash,
10717+
reason,
10718+
failure_type,
10719+
));
10720+
};
1069910721

1070010722
if !is_our_scid
1070110723
&& 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/
1072910751
entry.insert(pending_add);
1073010752
},
1073110753
hash_map::Entry::Occupied(_) => {
10732-
let logger = WithContext::from(
10733-
&self.logger,
10734-
None,
10735-
Some(prev_channel_id),
10736-
Some(payment_hash),
10737-
);
1073810754
log_info!(
1073910755
logger,
1074010756
"Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}",
1074110757
scid
1074210758
);
10743-
let htlc_source = HTLCSource::PreviousHopData(
10744-
pending_add.htlc_previous_hop_data(),
10745-
);
10746-
let reason = HTLCFailReason::from_failure_code(
10747-
LocalHTLCFailureReason::UnknownNextPeer,
10748-
);
10749-
let failure_type = HTLCHandlingFailureType::InvalidForward {
10750-
requested_forward_scid: scid,
10751-
};
10752-
failed_intercept_forwards.push((
10753-
htlc_source,
10754-
payment_hash,
10755-
reason,
10756-
failure_type,
10757-
));
10759+
fail_intercepted_htlc(pending_add);
1075810760
},
1075910761
}
1076010762
} else {

0 commit comments

Comments
 (0)