@@ -40,8 +40,8 @@ use std::ops::Deref;
40
40
/// [`ChannelManager`] persistence should be done in the background.
41
41
/// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`]
42
42
/// at the appropriate intervals.
43
- /// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`GossipSync`] is provided to
44
- /// [`BackgroundProcessor::start`]).
43
+ /// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`GossipSync`] with a [`NetworkGraph`]
44
+ /// is provided to [`BackgroundProcessor::start`]).
45
45
///
46
46
/// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied
47
47
/// upon as doing so may result in high latency.
@@ -102,6 +102,8 @@ where A::Target: chain::Access, L::Target: Logger {
102
102
P2P ( P ) ,
103
103
/// Rapid gossip sync from a trusted server.
104
104
Rapid ( R ) ,
105
+ /// No gossip sync.
106
+ None ,
105
107
}
106
108
107
109
impl <
@@ -112,10 +114,11 @@ impl<
112
114
L : Deref ,
113
115
> GossipSync < P , R , G , A , L >
114
116
where A :: Target : chain:: Access , L :: Target : Logger {
115
- fn network_graph ( & self ) -> & G {
117
+ fn network_graph ( & self ) -> Option < & G > {
116
118
match self {
117
- GossipSync :: P2P ( gossip_sync) => gossip_sync. network_graph ( ) ,
118
- GossipSync :: Rapid ( gossip_sync) => gossip_sync. network_graph ( ) ,
119
+ GossipSync :: P2P ( gossip_sync) => Some ( gossip_sync. network_graph ( ) ) ,
120
+ GossipSync :: Rapid ( gossip_sync) => Some ( gossip_sync. network_graph ( ) ) ,
121
+ GossipSync :: None => None ,
119
122
}
120
123
}
121
124
@@ -129,14 +132,15 @@ where A::Target: chain::Access, L::Target: Logger {
129
132
None
130
133
}
131
134
} ,
135
+ GossipSync :: None => None ,
132
136
}
133
137
}
134
138
}
135
139
136
140
/// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s.
137
141
struct DecoratingEventHandler <
142
+ ' a ,
138
143
E : EventHandler ,
139
- GS : Deref < Target = GossipSync < PGS , RGS , G , A , L > > ,
140
144
PGS : Deref < Target = P2PGossipSync < G , A , L > > ,
141
145
RGS : Deref < Target = RapidGossipSync < G , L > > ,
142
146
G : Deref < Target = NetworkGraph < L > > ,
@@ -145,22 +149,22 @@ struct DecoratingEventHandler<
145
149
>
146
150
where A :: Target : chain:: Access , L :: Target : Logger {
147
151
event_handler : E ,
148
- gossip_sync : Option < GS > ,
152
+ gossip_sync : & ' a GossipSync < PGS , RGS , G , A , L > ,
149
153
}
150
154
151
155
impl <
156
+ ' a ,
152
157
E : EventHandler ,
153
- GS : Deref < Target = GossipSync < PGS , RGS , G , A , L > > ,
154
158
PGS : Deref < Target = P2PGossipSync < G , A , L > > ,
155
159
RGS : Deref < Target = RapidGossipSync < G , L > > ,
156
160
G : Deref < Target = NetworkGraph < L > > ,
157
161
A : Deref ,
158
162
L : Deref ,
159
- > EventHandler for DecoratingEventHandler < E , GS , PGS , RGS , G , A , L >
163
+ > EventHandler for DecoratingEventHandler < ' a , E , PGS , RGS , G , A , L >
160
164
where A :: Target : chain:: Access , L :: Target : Logger {
161
165
fn handle_event ( & self , event : & Event ) {
162
- if let Some ( gossip_sync ) = & self . gossip_sync {
163
- gossip_sync . network_graph ( ) . handle_event ( event) ;
166
+ if let Some ( network_graph ) = self . gossip_sync . network_graph ( ) {
167
+ network_graph. handle_event ( event) ;
164
168
}
165
169
self . event_handler . handle_event ( event) ;
166
170
}
@@ -198,9 +202,9 @@ impl BackgroundProcessor {
198
202
///
199
203
/// # Rapid Gossip Sync
200
204
///
201
- /// If rapid gossip sync is meant to run at startup, pass an optional [`RapidGossipSync`]
202
- /// to `gossip_sync` to indicate that the [`BackgroundProcessor`] should not prune the
203
- /// [`NetworkGraph`] instance until the [`RapidGossipSync`] instance completes its first sync.
205
+ /// If rapid gossip sync is meant to run at startup, pass a [`RapidGossipSync`] to `gossip_sync`
206
+ /// to indicate that the [`BackgroundProcessor`] should not prune the [`NetworkGraph`] instance
207
+ /// until the [`RapidGossipSync`] instance completes its first sync.
204
208
///
205
209
/// [top-level documentation]: BackgroundProcessor
206
210
/// [`join`]: Self::join
@@ -238,8 +242,7 @@ impl BackgroundProcessor {
238
242
SC : WriteableScore < ' a > ,
239
243
> (
240
244
persister : PS , event_handler : EH , chain_monitor : M , channel_manager : CM ,
241
- gossip_sync : Option < GossipSync < PGS , RGS , G , CA , L > > , peer_manager : PM , logger : L ,
242
- scorer : Option < S > ,
245
+ gossip_sync : GossipSync < PGS , RGS , G , CA , L > , peer_manager : PM , logger : L , scorer : Option < S > ,
243
246
) -> Self
244
247
where
245
248
CA :: Target : ' static + chain:: Access ,
@@ -260,7 +263,7 @@ impl BackgroundProcessor {
260
263
let handle = thread:: spawn ( move || -> Result < ( ) , std:: io:: Error > {
261
264
let event_handler = DecoratingEventHandler {
262
265
event_handler,
263
- gossip_sync : gossip_sync. as_ref ( ) ,
266
+ gossip_sync : & gossip_sync,
264
267
} ;
265
268
266
269
log_trace ! ( logger, "Calling ChannelManager's timer_tick_occurred on startup" ) ;
@@ -340,10 +343,7 @@ impl BackgroundProcessor {
340
343
if last_prune_call. elapsed ( ) . as_secs ( ) > if have_pruned { NETWORK_PRUNE_TIMER } else { FIRST_NETWORK_PRUNE_TIMER } {
341
344
// The network graph must not be pruned while rapid sync completion is pending
342
345
log_trace ! ( logger, "Assessing prunability of network graph" ) ;
343
- let graph_to_prune = gossip_sync
344
- . as_ref ( )
345
- . and_then ( |gossip_sync| gossip_sync. prunable_network_graph ( ) ) ;
346
- if let Some ( network_graph) = graph_to_prune {
346
+ if let Some ( network_graph) = gossip_sync. prunable_network_graph ( ) {
347
347
network_graph. remove_stale_channels ( ) ;
348
348
349
349
if let Err ( e) = persister. persist_graph ( network_graph) {
@@ -379,8 +379,8 @@ impl BackgroundProcessor {
379
379
}
380
380
381
381
// Persist NetworkGraph on exit
382
- if let Some ( ref gossip_sync ) = gossip_sync {
383
- persister. persist_graph ( gossip_sync . network_graph ( ) ) ?;
382
+ if let Some ( network_graph ) = gossip_sync. network_graph ( ) {
383
+ persister. persist_graph ( network_graph) ?;
384
384
}
385
385
386
386
Ok ( ( ) )
@@ -500,16 +500,16 @@ mod tests {
500
500
}
501
501
502
502
impl Node {
503
- fn p2p_gossip_sync ( & self ) -> Option < GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > > {
504
- Some ( GossipSync :: P2P ( self . p2p_gossip_sync . clone ( ) ) )
503
+ fn p2p_gossip_sync ( & self ) -> GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > {
504
+ GossipSync :: P2P ( self . p2p_gossip_sync . clone ( ) )
505
505
}
506
506
507
- fn rapid_gossip_sync ( & self ) -> Option < GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > > {
508
- Some ( GossipSync :: Rapid ( self . rapid_gossip_sync . clone ( ) ) )
507
+ fn rapid_gossip_sync ( & self ) -> GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > {
508
+ GossipSync :: Rapid ( self . rapid_gossip_sync . clone ( ) )
509
509
}
510
510
511
- fn no_gossip_sync ( & self ) -> Option < GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > > {
512
- None
511
+ fn no_gossip_sync ( & self ) -> GossipSync < PGS , RGS , Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > {
512
+ GossipSync :: None
513
513
}
514
514
}
515
515
0 commit comments