Skip to content

Commit

Permalink
[net] Add debug messages when receiving old Events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
y committed Nov 17, 2023
1 parent 0708f7d commit c7727c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/event_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub struct EventGraph {
/// Event subscriber, this notifies whenever an event is
/// inserted into the DAG
pub event_sub: SubscriberPtr<Event>,
days_rotation: u64,
genesis: Event,
}

impl EventGraph {
Expand All @@ -105,18 +107,19 @@ 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(),
unreferenced_tips,
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())? {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/event_graph/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7727c8

Please sign in to comment.