From: Valentine Wallace Date: Fri, 26 Jan 2024 20:17:27 +0000 (-0500) Subject: Add min_final_cltv_delta to aggregated CLTV delta. X-Git-Tag: v0.0.123-beta~75^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=fff1aa7cb0ed14ad414052adfe445eda5421acf5;p=rust-lightning Add min_final_cltv_delta to aggregated CLTV delta. The spec was previously missing this requirement. --- diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index c242e20f3..e70f310f5 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -114,7 +114,9 @@ impl BlindedPath { let blinding_secret_bytes = entropy_source.get_secure_random_bytes(); let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted"); - let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?; + let blinded_payinfo = payment::compute_payinfo( + intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta + )?; Ok((blinded_payinfo, BlindedPath { introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id), blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret), diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 5d332a76f..106cd802c 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -215,11 +215,12 @@ pub(crate) fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &Payment } pub(super) fn compute_payinfo( - intermediate_nodes: &[ForwardNode], payee_tlvs: &ReceiveTlvs, payee_htlc_maximum_msat: u64 + intermediate_nodes: &[ForwardNode], payee_tlvs: &ReceiveTlvs, payee_htlc_maximum_msat: u64, + min_final_cltv_expiry_delta: u16 ) -> Result { let mut curr_base_fee: u64 = 0; let mut curr_prop_mil: u64 = 0; - let mut cltv_expiry_delta: u16 = 0; + let mut cltv_expiry_delta: u16 = min_final_cltv_expiry_delta; for tlvs in intermediate_nodes.iter().rev().map(|n| &n.tlvs) { // In the future, we'll want to take the intersection of all supported features for the // `BlindedPayInfo`, but there are no features in that context right now. @@ -292,6 +293,7 @@ mod tests { use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentRelay}; use crate::ln::PaymentSecret; use crate::ln::features::BlindedHopFeatures; + use crate::ln::functional_test_utils::TEST_FINAL_CLTV; #[test] fn compute_payinfo() { @@ -339,10 +341,10 @@ mod tests { }, }; let htlc_maximum_msat = 100_000; - let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap(); + let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, 12).unwrap(); assert_eq!(blinded_payinfo.fee_base_msat, 201); assert_eq!(blinded_payinfo.fee_proportional_millionths, 1001); - assert_eq!(blinded_payinfo.cltv_expiry_delta, 288); + assert_eq!(blinded_payinfo.cltv_expiry_delta, 300); assert_eq!(blinded_payinfo.htlc_minimum_msat, 900); assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat); } @@ -356,10 +358,10 @@ mod tests { htlc_minimum_msat: 1, }, }; - let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242).unwrap(); + let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242, TEST_FINAL_CLTV as u16).unwrap(); assert_eq!(blinded_payinfo.fee_base_msat, 0); assert_eq!(blinded_payinfo.fee_proportional_millionths, 0); - assert_eq!(blinded_payinfo.cltv_expiry_delta, 0); + assert_eq!(blinded_payinfo.cltv_expiry_delta, TEST_FINAL_CLTV as u16); assert_eq!(blinded_payinfo.htlc_minimum_msat, 1); assert_eq!(blinded_payinfo.htlc_maximum_msat, 4242); } @@ -410,7 +412,7 @@ mod tests { }, }; let htlc_maximum_msat = 100_000; - let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap(); + let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap(); assert_eq!(blinded_payinfo.htlc_minimum_msat, 2_000); } @@ -460,10 +462,10 @@ mod tests { }, }; let htlc_minimum_msat = 3798; - assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1).is_err()); + assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1, TEST_FINAL_CLTV as u16).is_err()); let htlc_maximum_msat = htlc_minimum_msat + 1; - let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap(); + let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap(); assert_eq!(blinded_payinfo.htlc_minimum_msat, htlc_minimum_msat); assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat); } @@ -514,7 +516,7 @@ mod tests { }, }; - let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000).unwrap(); + let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000, TEST_FINAL_CLTV as u16).unwrap(); assert_eq!(blinded_payinfo.htlc_maximum_msat, 3997); } } diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index fd54a65a4..267929517 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -697,7 +697,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false); }, ReceiveCheckFail::ProcessPendingHTLCsCheck => { - 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); + 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); nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);