Skip to content

Commit 5eed8d9

Browse files
Support creating reply_path for HeldHtlcAvailable
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 add a method for creating said reply path, which will be used in the next commit.
1 parent 3fb6378 commit 5eed8d9

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode,
1919
use crate::crypto::streams::ChaChaPolyReadAdapter;
2020
use crate::io;
2121
use crate::io::Cursor;
22-
use crate::ln::channelmanager::PaymentId;
22+
use crate::ln::channelmanager::{InterceptId, PaymentId};
2323
use crate::ln::msgs::DecodeError;
2424
use crate::ln::onion_utils;
2525
use crate::offers::nonce::Nonce;
@@ -556,7 +556,7 @@ pub enum AsyncPaymentsContext {
556556
},
557557
/// Context contained within the reply [`BlindedMessagePath`] we put in outbound
558558
/// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`]
559-
/// messages.
559+
/// messages if we are an always-online sender paying an async recipient.
560560
///
561561
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
562562
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
@@ -577,6 +577,17 @@ pub enum AsyncPaymentsContext {
577577
/// able to trivially ask if we're online forever.
578578
path_absolute_expiry: core::time::Duration,
579579
},
580+
/// Context contained within the reply [`BlindedMessagePath`] put in outbound
581+
/// [`HeldHtlcAvailable`] messages, provided back to the async sender's always-online counterparty
582+
/// in corresponding [`ReleaseHeldHtlc`] messages.
583+
///
584+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
585+
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
586+
ReleaseHeldHtlc {
587+
/// An identifier for the HTLC that should be released by us as the sender's always-online
588+
/// channel counterparty to the often-offline recipient.
589+
intercept_id: InterceptId,
590+
},
580591
}
581592

582593
impl_writeable_tlv_based_enum!(MessageContext,
@@ -632,6 +643,9 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
632643
(2, invoice_slot, required),
633644
(4, path_absolute_expiry, required),
634645
},
646+
(6, ReleaseHeldHtlc) => {
647+
(0, intercept_id, required),
648+
},
635649
);
636650

637651
/// Contains a simple nonce for use in a blinded path's context.

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5467,6 +5467,18 @@ where
54675467
res
54685468
}
54695469

5470+
/// If we are holding an HTLC on behalf of an often-offline sender, this method allows us to
5471+
/// create a path for the sender to use as the reply path when they send the recipient a
5472+
/// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be
5473+
/// received to our node.
5474+
fn path_for_release_held_htlc(
5475+
&self, htlc_id: u64, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
5476+
) -> BlindedMessagePath {
5477+
let intercept_id =
5478+
InterceptId::from_htlc_id_and_chan_id(htlc_id, channel_id, counterparty_node_id);
5479+
self.flow.path_for_release_held_htlc(intercept_id, &*self.entropy_source)
5480+
}
5481+
54705482
/// Signals that no further attempts for the given payment should occur. Useful if you have a
54715483
/// pending outbound payment with retries remaining, but wish to stop retrying the payment before
54725484
/// retries are exhausted.

lightning/src/offers/flow.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::prelude::*;
3232

3333
use crate::chain::BestBlock;
3434
use crate::ln::channel_state::ChannelDetails;
35-
use crate::ln::channelmanager::{PaymentId, CLTV_FAR_FAR_AWAY};
35+
use crate::ln::channelmanager::{InterceptId, PaymentId, CLTV_FAR_FAR_AWAY};
3636
use crate::ln::inbound_payment;
3737
use crate::offers::async_receive_offer_cache::AsyncReceiveOfferCache;
3838
use crate::offers::invoice::{
@@ -52,7 +52,7 @@ use crate::onion_message::async_payments::{
5252
StaticInvoicePersisted,
5353
};
5454
use crate::onion_message::messenger::{
55-
Destination, MessageRouter, MessageSendInstructions, Responder,
55+
Destination, MessageRouter, MessageSendInstructions, Responder, PADDED_PATH_LENGTH,
5656
};
5757
use crate::onion_message::offers::OffersMessage;
5858
use crate::onion_message::packet::OnionMessageContents;
@@ -1163,6 +1163,33 @@ where
11631163
Ok(())
11641164
}
11651165

1166+
/// If we are holding an HTLC on behalf of an often-offline sender, this method allows us to
1167+
/// create a path for the sender to use as the reply path when they send the recipient a
1168+
/// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be
1169+
/// received to our node.
1170+
///
1171+
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
1172+
pub fn path_for_release_held_htlc<ES: Deref>(
1173+
&self, intercept_id: InterceptId, entropy: ES,
1174+
) -> BlindedMessagePath
1175+
where
1176+
ES::Target: EntropySource,
1177+
{
1178+
// In the future, we should support multi-hop paths here.
1179+
let context =
1180+
MessageContext::AsyncPayments(AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id });
1181+
let num_dummy_hops = PADDED_PATH_LENGTH.saturating_sub(1);
1182+
BlindedMessagePath::new_with_dummy_hops(
1183+
&[],
1184+
self.get_our_node_id(),
1185+
num_dummy_hops,
1186+
self.receive_auth_key,
1187+
context,
1188+
&*entropy,
1189+
&self.secp_ctx,
1190+
)
1191+
}
1192+
11661193
/// Enqueues the created [`DNSSECQuery`] to be sent to the counterparty.
11671194
///
11681195
/// # Peers

0 commit comments

Comments
 (0)