@@ -58,7 +58,7 @@ use lightning_rapid_gossip_sync::RapidGossipSync;
58
58
#[ must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown." ]
59
59
pub struct BackgroundProcessor {
60
60
stop_thread : Arc < AtomicBool > ,
61
- thread_handle : Option < JoinHandle < Result < ( ) , std:: io:: Error > > >
61
+ thread_handle : Option < JoinHandle < Result < ( ) , std:: io:: Error > > > ,
62
62
}
63
63
64
64
#[ cfg( not( test) ) ]
@@ -156,9 +156,10 @@ impl BackgroundProcessor {
156
156
///
157
157
/// # Rapid Gossip Sync
158
158
///
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.
162
163
pub fn start <
163
164
' a ,
164
165
Signer : ' static + Sign ,
@@ -186,7 +187,7 @@ impl BackgroundProcessor {
186
187
> (
187
188
persister : PS , event_handler : EH , chain_monitor : M , channel_manager : CM ,
188
189
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 > >
190
191
) -> Self
191
192
where
192
193
CA :: Target : ' static + chain:: Access ,
@@ -289,13 +290,14 @@ impl BackgroundProcessor {
289
290
if let Some ( ref handler) = net_graph_msg_handler {
290
291
log_trace ! ( logger, "Assessing prunability of network graph" ) ;
291
292
// 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 {
294
297
log_trace ! ( logger, "Not pruning network graph due to pending gossip sync" ) ;
295
298
continue ;
296
299
}
297
- log_trace ! ( logger, "Pruning network graph of stale entries" ) ;
298
- handler. network_graph ( ) . remove_stale_channels ( ) ;
300
+
299
301
if let Err ( e) = persister. persist_graph ( handler. network_graph ( ) ) {
300
302
log_error ! ( logger, "Error: Failed to persist network graph, check your disk and permissions {}" , e)
301
303
}
@@ -830,7 +832,7 @@ mod tests {
830
832
let ( sender, receiver) = std:: sync:: mpsc:: sync_channel ( 1 ) ;
831
833
let persister = Arc :: new ( Persister :: new ( data_dir. clone ( ) ) . with_graph_persistence_notifier ( sender) ) ;
832
834
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 ( ) ) ;
834
836
let features = ChannelFeatures :: empty ( ) ;
835
837
network_graph. add_channel_from_partial_announcement ( 42 , 53 , features, nodes[ 0 ] . node . get_our_node_id ( ) , nodes[ 1 ] . node . get_our_node_id ( ) )
836
838
. expect ( "Failed to update channel from partial announcement" ) ;
@@ -839,7 +841,7 @@ mod tests {
839
841
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 1 ) ;
840
842
841
843
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) ) ;
843
845
844
846
loop {
845
847
let log_entries = nodes[ 0 ] . logger . lines . lock ( ) . unwrap ( ) ;
0 commit comments