Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ impl GossipSource {
}
}

pub async fn update_rgs_snapshot(&self) -> Result<u32, Error> {
pub async fn update_rgs_snapshot(&self, do_full_sync: bool) -> Result<u32, Error> {
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(
Expand Down
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<u32, Error> {
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
Expand Down
Loading