Skip to content

Commit 3c0a18a

Browse files
alecchendevTheBlueMatt
authored andcommitted
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 <[email protected]>
1 parent 2bb3b7e commit 3c0a18a

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
@@ -167,6 +167,8 @@ pub enum PendingHTLCRouting {
167167
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
168168
/// Set if this HTLC is being forwarded within a blinded path.
169169
blinded: Option<BlindedForward>,
170+
/// The absolute CLTV of the inbound HTLC
171+
incoming_cltv_expiry: Option<u32>,
170172
},
171173
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
172174
///
@@ -272,6 +274,14 @@ impl PendingHTLCRouting {
272274
_ => None,
273275
}
274276
}
277+
278+
fn incoming_cltv_expiry(&self) -> Option<u32> {
279+
match self {
280+
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
281+
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
282+
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
283+
}
284+
}
275285
}
276286

277287
/// Information about an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
@@ -5508,9 +5518,9 @@ where
55085518
})?;
55095519

55105520
let routing = match payment.forward_info.routing {
5511-
PendingHTLCRouting::Forward { onion_packet, blinded, .. } => {
5521+
PendingHTLCRouting::Forward { onion_packet, blinded, incoming_cltv_expiry, .. } => {
55125522
PendingHTLCRouting::Forward {
5513-
onion_packet, blinded, short_channel_id: next_hop_scid
5523+
onion_packet, blinded, incoming_cltv_expiry, short_channel_id: next_hop_scid,
55145524
}
55155525
},
55165526
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
@@ -12367,6 +12377,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1236712377
(0, onion_packet, required),
1236812378
(1, blinded, option),
1236912379
(2, short_channel_id, required),
12380+
(3, incoming_cltv_expiry, option),
1237012381
},
1237112382
(1, Receive) => {
1237212383
(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)