y 2 лет назад
Родитель
Сommit
117b4c6750
2 измененных файлов с 8 добавлено и 7 удалено
  1. 3 2
      src/event_graph/mod.rs
  2. 5 5
      src/event_graph/util.rs

+ 3 - 2
src/event_graph/mod.rs

@@ -32,9 +32,10 @@ use smol::{
 };
 
 use crate::{
+    event_graph::util::seconds_until_next_rotation,
     net::P2pPtr,
     system::{sleep, timeout::timeout, StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr},
-    Error, Result, event_graph::util::seconds_until_next_rotation,
+    Error, Result,
 };
 
 /// An event graph event
@@ -460,7 +461,7 @@ impl EventGraph {
 
             // Sleep until it's time to rotate.
             let s = seconds_until_next_rotation(next_rotation);
-            
+
             debug!(target: "event_graph::dag_prune_task()", "Sleeping {}s until next DAG prune", s);
             sleep(s).await;
             debug!(target: "event_graph::dag_prune_task()", "Rotation period reached");

+ 5 - 5
src/event_graph/util.rs

@@ -67,10 +67,10 @@ pub(super) fn next_rotation_timestamp(starting_timestamp: u64, rotation_period:
         (rotations_since_start * rotation_period - days_passed).try_into().unwrap();
 
     // Get the timestamp for the next rotation
-    if days_until_next_rotation == 0 { 
+    if days_until_next_rotation == 0 {
         // If there are 0 days until the next rotation, we want
         // to rotate tomorrow, at midnight. This is a special case.
-        return midnight_timestamp(1);
+        return midnight_timestamp(1)
     }
     midnight_timestamp(days_until_next_rotation)
 }
@@ -80,7 +80,7 @@ pub(super) fn next_rotation_timestamp(starting_timestamp: u64, rotation_period:
 /// `next_rotation` here represents a timestamp in UNIX epoch format.
 pub(super) fn seconds_until_next_rotation(next_rotation: u64) -> u64 {
     // Store `now` in a variable in order to avoid a TOCTOU error.
-    // There may be a drift of one second between this panic check and 
+    // There may be a drift of one second between this panic check and
     // the return value if we get unlucky.
     let now = UNIX_EPOCH.elapsed().unwrap().as_secs();
     if next_rotation < now {
@@ -114,7 +114,7 @@ mod tests {
         let expected = midnight_timestamp(4);
         assert_eq!(next_rotation_timestamp(starting_point, rotation_period), expected);
 
-        // When starting from today with a rotation period of 1 (day), 
+        // When starting from today with a rotation period of 1 (day),
         // we should get tomorrow's timestamp.
         // This is a special case.
         let midnight_today: u64 = midnight_timestamp(0);
@@ -140,7 +140,7 @@ mod tests {
         // The amount of time in seconds between rotations.
         let rotation_interval = days_rotation * 86400u64;
         let next_rotation_timestamp = next_rotation_timestamp(INITIAL_GENESIS, days_rotation);
-        let s = seconds_until_next_rotation(next_rotation_timestamp); 
+        let s = seconds_until_next_rotation(next_rotation_timestamp);
         assert!(s < rotation_interval);
     }
 }