Skip to content

Commit 56d4647

Browse files
committed
Add TrampolineForward variant to PendingHTLCRouting
Forwarding Trampoline packets requires storing their shared secrets on top of the outer onion's shared secrets, as well as referencing the next hop by its node ID as opposed to by an SCID. We modify PendingHTLCRouting to adequately represent this information.
1 parent 4d9deff commit 56d4647

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use crate::ln::channel_state::ChannelDetails;
5555
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5656
#[cfg(any(feature = "_test_utils", test))]
5757
use crate::types::features::Bolt11InvoiceFeatures;
58+
use crate::routing::gossip::NodeId;
5859
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
5960
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
6061
use crate::ln::msgs;
@@ -169,6 +170,23 @@ pub enum PendingHTLCRouting {
169170
/// The absolute CLTV of the inbound HTLC
170171
incoming_cltv_expiry: Option<u32>,
171172
},
173+
/// An HTLC which should be forwarded on to another Trampoline node.
174+
TrampolineForward {
175+
/// The onion shared secret we build with the sender (or the preceding Trampoline node) used
176+
/// to decrypt the onion.
177+
///
178+
/// This is later used to encrypt failure packets in the event that the HTLC is failed.
179+
incoming_shared_secret: [u8; 32],
180+
/// The onion which should be included in the forwarded HTLC, telling the next hop what to
181+
/// do with the HTLC.
182+
onion_packet: msgs::TrampolineOnionPacket,
183+
/// The node ID of the Trampoline node which we need to route this HTLC to.
184+
node_id: NodeId,
185+
/// Set if this HTLC is being forwarded within a blinded path.
186+
blinded: Option<BlindedForward>,
187+
/// The absolute CLTV of the inbound HTLC
188+
incoming_cltv_expiry: u32,
189+
},
172190
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
173191
///
174192
/// Note that at this point, we have not checked that the invoice being paid was actually
@@ -270,6 +288,7 @@ impl PendingHTLCRouting {
270288
fn blinded_failure(&self) -> Option<BlindedFailure> {
271289
match self {
272290
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
291+
Self::TrampolineForward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
273292
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
274293
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
275294
_ => None,
@@ -279,6 +298,7 @@ impl PendingHTLCRouting {
279298
fn incoming_cltv_expiry(&self) -> Option<u32> {
280299
match self {
281300
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
301+
Self::TrampolineForward { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
282302
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
283303
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
284304
}
@@ -8909,6 +8929,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89098929
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
89108930
let scid = match forward_info.routing {
89118931
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
8932+
PendingHTLCRouting::TrampolineForward { .. } => 0,
89128933
PendingHTLCRouting::Receive { .. } => 0,
89138934
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
89148935
};
@@ -12476,6 +12497,13 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1247612497
(9, payment_context, option),
1247712498
(11, invoice_request, option),
1247812499
},
12500+
(3, TrampolineForward) => {
12501+
(0, incoming_shared_secret, required),
12502+
(2, onion_packet, required),
12503+
(4, blinded, option),
12504+
(6, node_id, required),
12505+
(8, incoming_cltv_expiry, required),
12506+
}
1247912507
);
1248012508

1248112509
impl_writeable_tlv_based!(PendingHTLCInfo, {

0 commit comments

Comments
 (0)