Skip to content

Commit bace469

Browse files
Factor invreq into payment path len limiting.
1 parent f3e23c1 commit bace469

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 3 additions & 2 deletions
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 {
@@ -367,7 +368,7 @@ pub(crate) fn set_max_path_length(
367368
&recipient_onion,
368369
best_block_height,
369370
&keysend_preimage,
370-
None,
371+
invoice_request,
371372
|_, payload| {
372373
num_reserved_bytes = num_reserved_bytes
373374
.saturating_add(payload.serialized_length())

lightning/src/ln/outbound_payment.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -992,26 +992,29 @@ impl OutboundPayments {
992992
IH: Fn() -> InFlightHtlcs,
993993
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
994994
{
995-
let (payment_hash, keysend_preimage, mut route_params) =
995+
let (payment_hash, route_params) =
996996
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
997-
hash_map::Entry::Occupied(entry) => match entry.get() {
997+
hash_map::Entry::Occupied(mut entry) => match entry.get_mut() {
998998
PendingOutboundPayment::StaticInvoiceReceived {
999-
payment_hash, payment_release_secret: release_secret, keysend_preimage, route_params, ..
999+
payment_hash, payment_release_secret: release_secret, keysend_preimage, invoice_request,
1000+
route_params, ..
10001001
} => {
10011002
if payment_release_secret != *release_secret {
10021003
return Err(Bolt12PaymentError::UnexpectedInvoice)
10031004
}
1004-
(*payment_hash, *keysend_preimage, route_params.clone())
1005+
1006+
onion_utils::set_max_path_length(
1007+
route_params, &RecipientOnionFields::spontaneous_empty(),
1008+
Some(*keysend_preimage), Some(invoice_request), best_block_height
1009+
).map_err(|()| Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))?;
1010+
1011+
(*payment_hash, route_params.clone())
10051012
},
10061013
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
10071014
},
10081015
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
10091016
};
10101017

1011-
onion_utils::set_max_path_length(
1012-
&mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage), best_block_height
1013-
).map_err(|()| Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))?;
1014-
10151018
self.find_route_and_send_payment(
10161019
payment_hash, payment_id, route_params, router, first_hops, &inflight_htlcs,
10171020
entropy_source, node_signer, best_block_height, logger, pending_events,
@@ -1106,7 +1109,7 @@ impl OutboundPayments {
11061109
}
11071110

11081111
onion_utils::set_max_path_length(
1109-
route_params, recipient_onion, keysend_preimage, best_block_height
1112+
route_params, recipient_onion, keysend_preimage, None, best_block_height
11101113
).map_err(|()| RetryableSendFailure::OnionPacketSizeExceeded)?;
11111114

11121115
let mut route = router.find_route_with_id(

lightning/src/routing/router.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ impl RouteParameters {
641641
&mut self, recipient_onion: &RecipientOnionFields, is_keysend: bool, best_block_height: u32
642642
) -> Result<(), ()> {
643643
let keysend_preimage_opt = is_keysend.then(|| PaymentPreimage([42; 32]));
644+
// TODO: no way to account for the invoice request here yet
644645
onion_utils::set_max_path_length(
645-
self, recipient_onion, keysend_preimage_opt, best_block_height
646+
self, recipient_onion, keysend_preimage_opt, None, best_block_height
646647
)
647648
}
648649
}

0 commit comments

Comments
 (0)