Skip to content

Commit 5ea8724

Browse files
Support held_htlc_available counterparty reply path
As part of supporting sending payments as an often-offline sender, the sender needs to send held_htlc_available onion messages such that the reply path to the message terminates at their always-online channel counterparty that is holding the HTLC. That way when the recipient responds with release_held_htlc, the sender's counterparty will receive that message. Here we lay some groundwork for using a counterparty-created reply path when sending held_htlc_available as an async sender in the next commit.
1 parent 0bebd49 commit 5ea8724

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use crate::ln::outbound_payment::{
9292
};
9393
use crate::ln::types::ChannelId;
9494
use crate::offers::async_receive_offer_cache::AsyncReceiveOfferCache;
95-
use crate::offers::flow::{InvreqResponseInstructions, OffersMessageFlow};
95+
use crate::offers::flow::{HeldHtlcReplyPath, InvreqResponseInstructions, OffersMessageFlow};
9696
use crate::offers::invoice::{
9797
Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, DEFAULT_RELATIVE_EXPIRY,
9898
};
@@ -5436,11 +5436,12 @@ where
54365436
);
54375437
}
54385438
} else {
5439-
let enqueue_held_htlc_available_res = self.flow.enqueue_held_htlc_available(
5440-
invoice,
5439+
let reply_path = HeldHtlcReplyPath::ToUs {
54415440
payment_id,
5442-
self.get_peers_for_blinded_path(),
5443-
);
5441+
peers: self.get_peers_for_blinded_path(),
5442+
};
5443+
let enqueue_held_htlc_available_res =
5444+
self.flow.enqueue_held_htlc_available(invoice, reply_path);
54445445
if enqueue_held_htlc_available_res.is_err() {
54455446
self.abandon_payment_with_reason(
54465447
payment_id,

lightning/src/offers/flow.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,26 @@ pub enum InvreqResponseInstructions {
412412
},
413413
}
414414

415+
/// Parameters for the reply path to a [`HeldHtlcAvailable`] onion message.
416+
pub enum HeldHtlcReplyPath {
417+
/// The reply path to the [`HeldHtlcAvailable`] message should terminate at our node.
418+
ToUs {
419+
/// The id of the payment.
420+
payment_id: PaymentId,
421+
/// The peers to use when creating this reply path.
422+
peers: Vec<MessageForwardNode>,
423+
},
424+
/// The reply path to the [`HeldHtlcAvailable`] message should terminate at our next-hop channel
425+
/// counterparty, as they are holding our HTLC until they receive the corresponding
426+
/// [`ReleaseHeldHtlc`] message.
427+
///
428+
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
429+
ToCounterparty {
430+
/// The blinded path provided to us by our counterparty.
431+
path: BlindedMessagePath,
432+
},
433+
}
434+
415435
impl<MR: Deref> OffersMessageFlow<MR>
416436
where
417437
MR::Target: MessageRouter,
@@ -1131,14 +1151,19 @@ where
11311151
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
11321152
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
11331153
pub fn enqueue_held_htlc_available(
1134-
&self, invoice: &StaticInvoice, payment_id: PaymentId, peers: Vec<MessageForwardNode>,
1154+
&self, invoice: &StaticInvoice, reply_path_params: HeldHtlcReplyPath,
11351155
) -> Result<(), Bolt12SemanticError> {
1136-
let context =
1137-
MessageContext::AsyncPayments(AsyncPaymentsContext::OutboundPayment { payment_id });
1138-
1139-
let reply_paths = self
1140-
.create_blinded_paths(peers, context)
1141-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1156+
let reply_paths = match reply_path_params {
1157+
HeldHtlcReplyPath::ToUs { payment_id, peers } => {
1158+
let context =
1159+
MessageContext::AsyncPayments(AsyncPaymentsContext::OutboundPayment {
1160+
payment_id,
1161+
});
1162+
self.create_blinded_paths(peers, context)
1163+
.map_err(|_| Bolt12SemanticError::MissingPaths)?
1164+
},
1165+
HeldHtlcReplyPath::ToCounterparty { path } => vec![path],
1166+
};
11421167

11431168
let mut pending_async_payments_messages =
11441169
self.pending_async_payments_messages.lock().unwrap();

0 commit comments

Comments
 (0)