Skip to content

Commit 38a3d7e

Browse files
Support encoding invreqs in outbound onion payloads
Per <lightning/bolts#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.
1 parent 8463b33 commit 38a3d7e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lightning/src/ln/max_payment_path_len_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ fn one_hop_blinded_path_with_custom_tlv() {
184184
encrypted_tlvs: &blinded_path.blinded_hops()[0].encrypted_payload,
185185
intro_node_blinding_point: Some(blinded_path.blinding_point()),
186186
keysend_preimage: None,
187+
invoice_request: None,
187188
custom_tlvs: &Vec::new()
188189
}.serialized_length();
189190
let max_custom_tlv_len = 1300

lightning/src/ln/msgs.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,7 @@ pub struct FinalOnionHopData {
17471747
mod fuzzy_internal_msgs {
17481748
use bitcoin::secp256k1::PublicKey;
17491749
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, PaymentRelay};
1750+
use crate::offers::invoice_request::InvoiceRequest;
17501751
use crate::types::payment::{PaymentPreimage, PaymentSecret};
17511752
use crate::types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
17521753
use super::{FinalOnionHopData, TrampolineOnionPacket};
@@ -1827,6 +1828,7 @@ mod fuzzy_internal_msgs {
18271828
intro_node_blinding_point: Option<PublicKey>, // Set if the introduction node of the blinded path is the final node
18281829
keysend_preimage: Option<PaymentPreimage>,
18291830
custom_tlvs: &'a Vec<(u64, Vec<u8>)>,
1831+
invoice_request: Option<&'a InvoiceRequest>,
18301832
}
18311833
}
18321834

@@ -2760,13 +2762,17 @@ impl<'a> Writeable for OutboundOnionPayload<'a> {
27602762
},
27612763
Self::BlindedReceive {
27622764
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
2763-
intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
2765+
intro_node_blinding_point, keysend_preimage, ref invoice_request, ref custom_tlvs,
27642766
} => {
27652767
// We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
27662768
// to reject any reserved types in the experimental range if new ones are ever
27672769
// standardized.
2770+
let invoice_request_tlv = invoice_request.map(|invreq| (77_777, invreq.encode())); // TODO: update TLV type once the async payments spec is merged
27682771
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
2769-
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
2772+
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter()
2773+
.chain(invoice_request_tlv.iter())
2774+
.chain(keysend_tlv.iter())
2775+
.collect();
27702776
custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
27712777
_encode_varint_length_prefixed_tlv!(w, {
27722778
(2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),

lightning/src/ln/onion_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ where
262262
encrypted_tlvs: &blinded_hop.encrypted_payload,
263263
intro_node_blinding_point: blinding_point.take(),
264264
keysend_preimage: *keysend_preimage,
265+
invoice_request: None,
265266
custom_tlvs: &recipient_onion.custom_tlvs,
266267
},
267268
);

0 commit comments

Comments
 (0)