]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Parameterize BlindedPath::new_for_payment by min final CLTV delta.
authorValentine Wallace <vwallace@protonmail.com>
Fri, 26 Jan 2024 19:34:40 +0000 (14:34 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 7 Feb 2024 17:02:24 +0000 (12:02 -0500)
Currently we are not including this value in the aggregated CLTV delta, which
is wrong.

lightning/src/blinded_path/mod.rs
lightning/src/ln/blinded_payment_tests.rs
lightning/src/routing/router.rs

index b1fc9e1c0a443c36cbb5d3a772ac944a869d7268..c242e20f32277a09596f1417aa46e480b908f386 100644 (file)
@@ -85,14 +85,15 @@ impl BlindedPath {
 
        /// Create a one-hop blinded path for a payment.
        pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
-               payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, entropy_source: &ES,
-               secp_ctx: &Secp256k1<T>
+               payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
+               entropy_source: &ES, secp_ctx: &Secp256k1<T>
        ) -> Result<(BlindedPayInfo, Self), ()> {
                // This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
                // be in relation to a specific channel.
                let htlc_maximum_msat = u64::max_value();
                Self::new_for_payment(
-                       &[], payee_node_id, payee_tlvs, htlc_maximum_msat, entropy_source, secp_ctx
+                       &[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
+                       entropy_source, secp_ctx
                )
        }
 
@@ -107,8 +108,8 @@ impl BlindedPath {
        //  TODO: make all payloads the same size with padding + add dummy hops
        pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
                intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
-               payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES,
-               secp_ctx: &Secp256k1<T>
+               payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
+               entropy_source: &ES, secp_ctx: &Secp256k1<T>
        ) -> Result<(BlindedPayInfo, Self), ()> {
                let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
                let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
index 04742d6ba4ded3840511208274cfd6049deb7dc8..fd54a65a432046778eaaba10f01ca81c61b01d26 100644 (file)
@@ -61,7 +61,7 @@ fn blinded_payment_path(
        let mut secp_ctx = Secp256k1::new();
        BlindedPath::new_for_payment(
                &intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
-               channel_upds.last().unwrap().htlc_maximum_msat, keys_manager, &secp_ctx
+               channel_upds.last().unwrap().htlc_maximum_msat, TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx
        ).unwrap()
 }
 
@@ -100,7 +100,8 @@ fn do_one_hop_blinded_path(success: bool) {
        };
        let mut secp_ctx = Secp256k1::new();
        let blinded_path = BlindedPath::one_hop_for_payment(
-               nodes[1].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[1].keys_manager, &secp_ctx
+               nodes[1].node.get_our_node_id(), payee_tlvs, TEST_FINAL_CLTV as u16,
+               &chanmon_cfgs[1].keys_manager, &secp_ctx
        ).unwrap();
 
        let route_params = RouteParameters::from_payment_params_and_value(
@@ -141,7 +142,8 @@ fn mpp_to_one_hop_blinded_path() {
                },
        };
        let blinded_path = BlindedPath::one_hop_for_payment(
-               nodes[3].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[3].keys_manager, &secp_ctx
+               nodes[3].node.get_our_node_id(), payee_tlvs, TEST_FINAL_CLTV as u16,
+               &chanmon_cfgs[3].keys_manager, &secp_ctx
        ).unwrap();
 
        let bolt12_features =
index 85b65188a7f2d80ee96871004d36c540aaaaaad9..f298f278439f284ccb15bcd66973eb94991d8174 100644 (file)
@@ -14,7 +14,7 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
 use crate::blinded_path::{BlindedHop, BlindedPath};
 use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
 use crate::ln::PaymentHash;
-use crate::ln::channelmanager::{ChannelDetails, PaymentId};
+use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA};
 use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
 use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
@@ -134,7 +134,8 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
                        })
                        .map(|forward_node| {
                                BlindedPath::new_for_payment(
-                                       &[forward_node], recipient, tlvs.clone(), u64::MAX, &*self.entropy_source, secp_ctx
+                                       &[forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
+                                       &*self.entropy_source, secp_ctx
                                )
                        })
                        .take(MAX_PAYMENT_PATHS)
@@ -144,8 +145,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
                        Ok(paths) if !paths.is_empty() => Ok(paths),
                        _ => {
                                if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
-                                       BlindedPath::one_hop_for_payment(recipient, tlvs, &*self.entropy_source, secp_ctx)
-                                               .map(|path| vec![path])
+                                       BlindedPath::one_hop_for_payment(
+                                               recipient, tlvs, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source, secp_ctx
+                                       ).map(|path| vec![path])
                                } else {
                                        Err(())
                                }