Only allow creating 1-hop blinded paths.
authorValentine Wallace <vwallace@protonmail.com>
Sun, 10 Sep 2023 04:42:18 +0000 (00:42 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 12 Sep 2023 22:12:03 +0000 (18:12 -0400)
Useful until forwarding and receiving to multi-hop blinded paths is supported.

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

index 927bbea9f6e99ab6e15db2cbb619af0e187060ec..89bf7ce5d2f405c4ab7dd87e9ae5347875ad99a1 100644 (file)
@@ -76,6 +76,19 @@ impl BlindedPath {
                })
        }
 
+       /// Create a one-hop blinded path for a payment.
+       pub fn one_hop_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
+               payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, 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
+               )
+       }
+
        /// 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<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
+       pub(crate) fn new_for_payment<ES: EntropySource, 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>
index dbc0420bfee184f967bf9df5d7c80a1049c9eedf..826eaa86f48f1dd073a57d11dbb0831129b99e27 100644 (file)
@@ -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 =