Skip to content

Commit f97e0e0

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 dcbb83f commit f97e0e0

1 file changed

Lines changed: 41 additions & 11 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14736,18 +14736,48 @@ where
1473614736
}
1473714737

1473814738
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14739-
let payment_id = match context {
14740-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14739+
match context {
14740+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14741+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14742+
log_trace!(
14743+
self.logger,
14744+
"Failed to release held HTLC with payment id {}: {:?}",
14745+
payment_id,
14746+
e
14747+
);
14748+
}
14749+
},
14750+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14751+
let mut htlc = {
14752+
let mut pending_intercept_htlcs =
14753+
self.pending_intercepted_htlcs.lock().unwrap();
14754+
match pending_intercept_htlcs.remove(&intercept_id) {
14755+
Some(htlc) => htlc,
14756+
None => return,
14757+
}
14758+
};
14759+
match htlc.forward_info.routing {
14760+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14761+
debug_assert!(hold_htlc.is_some());
14762+
*hold_htlc = None;
14763+
},
14764+
_ => {
14765+
debug_assert!(false, "HTLC intercepts can only be forwards");
14766+
return;
14767+
},
14768+
}
14769+
let mut per_source_pending_forward = [(
14770+
htlc.prev_short_channel_id,
14771+
htlc.prev_counterparty_node_id,
14772+
htlc.prev_funding_outpoint,
14773+
htlc.prev_channel_id,
14774+
htlc.prev_user_channel_id,
14775+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14776+
)];
14777+
self.forward_htlcs(&mut per_source_pending_forward);
14778+
PersistenceNotifierGuard::notify_on_drop(self);
14779+
},
1474114780
_ => return,
14742-
};
14743-
14744-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14745-
log_trace!(
14746-
self.logger,
14747-
"Failed to release held HTLC with payment id {}: {:?}",
14748-
payment_id,
14749-
e
14750-
);
1475114781
}
1475214782
}
1475314783

0 commit comments

Comments
 (0)