diff --git a/src/event_graph/mod.rs b/src/event_graph/mod.rs index b97b784ce439..3cc908f48256 100644 --- a/src/event_graph/mod.rs +++ b/src/event_graph/mod.rs @@ -88,6 +88,8 @@ pub struct EventGraph { /// Event subscriber, this notifies whenever an event is /// inserted into the DAG pub event_sub: SubscriberPtr, + days_rotation: u64, + genesis: Event, } impl EventGraph { @@ -105,6 +107,8 @@ impl EventGraph { let broadcasted_ids = RwLock::new(HashSet::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 { p2p, dag: dag.clone(), @@ -112,11 +116,10 @@ impl EventGraph { broadcasted_ids, prune_task: OnceCell::new(), 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. // If not, we can prune the DAG and insert this new genesis event. if !dag.contains_key(current_genesis.id().as_bytes())? { @@ -149,6 +152,14 @@ impl EventGraph { 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) { info!(target: "event_graph::_handle_stop()", "[EVENTGRAPH] Prune task stopped, flushing sled"); sled_db.flush_async().await.unwrap(); diff --git a/src/event_graph/proto.rs b/src/event_graph/proto.rs index a94039a29b4a..7ca87068b3c9 100644 --- a/src/event_graph/proto.rs +++ b/src/event_graph/proto.rs @@ -142,6 +142,14 @@ impl ProtocolEventGraph { target: "event_graph::protocol::handle_event_put()", "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. // Also check if we have the event's parents. In the case we do