Skip to content

Commit 3f1d894

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 3f1d894

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Diff for: lightning/src/ln/channelmanager.rs

+28-1
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;
@@ -131,7 +132,6 @@ pub use crate::ln::outbound_payment::{Bolt12PaymentError, ProbeSendFailure, Retr
131132
#[cfg(test)]
132133
pub(crate) use crate::ln::outbound_payment::PaymentSendFailure;
133134
use crate::ln::script::ShutdownScript;
134-
135135
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
136136
//
137137
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
@@ -169,6 +169,23 @@ pub enum PendingHTLCRouting {
169169
/// The absolute CLTV of the inbound HTLC
170170
incoming_cltv_expiry: Option<u32>,
171171
},
172+
/// An HTLC which should be forwarded on to another Trampoline node.
173+
TrampolineForward {
174+
/// The onion shared secret we build with the sender (or the preceding Trampoline node) used
175+
/// to decrypt the onion.
176+
///
177+
/// This is later used to encrypt failure packets in the event that the HTLC is failed.
178+
incoming_shared_secret: [u8; 32],
179+
/// The onion which should be included in the forwarded HTLC, telling the next hop what to
180+
/// do with the HTLC.
181+
onion_packet: msgs::TrampolineOnionPacket,
182+
/// The node ID of the Trampoline node which we need to route this HTLC to.
183+
node_id: NodeId,
184+
/// Set if this HTLC is being forwarded within a blinded path.
185+
blinded: Option<BlindedForward>,
186+
/// The absolute CLTV of the inbound HTLC
187+
incoming_cltv_expiry: u32,
188+
},
172189
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
173190
///
174191
/// Note that at this point, we have not checked that the invoice being paid was actually
@@ -270,6 +287,7 @@ impl PendingHTLCRouting {
270287
fn blinded_failure(&self) -> Option<BlindedFailure> {
271288
match self {
272289
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
290+
Self::TrampolineForward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
273291
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
274292
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
275293
_ => None,
@@ -279,6 +297,7 @@ impl PendingHTLCRouting {
279297
fn incoming_cltv_expiry(&self) -> Option<u32> {
280298
match self {
281299
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
300+
Self::TrampolineForward { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
282301
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
283302
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
284303
}
@@ -8909,6 +8928,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89098928
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
89108929
let scid = match forward_info.routing {
89118930
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
8931+
PendingHTLCRouting::TrampolineForward { .. } => 0,
89128932
PendingHTLCRouting::Receive { .. } => 0,
89138933
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
89148934
};
@@ -12476,6 +12496,13 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1247612496
(9, payment_context, option),
1247712497
(11, invoice_request, option),
1247812498
},
12499+
(3, TrampolineForward) => {
12500+
(0, incoming_shared_secret, required),
12501+
(2, onion_packet, required),
12502+
(4, blinded, option),
12503+
(6, node_id, required),
12504+
(8, incoming_cltv_expiry, option),
12505+
}
1247912506
);
1248012507

1248112508
impl_writeable_tlv_based!(PendingHTLCInfo, {

0 commit comments

Comments
 (0)