ソースを参照

src/event_graph: aquire locks outside loops

Dastan-glitch 2 年 前
コミット
d3be6c2819
2 ファイル変更8 行追加8 行削除
  1. 0 1
      src/event_graph/mod.rs
  2. 8 7
      src/event_graph/proto.rs

+ 0 - 1
src/event_graph/mod.rs

@@ -401,7 +401,6 @@ impl EventGraph {
                 );
                 return Err(Error::DagSyncFailed)
             }
-            // }
         } // <-- while !missing_parents.is_empty
 
         // At this point we should've got all the events.

+ 8 - 7
src/event_graph/proto.rs

@@ -416,8 +416,10 @@ impl ProtocolEventGraph {
             // Check if the incoming event is older than the genesis event. If so, something
             // has gone wrong. The event should have been pruned during the last
             // rotation.
-            for event in events.clone() {
-                let genesis_timestamp = self.event_graph.current_genesis.read().await.timestamp;
+            let genesis_timestamp = self.event_graph.current_genesis.read().await.timestamp;
+            let mut bcast_ids = self.event_graph.broadcasted_ids.write().await;
+
+            for event in events.iter() {
                 if event.timestamp < genesis_timestamp {
                     error!(
                         target: "event_graph::protocol::handle_event_req()",
@@ -429,17 +431,16 @@ impl ProtocolEventGraph {
 
                 // 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;
                 for parent_id in event.parents.iter() {
                     if parent_id != &NULL_ID {
                         bcast_ids.insert(*parent_id);
                     }
                 }
-                // TODO: We should remove the reply from the bcast IDs for this specific channel.
-                //       We can't remove them for everyone.
-                //bcast_ids.remove(&event_id);
-                drop(bcast_ids);
             }
+            // TODO: We should remove the reply from the bcast IDs for this specific channel.
+            //       We can't remove them for everyone.
+            //bcast_ids.remove(&event_id);
+            drop(bcast_ids);
 
             // Reply with the event
             self.channel.send(&EventRep(events)).await?;