Skip to content

Commit b079c36

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 529d00c commit b079c36

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
@@ -14718,18 +14718,48 @@ where
1471814718
}
1471914719

1472014720
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14721-
let payment_id = match context {
14722-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14721+
match context {
14722+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14723+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14724+
log_trace!(
14725+
self.logger,
14726+
"Failed to release held HTLC with payment id {}: {:?}",
14727+
payment_id,
14728+
e
14729+
);
14730+
}
14731+
},
14732+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14733+
let mut htlc = {
14734+
let mut pending_intercept_htlcs =
14735+
self.pending_intercepted_htlcs.lock().unwrap();
14736+
match pending_intercept_htlcs.remove(&intercept_id) {
14737+
Some(htlc) => htlc,
14738+
None => return,
14739+
}
14740+
};
14741+
match htlc.forward_info.routing {
14742+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14743+
debug_assert!(hold_htlc.is_some());
14744+
*hold_htlc = None;
14745+
},
14746+
_ => {
14747+
debug_assert!(false, "HTLC intercepts can only be forwards");
14748+
return;
14749+
},
14750+
}
14751+
let mut per_source_pending_forward = [(
14752+
htlc.prev_short_channel_id,
14753+
htlc.prev_counterparty_node_id,
14754+
htlc.prev_funding_outpoint,
14755+
htlc.prev_channel_id,
14756+
htlc.prev_user_channel_id,
14757+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14758+
)];
14759+
self.forward_htlcs(&mut per_source_pending_forward);
14760+
PersistenceNotifierGuard::notify_on_drop(self);
14761+
},
1472314762
_ => return,
14724-
};
14725-
14726-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14727-
log_trace!(
14728-
self.logger,
14729-
"Failed to release held HTLC with payment id {}: {:?}",
14730-
payment_id,
14731-
e
14732-
);
1473314763
}
1473414764
}
1473514765

0 commit comments

Comments
 (0)