const NETWORK_PRUNE_TIMER: u64 = 60 * 60;
#[cfg(not(test))]
-const SCORER_PERSIST_TIMER: u64 = 30;
+const SCORER_PERSIST_TIMER: u64 = 60 * 60;
#[cfg(test)]
const SCORER_PERSIST_TIMER: u64 = 1;
}
}
+/// Updates scorer based on event and returns whether an update occurred so we can decide whether
+/// to persist.
fn update_scorer<'a, S: 'static + Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
scorer: &'a S, event: &Event
-) {
+) -> bool {
let mut score = scorer.lock();
match event {
Event::PaymentPathFailed { ref path, short_channel_id: Some(scid), .. } => {
Event::ProbeFailed { path, short_channel_id: Some(scid), .. } => {
score.probe_failed(path, *scid);
},
- _ => {},
+ _ => return false,
}
+ true
}
macro_rules! define_run_body {
let network_graph = gossip_sync.network_graph();
let event_handler = &event_handler;
let scorer = &scorer;
+ let logger = &logger;
+ let persister = &persister;
async move {
if let Some(network_graph) = network_graph {
handle_network_graph_update(network_graph, &event)
}
if let Some(ref scorer) = scorer {
- update_scorer(scorer, &event);
+ if update_scorer(scorer, &event) {
+ log_trace!(logger, "Persisting scorer after update");
+ if let Err(e) = persister.persist_scorer(&scorer) {
+ log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
+ }
+ }
}
event_handler(event).await;
}
handle_network_graph_update(network_graph, &event)
}
if let Some(ref scorer) = scorer {
- update_scorer(scorer, &event);
+ if update_scorer(scorer, &event) {
+ log_trace!(logger, "Persisting scorer after update");
+ if let Err(e) = persister.persist_scorer(&scorer) {
+ log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
+ }
+ }
}
event_handler.handle_event(event);
};
if !std::thread::panicking() {
bg_processor.stop().unwrap();
}
+
+ let log_entries = nodes[0].logger.lines.lock().unwrap();
+ let expected_log = "Persisting scorer after update".to_string();
+ assert_eq!(*log_entries.get(&("lightning_background_processor".to_string(), expected_log)).unwrap(), 5);
}
#[tokio::test]
let t2 = tokio::spawn(async move {
do_test_payment_path_scoring!(nodes, receiver.recv().await);
exit_sender.send(()).unwrap();
+
+ let log_entries = nodes[0].logger.lines.lock().unwrap();
+ let expected_log = "Persisting scorer after update".to_string();
+ assert_eq!(*log_entries.get(&("lightning_background_processor".to_string(), expected_log)).unwrap(), 5);
});
let (r1, r2) = tokio::join!(t1, t2);