Skip to content

Commit 40f75a4

Browse files
committed
ln/refactor: pass minimum delta into check_incoming_htlc_cltv
For trampoline payments, we don't want to enforce a minimum cltv delta between our incoming and outer onion outgoing CLTV because we'll calculate our delta from the inner trampoline onion's value. However, we still want to check that we get at least the CLTV that the sending node intended for us and we still want to validate our incoming value. Refactor to allow setting a zero delta, for use for trampoline payments.
1 parent 1913746 commit 40f75a4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5219,8 +5219,12 @@ impl<
52195219
};
52205220

52215221
let cur_height = self.best_block.read().unwrap().height + 1;
5222-
check_incoming_htlc_cltv(cur_height, next_hop.outgoing_cltv_value, msg.cltv_expiry)?;
5223-
5222+
check_incoming_htlc_cltv(
5223+
cur_height,
5224+
next_hop.outgoing_cltv_value,
5225+
msg.cltv_expiry,
5226+
MIN_CLTV_EXPIRY_DELTA,
5227+
)?;
52245228
Ok(intercept)
52255229
}
52265230

lightning/src/ln/onion_payment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ pub fn peel_payment_onion<NS: NodeSigner, L: Logger, T: secp256k1::Verification>
515515
};
516516

517517
if let Err(reason) = check_incoming_htlc_cltv(
518-
cur_height, outgoing_cltv_value, msg.cltv_expiry,
518+
cur_height, outgoing_cltv_value, msg.cltv_expiry, MIN_CLTV_EXPIRY_DELTA,
519519
) {
520520
return Err(InboundHTLCErr {
521521
msg: "incoming cltv check failed",
@@ -719,9 +719,9 @@ pub(super) fn decode_incoming_update_add_htlc_onion<NS: NodeSigner, L: Logger, T
719719
}
720720

721721
pub(super) fn check_incoming_htlc_cltv(
722-
cur_height: u32, outgoing_cltv_value: u32, cltv_expiry: u32,
722+
cur_height: u32, outgoing_cltv_value: u32, cltv_expiry: u32, min_cltv_expiry_delta: u16,
723723
) -> Result<(), LocalHTLCFailureReason> {
724-
if (cltv_expiry as u64) < (outgoing_cltv_value) as u64 + MIN_CLTV_EXPIRY_DELTA as u64 {
724+
if (cltv_expiry as u64) < (outgoing_cltv_value) as u64 + min_cltv_expiry_delta as u64 {
725725
return Err(LocalHTLCFailureReason::IncorrectCLTVExpiry);
726726
}
727727
// Theoretically, channel counterparty shouldn't send us a HTLC expiring now,

0 commit comments

Comments
 (0)