Skip to content

Commit eed99e2

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 268a710 commit eed99e2

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 4 deletions
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
///
@@ -6011,7 +6013,7 @@ where
60116013
let blinded_failure = routing.blinded_failure();
60126014
let (
60136015
cltv_expiry, onion_payload, payment_data, payment_context, phantom_shared_secret,
6014-
mut onion_fields, has_recipient_created_payment_secret
6016+
mut onion_fields, has_recipient_created_payment_secret, _invoice_request_opt
60156017
) = match routing {
60166018
PendingHTLCRouting::Receive {
60176019
payment_data, payment_metadata, payment_context,
@@ -6023,12 +6025,12 @@ where
60236025
payment_metadata, custom_tlvs };
60246026
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data },
60256027
Some(payment_data), payment_context, phantom_shared_secret, onion_fields,
6026-
true)
6028+
true, None)
60276029
},
60286030
PendingHTLCRouting::ReceiveKeysend {
60296031
payment_data, payment_preimage, payment_metadata,
60306032
incoming_cltv_expiry, custom_tlvs, requires_blinded_error: _,
6031-
has_recipient_created_payment_secret, payment_context,
6033+
has_recipient_created_payment_secret, payment_context, invoice_request,
60326034
} => {
60336035
let onion_fields = RecipientOnionFields {
60346036
payment_secret: payment_data.as_ref().map(|data| data.payment_secret),
@@ -6037,7 +6039,7 @@ where
60376039
};
60386040
(incoming_cltv_expiry, OnionPayload::Spontaneous(payment_preimage),
60396041
payment_data, payment_context, None, onion_fields,
6040-
has_recipient_created_payment_secret)
6042+
has_recipient_created_payment_secret, invoice_request)
60416043
},
60426044
_ => {
60436045
panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
@@ -12429,6 +12431,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1242912431
(5, custom_tlvs, optional_vec),
1243012432
(7, has_recipient_created_payment_secret, (default_value, false)),
1243112433
(9, payment_context, option),
12434+
(11, invoice_request, option),
1243212435
},
1243312436
);
1243412437

lightning/src/ln/msgs.rs

Lines changed: 8 additions & 3 deletions
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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,19 @@ pub(super) fn create_recv_pending_htlc_info(
135135
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
136136
let (
137137
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry,
138-
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret
138+
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret,
139+
invoice_request
139140
) = match hop_data {
140141
msgs::InboundOnionPayload::Receive {
141142
payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
142143
cltv_expiry_height, payment_metadata, ..
143144
} =>
144145
(payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
145-
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none()),
146+
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none(), None),
146147
msgs::InboundOnionPayload::BlindedReceive {
147148
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret,
148149
intro_node_blinding_point, payment_constraints, payment_context, keysend_preimage,
149-
custom_tlvs
150+
custom_tlvs, invoice_request
150151
} => {
151152
check_blinded_payment_constraints(
152153
sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints
@@ -161,7 +162,7 @@ pub(super) fn create_recv_pending_htlc_info(
161162
let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat };
162163
(Some(payment_data), keysend_preimage, custom_tlvs,
163164
sender_intended_htlc_amt_msat, cltv_expiry_height, None, Some(payment_context),
164-
intro_node_blinding_point.is_none(), true)
165+
intro_node_blinding_point.is_none(), true, invoice_request)
165166
}
166167
msgs::InboundOnionPayload::Forward { .. } => {
167168
return Err(InboundHTLCErr {
@@ -236,6 +237,7 @@ pub(super) fn create_recv_pending_htlc_info(
236237
requires_blinded_error,
237238
has_recipient_created_payment_secret,
238239
payment_context,
240+
invoice_request,
239241
}
240242
} else if let Some(data) = payment_data {
241243
PendingHTLCRouting::Receive {

0 commit comments

Comments
 (0)