]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Extract snapshot reminder inclusion check method.
authorArik Sosman <git@arik.io>
Tue, 2 Jul 2024 07:29:00 +0000 (00:29 -0700)
committerArik Sosman <git@arik.io>
Wed, 18 Sep 2024 17:07:23 +0000 (10:07 -0700)
We will need to determine whether or not a snapshot should include
reminders for both channel and node update messages. To prepare for
that, we extract the decision logic into its own method.

src/lookup.rs

index 209e5ec1956837183d56358128c6b27ba66a2b18..026bdeb34974bd7a8bfeb0bb7477112534ddd5bd 100644 (file)
@@ -112,6 +112,24 @@ impl Default for DirectedUpdateDelta {
        }
 }
 
+fn should_snapshot_include_reminders<L: Deref>(last_sync_timestamp: u32, current_timestamp: u64, logger: &L) -> bool where L::Target: Logger {
+       let current_hour = current_timestamp / 3600;
+       let current_day = current_timestamp / (24 * 3600);
+
+       log_debug!(logger, "Current day index: {}", current_day);
+       log_debug!(logger, "Current hour: {}", current_hour);
+
+       // every 5th day at midnight
+       let is_reminder_hour = (current_hour % 24) == 0;
+       let is_reminder_day = (current_day % 5) == 0;
+
+       let snapshot_scope = current_timestamp.saturating_sub(last_sync_timestamp as u64);
+       let is_reminder_scope = snapshot_scope > (50 * 3600);
+       log_debug!(logger, "Snapshot scope: {}s", snapshot_scope);
+
+       (is_reminder_hour && is_reminder_day) || is_reminder_scope
+}
+
 /// Fetch all the channel announcements that are presently in the network graph, regardless of
 /// whether they had been seen before.
 /// Also include all announcements for which the first update was announced
@@ -135,23 +153,7 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
        let current_timestamp = snapshot_reference_timestamp.unwrap_or(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs());
        log_info!(logger, "Current timestamp: {}", current_timestamp);
 
-       let include_reminders = {
-               let current_hour = current_timestamp / 3600;
-               let current_day = current_timestamp / (24 * 3600);
-
-               log_debug!(logger, "Current day index: {}", current_day);
-               log_debug!(logger, "Current hour: {}", current_hour);
-
-               // every 5th day at midnight
-               let is_reminder_hour = (current_hour % 24) == 0;
-               let is_reminder_day = (current_day % 5) == 0;
-
-               let snapshot_scope = current_timestamp.saturating_sub(last_sync_timestamp as u64);
-               let is_reminder_scope = snapshot_scope > (50 * 3600);
-               log_debug!(logger, "Snapshot scope: {}s", snapshot_scope);
-
-               (is_reminder_hour && is_reminder_day) || is_reminder_scope
-       };
+       let include_reminders = should_snapshot_include_reminders(last_sync_timestamp, current_timestamp, &logger);
 
        log_info!(logger, "Obtaining corresponding database entries");
        // get all the channel announcements that are currently in the network graph