Skip to content

Commit fff1aa7

Browse files
Add min_final_cltv_delta to aggregated CLTV delta.
The spec was previously missing this requirement.
1 parent fa44185 commit fff1aa7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lightning/src/blinded_path/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ impl BlindedPath {
114114
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
115115
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
116116

117-
let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?;
117+
let blinded_payinfo = payment::compute_payinfo(
118+
intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
119+
)?;
118120
Ok((blinded_payinfo, BlindedPath {
119121
introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id),
120122
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),

lightning/src/blinded_path/payment.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ pub(crate) fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &Payment
215215
}
216216

217217
pub(super) fn compute_payinfo(
218-
intermediate_nodes: &[ForwardNode], payee_tlvs: &ReceiveTlvs, payee_htlc_maximum_msat: u64
218+
intermediate_nodes: &[ForwardNode], payee_tlvs: &ReceiveTlvs, payee_htlc_maximum_msat: u64,
219+
min_final_cltv_expiry_delta: u16
219220
) -> Result<BlindedPayInfo, ()> {
220221
let mut curr_base_fee: u64 = 0;
221222
let mut curr_prop_mil: u64 = 0;
222-
let mut cltv_expiry_delta: u16 = 0;
223+
let mut cltv_expiry_delta: u16 = min_final_cltv_expiry_delta;
223224
for tlvs in intermediate_nodes.iter().rev().map(|n| &n.tlvs) {
224225
// In the future, we'll want to take the intersection of all supported features for the
225226
// `BlindedPayInfo`, but there are no features in that context right now.
@@ -292,6 +293,7 @@ mod tests {
292293
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentRelay};
293294
use crate::ln::PaymentSecret;
294295
use crate::ln::features::BlindedHopFeatures;
296+
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
295297

296298
#[test]
297299
fn compute_payinfo() {
@@ -339,10 +341,10 @@ mod tests {
339341
},
340342
};
341343
let htlc_maximum_msat = 100_000;
342-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
344+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, 12).unwrap();
343345
assert_eq!(blinded_payinfo.fee_base_msat, 201);
344346
assert_eq!(blinded_payinfo.fee_proportional_millionths, 1001);
345-
assert_eq!(blinded_payinfo.cltv_expiry_delta, 288);
347+
assert_eq!(blinded_payinfo.cltv_expiry_delta, 300);
346348
assert_eq!(blinded_payinfo.htlc_minimum_msat, 900);
347349
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
348350
}
@@ -356,10 +358,10 @@ mod tests {
356358
htlc_minimum_msat: 1,
357359
},
358360
};
359-
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242).unwrap();
361+
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242, TEST_FINAL_CLTV as u16).unwrap();
360362
assert_eq!(blinded_payinfo.fee_base_msat, 0);
361363
assert_eq!(blinded_payinfo.fee_proportional_millionths, 0);
362-
assert_eq!(blinded_payinfo.cltv_expiry_delta, 0);
364+
assert_eq!(blinded_payinfo.cltv_expiry_delta, TEST_FINAL_CLTV as u16);
363365
assert_eq!(blinded_payinfo.htlc_minimum_msat, 1);
364366
assert_eq!(blinded_payinfo.htlc_maximum_msat, 4242);
365367
}
@@ -410,7 +412,7 @@ mod tests {
410412
},
411413
};
412414
let htlc_maximum_msat = 100_000;
413-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
415+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap();
414416
assert_eq!(blinded_payinfo.htlc_minimum_msat, 2_000);
415417
}
416418

@@ -460,10 +462,10 @@ mod tests {
460462
},
461463
};
462464
let htlc_minimum_msat = 3798;
463-
assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1).is_err());
465+
assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1, TEST_FINAL_CLTV as u16).is_err());
464466

465467
let htlc_maximum_msat = htlc_minimum_msat + 1;
466-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
468+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap();
467469
assert_eq!(blinded_payinfo.htlc_minimum_msat, htlc_minimum_msat);
468470
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
469471
}
@@ -514,7 +516,7 @@ mod tests {
514516
},
515517
};
516518

517-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000).unwrap();
519+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000, TEST_FINAL_CLTV as u16).unwrap();
518520
assert_eq!(blinded_payinfo.htlc_maximum_msat, 3997);
519521
}
520522
}

lightning/src/ln/blinded_payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
697697
commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false);
698698
},
699699
ReceiveCheckFail::ProcessPendingHTLCsCheck => {
700-
assert_eq!(payment_event_1_2.msgs[0].cltv_expiry, nodes[0].best_block_info().1 + 1 + excess_final_cltv_delta_opt.unwrap() as u32);
700+
assert_eq!(payment_event_1_2.msgs[0].cltv_expiry, nodes[0].best_block_info().1 + 1 + excess_final_cltv_delta_opt.unwrap() as u32 + TEST_FINAL_CLTV);
701701
nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]);
702702
check_added_monitors!(nodes[2], 0);
703703
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);

0 commit comments

Comments
 (0)