@@ -6124,7 +6124,8 @@ where
61246124 Ok(())
61256125 }
61266126
6127- pub(crate) fn process_pending_update_add_htlcs(&self) {
6127+ pub(crate) fn process_pending_update_add_htlcs(&self) -> bool {
6128+ let mut should_persist = false;
61286129 let mut decode_update_add_htlcs = new_hash_map();
61296130 mem::swap(&mut decode_update_add_htlcs, &mut self.decode_update_add_htlcs.lock().unwrap());
61306131
@@ -6147,6 +6148,8 @@ where
61476148 };
61486149
61496150 'outer_loop: for (incoming_scid, update_add_htlcs) in decode_update_add_htlcs {
6151+ // If any decoded update_add_htlcs were processed, we need to persist.
6152+ should_persist = true;
61506153 let incoming_channel_details_opt =
61516154 self.do_funded_channel_callback(incoming_scid, |chan: &mut FundedChannel<SP>| {
61526155 let counterparty_node_id = chan.context.get_counterparty_node_id();
@@ -6310,6 +6313,7 @@ where
63106313 ));
63116314 }
63126315 }
6316+ should_persist
63136317 }
63146318
63156319 /// Returns whether we have pending HTLC forwards that need to be processed via
@@ -6341,8 +6345,11 @@ where
63416345
63426346 // Returns whether or not we need to re-persist.
63436347 fn internal_process_pending_htlc_forwards(&self) -> NotifyOption {
6344- let should_persist = NotifyOption::DoPersist;
6345- self.process_pending_update_add_htlcs();
6348+ let mut should_persist = NotifyOption::SkipPersistNoEvents;
6349+
6350+ if self.process_pending_update_add_htlcs() {
6351+ should_persist = NotifyOption::DoPersist;
6352+ }
63466353
63476354 let mut new_events = VecDeque::new();
63486355 let mut failed_forwards = Vec::new();
@@ -6351,6 +6358,7 @@ where
63516358 mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
63526359
63536360 for (short_chan_id, mut pending_forwards) in forward_htlcs {
6361+ should_persist = NotifyOption::DoPersist;
63546362 if short_chan_id != 0 {
63556363 self.process_forward_htlcs(
63566364 short_chan_id,
@@ -6368,7 +6376,7 @@ where
63686376 }
63696377
63706378 let best_block_height = self.best_block.read().unwrap().height;
6371- self.pending_outbound_payments.check_retry_payments(
6379+ let needs_persist = self.pending_outbound_payments.check_retry_payments(
63726380 &self.router,
63736381 || self.list_usable_channels(),
63746382 || self.compute_inflight_htlcs(),
@@ -6379,6 +6387,9 @@ where
63796387 &self.logger,
63806388 |args| self.send_payment_along_path(args),
63816389 );
6390+ if needs_persist {
6391+ should_persist = NotifyOption::DoPersist;
6392+ }
63826393
63836394 for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
63846395 self.fail_htlc_backwards_internal(
@@ -6394,13 +6405,17 @@ where
63946405 // next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
63956406 // nice to do the work now if we can rather than while we're trying to get messages in the
63966407 // network stack.
6397- self.check_free_holding_cells();
6408+ if self.check_free_holding_cells() {
6409+ should_persist = NotifyOption::DoPersist;
6410+ }
63986411
63996412 if new_events.is_empty() {
64006413 return should_persist;
64016414 }
64026415 let mut events = self.pending_events.lock().unwrap();
64036416 events.append(&mut new_events);
6417+ should_persist = NotifyOption::DoPersist;
6418+
64046419 should_persist
64056420 }
64066421
0 commit comments