Skip to content

Commit 2cf6fc5

Browse files
committed
Create separate timer for scorer persistence in background processor.
1 parent 03a62e2 commit 2cf6fc5

File tree

2 files changed

+22
-13
lines changed
  • lightning-background-processor/src
  • lightning-rapid-gossip-sync/src

2 files changed

+22
-13
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! running properly, and (2) either can or should be run in the background. See docs for
33
//! [`BackgroundProcessor`] for more details on the nitty-gritty.
44
5-
#![deny(broken_intra_doc_links)]
5+
#![deny(rustdoc::broken_intra_doc_links)]
66
#![deny(missing_docs)]
77
#![deny(unsafe_code)]
88

@@ -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 {
@@ -306,15 +312,16 @@ impl BackgroundProcessor {
306312
log_trace!(logger, "Not pruning network graph due to pending gossip sync");
307313
}
308314
}
315+
}
316+
317+
if last_scorer_persist_call.elapsed().as_secs() > SCORER_PERSIST_TIMER {
309318
if let Some(ref scorer) = scorer {
310319
log_trace!(logger, "Persisting scorer");
311320
if let Err(e) = persister.persist_scorer(&scorer) {
312321
log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
313322
}
314323
}
315-
316-
last_prune_call = Instant::now();
317-
have_pruned = true;
324+
last_scorer_persist_call = Instant::now();
318325
}
319326
}
320327

@@ -899,7 +906,7 @@ mod tests {
899906
assert_eq!(network_graph.read_only().channels().len(), 3);
900907

901908
let _ = receiver
902-
.recv_timeout(Duration::from_secs(super::FIRST_NETWORK_PRUNE_TIMER * 2))
909+
.recv_timeout(Duration::from_secs(super::FIRST_NETWORK_PRUNE_TIMER * 5))
903910
.expect("Network graph not pruned within deadline");
904911

905912
background_processor.stop().unwrap();

lightning-rapid-gossip-sync/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ extern crate test;
6060

6161
use std::fs::File;
6262
use std::ops::Deref;
63-
use std::sync::Arc;
6463
use std::sync::atomic::{AtomicBool, Ordering};
6564

6665
use lightning::routing::network_graph::NetworkGraph;
@@ -74,17 +73,20 @@ pub mod error;
7473
pub mod processing;
7574

7675
/// Rapid Gossip Sync holder struct
76+
/// See [module-level documentation] for usage.
77+
///
78+
/// [module-level documentation]: crate
7779
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph>> {
7880
network_graph: NG,
79-
is_initial_sync_complete: Arc<AtomicBool>
81+
is_initial_sync_complete: AtomicBool
8082
}
8183

8284
impl<NG: Deref<Target=NetworkGraph>> RapidGossipSync<NG> {
83-
/// Instantiate a new RapidGossipSync holder
85+
/// Instantiate a new RapidGossipSync instance
8486
pub fn new(network_graph: NG) -> Self {
8587
Self {
8688
network_graph,
87-
is_initial_sync_complete: Arc::new(AtomicBool::new(false))
89+
is_initial_sync_complete: AtomicBool::new(false)
8890
}
8991
}
9092

@@ -103,7 +105,7 @@ impl<NG: Deref<Target=NetworkGraph>> RapidGossipSync<NG> {
103105
self.update_network_graph_from_byte_stream(&mut file)
104106
}
105107

106-
/// Bool indicating whether a rapid gossip sync has completed at least once
108+
/// Returns whether a rapid gossip sync has completed at least once
107109
pub fn is_initial_sync_complete(&self) -> bool {
108110
self.is_initial_sync_complete.load(Ordering::Acquire)
109111
}
@@ -213,12 +215,12 @@ mod tests {
213215

214216
assert_eq!(network_graph.read_only().channels().len(), 0);
215217

216-
let rapid_sync = RapidGossipSync::new(network_graph);
218+
let rapid_sync = RapidGossipSync::new(&network_graph);
217219
let start = std::time::Instant::now();
218220
let sync_result = rapid_sync
219221
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
220222
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
221-
let error_string = format!("Input file lightning-graph-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);
223+
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);
222224
#[cfg(not(require_route_graph_test))]
223225
{
224226
println!("{}", error_string);
@@ -255,7 +257,7 @@ pub mod bench {
255257
let rapid_sync = RapidGossipSync::new(&network_graph);
256258
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
257259
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
258-
let error_string = format!("Input file lightning-graph-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);
260+
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);
259261
#[cfg(not(require_route_graph_test))]
260262
{
261263
println!("{}", error_string);

0 commit comments

Comments
 (0)