Skip to content

Commit 3fd1855

Browse files
committed
Skip unnecessary persists in process_pending_htlc_forwards
We skip repersisting `ChannelManager` when nothing is actually processed.
1 parent 68c39ac commit 3fd1855

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6341,7 +6341,7 @@ where
63416341

63426342
// Returns whether or not we need to re-persist.
63436343
fn internal_process_pending_htlc_forwards(&self) -> NotifyOption {
6344-
let should_persist = NotifyOption::DoPersist;
6344+
let mut should_persist = NotifyOption::SkipPersistNoEvents;
63456345
self.process_pending_update_add_htlcs();
63466346

63476347
let mut new_events = VecDeque::new();
@@ -6351,6 +6351,7 @@ where
63516351
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
63526352

63536353
for (short_chan_id, mut pending_forwards) in forward_htlcs {
6354+
should_persist = NotifyOption::DoPersist;
63546355
if short_chan_id != 0 {
63556356
self.process_forward_htlcs(
63566357
short_chan_id,
@@ -6368,7 +6369,7 @@ where
63686369
}
63696370

63706371
let best_block_height = self.best_block.read().unwrap().height;
6371-
self.pending_outbound_payments.check_retry_payments(
6372+
let needs_persist = self.pending_outbound_payments.check_retry_payments(
63726373
&self.router,
63736374
|| self.list_usable_channels(),
63746375
|| self.compute_inflight_htlcs(),
@@ -6379,6 +6380,9 @@ where
63796380
&self.logger,
63806381
|args| self.send_payment_along_path(args),
63816382
);
6383+
if needs_persist {
6384+
should_persist = NotifyOption::DoPersist;
6385+
}
63826386

63836387
for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
63846388
self.fail_htlc_backwards_internal(
@@ -6394,13 +6398,17 @@ where
63946398
// next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
63956399
// nice to do the work now if we can rather than while we're trying to get messages in the
63966400
// network stack.
6397-
self.check_free_holding_cells();
6401+
if self.check_free_holding_cells() {
6402+
should_persist = NotifyOption::DoPersist;
6403+
}
63986404

63996405
if new_events.is_empty() {
64006406
return should_persist;
64016407
}
64026408
let mut events = self.pending_events.lock().unwrap();
64036409
events.append(&mut new_events);
6410+
should_persist = NotifyOption::DoPersist;
6411+
64046412
should_persist
64056413
}
64066414

lightning/src/ln/outbound_payment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,14 @@ impl OutboundPayments {
12261226
)
12271227
}
12281228

1229+
// Returns whether the data changed and needs to be repersisted.
12291230
pub(super) fn check_retry_payments<R: Deref, ES: Deref, NS: Deref, SP, IH, FH, L: Deref>(
12301231
&self, router: &R, first_hops: FH, inflight_htlcs: IH, entropy_source: &ES,
12311232
node_signer: &NS, best_block_height: u32,
12321233
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
12331234
logger: &L, send_payment_along_path: SP,
1234-
) where
1235+
) -> bool
1236+
where
12351237
R::Target: Router,
12361238
ES::Target: EntropySource,
12371239
NS::Target: NodeSigner,
@@ -1241,6 +1243,7 @@ impl OutboundPayments {
12411243
L::Target: Logger,
12421244
{
12431245
let _single_thread = self.retry_lock.lock().unwrap();
1246+
let mut should_persist = false;
12441247
loop {
12451248
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
12461249
let mut retry_id_route_params = None;
@@ -1288,7 +1291,8 @@ impl OutboundPayments {
12881291
logger,
12891292
pending_events,
12901293
&send_payment_along_path,
1291-
)
1294+
);
1295+
should_persist = true;
12921296
} else {
12931297
break;
12941298
}
@@ -1312,10 +1316,12 @@ impl OutboundPayments {
13121316
None,
13131317
));
13141318
retain = false;
1319+
should_persist = true;
13151320
}
13161321
}
13171322
retain
13181323
});
1324+
should_persist
13191325
}
13201326

13211327
pub(super) fn needs_abandon_or_retry(&self) -> bool {

0 commit comments

Comments
 (0)