]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Set max path len on receipt of static invoice.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 29 Aug 2024 19:12:41 +0000 (15:12 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 13 Sep 2024 14:40:06 +0000 (10:40 -0400)
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.

lightning/src/ln/channelmanager.rs
lightning/src/ln/outbound_payment.rs

index dbd44ec0db73f89e75c65d0c724440c5c2e37a0a..f5254285516af66bacf22920780f2737aa5049f1 100644 (file)
@@ -4326,9 +4326,11 @@ where
        ) -> Result<(), Bolt12PaymentError> {
                let mut res = Ok(());
                PersistenceNotifierGuard::optionally_notify(self, || {
+                       let best_block_height = self.best_block.read().unwrap().height;
                        let features = self.bolt12_invoice_features();
                        let outbound_pmts_res = self.pending_outbound_payments.static_invoice_received(
-                               invoice, payment_id, features, &*self.entropy_source, &self.pending_events
+                               invoice, payment_id, features, best_block_height, &*self.entropy_source,
+                               &self.pending_events
                        );
                        let payment_release_secret = match outbound_pmts_res {
                                Ok(secret) => secret,
index f6ba4d9f859aebb71ae743c1670432d92212ae9f..e616c445fafc42552540776512eb646e67ceba7e 100644 (file)
@@ -937,7 +937,7 @@ impl OutboundPayments {
        #[cfg(async_payments)]
        pub(super) fn static_invoice_received<ES: Deref>(
                &self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures,
-               entropy_source: ES,
+               best_block_height: u32, entropy_source: ES,
                pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>
        ) -> Result<[u8; 32], Bolt12PaymentError> where ES::Target: EntropySource {
                macro_rules! abandon_with_entry {
@@ -988,6 +988,15 @@ impl OutboundPayments {
                                        let pay_params = PaymentParameters::from_static_invoice(invoice);
                                        let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
                                        route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
+
+                                       if let Err(()) = onion_utils::set_max_path_length(
+                                               &mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage),
+                                               best_block_height
+                                       ) {
+                                               abandon_with_entry!(entry, PaymentFailureReason::RouteNotFound);
+                                               return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))
+                                       }
+
                                        *entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived {
                                                payment_hash,
                                                keysend_preimage,