Просмотр исходного кода

event_graph: fixes a bug due to how message subscription is handled between dag_sync and event_handle_put that triggers "peer replied with wrong event" when a valid event is replied from a peer

 - when events are requested during dag_sync there are two subscribers for EventRep message, one is the one in dag_sync the other one is in EventGraph,
   so _trigger_all in message dispatcher sends EventRep to all subscribers, thus the subscriber for EventRep in EventGraph will have messages queued
   when event_handle_put starts executing, thus when requesting for missing_parents events in handle_event_put, it will get the queued EventRep
   from dag_sync and it will result in "replied with wrong event" error
 - the fix is to clean the message subscription queue before starting handling the new message in event_handle_put
oars 10 месяцев назад
Родитель
Сommit
6079b19cd0
2 измененных файлов с 6 добавлено и 0 удалено
  1. 3 0
      src/event_graph/mod.rs
  2. 3 0
      src/event_graph/proto.rs

+ 3 - 0
src/event_graph/mod.rs

@@ -1401,6 +1401,7 @@ async fn request_header(
         return Err(Error::EventNotFound("Peer didn't reply with headers in time".to_owned()));
         return Err(Error::EventNotFound("Peer didn't reply with headers in time".to_owned()));
     };
     };
 
 
+    hdr_rep_sub.unsubscribe().await;
     let peer_headers = &peer_headers.0;
     let peer_headers = &peer_headers.0;
     Ok(peer_headers.to_vec())
     Ok(peer_headers.to_vec())
 }
 }
@@ -1462,5 +1463,7 @@ async fn request_event(
         );
         );
     };
     };
 
 
+    ev_rep_sub.unsubscribe().await;
+
     (Ok(event.0.clone()), chunk_id, peer)
     (Ok(event.0.clone()), chunk_id, peer)
 }
 }

+ 3 - 0
src/event_graph/proto.rs

@@ -413,6 +413,9 @@ impl ProtocolEventGraph {
                 continue
                 continue
             }
             }
 
 
+            // Remove lingering messages from dag_sync event request response
+            _ = self.ev_rep_sub.clean().await;
+
             // If we have already seen the event, we'll stay quiet.
             // If we have already seen the event, we'll stay quiet.
             let current_genesis = self.event_graph.current_genesis.read().await;
             let current_genesis = self.event_graph.current_genesis.read().await;
             let genesis_timestamp = current_genesis.header.timestamp;
             let genesis_timestamp = current_genesis.header.timestamp;