]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Prune and persist RGS network graph after initial sync
authorAlec Chen <alecchendev@gmail.com>
Mon, 15 May 2023 23:51:05 +0000 (18:51 -0500)
committerAlec Chen <alecchendev@gmail.com>
Mon, 15 May 2023 23:51:08 +0000 (18:51 -0500)
Previously we would wait 60 seconds after startup, however for RGS we
prune/persist after its initial sync since 60 seconds is likely too
long.

lightning-background-processor/src/lib.rs

index 3227b63fdee5d72c30d509c98a945d86a5a5a16e..406c56b25794bbe8e521b2843c0f457bc2e7ab4f 100644 (file)
@@ -351,9 +351,15 @@ macro_rules! define_run_body {
                        // Note that we want to run a graph prune once not long after startup before
                        // falling back to our usual hourly prunes. This avoids short-lived clients never
                        // pruning their network graph. We run once 60 seconds after startup before
-                       // continuing our normal cadence.
+                       // continuing our normal cadence. For RGS, since 60 seconds is likely too long,
+                       // we prune after an initial sync completes.
                        let prune_timer = if have_pruned { NETWORK_PRUNE_TIMER } else { FIRST_NETWORK_PRUNE_TIMER };
-                       if $timer_elapsed(&mut last_prune_call, prune_timer) {
+                       let prune_timer_elapsed = $timer_elapsed(&mut last_prune_call, prune_timer);
+                       let should_prune = match $gossip_sync {
+                               GossipSync::Rapid(_) => !have_pruned || prune_timer_elapsed,
+                               _ => prune_timer_elapsed,
+                       };
+                       if should_prune {
                                // The network graph must not be pruned while rapid sync completion is pending
                                if let Some(network_graph) = $gossip_sync.prunable_network_graph() {
                                        #[cfg(feature = "std")] {