Skip to content

Commit 6368dfb

Browse files
Add cltv expiry to PendingHTLCRouting::Forward
In a coming commit we'll expire HTLCs backwards even if we haven't yet claimed them on-chain based on their inbound edge being close to causing a channel force-closure. Here we track the incoming edge's CLTV expiry in the pending-routing state so that we can include it in the `HTLCSource` in the next commit. Co-authored-by: Matt Corallo <git@bluematt.me>
1 parent 3d2b4de commit 6368dfb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub enum PendingHTLCRouting {
169169
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
170170
/// Set if this HTLC is being forwarded within a blinded path.
171171
blinded: Option<BlindedForward>,
172+
/// The absolute CLTV of the inbound HTLC
173+
incoming_cltv_expiry: Option<u32>,
172174
},
173175
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
174176
///
@@ -269,6 +271,14 @@ impl PendingHTLCRouting {
269271
_ => None,
270272
}
271273
}
274+
275+
fn incoming_cltv_expiry(&self) -> Option<u32> {
276+
match self {
277+
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
278+
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
279+
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
280+
}
281+
}
272282
}
273283

274284
/// Information about an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
@@ -5522,9 +5532,9 @@ where
55225532
})?;
55235533

55245534
let routing = match payment.forward_info.routing {
5525-
PendingHTLCRouting::Forward { onion_packet, blinded, .. } => {
5535+
PendingHTLCRouting::Forward { onion_packet, blinded, incoming_cltv_expiry, .. } => {
55265536
PendingHTLCRouting::Forward {
5527-
onion_packet, blinded, short_channel_id: next_hop_scid
5537+
onion_packet, blinded, incoming_cltv_expiry, short_channel_id: next_hop_scid,
55285538
}
55295539
},
55305540
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
@@ -12433,6 +12443,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1243312443
(0, onion_packet, required),
1243412444
(1, blinded, option),
1243512445
(2, short_channel_id, required),
12446+
(3, incoming_cltv_expiry, option),
1243612447
},
1243712448
(1, Receive) => {
1243812449
(0, payment_data, required),

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub(super) fn create_fwd_pending_htlc_info(
110110
routing: PendingHTLCRouting::Forward {
111111
onion_packet: outgoing_packet,
112112
short_channel_id,
113+
incoming_cltv_expiry: Some(msg.cltv_expiry),
113114
blinded: intro_node_blinding_point.or(msg.blinding_point)
114115
.map(|bp| BlindedForward {
115116
inbound_blinding_point: bp,

0 commit comments

Comments
 (0)