Skip to content

Commit 1b2f65d

Browse files
committed
Respond to comments
1 parent 8cdac12 commit 1b2f65d

File tree

2 files changed

+28
-12
lines changed
  • lightning-background-processor/src
  • lightning-rapid-gossip-sync/src

2 files changed

+28
-12
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,28 +288,36 @@ impl BackgroundProcessor {
288288
// pruning their network graph. We run once 60 seconds after startup before
289289
// continuing our normal cadence.
290290
if last_prune_call.elapsed().as_secs() > if have_pruned { NETWORK_PRUNE_TIMER } else { FIRST_NETWORK_PRUNE_TIMER } {
291-
if let Some(ref handler) = net_graph_msg_handler {
292-
log_trace!(logger, "Assessing prunability of network graph");
293291

294-
// The network graph must not be pruned while rapid sync completion is pending
295-
let should_prune = match rapid_gossip_sync.as_ref(){
296-
Some(rapid_sync) => rapid_sync.is_initial_sync_complete(),
297-
None => true
292+
// The network graph must not be pruned while rapid sync completion is pending
293+
log_trace!(logger, "Assessing prunability of network graph");
294+
let should_prune = match rapid_gossip_sync.as_ref(){
295+
Some(rapid_sync) => rapid_sync.is_initial_sync_complete(),
296+
None => true
297+
};
298+
299+
if should_prune {
300+
log_trace!(logger, "Pruning network graph of stale entries");
301+
let network_graph_optional = if let Some(ref handler) = net_graph_msg_handler {
302+
Some(handler.network_graph())
303+
} else if let Some(ref rapid_sync) = rapid_gossip_sync {
304+
Some(rapid_sync.network_graph())
305+
} else {
306+
None
298307
};
299308

300-
if should_prune {
301-
log_trace!(logger, "Pruning network graph of stale entries");
302-
handler.network_graph().remove_stale_channels();
309+
if let Some(network_graph_reference) = network_graph_optional {
310+
network_graph_reference.remove_stale_channels();
303311

304-
if let Err(e) = persister.persist_graph(handler.network_graph()) {
312+
if let Err(e) = persister.persist_graph(network_graph_reference) {
305313
log_error!(logger, "Error: Failed to persist network graph, check your disk and permissions {}", e)
306314
}
307315

308316
last_prune_call = Instant::now();
309317
have_pruned = true;
310-
} else {
311-
log_trace!(logger, "Not pruning network graph due to pending gossip sync");
312318
}
319+
} else {
320+
log_trace!(logger, "Not pruning network graph due to pending gossip sync");
313321
}
314322
}
315323

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ impl<NG: Deref<Target=NetworkGraph>> RapidGossipSync<NG> {
105105
self.update_network_graph_from_byte_stream(&mut file)
106106
}
107107

108+
/// Gets a reference to the underlying [`NetworkGraph`] which was provided in
109+
/// [`RapidGossipSync::new`].
110+
///
111+
/// (C-not exported) as bindings don't support a reference-to-a-reference yet
112+
pub fn network_graph(&self) -> &NG {
113+
&self.network_graph
114+
}
115+
108116
/// Returns whether a rapid gossip sync has completed at least once
109117
pub fn is_initial_sync_complete(&self) -> bool {
110118
self.is_initial_sync_complete.load(Ordering::Acquire)

0 commit comments

Comments
 (0)