Skip to content

Commit dca3ac9

Browse files
Factor invreq into payment path len limiting.
1 parent f48a024 commit dca3ac9

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lightning/src/ln/onion_utils.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ pub(crate) const MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY: u64 = 100_000_000;
320320

321321
pub(crate) fn set_max_path_length(
322322
route_params: &mut RouteParameters, recipient_onion: &RecipientOnionFields,
323-
keysend_preimage: Option<PaymentPreimage>, best_block_height: u32,
323+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
324+
best_block_height: u32,
324325
) -> Result<(), ()> {
325326
const PAYLOAD_HMAC_LEN: usize = 32;
326327
let unblinded_intermed_payload_len = msgs::OutboundOnionPayload::Forward {
@@ -368,7 +369,7 @@ pub(crate) fn set_max_path_length(
368369
&recipient_onion,
369370
best_block_height,
370371
&keysend_preimage,
371-
None,
372+
invoice_request,
372373
|_, payload| {
373374
num_reserved_bytes = num_reserved_bytes
374375
.saturating_add(payload.serialized_length())

lightning/src/ln/outbound_payment.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ impl OutboundPayments {
872872
payment_params, amount_msat
873873
);
874874
onion_utils::set_max_path_length(
875-
&mut route_params, &RecipientOnionFields::spontaneous_empty(), None, best_block_height
875+
&mut route_params, &RecipientOnionFields::spontaneous_empty(), None, None, best_block_height
876876
).map_err(|()| Bolt12PaymentError::OnionPacketSizeExceeded)?;
877877

878878
if let Some(max_fee_msat) = max_total_routing_fee_msat {
@@ -939,13 +939,19 @@ impl OutboundPayments {
939939
{
940940
let (payment_hash, route_params) =
941941
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
942-
hash_map::Entry::Occupied(entry) => match entry.get() {
942+
hash_map::Entry::Occupied(mut entry) => match entry.get_mut() {
943943
PendingOutboundPayment::StaticInvoiceReceived {
944-
payment_hash, payment_release_secret: release_secret, route_params, ..
944+
payment_hash, keysend_preimage, payment_release_secret: release_secret, invoice_request,
945+
ref mut route_params, ..
945946
} => {
946947
if payment_release_secret != *release_secret {
947948
return Err(Bolt12PaymentError::UnexpectedInvoice)
948949
}
950+
onion_utils::set_max_path_length(
951+
route_params, &RecipientOnionFields::spontaneous_empty(),
952+
Some(*keysend_preimage), Some(invoice_request), best_block_height
953+
).map_err(|()| Bolt12PaymentError::OnionPacketSizeExceeded)?;
954+
949955
(*payment_hash, route_params.clone())
950956
},
951957
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
@@ -1055,7 +1061,7 @@ impl OutboundPayments {
10551061
}
10561062

10571063
onion_utils::set_max_path_length(
1058-
&mut route_params, &recipient_onion, keysend_preimage, best_block_height
1064+
&mut route_params, &recipient_onion, keysend_preimage, None, best_block_height
10591065
)
10601066
.map_err(|()| {
10611067
log_error!(logger, "Can't construct an onion packet without exceeding 1300-byte onion \

lightning/src/routing/router.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,9 @@ impl RouteParameters {
643643
&mut self, recipient_onion: &RecipientOnionFields, is_keysend: bool, best_block_height: u32
644644
) -> Result<(), ()> {
645645
let keysend_preimage_opt = is_keysend.then(|| PaymentPreimage([42; 32]));
646+
// TODO: no way to account for the invoice request here yet
646647
onion_utils::set_max_path_length(
647-
self, recipient_onion, keysend_preimage_opt, best_block_height
648+
self, recipient_onion, keysend_preimage_opt, None, best_block_height
648649
)
649650
}
650651
}

0 commit comments

Comments
 (0)