@@ -38,13 +38,14 @@ const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
38
38
const STALE_RGS_UPDATE_AGE_LIMIT_SECS : u64 = 60 * 60 * 24 * 14 ;
39
39
40
40
impl < NG : Deref < Target =NetworkGraph < L > > , L : Deref > RapidGossipSync < NG , L > where L :: Target : Logger {
41
+ #[ cfg( feature = "std" ) ]
41
42
pub ( crate ) fn update_network_graph_from_byte_stream < R : io:: Read > (
42
43
& self ,
43
44
read_cursor : & mut R ,
44
45
) -> Result < u32 , GraphSyncError > {
45
46
#[ allow( unused_mut, unused_assignments) ]
46
47
let mut current_time_unix = None ;
47
- #[ cfg( all ( feature = "std" , not( test) ) ) ]
48
+ #[ cfg( not( test) ) ]
48
49
{
49
50
// Note that many tests rely on being able to set arbitrarily old timestamps, thus we
50
51
// disable this check during tests!
@@ -237,6 +238,11 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
237
238
}
238
239
239
240
self . network_graph . set_last_rapid_gossip_sync_timestamp ( latest_seen_timestamp) ;
241
+
242
+ if let Some ( time) = current_time_unix {
243
+ self . network_graph . remove_stale_channels_and_tracking_with_time ( time)
244
+ }
245
+
240
246
self . is_initial_sync_complete . store ( true , Ordering :: Release ) ;
241
247
log_trace ! ( self . logger, "Done processing RGS data from {}" , latest_seen_timestamp) ;
242
248
Ok ( latest_seen_timestamp)
@@ -247,7 +253,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
247
253
mod tests {
248
254
use bitcoin:: Network ;
249
255
256
+ #[ cfg( feature = "std" ) ]
250
257
use lightning:: ln:: msgs:: DecodeError ;
258
+
251
259
use lightning:: routing:: gossip:: NetworkGraph ;
252
260
use lightning:: util:: test_utils:: TestLogger ;
253
261
@@ -275,6 +283,7 @@ mod tests {
275
283
const VALID_BINARY_TIMESTAMP : u64 = 1642291930 ;
276
284
277
285
#[ test]
286
+ #[ cfg( feature = "std" ) ]
278
287
fn network_graph_fails_to_update_from_clipped_input ( ) {
279
288
let logger = TestLogger :: new ( ) ;
280
289
let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
@@ -306,6 +315,7 @@ mod tests {
306
315
}
307
316
308
317
#[ test]
318
+ #[ cfg( feature = "std" ) ]
309
319
fn incremental_only_update_ignores_missing_channel ( ) {
310
320
let incremental_update_input = vec ! [
311
321
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
@@ -326,6 +336,7 @@ mod tests {
326
336
}
327
337
328
338
#[ test]
339
+ #[ cfg( feature = "std" ) ]
329
340
fn incremental_only_update_fails_without_prior_updates ( ) {
330
341
let announced_update_input = vec ! [
331
342
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
@@ -353,6 +364,7 @@ mod tests {
353
364
}
354
365
355
366
#[ test]
367
+ #[ cfg( feature = "std" ) ]
356
368
fn incremental_only_update_fails_without_prior_same_direction_updates ( ) {
357
369
let initialization_input = vec ! [
358
370
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
@@ -408,6 +420,7 @@ mod tests {
408
420
}
409
421
410
422
#[ test]
423
+ #[ cfg( feature = "std" ) ]
411
424
fn incremental_update_succeeds_with_prior_announcements_and_full_updates ( ) {
412
425
let initialization_input = vec ! [
413
426
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
@@ -467,6 +480,7 @@ mod tests {
467
480
}
468
481
469
482
#[ test]
483
+ #[ cfg( feature = "std" ) ]
470
484
fn update_succeeds_when_duplicate_gossip_is_applied ( ) {
471
485
let initialization_input = vec ! [
472
486
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
@@ -510,6 +524,7 @@ mod tests {
510
524
}
511
525
512
526
#[ test]
527
+ #[ cfg( feature = "std" ) ]
513
528
fn full_update_succeeds ( ) {
514
529
let logger = TestLogger :: new ( ) ;
515
530
let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
@@ -554,6 +569,34 @@ mod tests {
554
569
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
555
570
}
556
571
572
+ #[ test]
573
+ fn prunes_after_update ( ) {
574
+ // this is the timestamp encoded in the binary data of valid_input below
575
+ let logger = TestLogger :: new ( ) ;
576
+
577
+ let latest_nonpruning_time = VALID_BINARY_TIMESTAMP + 60 * 60 * 24 * 7 ;
578
+
579
+ {
580
+ let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
581
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
582
+
583
+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
584
+ let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_nonpruning_time) ) ;
585
+ assert ! ( update_result. is_ok( ) ) ;
586
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
587
+ }
588
+
589
+ {
590
+ let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
591
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
592
+
593
+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
594
+ let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_nonpruning_time + 1 ) ) ;
595
+ assert ! ( update_result. is_ok( ) ) ;
596
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
597
+ }
598
+ }
599
+
557
600
#[ test]
558
601
fn timestamp_edge_cases_are_handled_correctly ( ) {
559
602
// this is the timestamp encoded in the binary data of valid_input below
@@ -569,7 +612,7 @@ mod tests {
569
612
let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
570
613
let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_succeeding_time) ) ;
571
614
assert ! ( update_result. is_ok( ) ) ;
572
- assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
615
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
573
616
}
574
617
575
618
{
@@ -591,6 +634,7 @@ mod tests {
591
634
}
592
635
593
636
#[ test]
637
+ #[ cfg( feature = "std" ) ]
594
638
pub fn update_fails_with_unknown_version ( ) {
595
639
let unknown_version_input = vec ! [
596
640
76 , 68 , 75 , 2 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
0 commit comments