]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support encoding invreqs in outbound onion payloads
authorValentine Wallace <vwallace@protonmail.com>
Fri, 28 Jun 2024 15:40:53 +0000 (11:40 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 30 Oct 2024 20:17:12 +0000 (16:17 -0400)
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.

We use an experimental TLV type for this new onion payload field, since the
spec is still not merged in the BOLTs.

lightning/src/ln/max_payment_path_len_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/outbound_payment.rs

index 8c24ef363397573dfc332bc6a35b8263e7a63daa..501ddcc5721d623d20ae0749d49226b77495cdb8 100644 (file)
@@ -184,6 +184,7 @@ fn one_hop_blinded_path_with_custom_tlv() {
                encrypted_tlvs: &blinded_path.blinded_hops()[0].encrypted_payload,
                intro_node_blinding_point: Some(blinded_path.blinding_point()),
                keysend_preimage: None,
+               invoice_request: None,
                custom_tlvs: &Vec::new()
        }.serialized_length();
        let max_custom_tlv_len = 1300
index 4837a40e1042df81dc2dbb3f687903b24e900686..6f508efa6363febc4c403fca27760aa8e66c6b7b 100644 (file)
@@ -1747,6 +1747,7 @@ pub struct FinalOnionHopData {
 mod fuzzy_internal_msgs {
        use bitcoin::secp256k1::PublicKey;
        use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, PaymentRelay};
+       use crate::offers::invoice_request::InvoiceRequest;
        use crate::types::payment::{PaymentPreimage, PaymentSecret};
        use crate::types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
        use super::{FinalOnionHopData, TrampolineOnionPacket};
@@ -1827,6 +1828,7 @@ mod fuzzy_internal_msgs {
                        intro_node_blinding_point: Option<PublicKey>, // Set if the introduction node of the blinded path is the final node
                        keysend_preimage: Option<PaymentPreimage>,
                        custom_tlvs: &'a Vec<(u64, Vec<u8>)>,
+                       invoice_request: Option<&'a InvoiceRequest>,
                }
        }
 
@@ -2760,13 +2762,17 @@ impl<'a> Writeable for OutboundOnionPayload<'a> {
                        },
                        Self::BlindedReceive {
                                sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
-                               intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
+                               intro_node_blinding_point, keysend_preimage, ref invoice_request, ref custom_tlvs,
                        } => {
                                // We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
                                // to reject any reserved types in the experimental range if new ones are ever
                                // standardized.
+                               let invoice_request_tlv = invoice_request.map(|invreq| (77_777, invreq.encode())); // TODO: update TLV type once the async payments spec is merged
                                let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
-                               let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
+                               let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter()
+                                       .chain(invoice_request_tlv.iter())
+                                       .chain(keysend_tlv.iter())
+                                       .collect();
                                custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
                                _encode_varint_length_prefixed_tlv!(w, {
                                        (2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),
index 208096c128e2e2c554da8a8543b64ad2e7368677..68866fc03f83f5b33f4529bce22fe4875cc8ba73 100644 (file)
@@ -262,6 +262,7 @@ where
                                                                encrypted_tlvs: &blinded_hop.encrypted_payload,
                                                                intro_node_blinding_point: blinding_point.take(),
                                                                keysend_preimage: *keysend_preimage,
+                                                               invoice_request: None,
                                                                custom_tlvs: &recipient_onion.custom_tlvs,
                                                        },
                                                );
index 04736f2a8c2cc65a5107d2cdeb5f5178c9e23aac..01f6c1d09639f6ec3adc2e76de2e8225058263b4 100644 (file)
@@ -641,6 +641,7 @@ impl RecipientOnionFields {
                for (typ, _) in custom_tlvs.iter() {
                        if *typ < 1 << 16 { return Err(()); }
                        if *typ == 5482373484 { return Err(()); } // keysend
+                       if *typ == 77_777 { return Err(()); } // invoice requests for async payments
                        match prev_type {
                                Some(prev) if prev >= *typ => return Err(()),
                                _ => {},