Skip to content

Commit

Permalink
Support decoding invreqs in inbound onion payloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Aug 20, 2024
1 parent bace469 commit 6c56443
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs}
use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
use crate::ln::onion_utils;
use crate::offers::invoice_request::InvoiceRequest;
use crate::onion_message;
use crate::sign::{NodeSigner, Recipient};

Expand Down Expand Up @@ -1776,6 +1777,7 @@ mod fuzzy_internal_msgs {
payment_context: PaymentContext,
intro_node_blinding_point: Option<PublicKey>,
keysend_preimage: Option<PaymentPreimage>,
invoice_request: Option<InvoiceRequest>,
custom_tlvs: Vec<(u64, Vec<u8>)>,
}
}
Expand Down Expand Up @@ -2775,6 +2777,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
let mut total_msat = None;
let mut keysend_preimage: Option<PaymentPreimage> = None;
let mut invoice_request: Option<InvoiceRequest> = None;
let mut custom_tlvs = Vec::new();

let tlv_len = BigSize::read(r)?;
Expand All @@ -2788,6 +2791,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
(12, intro_node_blinding_point, option),
(16, payment_metadata, option),
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
(77_777, invoice_request, option),
// See https://github.com/lightning/blips/blob/master/blip-0003.md
(5482373484, keysend_preimage, option)
}, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> {
Expand Down Expand Up @@ -2818,7 +2822,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
short_channel_id, payment_relay, payment_constraints, features, next_blinding_override
})} => {
if amt.is_some() || cltv_value.is_some() || total_msat.is_some() ||
keysend_preimage.is_some()
keysend_preimage.is_some() || invoice_request.is_some()
{
return Err(DecodeError::InvalidValue)
}
Expand All @@ -2844,21 +2848,22 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
payment_context,
intro_node_blinding_point,
keysend_preimage,
invoice_request,
custom_tlvs,
})
},
}
} else if let Some(short_channel_id) = short_id {
if payment_data.is_some() || payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
total_msat.is_some()
total_msat.is_some() || invoice_request.is_some()
{ return Err(DecodeError::InvalidValue) }
Ok(Self::Forward {
short_channel_id,
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
})
} else {
if encrypted_tlvs_opt.is_some() || total_msat.is_some() {
if encrypted_tlvs_opt.is_some() || total_msat.is_some() || invoice_request.is_some() {
return Err(DecodeError::InvalidValue)
}
if let Some(data) = &payment_data {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/onion_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(super) fn create_recv_pending_htlc_info(
msgs::InboundOnionPayload::BlindedReceive {
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret,
intro_node_blinding_point, payment_constraints, payment_context, keysend_preimage,
custom_tlvs
custom_tlvs, invoice_request: _
} => {
check_blinded_payment_constraints(
sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints
Expand Down

0 comments on commit 6c56443

Please sign in to comment.