]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support including invreqs when building payment onions
authorValentine Wallace <vwallace@protonmail.com>
Fri, 28 Jun 2024 17:45:28 +0000 (13:45 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 30 Oct 2024 20:17:32 +0000 (16:17 -0400)
Add a new invoice request parameter to onion_utils::create_payment_onion. As of
this commit it will always be passed in as None, to be updated in future
commits.

Per BOLTs PR 1149, when paying a static invoice we need to include our original
invoice request in the HTLC onion since the recipient wouldn't have received it
previously.

lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/max_payment_path_len_tests.rs
lightning/src/ln/onion_payment.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/payment_tests.rs

index 3a6d996b5a4a3fdd18e3bd7887c64ec27f3144f2..aa399b9d4d666399b99900a3bacbccc4e40bd0e6 100644 (file)
@@ -1447,7 +1447,7 @@ fn route_blinding_spec_test_vector() {
                }),
        };
        let cur_height = 747_000;
-       let (bob_onion, _, _) = onion_utils::create_payment_onion(&secp_ctx, &path, &session_priv, amt_msat, &RecipientOnionFields::spontaneous_empty(), cur_height, &PaymentHash([0; 32]), &None, [0; 32]).unwrap();
+       let (bob_onion, _, _) = onion_utils::create_payment_onion(&secp_ctx, &path, &session_priv, amt_msat, &RecipientOnionFields::spontaneous_empty(), cur_height, &PaymentHash([0; 32]), &None, None, [0; 32]).unwrap();
 
        struct TestEcdhSigner {
                node_secret: SecretKey,
index 691223fd3cfb111a33221a631192891bee5aa169..67efc889474834ab34b6bfcfef5bad58e12987ee 100644 (file)
@@ -4195,7 +4195,7 @@ where
 
                let (onion_packet, htlc_msat, htlc_cltv) = onion_utils::create_payment_onion(
                        &self.secp_ctx, &path, &session_priv, total_value, recipient_onion, cur_height,
-                       payment_hash, keysend_preimage, prng_seed
+                       payment_hash, keysend_preimage, None, prng_seed
                ).map_err(|e| {
                        let logger = WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None, Some(*payment_hash));
                        log_error!(logger, "Failed to build an onion for path for payment hash {}", payment_hash);
index 90326b9c54ce87339a93c6e8d487e825fe2e0dd8..af30003ee5db48856493ab355676eb9e22cd1f43 100644 (file)
@@ -110,7 +110,7 @@ fn large_payment_metadata() {
        let secp_ctx = Secp256k1::signing_only();
        route_0_1.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
        route_0_1.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
-       let err = onion_utils::create_payment_onion(&secp_ctx, &route_0_1.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_md, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, [0; 32]).unwrap_err();
+       let err = onion_utils::create_payment_onion(&secp_ctx, &route_0_1.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_md, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, None, [0; 32]).unwrap_err();
        match err {
                APIError::InvalidRoute { err } => {
                        assert_eq!(err, "Route size too large considering onion data");
@@ -318,7 +318,7 @@ fn blinded_path_with_custom_tlv() {
        let secp_ctx = Secp256k1::signing_only();
        route.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
        route.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
-       let err = onion_utils::create_payment_onion(&secp_ctx, &route.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_custom_tlv, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, [0; 32]).unwrap_err();
+       let err = onion_utils::create_payment_onion(&secp_ctx, &route.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_custom_tlv, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, None, [0; 32]).unwrap_err();
        match err {
                APIError::InvalidRoute { err } => {
                        assert_eq!(err, "Route size too large considering onion data");
index d76c0d3a99dc4a96501b61df093fe289b235bf8c..a62846f75cd411c5f6772e021196580610edff8c 100644 (file)
@@ -569,7 +569,7 @@ mod tests {
 
                let (onion, amount_msat, cltv_expiry) = create_payment_onion(
                        &secp_ctx, &path, &session_priv, total_amt_msat, &recipient_onion,
-                       cur_height, &payment_hash, &Some(preimage), prng_seed
+                       cur_height, &payment_hash, &Some(preimage), None, prng_seed
                ).unwrap();
 
                let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);
index 16b8885d2fb9bff53c5ed19d0fec5561bd617667..3757d67732072b2b3f49bd33badf1bc9cedb846a 100644 (file)
@@ -1163,7 +1163,8 @@ where
 pub fn create_payment_onion<T: secp256k1::Signing>(
        secp_ctx: &Secp256k1<T>, path: &Path, session_priv: &SecretKey, total_msat: u64,
        recipient_onion: &RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
-       keysend_preimage: &Option<PaymentPreimage>, prng_seed: [u8; 32],
+       keysend_preimage: &Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
+       prng_seed: [u8; 32],
 ) -> Result<(msgs::OnionPacket, u64, u32), APIError> {
        let onion_keys = construct_onion_keys(&secp_ctx, &path, &session_priv).map_err(|_| {
                APIError::InvalidRoute { err: "Pubkey along hop was maliciously selected".to_owned() }
@@ -1174,7 +1175,7 @@ pub fn create_payment_onion<T: secp256k1::Signing>(
                recipient_onion,
                cur_block_height,
                keysend_preimage,
-               None,
+               invoice_request,
        )?;
        let onion_packet = construct_onion_packet(onion_payloads, onion_keys, prng_seed, payment_hash)
                .map_err(|_| APIError::InvalidRoute {
index 7839b49be778acc40af5827af570c476ba6fa96e..ca386682fa05978371965453ff8398d57b3fa6ad 100644 (file)
@@ -4271,7 +4271,7 @@ fn peel_payment_onion_custom_tlvs() {
 
        let (onion_routing_packet, first_hop_msat, cltv_expiry) = onion_utils::create_payment_onion(
                &secp_ctx, &route.paths[0], &session_priv, amt_msat, &recipient_onion,
-               nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), prng_seed
+               nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), None, prng_seed
        ).unwrap();
 
        let update_add = msgs::UpdateAddHTLC {