Skip to content

Commit 5cc6bb1

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 5cc6bb1

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub use crate::ln::outbound_payment::{Bolt12PaymentError, ProbeSendFailure, Retr
131131
#[cfg(test)]
132132
pub(crate) use crate::ln::outbound_payment::PaymentSendFailure;
133133
use crate::ln::script::ShutdownScript;
134-
134+
use crate::routing::gossip::NodeId;
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,25 @@ pub enum PendingHTLCRouting {
169169
/// The absolute CLTV of the inbound HTLC
170170
incoming_cltv_expiry: Option<u32>,
171171
},
172+
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, // This should be NonZero<u64> eventually when we bump MSRV
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: Option<u32>,
189+
},
190+
172191
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
173192
///
174193
/// Note that at this point, we have not checked that the invoice being paid was actually
@@ -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, .. } => *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+
(1, onion_packet, required),
12503+
(2, blinded, option),
12504+
(3, node_id, required),
12505+
(4, incoming_cltv_expiry, option),
12506+
}
1247912507
);
1248012508

1248112509
impl_writeable_tlv_based!(PendingHTLCInfo, {

0 commit comments

Comments
 (0)