Skip to content

Commit 82ad53c

Browse files
Bubble up invreq from htlc onion to forwarding flow
As part of receiving an async payment, we need to verify the sender's original invoice request. Therefore, add support for parsing the invreq contained in the onion and storing it in PendingHTLCForwards to prepare for when we add this verification in an upcoming commit. The invreq also needs to be bubbled up for inclusion in the PaymentClaimable event's PaymentPurpose.
1 parent 6448a0d commit 82ad53c

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lightning/src/ln/channelmanager.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ pub enum PendingHTLCRouting {
240240
/// [`PaymentSecret`] and should verify it using our
241241
/// [`NodeSigner::get_inbound_payment_key`].
242242
has_recipient_created_payment_secret: bool,
243+
/// The [`InvoiceRequest`] associated with the [`Offer`] corresponding to this payment.
244+
invoice_request: Option<InvoiceRequest>,
243245
/// The context of the payment included by the recipient in a blinded path, or `None` if a
244246
/// blinded path was not used.
245247
///
@@ -6045,7 +6047,7 @@ where
60456047
let blinded_failure = routing.blinded_failure();
60466048
let (
60476049
cltv_expiry, onion_payload, payment_data, payment_context, phantom_shared_secret,
6048-
mut onion_fields, has_recipient_created_payment_secret
6050+
mut onion_fields, has_recipient_created_payment_secret, _invoice_request_opt
60496051
) = match routing {
60506052
PendingHTLCRouting::Receive {
60516053
payment_data, payment_metadata, payment_context,
@@ -6057,12 +6059,12 @@ where
60576059
payment_metadata, custom_tlvs };
60586060
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data },
60596061
Some(payment_data), payment_context, phantom_shared_secret, onion_fields,
6060-
true)
6062+
true, None)
60616063
},
60626064
PendingHTLCRouting::ReceiveKeysend {
60636065
payment_data, payment_preimage, payment_metadata,
60646066
incoming_cltv_expiry, custom_tlvs, requires_blinded_error: _,
6065-
has_recipient_created_payment_secret, payment_context,
6067+
has_recipient_created_payment_secret, payment_context, invoice_request,
60666068
} => {
60676069
let onion_fields = RecipientOnionFields {
60686070
payment_secret: payment_data.as_ref().map(|data| data.payment_secret),
@@ -6071,7 +6073,7 @@ where
60716073
};
60726074
(incoming_cltv_expiry, OnionPayload::Spontaneous(payment_preimage),
60736075
payment_data, payment_context, None, onion_fields,
6074-
has_recipient_created_payment_secret)
6076+
has_recipient_created_payment_secret, invoice_request)
60756077
},
60766078
_ => {
60776079
panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
@@ -12411,6 +12413,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1241112413
(5, custom_tlvs, optional_vec),
1241212414
(7, has_recipient_created_payment_secret, (default_value, false)),
1241312415
(9, payment_context, option),
12416+
(11, invoice_request, option),
1241412417
},
1241512418
);
1241612419

lightning/src/ln/msgs.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::ln::types::ChannelId;
3737
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
3838
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
3939
use crate::ln::onion_utils;
40+
use crate::offers::invoice_request::InvoiceRequest;
4041
use crate::onion_message;
4142
use crate::sign::{NodeSigner, Recipient};
4243

@@ -1791,6 +1792,7 @@ mod fuzzy_internal_msgs {
17911792
payment_context: PaymentContext,
17921793
intro_node_blinding_point: Option<PublicKey>,
17931794
keysend_preimage: Option<PaymentPreimage>,
1795+
invoice_request: Option<InvoiceRequest>,
17941796
custom_tlvs: Vec<(u64, Vec<u8>)>,
17951797
}
17961798
}
@@ -2852,6 +2854,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
28522854
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
28532855
let mut total_msat = None;
28542856
let mut keysend_preimage: Option<PaymentPreimage> = None;
2857+
let mut invoice_request: Option<InvoiceRequest> = None;
28552858
let mut custom_tlvs = Vec::new();
28562859

28572860
let tlv_len = BigSize::read(r)?;
@@ -2865,6 +2868,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
28652868
(12, intro_node_blinding_point, option),
28662869
(16, payment_metadata, option),
28672870
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
2871+
(77_777, invoice_request, option),
28682872
// See https://github.com/lightning/blips/blob/master/blip-0003.md
28692873
(5482373484, keysend_preimage, option)
28702874
}, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> {
@@ -2895,7 +2899,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
28952899
short_channel_id, payment_relay, payment_constraints, features, next_blinding_override
28962900
})} => {
28972901
if amt.is_some() || cltv_value.is_some() || total_msat.is_some() ||
2898-
keysend_preimage.is_some()
2902+
keysend_preimage.is_some() || invoice_request.is_some()
28992903
{
29002904
return Err(DecodeError::InvalidValue)
29012905
}
@@ -2928,21 +2932,22 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29282932
payment_context,
29292933
intro_node_blinding_point,
29302934
keysend_preimage,
2935+
invoice_request,
29312936
custom_tlvs,
29322937
})
29332938
},
29342939
}
29352940
} else if let Some(short_channel_id) = short_id {
29362941
if payment_data.is_some() || payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
2937-
total_msat.is_some()
2942+
total_msat.is_some() || invoice_request.is_some()
29382943
{ return Err(DecodeError::InvalidValue) }
29392944
Ok(Self::Forward {
29402945
short_channel_id,
29412946
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
29422947
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
29432948
})
29442949
} else {
2945-
if encrypted_tlvs_opt.is_some() || total_msat.is_some() {
2950+
if encrypted_tlvs_opt.is_some() || total_msat.is_some() || invoice_request.is_some() {
29462951
return Err(DecodeError::InvalidValue)
29472952
}
29482953
if let Some(data) = &payment_data {

lightning/src/ln/onion_payment.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ pub(super) fn create_recv_pending_htlc_info(
136136
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
137137
let (
138138
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry,
139-
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret
139+
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret,
140+
invoice_request
140141
) = match hop_data {
141142
msgs::InboundOnionPayload::Receive {
142143
payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
143144
cltv_expiry_height, payment_metadata, ..
144145
} =>
145146
(payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
146-
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none()),
147+
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none(), None),
147148
msgs::InboundOnionPayload::BlindedReceive {
148149
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret,
149150
intro_node_blinding_point, payment_constraints, payment_context, keysend_preimage,
150-
custom_tlvs
151+
custom_tlvs, invoice_request
151152
} => {
152153
check_blinded_payment_constraints(
153154
sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints
@@ -162,7 +163,7 @@ pub(super) fn create_recv_pending_htlc_info(
162163
let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat };
163164
(Some(payment_data), keysend_preimage, custom_tlvs,
164165
sender_intended_htlc_amt_msat, cltv_expiry_height, None, Some(payment_context),
165-
intro_node_blinding_point.is_none(), true)
166+
intro_node_blinding_point.is_none(), true, invoice_request)
166167
}
167168
msgs::InboundOnionPayload::Forward { .. } => {
168169
return Err(InboundHTLCErr {
@@ -237,6 +238,7 @@ pub(super) fn create_recv_pending_htlc_info(
237238
requires_blinded_error,
238239
has_recipient_created_payment_secret,
239240
payment_context,
241+
invoice_request,
240242
}
241243
} else if let Some(data) = payment_data {
242244
PendingHTLCRouting::Receive {

0 commit comments

Comments
 (0)