Skip to content

Commit f569398

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 6f4b099 commit f569398

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14781,18 +14781,64 @@ where
1478114781
}
1478214782

1478314783
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14784-
let payment_id = match context {
14785-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14786-
_ => return,
14787-
};
14784+
match context {
14785+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14786+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14787+
log_trace!(
14788+
self.logger,
14789+
"Failed to release held HTLC with payment id {}: {:?}",
14790+
payment_id,
14791+
e
14792+
);
14793+
}
14794+
},
14795+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14796+
let mut htlc = {
14797+
let mut pending_intercept_htlcs =
14798+
self.pending_intercepted_htlcs.lock().unwrap();
14799+
match pending_intercept_htlcs.remove(&intercept_id) {
14800+
Some(htlc) => htlc,
14801+
None => {
14802+
log_trace!(
14803+
self.logger,
14804+
"Failed to release HTLC with intercept_id {}: HTLC not found",
14805+
intercept_id
14806+
);
14807+
return;
14808+
},
14809+
}
14810+
};
14811+
match htlc.forward_info.routing {
14812+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14813+
debug_assert!(hold_htlc.is_some());
14814+
*hold_htlc = None;
14815+
},
14816+
_ => {
14817+
debug_assert!(false, "HTLC intercepts can only be forwards");
14818+
return;
14819+
},
14820+
}
1478814821

14789-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14790-
log_trace!(
14791-
self.logger,
14792-
"Failed to release held HTLC with payment id {}: {:?}",
14793-
payment_id,
14794-
e
14795-
);
14822+
let logger = WithContext::from(
14823+
&self.logger,
14824+
Some(htlc.prev_counterparty_node_id),
14825+
Some(htlc.prev_channel_id),
14826+
Some(htlc.forward_info.payment_hash),
14827+
);
14828+
log_trace!(logger, "Releasing held htlc with intercept_id {}", intercept_id);
14829+
14830+
let mut per_source_pending_forward = [(
14831+
htlc.prev_short_channel_id,
14832+
htlc.prev_counterparty_node_id,
14833+
htlc.prev_funding_outpoint,
14834+
htlc.prev_channel_id,
14835+
htlc.prev_user_channel_id,
14836+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14837+
)];
14838+
self.forward_htlcs(&mut per_source_pending_forward);
14839+
PersistenceNotifierGuard::notify_on_drop(self);
14840+
},
14841+
_ => return,
1479614842
}
1479714843
}
1479814844

0 commit comments

Comments
 (0)