Skip to content

Commit 6e8efb6

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 ab542c7 commit 6e8efb6

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
};
@@ -5426,11 +5426,12 @@ where
54265426
);
54275427
}
54285428
} else {
5429-
let enqueue_held_htlc_available_res = self.flow.enqueue_held_htlc_available(
5430-
invoice,
5429+
let reply_path = HeldHtlcReplyPath::ToUs {
54315430
payment_id,
5432-
self.get_peers_for_blinded_path(),
5433-
);
5431+
peers: self.get_peers_for_blinded_path(),
5432+
};
5433+
let enqueue_held_htlc_available_res =
5434+
self.flow.enqueue_held_htlc_available(invoice, reply_path);
54345435
if enqueue_held_htlc_available_res.is_err() {
54355436
self.abandon_payment_with_reason(
54365437
payment_id,

lightning/src/offers/flow.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,26 @@ pub enum InvreqResponseInstructions {
415415
},
416416
}
417417

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

11461171
let mut pending_async_payments_messages =
11471172
self.pending_async_payments_messages.lock().unwrap();

0 commit comments

Comments
 (0)