Create separate timer for scorer persistence in background processor
authorArik Sosman <git@arik.io>
Wed, 1 Jun 2022 23:25:30 +0000 (16:25 -0700)
committerArik Sosman <git@arik.io>
Thu, 2 Jun 2022 17:14:13 +0000 (10:14 -0700)
lightning-background-processor/src/lib.rs

index 603dc545eb86129946506a0d43c4d0ad02af8101..0fab3e61a4af982fb49f14d89865133af29dad45 100644 (file)
@@ -79,6 +79,11 @@ const PING_TIMER: u64 = 1;
 /// Prune the network graph of stale entries hourly.
 const NETWORK_PRUNE_TIMER: u64 = 60 * 60;
 
+#[cfg(all(not(test), debug_assertions))]
+const SCORER_PERSIST_TIMER: u64 = 30;
+#[cfg(test)]
+const SCORER_PERSIST_TIMER: u64 = 1;
+
 #[cfg(not(test))]
 const FIRST_NETWORK_PRUNE_TIMER: u64 = 60;
 #[cfg(test)]
@@ -214,6 +219,7 @@ impl BackgroundProcessor {
                        let mut last_freshness_call = Instant::now();
                        let mut last_ping_call = Instant::now();
                        let mut last_prune_call = Instant::now();
+                       let mut last_scorer_persist_call = Instant::now();
                        let mut have_pruned = false;
 
                        loop {
@@ -307,12 +313,16 @@ impl BackgroundProcessor {
                                        } else {
                                                log_trace!(logger, "Not pruning network graph, either due to pending rapid gossip sync or absence of a prunable graph.");
                                        }
+                               }
+
+                               if last_scorer_persist_call.elapsed().as_secs() > SCORER_PERSIST_TIMER {
                                        if let Some(ref scorer) = scorer {
                                                log_trace!(logger, "Persisting scorer");
                                                if let Err(e) = persister.persist_scorer(&scorer) {
                                                        log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
                                                }
                                        }
+                                       last_scorer_persist_call = Instant::now();
                                }
                        }