@@ -237,6 +237,11 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
237
237
}
238
238
239
239
self . network_graph . set_last_rapid_gossip_sync_timestamp ( latest_seen_timestamp) ;
240
+
241
+ if let Some ( time) = current_time_unix {
242
+ self . network_graph . remove_stale_channels_and_tracking_with_time ( time)
243
+ }
244
+
240
245
self . is_initial_sync_complete . store ( true , Ordering :: Release ) ;
241
246
log_trace ! ( self . logger, "Done processing RGS data from {}" , latest_seen_timestamp) ;
242
247
Ok ( latest_seen_timestamp)
@@ -554,6 +559,34 @@ mod tests {
554
559
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
555
560
}
556
561
562
+ #[ test]
563
+ fn prunes_after_update ( ) {
564
+ // this is the timestamp encoded in the binary data of valid_input below
565
+ let logger = TestLogger :: new ( ) ;
566
+
567
+ let latest_nonpruning_time = VALID_BINARY_TIMESTAMP + 60 * 60 * 24 * 7 ;
568
+
569
+ {
570
+ let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
571
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
572
+
573
+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
574
+ let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_nonpruning_time) ) ;
575
+ assert ! ( update_result. is_ok( ) ) ;
576
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
577
+ }
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 + 1 ) ) ;
585
+ assert ! ( update_result. is_ok( ) ) ;
586
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
587
+ }
588
+ }
589
+
557
590
#[ test]
558
591
fn timestamp_edge_cases_are_handled_correctly ( ) {
559
592
// this is the timestamp encoded in the binary data of valid_input below
@@ -569,7 +602,7 @@ mod tests {
569
602
let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
570
603
let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_succeeding_time) ) ;
571
604
assert ! ( update_result. is_ok( ) ) ;
572
- assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
605
+ assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
573
606
}
574
607
575
608
{
0 commit comments