|
|
@@ -30,7 +30,7 @@ use darkfi_serial::{async_trait, deserialize_async, SerialDecodable, SerialEncod
|
|
|
use log::{debug, error, trace, warn};
|
|
|
use smol::Executor;
|
|
|
|
|
|
-use super::{Event, EventGraphPtr, NULL_ID};
|
|
|
+use super::{Event, EventGraph, EventGraphPtr, NULL_ID};
|
|
|
use crate::{impl_p2p_message, net::*, system::timeout::timeout, Error, Result};
|
|
|
|
|
|
/// Malicious behaviour threshold. If the threshold is reached, we will
|
|
|
@@ -142,12 +142,20 @@ 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 {
|
|
|
+ // Check if the event is older than the genesis event. If so, we should
|
|
|
+ // not include it in our Dag.
|
|
|
+ // The genesis event marks the last time the Dag has been pruned of old
|
|
|
+ // events. The pruning interval is defined by the days_rotation field
|
|
|
+ // of [`EventGraph`].
|
|
|
+ // TODO it would be better to store/cache this instead of calculating
|
|
|
+ // on every broadcast/relay.
|
|
|
+ let genesis_timestamp =
|
|
|
+ EventGraph::generate_genesis(self.event_graph.days_rotation()).timestamp;
|
|
|
+ if event.timestamp < 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
|
|
|
+ event.id(), event.timestamp, genesis_timestamp
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -362,6 +370,22 @@ impl ProtocolEventGraph {
|
|
|
let event = self.event_graph.dag.get(event_id.as_bytes()).unwrap().unwrap();
|
|
|
let event: Event = deserialize_async(&event).await.unwrap();
|
|
|
|
|
|
+ // Check if the event is older than the genesis event. If so, something
|
|
|
+ // has gone wrong. The event should have been pruned during the last
|
|
|
+ // rotation.
|
|
|
+ // TODO it would be better to store/cache this instead of calculating
|
|
|
+ // on every broadcast/relay.
|
|
|
+ let genesis_timestamp =
|
|
|
+ EventGraph::generate_genesis(self.event_graph.days_rotation()).timestamp;
|
|
|
+ if event.timestamp < genesis_timestamp {
|
|
|
+ error!(
|
|
|
+ target: "event_graph::protocol::handle_event_req()",
|
|
|
+ "Requested event {} is older than previous rotation period. It should have been pruned.
|
|
|
+ Event timestamp: `{}`. Genesis timestamp: `{}`",
|
|
|
+ event.id(), event.timestamp, genesis_timestamp
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
// Now let's get the upper level of event IDs. When we reply, we could
|
|
|
// get requests for those IDs as well.
|
|
|
let mut bcast_ids = self.event_graph.broadcasted_ids.write().await;
|