Skip to content

Commit c0a89bb

Browse files
Release held htlcs on release_held_htlc
As part of supporting sending payments as an often-offline sender, the sender's always-online channel counterparty needs to hold onto the sender's HTLC until they receive a release_held_htlc onion message from the often-offline recipient. Here we implement forwarding these held HTLCs upon receipt of the release message from the recipient.
1 parent 73a87c8 commit c0a89bb

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14706,18 +14706,48 @@ where
1470614706
}
1470714707

1470814708
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14709-
let payment_id = match context {
14710-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14709+
match context {
14710+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14711+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14712+
log_trace!(
14713+
self.logger,
14714+
"Failed to release held HTLC with payment id {}: {:?}",
14715+
payment_id,
14716+
e
14717+
);
14718+
}
14719+
},
14720+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14721+
let mut htlc = {
14722+
let mut pending_intercept_htlcs =
14723+
self.pending_intercepted_htlcs.lock().unwrap();
14724+
match pending_intercept_htlcs.remove(&intercept_id) {
14725+
Some(htlc) => htlc,
14726+
None => return,
14727+
}
14728+
};
14729+
match htlc.forward_info.routing {
14730+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14731+
debug_assert!(hold_htlc.is_some());
14732+
*hold_htlc = None;
14733+
},
14734+
_ => {
14735+
debug_assert!(false, "HTLC intercepts can only be forwards");
14736+
return;
14737+
},
14738+
}
14739+
let mut per_source_pending_forward = [(
14740+
htlc.prev_short_channel_id,
14741+
htlc.prev_counterparty_node_id,
14742+
htlc.prev_funding_outpoint,
14743+
htlc.prev_channel_id,
14744+
htlc.prev_user_channel_id,
14745+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14746+
)];
14747+
self.forward_htlcs(&mut per_source_pending_forward);
14748+
PersistenceNotifierGuard::notify_on_drop(self);
14749+
},
1471114750
_ => return,
14712-
};
14713-
14714-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14715-
log_trace!(
14716-
self.logger,
14717-
"Failed to release held HTLC with payment id {}: {:?}",
14718-
payment_id,
14719-
e
14720-
);
1472114751
}
1472214752
}
1472314753

0 commit comments

Comments
 (0)