From d3be6c281970b07376e8612c82fa0d87dd43fb23 Mon Sep 17 00:00:00 2001 From: Dastan-glitch Date: Sat, 13 Jan 2024 20:41:17 +0300 Subject: [PATCH] src/event_graph: aquire locks outside loops --- src/event_graph/mod.rs | 1 - src/event_graph/proto.rs | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/event_graph/mod.rs b/src/event_graph/mod.rs index 32c74f305..90b0d6cfa 100644 --- a/src/event_graph/mod.rs +++ b/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. diff --git a/src/event_graph/proto.rs b/src/event_graph/proto.rs index 5d4caf2fb..9d26a1c60 100644 --- a/src/event_graph/proto.rs +++ b/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?;