Skip to content

Commit b616559

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 b616559

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ check-cfg = [
6262
"cfg(ldk_bench)",
6363
"cfg(ldk_test_vectors)",
6464
"cfg(taproot)",
65+
"cfg(trampoline)",
6566
"cfg(require_route_graph_test)",
6667
"cfg(splicing)",
6768
"cfg(async_payments)",

lightning/src/ln/channelmanager.rs

+63
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ 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+
#[cfg(trampoline)]
59+
use crate::routing::gossip::NodeId;
5860
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
5961
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};
6062
use crate::ln::msgs;
@@ -169,6 +171,24 @@ pub enum PendingHTLCRouting {
169171
/// The absolute CLTV of the inbound HTLC
170172
incoming_cltv_expiry: Option<u32>,
171173
},
174+
/// An HTLC which should be forwarded on to another Trampoline node.
175+
#[cfg(trampoline)]
176+
TrampolineForward {
177+
/// The onion shared secret we build with the sender (or the preceding Trampoline node) used
178+
/// to decrypt the onion.
179+
///
180+
/// This is later used to encrypt failure packets in the event that the HTLC is failed.
181+
incoming_shared_secret: [u8; 32],
182+
/// The onion which should be included in the forwarded HTLC, telling the next hop what to
183+
/// do with the HTLC.
184+
onion_packet: msgs::TrampolineOnionPacket,
185+
/// The node ID of the Trampoline node which we need to route this HTLC to.
186+
node_id: NodeId,
187+
/// Set if this HTLC is being forwarded within a blinded path.
188+
blinded: Option<BlindedForward>,
189+
/// The absolute CLTV of the inbound HTLC
190+
incoming_cltv_expiry: u32,
191+
},
172192
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
173193
///
174194
/// Note that at this point, we have not checked that the invoice being paid was actually
@@ -270,6 +290,8 @@ impl PendingHTLCRouting {
270290
fn blinded_failure(&self) -> Option<BlindedFailure> {
271291
match self {
272292
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
293+
#[cfg(trampoline)]
294+
Self::TrampolineForward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
273295
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
274296
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
275297
_ => None,
@@ -279,6 +301,8 @@ impl PendingHTLCRouting {
279301
fn incoming_cltv_expiry(&self) -> Option<u32> {
280302
match self {
281303
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
304+
#[cfg(trampoline)]
305+
Self::TrampolineForward { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
282306
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
283307
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
284308
}
@@ -8909,6 +8933,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89098933
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
89108934
let scid = match forward_info.routing {
89118935
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
8936+
#[cfg(trampoline)]
8937+
PendingHTLCRouting::TrampolineForward { .. } => 0,
89128938
PendingHTLCRouting::Receive { .. } => 0,
89138939
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
89148940
};
@@ -12449,6 +12475,7 @@ impl_writeable_tlv_based!(BlindedForward, {
1244912475
(3, next_blinding_override, option),
1245012476
});
1245112477

12478+
#[cfg(not(trampoline))]
1245212479
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1245312480
(0, Forward) => {
1245412481
(0, onion_packet, required),
@@ -12477,6 +12504,42 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1247712504
(11, invoice_request, option),
1247812505
},
1247912506
);
12507+
#[cfg(trampoline)]
12508+
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
12509+
(0, Forward) => {
12510+
(0, onion_packet, required),
12511+
(1, blinded, option),
12512+
(2, short_channel_id, required),
12513+
(3, incoming_cltv_expiry, option),
12514+
},
12515+
(1, Receive) => {
12516+
(0, payment_data, required),
12517+
(1, phantom_shared_secret, option),
12518+
(2, incoming_cltv_expiry, required),
12519+
(3, payment_metadata, option),
12520+
(5, custom_tlvs, optional_vec),
12521+
(7, requires_blinded_error, (default_value, false)),
12522+
(9, payment_context, option),
12523+
},
12524+
(2, ReceiveKeysend) => {
12525+
(0, payment_preimage, required),
12526+
(1, requires_blinded_error, (default_value, false)),
12527+
(2, incoming_cltv_expiry, required),
12528+
(3, payment_metadata, option),
12529+
(4, payment_data, option), // Added in 0.0.116
12530+
(5, custom_tlvs, optional_vec),
12531+
(7, has_recipient_created_payment_secret, (default_value, false)),
12532+
(9, payment_context, option),
12533+
(11, invoice_request, option),
12534+
},
12535+
(3, TrampolineForward) => {
12536+
(0, incoming_shared_secret, required),
12537+
(2, onion_packet, required),
12538+
(4, blinded, option),
12539+
(6, node_id, required),
12540+
(8, incoming_cltv_expiry, required),
12541+
}
12542+
);
1248012543

1248112544
impl_writeable_tlv_based!(PendingHTLCInfo, {
1248212545
(0, routing, required),

0 commit comments

Comments
 (0)