Skip to content

Commit 2fe36ef

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 1853841 commit 2fe36ef

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
};
@@ -5460,11 +5460,12 @@ where
54605460
);
54615461
}
54625462
} else {
5463-
let enqueue_held_htlc_available_res = self.flow.enqueue_held_htlc_available(
5464-
invoice,
5463+
let reply_path = HeldHtlcReplyPath::ToUs {
54655464
payment_id,
5466-
self.get_peers_for_blinded_path(),
5467-
);
5465+
peers: self.get_peers_for_blinded_path(),
5466+
};
5467+
let enqueue_held_htlc_available_res =
5468+
self.flow.enqueue_held_htlc_available(invoice, reply_path);
54685469
if enqueue_held_htlc_available_res.is_err() {
54695470
self.abandon_payment_with_reason(
54705471
payment_id,

lightning/src/offers/flow.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,26 @@ pub enum InvreqResponseInstructions {
422422
},
423423
}
424424

425+
/// Parameters for the reply path to a [`HeldHtlcAvailable`] onion message.
426+
pub enum HeldHtlcReplyPath {
427+
/// The reply path to the [`HeldHtlcAvailable`] message should terminate at our node.
428+
ToUs {
429+
/// The id of the payment.
430+
payment_id: PaymentId,
431+
/// The peers to use when creating this reply path.
432+
peers: Vec<MessageForwardNode>,
433+
},
434+
/// The reply path to the [`HeldHtlcAvailable`] message should terminate at our next-hop channel
435+
/// counterparty, as they are holding our HTLC until they receive the corresponding
436+
/// [`ReleaseHeldHtlc`] message.
437+
///
438+
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
439+
ToCounterparty {
440+
/// The blinded path provided to us by our counterparty.
441+
path: BlindedMessagePath,
442+
},
443+
}
444+
425445
impl<MR: Deref, L: Deref> OffersMessageFlow<MR, L>
426446
where
427447
MR::Target: MessageRouter,
@@ -1143,14 +1163,19 @@ where
11431163
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
11441164
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
11451165
pub fn enqueue_held_htlc_available(
1146-
&self, invoice: &StaticInvoice, payment_id: PaymentId, peers: Vec<MessageForwardNode>,
1166+
&self, invoice: &StaticInvoice, reply_path_params: HeldHtlcReplyPath,
11471167
) -> Result<(), Bolt12SemanticError> {
1148-
let context =
1149-
MessageContext::AsyncPayments(AsyncPaymentsContext::OutboundPayment { payment_id });
1150-
1151-
let reply_paths = self
1152-
.create_blinded_paths(peers, context)
1153-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1168+
let reply_paths = match reply_path_params {
1169+
HeldHtlcReplyPath::ToUs { payment_id, peers } => {
1170+
let context =
1171+
MessageContext::AsyncPayments(AsyncPaymentsContext::OutboundPayment {
1172+
payment_id,
1173+
});
1174+
self.create_blinded_paths(peers, context)
1175+
.map_err(|_| Bolt12SemanticError::MissingPaths)?
1176+
},
1177+
HeldHtlcReplyPath::ToCounterparty { path } => vec![path],
1178+
};
11541179

11551180
let mut pending_async_payments_messages =
11561181
self.pending_async_payments_messages.lock().unwrap();

0 commit comments

Comments
 (0)