From: Valentine Wallace Date: Fri, 26 Jan 2024 19:34:40 +0000 (-0500) Subject: Parameterize BlindedPath::new_for_payment by min final CLTV delta. X-Git-Tag: v0.0.123-beta~75^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=fa44185ba8e0b44458cc1c1edb65918dad6e8f5a;p=rust-lightning Parameterize BlindedPath::new_for_payment by min final CLTV delta. Currently we are not including this value in the aggregated CLTV delta, which is wrong. --- diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index b1fc9e1c0..c242e20f3 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -85,14 +85,15 @@ impl BlindedPath { /// Create a one-hop blinded path for a payment. pub fn one_hop_for_payment( - payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, entropy_source: &ES, - secp_ctx: &Secp256k1 + payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16, + entropy_source: &ES, secp_ctx: &Secp256k1 ) -> 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( intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey, - payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES, - secp_ctx: &Secp256k1 + payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16, + entropy_source: &ES, secp_ctx: &Secp256k1 ) -> 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"); diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index 04742d6ba..fd54a65a4 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -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 = diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 85b65188a..f298f2784 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -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> + 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> + 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(()) }