Skip to content

Commit c487147

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 5fc3e01 commit c487147

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

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

0 commit comments

Comments
 (0)