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

[net] Add debug messages when receiving old Events

Added debug statements when an EventPut occurs for an event with
a timestamp that is older than the Genesis event of the EventGraph.

Ideally this shouldn't happen but could theoretically occur if a node
does not properly prune its DAG.

In order to do this, `genesis` and `days_rotation` were added as fields
to EventGraph and 'getter' methods were added to retrieve these values.
y 2 лет назад
Родитель
Сommit
c7727c8633
2 измененных файлов с 22 добавлено и 3 удалено
  1. 14 3
      src/event_graph/mod.rs
  2. 8 0
      src/event_graph/proto.rs

+ 14 - 3
src/event_graph/mod.rs

@@ -88,6 +88,8 @@ pub struct EventGraph {
     /// Event subscriber, this notifies whenever an event is
     /// Event subscriber, this notifies whenever an event is
     /// inserted into the DAG
     /// inserted into the DAG
     pub event_sub: SubscriberPtr<Event>,
     pub event_sub: SubscriberPtr<Event>,
+    days_rotation: u64,
+    genesis: Event,
 }
 }
 
 
 impl EventGraph {
 impl EventGraph {
@@ -105,6 +107,8 @@ impl EventGraph {
         let broadcasted_ids = RwLock::new(HashSet::new());
         let broadcasted_ids = RwLock::new(HashSet::new());
         let event_sub = Subscriber::new();
         let event_sub = Subscriber::new();
 
 
+        // Create the current genesis event based on the `days_rotation`
+        let current_genesis = Self::generate_genesis(days_rotation);
         let self_ = Arc::new(Self {
         let self_ = Arc::new(Self {
             p2p,
             p2p,
             dag: dag.clone(),
             dag: dag.clone(),
@@ -112,11 +116,10 @@ impl EventGraph {
             broadcasted_ids,
             broadcasted_ids,
             prune_task: OnceCell::new(),
             prune_task: OnceCell::new(),
             event_sub,
             event_sub,
+            days_rotation,
+            genesis: current_genesis.clone(),
         });
         });
 
 
-        // Create the current genesis event based on the `days_rotation`
-        let current_genesis = Self::generate_genesis(days_rotation);
-
         // Check if we have it in our DAG.
         // Check if we have it in our DAG.
         // If not, we can prune the DAG and insert this new genesis event.
         // If not, we can prune the DAG and insert this new genesis event.
         if !dag.contains_key(current_genesis.id().as_bytes())? {
         if !dag.contains_key(current_genesis.id().as_bytes())? {
@@ -149,6 +152,14 @@ impl EventGraph {
         Ok(self_)
         Ok(self_)
     }
     }
 
 
+    pub fn days_rotation(&self) -> u64 {
+        self.days_rotation
+    }
+
+    pub fn genesis(&self) -> Event {
+        self.genesis.clone()
+    }
+
     async fn _handle_stop(&self, sled_db: sled::Db) {
     async fn _handle_stop(&self, sled_db: sled::Db) {
         info!(target: "event_graph::_handle_stop()", "[EVENTGRAPH] Prune task stopped, flushing sled");
         info!(target: "event_graph::_handle_stop()", "[EVENTGRAPH] Prune task stopped, flushing sled");
         sled_db.flush_async().await.unwrap();
         sled_db.flush_async().await.unwrap();

+ 8 - 0
src/event_graph/proto.rs

@@ -142,6 +142,14 @@ impl ProtocolEventGraph {
                  target: "event_graph::protocol::handle_event_put()",
                  target: "event_graph::protocol::handle_event_put()",
                  "Got EventPut: {} [{}]", event.id(), self.channel.address(),
                  "Got EventPut: {} [{}]", event.id(), self.channel.address(),
             );
             );
+            // Check if event is older than the previous rotation period
+            if event.timestamp < self.event_graph.genesis().timestamp {
+                debug!(
+                    target: "event_graph::protocol::handle_event_put()",
+                    "Event {} is older than genesis. Event timestamp: `{}`. Genesis timestamp: `{}`",
+                event.id(), event.timestamp, self.event_graph.genesis().timestamp
+                );
+            }
 
 
             // We received an event. Check if we already have it in our DAG.
             // We received an event. Check if we already have it in our DAG.
             // Also check if we have the event's parents. In the case we do
             // Also check if we have the event's parents. In the case we do