Skip to content

Commit e62e9fb

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 <[email protected]>
1 parent 09d69fe commit e62e9fb

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
@@ -164,6 +164,8 @@ pub enum PendingHTLCRouting {
164164
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
165165
/// Set if this HTLC is being forwarded within a blinded path.
166166
blinded: Option<BlindedForward>,
167+
/// The absolute CLTV of the inbound HTLC
168+
incoming_cltv_expiry: Option<u32>,
167169
},
168170
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
169171
///
@@ -264,6 +266,14 @@ impl PendingHTLCRouting {
264266
_ => None,
265267
}
266268
}
269+
270+
fn incoming_cltv_expiry(&self) -> Option<u32> {
271+
match self {
272+
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
273+
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
274+
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
275+
}
276+
}
267277
}
268278

269279
/// Information about an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
@@ -5541,9 +5551,9 @@ where
55415551
})?;
55425552

55435553
let routing = match payment.forward_info.routing {
5544-
PendingHTLCRouting::Forward { onion_packet, blinded, .. } => {
5554+
PendingHTLCRouting::Forward { onion_packet, blinded, incoming_cltv_expiry, .. } => {
55455555
PendingHTLCRouting::Forward {
5546-
onion_packet, blinded, short_channel_id: next_hop_scid
5556+
onion_packet, blinded, incoming_cltv_expiry, short_channel_id: next_hop_scid,
55475557
}
55485558
},
55495559
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
@@ -12378,6 +12388,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1237812388
(0, onion_packet, required),
1237912389
(1, blinded, option),
1238012390
(2, short_channel_id, required),
12391+
(3, incoming_cltv_expiry, option),
1238112392
},
1238212393
(1, Receive) => {
1238312394
(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)