Skip to content

Commit 0a858a9

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 6f1184f commit 0a858a9

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
@@ -14687,18 +14687,48 @@ where
1468714687
}
1468814688

1468914689
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14690-
let payment_id = match context {
14691-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14690+
match context {
14691+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14692+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14693+
log_trace!(
14694+
self.logger,
14695+
"Failed to release held HTLC with payment id {}: {:?}",
14696+
payment_id,
14697+
e
14698+
);
14699+
}
14700+
},
14701+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14702+
let mut htlc = {
14703+
let mut pending_intercept_htlcs =
14704+
self.pending_intercepted_htlcs.lock().unwrap();
14705+
match pending_intercept_htlcs.remove(&intercept_id) {
14706+
Some(htlc) => htlc,
14707+
None => return,
14708+
}
14709+
};
14710+
match htlc.forward_info.routing {
14711+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14712+
debug_assert!(hold_htlc.is_some());
14713+
*hold_htlc = None;
14714+
},
14715+
_ => {
14716+
debug_assert!(false, "HTLC intercepts can only be forwards");
14717+
return;
14718+
},
14719+
}
14720+
let mut per_source_pending_forward = [(
14721+
htlc.prev_short_channel_id,
14722+
htlc.prev_counterparty_node_id,
14723+
htlc.prev_funding_outpoint,
14724+
htlc.prev_channel_id,
14725+
htlc.prev_user_channel_id,
14726+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14727+
)];
14728+
self.forward_htlcs(&mut per_source_pending_forward);
14729+
PersistenceNotifierGuard::notify_on_drop(self);
14730+
},
1469214731
_ => return,
14693-
};
14694-
14695-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14696-
log_trace!(
14697-
self.logger,
14698-
"Failed to release held HTLC with payment id {}: {:?}",
14699-
payment_id,
14700-
e
14701-
);
1470214732
}
1470314733
}
1470414734

0 commit comments

Comments
 (0)