From 928429833507eb98b1f9a3793da4fe4527e11435 Mon Sep 17 00:00:00 2001 From: Maurice Poirrier Chuden Date: Wed, 28 May 2025 15:21:35 -0400 Subject: [PATCH] Rename `from_raw` to `from_blinded_path_and_payinfo` Similar to 8ce438c3885bebf2258cd227e79f7fbd3e6f8711, we rename `from_raw` function used in test/fuzzy scenarios to build `BlindedPaymentPath` to a public function `from_blinded_path_and_payinfo`. This function is useful when reconstructing a blinded path based on already serialized components. --- fuzz/src/router.rs | 2 +- lightning/src/blinded_path/payment.rs | 18 +++++++++++++----- lightning/src/ln/max_payment_path_len_tests.rs | 2 +- lightning/src/ln/msgs.rs | 2 +- lightning/src/offers/test_utils.rs | 4 ++-- lightning/src/routing/router.rs | 12 ++++++++---- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 61a034feb1c..a4fb00e61f9 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -401,7 +401,7 @@ pub fn do_test(data: &[u8], out: Out) { encrypted_payload: Vec::new(), }); } - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( hop.src_node_id, dummy_pk, blinded_hops, diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index f015886933a..95ad76c3644 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -246,19 +246,27 @@ impl BlindedPaymentPath { Self { inner_path, payinfo } } - #[cfg(any(test, fuzzing))] - pub fn from_raw( + /// Builds a new [`BlindedPaymentPath`] from its constituent parts. + /// + /// Useful when reconstructing a blinded path from previously serialized components. + /// + /// Parameters: + /// * `introduction_node_id`: The public key of the introduction node in the path. + /// * `blinding_point`: The public key used for blinding the path. + /// * `blinded_hops`: The encrypted routing information for each hop in the path. + /// * `payinfo`: The [`BlindedPayInfo`] for the blinded path. + pub fn from_blinded_path_and_payinfo( introduction_node_id: PublicKey, blinding_point: PublicKey, blinded_hops: Vec, payinfo: BlindedPayInfo, ) -> Self { - Self { - inner_path: BlindedPath { + Self::from_parts( + BlindedPath { introduction_node: IntroductionNode::NodeId(introduction_node_id), blinding_point, blinded_hops, }, payinfo, - } + ) } #[cfg(test)] diff --git a/lightning/src/ln/max_payment_path_len_tests.rs b/lightning/src/ln/max_payment_path_len_tests.rs index 95a1fbaaa10..5478fb048cd 100644 --- a/lightning/src/ln/max_payment_path_len_tests.rs +++ b/lightning/src/ln/max_payment_path_len_tests.rs @@ -373,7 +373,7 @@ fn bolt12_invoice_too_large_blinded_paths() { create_announced_chan_between_nodes(&nodes, 0, 1); nodes[1].router.expect_blinded_payment_paths(vec![ - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( PublicKey::from_slice(&[2; 33]).unwrap(), PublicKey::from_slice(&[2; 33]).unwrap(), vec![ BlindedHop { diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2e9c3b90957..bcb18ee78eb 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -6055,7 +6055,7 @@ mod tests { let trampoline_payload = OutboundTrampolinePayload::LegacyBlindedPathEntry { amt_to_forward: 150_000_000, outgoing_cltv_value: 800_000, - payment_paths: vec![BlindedPaymentPath::from_raw( + payment_paths: vec![BlindedPaymentPath::from_blinded_path_and_payinfo( introduction_node, blinding_point, vec![], diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 9888f0303af..d0decdf2c38 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -74,7 +74,7 @@ pub(super) fn privkey(byte: u8) -> SecretKey { pub(crate) fn payment_paths() -> Vec { vec![ - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( pubkey(40), pubkey(41), vec![ @@ -90,7 +90,7 @@ pub(crate) fn payment_paths() -> Vec { features: BlindedHopFeatures::empty(), }, ), - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( pubkey(40), pubkey(41), vec![ diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 67ea6e90fc6..940e0cbc0a8 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -3825,7 +3825,7 @@ mod tests { } fn dummy_blinded_path(intro_node: PublicKey, payinfo: BlindedPayInfo) -> BlindedPaymentPath { - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( intro_node, ln_test_utils::pubkey(42), vec![ BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }, @@ -3836,7 +3836,7 @@ mod tests { } fn dummy_one_hop_blinded_path(intro_node: PublicKey, payinfo: BlindedPayInfo) -> BlindedPaymentPath { - BlindedPaymentPath::from_raw( + BlindedPaymentPath::from_blinded_path_and_payinfo( intro_node, ln_test_utils::pubkey(42), vec![ BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }, @@ -7869,7 +7869,9 @@ mod tests { cltv_expiry_delta: 15, features: BlindedHopFeatures::empty(), }; - let blinded_path = BlindedPaymentPath::from_raw(nodes[2], ln_test_utils::pubkey(42), blinded_hops, blinded_payinfo.clone()); + let blinded_path = BlindedPaymentPath::from_blinded_path_and_payinfo( + nodes[2], ln_test_utils::pubkey(42), blinded_hops, blinded_payinfo.clone() + ); let payment_params = PaymentParameters::blinded(vec![blinded_path.clone(), blinded_path.clone()]); // Make sure we can round-trip read and write blinded payment params. @@ -7990,7 +7992,9 @@ mod tests { let mut blinded_payinfo_2 = blinded_payinfo_1; blinded_payinfo_2.htlc_maximum_msat = 70_000; - let blinded_path_2 = BlindedPaymentPath::from_raw(nodes[2], ln_test_utils::pubkey(43), + let blinded_path_2 = BlindedPaymentPath::from_blinded_path_and_payinfo( + nodes[2], + ln_test_utils::pubkey(43), vec![ BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }, BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }