Skip to content

Commit 2874198

Browse files
committed
Create separate timer for scorer persistence in background processor
1 parent 0d4aa4c commit 2874198

File tree

1 file changed

+13
-4
lines changed
  • lightning-background-processor/src

1 file changed

+13
-4
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ const PING_TIMER: u64 = 1;
7979
/// Prune the network graph of stale entries hourly.
8080
const NETWORK_PRUNE_TIMER: u64 = 60 * 60;
8181

82+
#[cfg(all(not(test), debug_assertions))]
83+
const SCORER_PERSIST_TIMER: u64 = 30;
84+
#[cfg(test)]
85+
const SCORER_PERSIST_TIMER: u64 = 1;
86+
8287
#[cfg(not(test))]
8388
const FIRST_NETWORK_PRUNE_TIMER: u64 = 60;
8489
#[cfg(test)]
@@ -214,6 +219,7 @@ impl BackgroundProcessor {
214219
let mut last_freshness_call = Instant::now();
215220
let mut last_ping_call = Instant::now();
216221
let mut last_prune_call = Instant::now();
222+
let mut last_scorer_persist_call = Instant::now();
217223
let mut have_pruned = false;
218224

219225
loop {
@@ -286,10 +292,9 @@ impl BackgroundProcessor {
286292
log_trace!(logger, "Assessing prunability of network graph");
287293

288294
// The network graph must not be pruned while rapid sync completion is pending
289-
let should_prune = if let Some(rapid_sync) = rapid_gossip_sync.as_ref() {
290-
rapid_sync.is_initial_sync_complete()
291-
} else {
292-
true
295+
let should_prune = match rapid_gossip_sync.as_ref(){
296+
Some(rapid_sync) => { rapid_sync.is_initial_sync_complete() }
297+
None => { true }
293298
};
294299

295300
if should_prune {
@@ -306,12 +311,16 @@ impl BackgroundProcessor {
306311
log_trace!(logger, "Not pruning network graph due to pending gossip sync");
307312
}
308313
}
314+
}
315+
316+
if last_scorer_persist_call.elapsed().as_secs() > SCORER_PERSIST_TIMER {
309317
if let Some(ref scorer) = scorer {
310318
log_trace!(logger, "Persisting scorer");
311319
if let Err(e) = persister.persist_scorer(&scorer) {
312320
log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
313321
}
314322
}
323+
last_scorer_persist_call = Instant::now();
315324
}
316325
}
317326

0 commit comments

Comments
 (0)