@@ -6124,7 +6124,8 @@ where
6124
6124
Ok(())
6125
6125
}
6126
6126
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;
6128
6129
let mut decode_update_add_htlcs = new_hash_map();
6129
6130
mem::swap(&mut decode_update_add_htlcs, &mut self.decode_update_add_htlcs.lock().unwrap());
6130
6131
@@ -6147,6 +6148,8 @@ where
6147
6148
};
6148
6149
6149
6150
'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;
6150
6153
let incoming_channel_details_opt =
6151
6154
self.do_funded_channel_callback(incoming_scid, |chan: &mut FundedChannel<SP>| {
6152
6155
let counterparty_node_id = chan.context.get_counterparty_node_id();
@@ -6310,6 +6313,7 @@ where
6310
6313
));
6311
6314
}
6312
6315
}
6316
+ should_persist
6313
6317
}
6314
6318
6315
6319
/// Returns whether we have pending HTLC forwards that need to be processed via
@@ -6341,8 +6345,11 @@ where
6341
6345
6342
6346
// Returns whether or not we need to re-persist.
6343
6347
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
+ }
6346
6353
6347
6354
let mut new_events = VecDeque::new();
6348
6355
let mut failed_forwards = Vec::new();
@@ -6351,6 +6358,7 @@ where
6351
6358
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
6352
6359
6353
6360
for (short_chan_id, mut pending_forwards) in forward_htlcs {
6361
+ should_persist = NotifyOption::DoPersist;
6354
6362
if short_chan_id != 0 {
6355
6363
self.process_forward_htlcs(
6356
6364
short_chan_id,
@@ -6368,7 +6376,7 @@ where
6368
6376
}
6369
6377
6370
6378
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(
6372
6380
&self.router,
6373
6381
|| self.list_usable_channels(),
6374
6382
|| self.compute_inflight_htlcs(),
@@ -6379,6 +6387,9 @@ where
6379
6387
&self.logger,
6380
6388
|args| self.send_payment_along_path(args),
6381
6389
);
6390
+ if needs_persist {
6391
+ should_persist = NotifyOption::DoPersist;
6392
+ }
6382
6393
6383
6394
for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
6384
6395
self.fail_htlc_backwards_internal(
@@ -6394,13 +6405,17 @@ where
6394
6405
// next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
6395
6406
// nice to do the work now if we can rather than while we're trying to get messages in the
6396
6407
// network stack.
6397
- self.check_free_holding_cells();
6408
+ if self.check_free_holding_cells() {
6409
+ should_persist = NotifyOption::DoPersist;
6410
+ }
6398
6411
6399
6412
if new_events.is_empty() {
6400
6413
return should_persist;
6401
6414
}
6402
6415
let mut events = self.pending_events.lock().unwrap();
6403
6416
events.append(&mut new_events);
6417
+ should_persist = NotifyOption::DoPersist;
6418
+
6404
6419
should_persist
6405
6420
}
6406
6421
0 commit comments