Parcourir la source

script/research/event_graph: little fix in the synchronization process

ghassmo il y a 3 ans
Parent
commit
0a1621f5f5
1 fichiers modifiés avec 18 ajouts et 13 suppressions
  1. 18 13
      script/research/event_graph/main.py

+ 18 - 13
script/research/event_graph/main.py

@@ -185,6 +185,7 @@ class Node:
         # Check if the parents of the orphan
         # Check if the parents of the orphan
         # are not missing from active pool
         # are not missing from active pool
         missing_parents = self.active_pool.check_events(orphan.parents)
         missing_parents = self.active_pool.check_events(orphan.parents)
+        missing_parents = self.check_pruned_events(missing_parents) 
         if missing_parents:
         if missing_parents:
             # Check the missing parents from orphan pool and sync with the
             # Check the missing parents from orphan pool and sync with the
             # network for missing ones
             # network for missing ones
@@ -196,8 +197,7 @@ class Node:
 
 
             # Check again that the parents of the orphan are in the active pool
             # Check again that the parents of the orphan are in the active pool
             missing_parents = self.active_pool.check_events(orphan.parents)
             missing_parents = self.active_pool.check_events(orphan.parents)
-            missing_parents = [p for p in missing_parents if p not in
-                               self.pruned_events]
+            missing_parents = self.check_pruned_events(missing_parents) 
             assert (not missing_parents)
             assert (not missing_parents)
 
 
             # Add the event to active pool
             # Add the event to active pool
@@ -206,7 +206,7 @@ class Node:
             self.add_to_active_pool(orphan)
             self.add_to_active_pool(orphan)
 
 
         # Last stage, Cleaning up the orphan pool:
         # Last stage, Cleaning up the orphan pool:
-        #  - Remove orphan if it is too old according to MAX_TIME_DIFF
+        #  - Remove orphan if it is too old according to `max_time_diff`
         #  - Move orphan to active pool if it doesn't have any missing parents
         #  - Move orphan to active pool if it doesn't have any missing parents
         self.clean_orphan_pool()
         self.clean_orphan_pool()
 
 
@@ -236,14 +236,15 @@ class Node:
         for event in self.active_pool.events.values():
         for event in self.active_pool.events.values():
 
 
             # Check if the event parents are old events
             # Check if the event parents are old events
-            old_parents = [e for e in oe_active_p if e in event.parents]
+            parents = self.check_pruned_events(event.parents) 
 
 
-            if not old_parents:
+            if parents:
                 continue
                 continue
-
+                
             # Add the event to tails if it has only old events as parents
             # Add the event to tails if it has only old events as parents
-            if len(event.parents) == len(old_parents):
-                self.update_tails(event)
+            self.update_tails(event)
+
+
 
 
     def clean_orphan_pool(self):
     def clean_orphan_pool(self):
         debug(f"{self.name} clean_orphan_pool()")
         debug(f"{self.name} clean_orphan_pool()")
@@ -259,6 +260,7 @@ class Node:
                 # Move the orphan to active pool if it doesn't have missing
                 # Move the orphan to active pool if it doesn't have missing
                 # parents in active pool
                 # parents in active pool
                 missing_parents = self.active_pool.check_events(orphan.parents)
                 missing_parents = self.active_pool.check_events(orphan.parents)
+                missing_parents = self.check_pruned_events(missing_parents) 
 
 
                 if not missing_parents:
                 if not missing_parents:
                     active_list.append(orphan)
                     active_list.append(orphan)
@@ -304,11 +306,12 @@ class Node:
                 # Check first if it's not in the active pool
                 # Check first if it's not in the active pool
                 if self.active_pool.events.get(event_hash) != None:
                 if self.active_pool.events.get(event_hash) != None:
                     continue
                     continue
+
+                # Check if it's not in pruned events
                 if event_hash in self.pruned_events:
                 if event_hash in self.pruned_events:
                     continue
                     continue
 
 
                 request_list.append(event_hash)
                 request_list.append(event_hash)
-
             else:
             else:
                 # Recursive call
                 # Recursive call
                 # Climb up for the event parents
                 # Climb up for the event parents
@@ -389,6 +392,10 @@ class Node:
 
 
         return event
         return event
 
 
+    # Clean up the given events from pruned events
+    def check_pruned_events(self, events):
+        return [ev for ev in events if ev not in self.pruned_events]
+
     # Check if the event is too old from now, by subtracting current timestamp
     # Check if the event is too old from now, by subtracting current timestamp
     # from event timestamp, it must be more than `max_time_diff' to be consider
     # from event timestamp, it must be more than `max_time_diff' to be consider
     # old event
     # old event
@@ -455,8 +462,6 @@ Run a simulation with the provided params:
     max_time_diff: a max difference in time to detect an old event 
     max_time_diff: a max difference in time to detect an old event 
     check: check if all nodes have the same graph
     check: check if all nodes have the same graph
 """
 """
-
-
 async def run(nodes_n=3, podm=0.30, broadcast_attempt=3, max_time_diff=180.0,
 async def run(nodes_n=3, podm=0.30, broadcast_attempt=3, max_time_diff=180.0,
               check=False, max_delay=None):
               check=False, max_delay=None):
 
 
@@ -729,8 +734,8 @@ if __name__ == "__main__":
                         handlers=[logging.FileHandler("debug.log", mode="w"),
                         handlers=[logging.FileHandler("debug.log", mode="w"),
                                   logging.StreamHandler()])
                                   logging.StreamHandler()])
 
 
-    # nodes = asyncio.run(run(nodes_n=10, podm=0, broadcast_attempt=4,
-    #                       max_time_diff=30, max_delay=7))
+    # nodes = asyncio.run(run(nodes_n=14, podm=0, broadcast_attempt=4,
+    #                     max_time_diff=30,check=True))
 
 
     # print_network_graph(nodes[0])
     # print_network_graph(nodes[0])
     # print_network_graph(nodes[0], unpruned=True)
     # print_network_graph(nodes[0], unpruned=True)