Skip to content

Commit e16e4e3

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 84054e8 commit e16e4e3

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
@@ -14806,18 +14806,64 @@ where
1480614806
}
1480714807

1480814808
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, context: AsyncPaymentsContext) {
14809-
let payment_id = match context {
14810-
AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
14811-
_ => return,
14812-
};
14809+
match context {
14810+
AsyncPaymentsContext::OutboundPayment { payment_id } => {
14811+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14812+
log_trace!(
14813+
self.logger,
14814+
"Failed to release held HTLC with payment id {}: {:?}",
14815+
payment_id,
14816+
e
14817+
);
14818+
}
14819+
},
14820+
AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
14821+
let mut htlc = {
14822+
let mut pending_intercept_htlcs =
14823+
self.pending_intercepted_htlcs.lock().unwrap();
14824+
match pending_intercept_htlcs.remove(&intercept_id) {
14825+
Some(htlc) => htlc,
14826+
None => {
14827+
log_trace!(
14828+
self.logger,
14829+
"Failed to release HTLC with intercept_id {}: HTLC not found",
14830+
intercept_id
14831+
);
14832+
return;
14833+
},
14834+
}
14835+
};
14836+
match htlc.forward_info.routing {
14837+
PendingHTLCRouting::Forward { ref mut hold_htlc, .. } => {
14838+
debug_assert!(hold_htlc.is_some());
14839+
*hold_htlc = None;
14840+
},
14841+
_ => {
14842+
debug_assert!(false, "HTLC intercepts can only be forwards");
14843+
return;
14844+
},
14845+
}
1481314846

14814-
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
14815-
log_trace!(
14816-
self.logger,
14817-
"Failed to release held HTLC with payment id {}: {:?}",
14818-
payment_id,
14819-
e
14820-
);
14847+
let logger = WithContext::from(
14848+
&self.logger,
14849+
Some(htlc.prev_counterparty_node_id),
14850+
Some(htlc.prev_channel_id),
14851+
Some(htlc.forward_info.payment_hash),
14852+
);
14853+
log_trace!(logger, "Releasing held htlc with intercept_id {}", intercept_id);
14854+
14855+
let mut per_source_pending_forward = [(
14856+
htlc.prev_short_channel_id,
14857+
htlc.prev_counterparty_node_id,
14858+
htlc.prev_funding_outpoint,
14859+
htlc.prev_channel_id,
14860+
htlc.prev_user_channel_id,
14861+
vec![(htlc.forward_info, htlc.prev_htlc_id)],
14862+
)];
14863+
self.forward_htlcs(&mut per_source_pending_forward);
14864+
PersistenceNotifierGuard::notify_on_drop(self);
14865+
},
14866+
_ => return,
1482114867
}
1482214868
}
1482314869

0 commit comments

Comments
 (0)