Skip to content

Commit ed2f26e

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 cdd1298 commit ed2f26e

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ mod fuzzy_internal_msgs {
17491749
use crate::blinded_path::payment::{PaymentConstraints, PaymentContext, PaymentRelay};
17501750
use crate::ln::types::{PaymentPreimage, PaymentSecret};
17511751
use crate::ln::features::BlindedHopFeatures;
1752+
use crate::offers::invoice_request::InvoiceRequest;
17521753
use super::{FinalOnionHopData, TrampolineOnionPacket};
17531754

17541755
#[allow(unused_imports)]
@@ -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

@@ -2733,13 +2735,17 @@ impl<'a> Writeable for OutboundOnionPayload<'a> {
27332735
},
27342736
Self::BlindedReceive {
27352737
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
2736-
intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
2738+
intro_node_blinding_point, keysend_preimage, ref invoice_request, ref custom_tlvs,
27372739
} => {
27382740
// We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
27392741
// to reject any reserved types in the experimental range if new ones are ever
27402742
// standardized.
2743+
let invoice_request_tlv = invoice_request.map(|invreq| (77_777, invreq.encode())); // TODO: update TLV type once the async payments spec is merged
27412744
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
2742-
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
2745+
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter()
2746+
.chain(invoice_request_tlv.iter())
2747+
.chain(keysend_tlv.iter())
2748+
.collect();
27432749
custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
27442750
_encode_varint_length_prefixed_tlv!(w, {
27452751
(2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 0 deletions
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)