Skip to content

Commit 8569830

Browse files
Set max path len on receipt of static invoice.
Because we may receive a static invoice to pay days before the recipient actually comes back online to receive the payment, it's good to do as many checks as we can up-front. Here we ensure that the blinded paths provided in the invoice won't cause us to exceed the maximum onion packet size.
1 parent e4d7681 commit 8569830

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4326,9 +4326,11 @@ where
43264326
) -> Result<(), Bolt12PaymentError> {
43274327
let mut res = Ok(());
43284328
PersistenceNotifierGuard::optionally_notify(self, || {
4329+
let best_block_height = self.best_block.read().unwrap().height;
43294330
let features = self.bolt12_invoice_features();
43304331
let outbound_pmts_res = self.pending_outbound_payments.static_invoice_received(
4331-
invoice, payment_id, features, &*self.entropy_source, &self.pending_events
4332+
invoice, payment_id, features, best_block_height, &*self.entropy_source,
4333+
&self.pending_events
43324334
);
43334335
let payment_release_secret = match outbound_pmts_res {
43344336
Ok(secret) => secret,

lightning/src/ln/outbound_payment.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ impl OutboundPayments {
937937
#[cfg(async_payments)]
938938
pub(super) fn static_invoice_received<ES: Deref>(
939939
&self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures,
940-
entropy_source: ES,
940+
best_block_height: u32, entropy_source: ES,
941941
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>
942942
) -> Result<[u8; 32], Bolt12PaymentError> where ES::Target: EntropySource {
943943
macro_rules! abandon_with_entry {
@@ -988,6 +988,15 @@ impl OutboundPayments {
988988
let pay_params = PaymentParameters::from_static_invoice(invoice);
989989
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
990990
route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
991+
992+
if let Err(()) = onion_utils::set_max_path_length(
993+
&mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage),
994+
best_block_height
995+
) {
996+
abandon_with_entry!(entry, PaymentFailureReason::RouteNotFound);
997+
return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))
998+
}
999+
9911000
*entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived {
9921001
payment_hash,
9931002
keysend_preimage,

0 commit comments

Comments
 (0)