Skip to content

Commit 9affc0c

Browse files
committed
Stop persisting RGS update timestamp separately
Stop persisting the RGS update timestamp separately and read the last applied RGS timestamp from `NetworkGraph` instead. This avoids skipping gossip updates after a crash by making the persisted graph the single source of truth. Co-Authored-By: HAL 9000
1 parent fae2746 commit 9affc0c

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

src/builder.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,22 +1656,11 @@ fn build_with_store_internal(
16561656
Arc::clone(&runtime),
16571657
Arc::clone(&logger),
16581658
));
1659-
1660-
// Reset the RGS sync timestamp in case we somehow switch gossip sources
1661-
{
1662-
let mut locked_node_metrics = node_metrics.write().unwrap();
1663-
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
1664-
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
1665-
.map_err(|e| {
1666-
log_error!(logger, "Failed writing to store: {}", e);
1667-
BuildError::WriteFailed
1668-
})?;
1669-
}
16701659
p2p_source
16711660
},
16721661
GossipSourceConfig::RapidGossipSync(rgs_server) => {
16731662
let latest_sync_timestamp =
1674-
node_metrics.read().unwrap().latest_rgs_snapshot_timestamp.unwrap_or(0);
1663+
network_graph.get_last_rapid_gossip_sync_timestamp().unwrap_or(0);
16751664
Arc::new(GossipSource::new_rgs(
16761665
rgs_server.clone(),
16771666
latest_sync_timestamp,

src/lib.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ impl Node {
293293

294294
if self.gossip_source.is_rgs() {
295295
let gossip_source = Arc::clone(&self.gossip_source);
296-
let gossip_sync_store = Arc::clone(&self.kv_store);
297296
let gossip_sync_logger = Arc::clone(&self.logger);
298-
let gossip_node_metrics = Arc::clone(&self.node_metrics);
299297
let mut stop_gossip_sync = self.stop_sender.subscribe();
300298
self.runtime.spawn_cancellable_background_task(async move {
301299
let mut interval = tokio::time::interval(RGS_SYNC_INTERVAL);
@@ -311,20 +309,12 @@ impl Node {
311309
_ = interval.tick() => {
312310
let now = Instant::now();
313311
match gossip_source.update_rgs_snapshot().await {
314-
Ok(updated_timestamp) => {
312+
Ok(_) => {
315313
log_info!(
316314
gossip_sync_logger,
317315
"Background sync of RGS gossip data finished in {}ms.",
318316
now.elapsed().as_millis()
319317
);
320-
{
321-
let mut locked_node_metrics = gossip_node_metrics.write().unwrap();
322-
locked_node_metrics.latest_rgs_snapshot_timestamp = Some(updated_timestamp);
323-
write_node_metrics(&*locked_node_metrics, &*gossip_sync_store, Arc::clone(&gossip_sync_logger))
324-
.unwrap_or_else(|e| {
325-
log_error!(gossip_sync_logger, "Persistence failed: {}", e);
326-
});
327-
}
328318
}
329319
Err(e) => {
330320
log_error!(
@@ -753,7 +743,7 @@ impl Node {
753743
let latest_fee_rate_cache_update_timestamp =
754744
locked_node_metrics.latest_fee_rate_cache_update_timestamp;
755745
let latest_rgs_snapshot_timestamp =
756-
locked_node_metrics.latest_rgs_snapshot_timestamp.map(|val| val as u64);
746+
self.network_graph.get_last_rapid_gossip_sync_timestamp().map(|val| val as u64);
757747
let latest_pathfinding_scores_sync_timestamp =
758748
locked_node_metrics.latest_pathfinding_scores_sync_timestamp;
759749
let latest_node_announcement_broadcast_timestamp =
@@ -1982,7 +1972,6 @@ pub(crate) struct NodeMetrics {
19821972
latest_lightning_wallet_sync_timestamp: Option<u64>,
19831973
latest_onchain_wallet_sync_timestamp: Option<u64>,
19841974
latest_fee_rate_cache_update_timestamp: Option<u64>,
1985-
latest_rgs_snapshot_timestamp: Option<u32>,
19861975
latest_pathfinding_scores_sync_timestamp: Option<u64>,
19871976
latest_node_announcement_broadcast_timestamp: Option<u64>,
19881977
}
@@ -1993,7 +1982,6 @@ impl Default for NodeMetrics {
19931982
latest_lightning_wallet_sync_timestamp: None,
19941983
latest_onchain_wallet_sync_timestamp: None,
19951984
latest_fee_rate_cache_update_timestamp: None,
1996-
latest_rgs_snapshot_timestamp: None,
19971985
latest_pathfinding_scores_sync_timestamp: None,
19981986
latest_node_announcement_broadcast_timestamp: None,
19991987
}
@@ -2005,7 +1993,8 @@ impl_writeable_tlv_based!(NodeMetrics, {
20051993
(1, latest_pathfinding_scores_sync_timestamp, option),
20061994
(2, latest_onchain_wallet_sync_timestamp, option),
20071995
(4, latest_fee_rate_cache_update_timestamp, option),
2008-
(6, latest_rgs_snapshot_timestamp, option),
1996+
// 6 used to be latest_rgs_snapshot_timestamp
1997+
(6, _legacy_latest_rgs_snapshot_timestamp, (legacy, u32, |_| Ok(()), |_: &NodeMetrics| None::<Option<u32>> )),
20091998
(8, latest_node_announcement_broadcast_timestamp, option),
20101999
// 10 used to be latest_channel_monitor_archival_height
20112000
(10, _legacy_latest_channel_monitor_archival_height, (legacy, u32, |_| Ok(()), |_: &NodeMetrics| None::<Option<u32>> )),

0 commit comments

Comments
 (0)