|
@@ -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();
|