Skip to content

Commit

Permalink
Support encoding invreqs in outbound onion payloads
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valentinewallace committed Sep 18, 2024
1 parent cdd1298 commit ed2f26e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions lightning/src/ln/max_payment_path_len_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,7 @@ mod fuzzy_internal_msgs {
use crate::blinded_path::payment::{PaymentConstraints, PaymentContext, PaymentRelay};
use crate::ln::types::{PaymentPreimage, PaymentSecret};
use crate::ln::features::BlindedHopFeatures;
use crate::offers::invoice_request::InvoiceRequest;
use super::{FinalOnionHopData, TrampolineOnionPacket};

#[allow(unused_imports)]
Expand Down Expand Up @@ -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>,
}
}

Expand Down Expand Up @@ -2733,13 +2735,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),
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down

0 comments on commit ed2f26e

Please sign in to comment.