Skip to content

Commit 5205616

Browse files
kaloudisclaude
andcommitted
Force full RGS sync when network graph is sparse
If the stored RGS timestamp is non-zero but the network graph has fewer than 1000 channels, force a full sync from timestamp 0. This handles cases where the graph failed to persist (e.g., VSS size limits) but the smaller node_metrics (containing the RGS timestamp) was saved successfully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e5adf05 commit 5205616

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/builder.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::liquidity::{
6464
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LSPS7ClientConfig,
6565
LiquiditySourceBuilder,
6666
};
67-
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
67+
use crate::logger::{log_error, log_info, LdkLogger, LogLevel, LogWriter, Logger};
6868
use crate::message_handler::NodeCustomMessageHandler;
6969
use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox;
7070
use crate::peer_store::PeerStore;
@@ -1525,8 +1525,25 @@ fn build_with_store_internal(
15251525
p2p_source
15261526
},
15271527
GossipSourceConfig::RapidGossipSync(rgs_server) => {
1528-
let latest_sync_timestamp =
1528+
let stored_timestamp =
15291529
node_metrics.read().unwrap().latest_rgs_snapshot_timestamp.unwrap_or(0);
1530+
let graph_channel_count = network_graph.read_only().channels().len();
1531+
1532+
// If the graph is sparse but we have a stored timestamp, force a full sync
1533+
// from timestamp 0. This handles cases where the graph failed to persist
1534+
// (e.g., VSS size limits) but the RGS timestamp was saved successfully.
1535+
let latest_sync_timestamp = if stored_timestamp > 0 && graph_channel_count < 1000 {
1536+
log_info!(
1537+
logger,
1538+
"Network graph has only {} channels but RGS timestamp is {}. Forcing full RGS sync.",
1539+
graph_channel_count,
1540+
stored_timestamp
1541+
);
1542+
0
1543+
} else {
1544+
stored_timestamp
1545+
};
1546+
15301547
Arc::new(GossipSource::new_rgs(
15311548
rgs_server.clone(),
15321549
latest_sync_timestamp,

0 commit comments

Comments
 (0)