Skip to content

Commit aeaa42d

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 6c252df commit aeaa42d

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
@@ -14726,18 +14726,48 @@ where
1472614726
}
1472714727

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

0 commit comments

Comments
 (0)