Просмотр исходного кода

event_graph: fix events validation with days_rotation set to zero

dasman 2 лет назад
Родитель
Сommit
95e7a53094
1 измененных файлов с 12 добавлено и 12 удалено
  1. 12 12
      src/event_graph/util.rs

+ 12 - 12
src/event_graph/util.rs

@@ -94,18 +94,18 @@ pub(super) fn seconds_until_next_rotation(next_rotation: u64) -> u64 {
 /// Generate a deterministic genesis event corresponding to the DAG's configuration.
 /// Generate a deterministic genesis event corresponding to the DAG's configuration.
 pub(super) fn generate_genesis(days_rotation: u64) -> Event {
 pub(super) fn generate_genesis(days_rotation: u64) -> Event {
     // Days rotation is u64 except zero
     // Days rotation is u64 except zero
-    let genesis_days_rotation = if days_rotation == 0 { 1 } else { days_rotation };
-
-    // First check how many days passed since initial genesis.
-    let days_passed = days_since(INITIAL_GENESIS);
-
-    // Calculate the number of days_rotation intervals since INITIAL_GENESIS
-    let rotations_since_genesis = days_passed / genesis_days_rotation;
-
-    // Calculate the timestamp of the most recent event
-    let timestamp =
-        INITIAL_GENESIS + (rotations_since_genesis * genesis_days_rotation * DAY as u64);
-
+    let timestamp = if days_rotation == 0 {
+        INITIAL_GENESIS
+    } else {
+        // First check how many days passed since initial genesis.
+        let days_passed = days_since(INITIAL_GENESIS);
+
+        // Calculate the number of days_rotation intervals since INITIAL_GENESIS
+        let rotations_since_genesis = days_passed / days_rotation;
+
+        // Calculate the timestamp of the most recent event
+        INITIAL_GENESIS + (rotations_since_genesis * days_rotation * DAY as u64)
+    };
     Event {
     Event {
         timestamp,
         timestamp,
         content: GENESIS_CONTENTS.to_vec(),
         content: GENESIS_CONTENTS.to_vec(),