From c4f3e2567bfe9d1793a29610d21be020dca348aa Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 29 Aug 2024 15:37:24 -0400 Subject: [PATCH] Don't trigger manager persistence on unexpected release_htlc message. 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 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 3278b8ec2..90d896edd 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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 -- 2.39.5