Prune stale channels from network graph after RGS sync

This commit is contained in:
benthecarman 2023-04-06 10:10:14 -05:00
parent 8fcbe64128
commit cff1b4bce3
No known key found for this signature in database
GPG key ID: D7CC770B81FD22A8
2 changed files with 36 additions and 3 deletions

View file

@ -1429,8 +1429,8 @@ mod tests {
]; ];
$nodes[0].rapid_gossip_sync.update_network_graph_no_std(&initialization_input[..], Some(1642291930)).unwrap(); $nodes[0].rapid_gossip_sync.update_network_graph_no_std(&initialization_input[..], Some(1642291930)).unwrap();
// this should have added two channels // this should have added two channels and pruned the previous one.
assert_eq!($nodes[0].network_graph.read_only().channels().len(), 3); assert_eq!($nodes[0].network_graph.read_only().channels().len(), 2);
$receive.expect("Network graph not pruned within deadline"); $receive.expect("Network graph not pruned within deadline");

View file

@ -237,6 +237,11 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
} }
self.network_graph.set_last_rapid_gossip_sync_timestamp(latest_seen_timestamp); self.network_graph.set_last_rapid_gossip_sync_timestamp(latest_seen_timestamp);
if let Some(time) = current_time_unix {
self.network_graph.remove_stale_channels_and_tracking_with_time(time)
}
self.is_initial_sync_complete.store(true, Ordering::Release); self.is_initial_sync_complete.store(true, Ordering::Release);
log_trace!(self.logger, "Done processing RGS data from {}", latest_seen_timestamp); log_trace!(self.logger, "Done processing RGS data from {}", latest_seen_timestamp);
Ok(latest_seen_timestamp) Ok(latest_seen_timestamp)
@ -554,6 +559,34 @@ mod tests {
assert_eq!(network_graph.read_only().channels().len(), 2); assert_eq!(network_graph.read_only().channels().len(), 2);
} }
#[test]
fn prunes_after_update() {
// this is the timestamp encoded in the binary data of valid_input below
let logger = TestLogger::new();
let latest_nonpruning_time = VALID_BINARY_TIMESTAMP + 60 * 60 * 24 * 7;
{
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
assert_eq!(network_graph.read_only().channels().len(), 0);
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_nonpruning_time));
assert!(update_result.is_ok());
assert_eq!(network_graph.read_only().channels().len(), 2);
}
{
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
assert_eq!(network_graph.read_only().channels().len(), 0);
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_nonpruning_time + 1));
assert!(update_result.is_ok());
assert_eq!(network_graph.read_only().channels().len(), 0);
}
}
#[test] #[test]
fn timestamp_edge_cases_are_handled_correctly() { fn timestamp_edge_cases_are_handled_correctly() {
// this is the timestamp encoded in the binary data of valid_input below // this is the timestamp encoded in the binary data of valid_input below
@ -569,7 +602,7 @@ mod tests {
let rapid_sync = RapidGossipSync::new(&network_graph, &logger); let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_succeeding_time)); let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_succeeding_time));
assert!(update_result.is_ok()); assert!(update_result.is_ok());
assert_eq!(network_graph.read_only().channels().len(), 2); assert_eq!(network_graph.read_only().channels().len(), 0);
} }
{ {