]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Don't trigger manager persistence on unexpected release_htlc message.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 29 Aug 2024 19:37:24 +0000 (15:37 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 13 Sep 2024 14:40:06 +0000 (10:40 -0400)
If someone sends us an unexpected or duplicate release_held_htlc onion message,
we should simply ignore it and not persist the entire ChannelManager in
response.

lightning/src/ln/channelmanager.rs

index 3278b8ec2a07ba1a1c2a0f3d2a7c57fa43966c29..90d896eddf0f615a452ab01017bd106986c53a02 100644 (file)
@@ -4392,14 +4392,26 @@ where
                &self, payment_id: PaymentId, payment_release_secret: [u8; 32]
        ) -> Result<(), Bolt12PaymentError> {
                let best_block_height = self.best_block.read().unwrap().height;
-               let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
-               self.pending_outbound_payments
-                       .send_payment_for_static_invoice(
+               let mut res = Ok(());
+               PersistenceNotifierGuard::optionally_notify(self, || {
+                       let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
                                payment_id, payment_release_secret, &self.router, self.list_usable_channels(),
                                || self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
                                &self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
                                |args| self.send_payment_along_path(args)
-                       )
+                       );
+                       match outbound_pmts_res {
+                               Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => {
+                                       res = outbound_pmts_res.map(|_| ());
+                                       NotifyOption::SkipPersistNoEvents
+                               },
+                               other_res => {
+                                       res = other_res;
+                                       NotifyOption::DoPersist
+                               }
+                       }
+               });
+               res
        }
 
        /// Signals that no further attempts for the given payment should occur. Useful if you have a