From ebdc4ae80a3ad50d17ff692b12857497681aa9c3 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Sun, 10 Sep 2023 00:42:18 -0400 Subject: [PATCH] Only allow creating 1-hop blinded paths. Useful until forwarding and receiving to multi-hop blinded paths is supported. --- lightning/src/blinded_path/mod.rs | 15 ++++++++++++++- lightning/src/ln/blinded_payment_tests.rs | 10 ++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index 927bbea9f..89bf7ce5d 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -76,6 +76,19 @@ 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 + ) -> 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 + ) + } + /// Create a blinded path for a payment, to be forwarded along `intermediate_nodes`. /// /// Errors if: @@ -85,7 +98,7 @@ impl BlindedPath { /// /// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs // TODO: make all payloads the same size with padding + add dummy hops - pub fn new_for_payment( + pub(crate) 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 diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index dbc0420bf..826eaa86f 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -43,9 +43,8 @@ fn do_one_hop_blinded_path(success: bool) { }, }; let mut secp_ctx = Secp256k1::new(); - let blinded_path = BlindedPath::new_for_payment( - &[], nodes[1].node.get_our_node_id(), payee_tlvs, chan_upd.htlc_maximum_msat, - &chanmon_cfgs[1].keys_manager, &secp_ctx + let blinded_path = BlindedPath::one_hop_for_payment( + nodes[1].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[1].keys_manager, &secp_ctx ).unwrap(); let route_params = RouteParameters { @@ -85,9 +84,8 @@ fn mpp_to_one_hop_blinded_path() { htlc_minimum_msat: chan_upd_1_3.htlc_minimum_msat, }, }; - let blinded_path = BlindedPath::new_for_payment( - &[], nodes[3].node.get_our_node_id(), payee_tlvs, u64::max_value(), - &chanmon_cfgs[3].keys_manager, &secp_ctx + let blinded_path = BlindedPath::one_hop_for_payment( + nodes[3].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[3].keys_manager, &secp_ctx ).unwrap(); let bolt12_features: Bolt12InvoiceFeatures = -- 2.39.5