diff --git a/src/gossip.rs b/src/gossip.rs index a8a6e3831..ea2364211 100644 --- a/src/gossip.rs +++ b/src/gossip.rs @@ -82,11 +82,15 @@ impl GossipSource { } } - pub async fn update_rgs_snapshot(&self) -> Result { + pub async fn update_rgs_snapshot(&self, do_full_sync: bool) -> Result { match self { Self::P2PNetwork { gossip_sync: _, .. } => Ok(0), Self::RapidGossipSync { gossip_sync, server_url, latest_sync_timestamp, logger } => { - let query_timestamp = latest_sync_timestamp.load(Ordering::Acquire); + let query_timestamp = if do_full_sync { + 0 + } else { + latest_sync_timestamp.load(Ordering::Acquire) + }; let query_url = format!("{}/{}", server_url, query_timestamp); let response = tokio::time::timeout( diff --git a/src/lib.rs b/src/lib.rs index 49e7c7e3a..d4e25d413 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -301,7 +301,7 @@ impl Node { _ = interval.tick() => { let gossip_sync_logger = Arc::clone(&gossip_sync_logger); let now = Instant::now(); - match gossip_source.update_rgs_snapshot().await { + match gossip_source.update_rgs_snapshot(false).await { Ok(updated_timestamp) => { log_trace!( gossip_sync_logger, @@ -1360,6 +1360,24 @@ impl Node { }) } + /// Manually sync the RGS snapshot. + /// + /// If `do_full_sync` is true, the RGS snapshot will be updated from scratch. Otherwise, the + /// snapshot will be updated from the last known sync point. + pub async fn sync_rgs(&self, do_full_sync: bool) -> Result { + let updated_timestamp = self.gossip_source.update_rgs_snapshot(do_full_sync).await?; + + let mut locked_node_metrics = self.node_metrics.write().unwrap(); + locked_node_metrics.latest_rgs_snapshot_timestamp = Some(updated_timestamp); + write_node_metrics( + &*locked_node_metrics, + Arc::clone(&self.kv_store), + Arc::clone(&self.logger), + )?; + + Ok(updated_timestamp) + } + /// Close a previously opened channel. /// /// Will attempt to close a channel coopertively. If this fails, users might need to resort to