Skip to content

Commit c65906c

Browse files
Support encoding invreqs in outbound onion payloads.
1 parent 9d71600 commit c65906c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-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: 11 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

@@ -2687,6 +2689,9 @@ impl Readable for FinalOnionHopData {
26872689
}
26882690
}
26892691

2692+
// This TLV type isn't stabilized in the BOLTs.
2693+
const ONION_INVREQ_TLV_TYPE: u64 = 77_777;
2694+
26902695
impl<'a> Writeable for OutboundOnionPayload<'a> {
26912696
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
26922697
match self {
@@ -2733,13 +2738,17 @@ impl<'a> Writeable for OutboundOnionPayload<'a> {
27332738
},
27342739
Self::BlindedReceive {
27352740
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
2736-
intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
2741+
intro_node_blinding_point, keysend_preimage, ref invoice_request, ref custom_tlvs,
27372742
} => {
27382743
// We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
27392744
// to reject any reserved types in the experimental range if new ones are ever
27402745
// standardized.
2746+
let invoice_request_tlv = invoice_request.map(|invreq| (ONION_INVREQ_TLV_TYPE, invreq.encode()));
27412747
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();
2748+
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter()
2749+
.chain(invoice_request_tlv.iter())
2750+
.chain(keysend_tlv.iter())
2751+
.collect();
27432752
custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
27442753
_encode_varint_length_prefixed_tlv!(w, {
27452754
(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)