Skip to content

Commit a46b685

Browse files
Factor invreq into payment path len limiting.
1 parent e4572c3 commit a46b685

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 {
@@ -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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -982,26 +982,29 @@ impl OutboundPayments {
982982
IH: Fn() -> InFlightHtlcs,
983983
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
984984
{
985-
let (payment_hash, keysend_preimage, mut route_params) =
985+
let (payment_hash, route_params) =
986986
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
987-
hash_map::Entry::Occupied(entry) => match entry.get() {
987+
hash_map::Entry::Occupied(mut entry) => match entry.get_mut() {
988988
PendingOutboundPayment::StaticInvoiceReceived {
989-
payment_hash, payment_release_secret: release_secret, keysend_preimage, route_params, ..
989+
payment_hash, payment_release_secret: release_secret, keysend_preimage, invoice_request,
990+
route_params, ..
990991
} => {
991992
if payment_release_secret != *release_secret {
992993
return Err(Bolt12PaymentError::UnexpectedInvoice)
993994
}
994-
(*payment_hash, *keysend_preimage, route_params.clone())
995+
996+
onion_utils::set_max_path_length(
997+
route_params, &RecipientOnionFields::spontaneous_empty(),
998+
Some(*keysend_preimage), Some(invoice_request), best_block_height
999+
).map_err(|()| Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))?;
1000+
1001+
(*payment_hash, route_params.clone())
9951002
},
9961003
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
9971004
},
9981005
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
9991006
};
10001007

1001-
onion_utils::set_max_path_length(
1002-
&mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage), best_block_height
1003-
).map_err(|()| Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))?;
1004-
10051008
self.find_route_and_send_payment(
10061009
payment_hash, payment_id, route_params, router, first_hops, &inflight_htlcs,
10071010
entropy_source, node_signer, best_block_height, logger, pending_events,
@@ -1096,7 +1099,7 @@ impl OutboundPayments {
10961099
}
10971100

10981101
onion_utils::set_max_path_length(
1099-
route_params, recipient_onion, keysend_preimage, best_block_height
1102+
route_params, recipient_onion, keysend_preimage, None, best_block_height
11001103
).map_err(|()| RetryableSendFailure::OnionPacketSizeExceeded)?;
11011104

11021105
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
@@ -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)