Skip to content

Commit f299bd3

Browse files
committed
Respond to comments.
1 parent f8580fd commit f299bd3

File tree

1 file changed

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

1 file changed

+13
-11
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use lightning_rapid_gossip_sync::RapidGossipSync;
5858
#[must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown."]
5959
pub struct BackgroundProcessor {
6060
stop_thread: Arc<AtomicBool>,
61-
thread_handle: Option<JoinHandle<Result<(), std::io::Error>>>
61+
thread_handle: Option<JoinHandle<Result<(), std::io::Error>>>,
6262
}
6363

6464
#[cfg(not(test))]
@@ -156,9 +156,10 @@ impl BackgroundProcessor {
156156
///
157157
/// # Rapid Gossip Sync
158158
///
159-
/// If a rapid gossip sync is meant to run at startup, set `await_rapid_gossip_sync_completion`
160-
/// to true to indicate to [`BackgroundProcessor`] not to prune the [`NetworkGraph`] instance
161-
/// until [`rapid_gossip_sync_complete`] is called.
159+
/// If a rapid gossip sync is meant to run at startup, pass an option with a set
160+
/// [`RapidGossipSync`] reference to `rapid_gossip_sync` to indicate to [`BackgroundProcessor`]
161+
/// not to prune the [`NetworkGraph`] instance until the [`RapidGossipSync`] instance
162+
/// completes its first sync.
162163
pub fn start<
163164
'a,
164165
Signer: 'static + Sign,
@@ -186,7 +187,7 @@ impl BackgroundProcessor {
186187
>(
187188
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
188189
net_graph_msg_handler: Option<NG>, peer_manager: PM, logger: L, scorer: Option<S>,
189-
rapid_gossip_sync: Option<Arc<RapidGossipSync<G>>>
190+
rapid_gossip_sync: Option<&RapidGossipSync<G>>
190191
) -> Self
191192
where
192193
CA::Target: 'static + chain::Access,
@@ -289,13 +290,14 @@ impl BackgroundProcessor {
289290
if let Some(ref handler) = net_graph_msg_handler {
290291
log_trace!(logger, "Assessing prunability of network graph");
291292
// The network graph must not be pruned while rapid sync completion is pending
292-
let is_currently_awaiting_graph_sync = !is_initial_sync_complete.load(Ordering::Acquire);
293-
if is_currently_awaiting_graph_sync {
293+
if is_initial_sync_complete.load(Ordering::Acquire) {
294+
log_trace!(logger, "Pruning network graph of stale entries");
295+
handler.network_graph().remove_stale_channels();
296+
} else {
294297
log_trace!(logger, "Not pruning network graph due to pending gossip sync");
295298
continue;
296299
}
297-
log_trace!(logger, "Pruning network graph of stale entries");
298-
handler.network_graph().remove_stale_channels();
300+
299301
if let Err(e) = persister.persist_graph(handler.network_graph()) {
300302
log_error!(logger, "Error: Failed to persist network graph, check your disk and permissions {}", e)
301303
}
@@ -830,7 +832,7 @@ mod tests {
830832
let (sender, receiver) = std::sync::mpsc::sync_channel(1);
831833
let persister = Arc::new(Persister::new(data_dir.clone()).with_graph_persistence_notifier(sender));
832834
let network_graph = nodes[0].network_graph.clone();
833-
let rapid_sync = Arc::new(RapidGossipSync::new(network_graph.clone()));
835+
let rapid_sync = RapidGossipSync::new(network_graph.clone());
834836
let features = ChannelFeatures::empty();
835837
network_graph.add_channel_from_partial_announcement(42, 53, features, nodes[0].node.get_our_node_id(), nodes[1].node.get_our_node_id())
836838
.expect("Failed to update channel from partial announcement");
@@ -839,7 +841,7 @@ mod tests {
839841
assert_eq!(network_graph.read_only().channels().len(), 1);
840842

841843
let event_handler = |_: &_| {};
842-
let background_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), Some(rapid_sync.clone()));
844+
let background_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()), Some(&rapid_sync));
843845

844846
loop {
845847
let log_entries = nodes[0].logger.lines.lock().unwrap();

0 commit comments

Comments
 (0)