Skip to content

Commit f8143cf

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 a20133d commit f8143cf

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
@@ -14788,18 +14788,64 @@ where
1478814788
}
1478914789

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

14796-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14797-
log_trace!(
14798-
self.logger,
14799-
"Failed to release held HTLC with payment id {}: {:?}",
14800-
payment_id,
14801-
e
14802-
);
14829+
let logger = WithContext::from(
14830+
&self.logger,
14831+
Some(htlc.prev_counterparty_node_id),
14832+
Some(htlc.prev_channel_id),
14833+
Some(htlc.forward_info.payment_hash),
14834+
);
14835+
log_trace!(logger, "Releasing held htlc with intercept_id {}", intercept_id);
14836+
14837+
let mut per_source_pending_forward = [(
14838+
htlc.prev_short_channel_id,
14839+
htlc.prev_counterparty_node_id,
14840+
htlc.prev_funding_outpoint,
14841+
htlc.prev_channel_id,
14842+
htlc.prev_user_channel_id,
14843+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14844+
)];
14845+
self.forward_htlcs(&mut per_source_pending_forward);
14846+
PersistenceNotifierGuard::notify_on_drop(self);
14847+
},
14848+
_ => return,
1480314849
}
1480414850
}
1480514851

0 commit comments

Comments
 (0)