Skip to content

Commit 48d57cf

Browse files
committed
Skip unnecessary persists in process_pending_htlc_forwards
We skip repersisting `ChannelManager` when nothing is actually processed.
1 parent a248a70 commit 48d57cf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,7 +6338,7 @@ where
63386338
/// Will regularly be called by the background processor.
63396339
pub fn process_pending_htlc_forwards(&self) {
63406340
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
6341-
let should_persist = NotifyOption::DoPersist;
6341+
let mut should_persist = NotifyOption::SkipPersistNoEvents;
63426342
self.process_pending_update_add_htlcs();
63436343

63446344
let mut new_events = VecDeque::new();
@@ -6349,6 +6349,7 @@ where
63496349
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
63506350

63516351
for (short_chan_id, mut pending_forwards) in forward_htlcs {
6352+
should_persist = NotifyOption::DoPersist;
63526353
if short_chan_id != 0 {
63536354
let mut forwarding_counterparty = None;
63546355
macro_rules! forwarding_channel_not_found {
@@ -7163,11 +7164,14 @@ where
71637164
// next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
71647165
// nice to do the work now if we can rather than while we're trying to get messages in the
71657166
// network stack.
7166-
self.check_free_holding_cells();
7167+
if self.check_free_holding_cells() {
7168+
should_persist = NotifyOption::DoPersist;
7169+
}
71677170

71687171
if !new_events.is_empty() {
71697172
let mut events = self.pending_events.lock().unwrap();
71707173
events.append(&mut new_events);
7174+
should_persist = NotifyOption::DoPersist;
71717175
}
71727176
should_persist
71737177
});

lightning/src/ln/outbound_payment.rs

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

1229+
// Returns whether the data changed and needs to be repersisted.
12291230
#[rustfmt::skip]
12301231
pub(super) fn check_retry_payments<R: Deref, ES: Deref, NS: Deref, SP, IH, FH, L: Deref>(
12311232
&self, router: &R, first_hops: FH, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
12321233
best_block_height: u32,
12331234
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, logger: &L,
12341235
send_payment_along_path: SP,
1235-
)
1236+
) -> bool
12361237
where
12371238
R::Target: Router,
12381239
ES::Target: EntropySource,
@@ -1243,6 +1244,7 @@ impl OutboundPayments {
12431244
L::Target: Logger,
12441245
{
12451246
let _single_thread = self.retry_lock.lock().unwrap();
1247+
let mut should_persist = false;
12461248
loop {
12471249
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
12481250
let mut retry_id_route_params = None;
@@ -1262,7 +1264,8 @@ impl OutboundPayments {
12621264
}
12631265
core::mem::drop(outbounds);
12641266
if let Some((payment_hash, payment_id, route_params)) = retry_id_route_params {
1265-
self.find_route_and_send_payment(payment_hash, payment_id, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path)
1267+
self.find_route_and_send_payment(payment_hash, payment_id, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path);
1268+
should_persist = true;
12661269
} else { break }
12671270
}
12681271

@@ -1278,10 +1281,12 @@ impl OutboundPayments {
12781281
reason: *reason,
12791282
}, None));
12801283
retain = false;
1284+
should_persist = true;
12811285
}
12821286
}
12831287
retain
12841288
});
1289+
should_persist
12851290
}
12861291

12871292
#[rustfmt::skip]

0 commit comments

Comments
 (0)