summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2022-09-29 02:19:18 -0500
committerEric Eastwood <erice@element.io>2022-09-29 02:25:42 -0500
commit5faebbdfcfe4af14bc41092d2ea9f7a2d2075367 (patch)
tree8cbfaab538f30576bb4daad6270afdaf168ca195
parentWorking once you connect the floating insertion event (diff)
downloadsynapse-5faebbdfcfe4af14bc41092d2ea9f7a2d2075367.tar.xz
Seems to work with Maria
-rw-r--r--synapse/handlers/federation_event.py6
-rw-r--r--synapse/handlers/message.py7
-rw-r--r--tests/handlers/test_federation_event.py94
3 files changed, 86 insertions, 21 deletions
diff --git a/synapse/handlers/federation_event.py b/synapse/handlers/federation_event.py
index 83a438bc7e..c864991bd1 100644
--- a/synapse/handlers/federation_event.py
+++ b/synapse/handlers/federation_event.py
@@ -660,7 +660,7 @@ class FederationEventHandler:
             # thrashing.
             reverse_chronological_events = events
             # `[::-1]` is just syntax to reverse the list and give us a copy
-            # chronological_events = reverse_chronological_events[::-1]
+            chronological_events = reverse_chronological_events[::-1]
 
             logger.info(
                 "backfill assumed reverse_chronological_events=%s",
@@ -716,8 +716,8 @@ class FederationEventHandler:
                 # Expecting to persist in chronological order here (oldest ->
                 # newest) so that events are persisted before they're referenced
                 # as a `prev_event`.
-                # chronological_events,
-                #reverse_chronological_events,
+                chronological_events,
+                # reverse_chronological_events,
                 backfilled=True,
             )
 
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index f2d0c425e6..d53f8dc28d 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -1106,6 +1106,13 @@ class EventCreationHandler:
             depth=depth,
         )
 
+        logger.info(
+            "create_new_client_event(event=%s) state_event_ids=%s resultant auth_event_ids=%s",
+            event.event_id,
+            state_event_ids,
+            auth_event_ids,
+        )
+
         # Pass on the outlier property from the builder to the event
         # after it is created
         if builder.internal_metadata.outlier:
diff --git a/tests/handlers/test_federation_event.py b/tests/handlers/test_federation_event.py
index c1458ab3dd..a0e3fcbe7d 100644
--- a/tests/handlers/test_federation_event.py
+++ b/tests/handlers/test_federation_event.py
@@ -897,11 +897,13 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
             self.assertEqual(destination, self.OTHER_SERVER_NAME)
             known_event_info = known_event_dict.get(event_id)
             if known_event_info is None:
-                self.fail(f"Event ({event_id}) not part of our known events list")
+                self.fail(
+                    f"stubbed get_room_state_ids: Event ({event_id}) not part of our known events list"
+                )
 
             known_event, known_event_state_list = known_event_info
             logger.info(
-                "stubbed get_room_state_ids destination=%s event_id=%s auth_event_ids=%s",
+                "stubbed get_room_state_ids: destination=%s event_id=%s auth_event_ids=%s",
                 destination,
                 event_id,
                 known_event.auth_event_ids(),
@@ -921,11 +923,13 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
             self.assertEqual(destination, self.OTHER_SERVER_NAME)
             known_event_info = known_event_dict.get(event_id)
             if known_event_info is None:
-                self.fail(f"Event ({event_id}) not part of our known events list")
+                self.fail(
+                    f"stubbed get_room_state: Event ({event_id}) not part of our known events list"
+                )
 
             known_event, known_event_state_list = known_event_info
             logger.info(
-                "stubbed get_room_state destination=%s event_id=%s auth_event_ids=%s",
+                "stubbed get_room_state: destination=%s event_id=%s auth_event_ids=%s",
                 destination,
                 event_id,
                 known_event.auth_event_ids(),
@@ -937,7 +941,7 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
                 known_event_info = known_event_dict.get(event_id)
                 if known_event_info is None:
                     self.fail(
-                        f"Auth event ({auth_event_id}) is not part of our known events list"
+                        f"stubbed get_room_state: Auth event ({auth_event_id}) is not part of our known events list"
                     )
                 known_auth_event, _ = known_event_info
                 auth_events.append(known_auth_event)
@@ -947,6 +951,17 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
                 auth_events=auth_events,
             )
 
+        async def get_event(destination: str, event_id: str, timeout=None):
+            self.assertEqual(destination, self.OTHER_SERVER_NAME)
+            known_event_info = known_event_dict.get(event_id)
+            if known_event_info is None:
+                self.fail(
+                    f"stubbed get_event: Event ({event_id}) not part of our known events list"
+                )
+
+            known_event, _ = known_event_info
+            return {"pdus": [known_event.get_pdu_json()]}
+
         self.mock_federation_transport_client.get_room_state_ids.side_effect = (
             get_room_state_ids
         )
@@ -954,6 +969,8 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
             get_room_state
         )
 
+        self.mock_federation_transport_client.get_event.side_effect = get_event
+
         # create the room
         room_creator = self.appservice.sender
         room_id = self.helper.create_room_as(
@@ -997,17 +1014,46 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
         for state_event in state_map.values():
             _add_to_known_event_list(state_event)
 
-        historical_auth_event_ids = [
+        # This should be the successor of the event we want to insert next to
+        # (the successor of event_before is event_after).
+        inherited_depth = event_after.depth
+
+        historical_base_auth_event_ids = [
             room_create_event.event_id,
             pl_event.event_id,
-            as_membership_event.event_id,
         ]
         historical_state_events = list(state_map.values())
         historical_state_event_ids = [
             state_event.event_id for state_event in historical_state_events
         ]
 
-        inherited_depth = event_after.depth
+        maria_mxid = "@maria:test"
+        maria_membership_event, _ = self.get_success(
+            create_event(
+                self.hs,
+                room_id=room_id,
+                sender=maria_mxid,
+                state_key=maria_mxid,
+                type=EventTypes.Member,
+                content={
+                    "membership": "join",
+                },
+                # It all works when I add a prev_event for the floating
+                # insertion event but the event no longer floats.
+                # It's able to resolve state at the prev_events though.
+                # prev_event_ids=[event_before.event_id],
+                allow_no_prev_events=True,
+                prev_event_ids=[],
+                auth_event_ids=historical_base_auth_event_ids,
+                state_event_ids=historical_state_event_ids,
+                depth=inherited_depth,
+            )
+        )
+        _add_to_known_event_list(maria_membership_event, historical_state_events)
+
+        historical_state_events.append(maria_membership_event)
+        historical_state_event_ids.append(maria_membership_event.event_id)
+
         batch_id = random_string(8)
         next_batch_id = random_string(8)
         insertion_event, _ = self.get_success(
@@ -1020,13 +1066,16 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
                     EventContentFields.MSC2716_NEXT_BATCH_ID: next_batch_id,
                     EventContentFields.MSC2716_HISTORICAL: True,
                 },
-                # It all works when I add a prev_event for the floating
-                # insertion event but the event no longer floats.
-                # It's able to resolve state at the prev_events though.
-                prev_event_ids=[event_before.event_id],
+                # The difference from the actual room /batch_send is that this is normally
+                # floating as well. But seems to work once we connect it to the
+                # floating historical state chain.
+                prev_event_ids=[maria_membership_event.event_id],
                 # allow_no_prev_events=True,
                 # prev_event_ids=[],
-                auth_event_ids=historical_auth_event_ids,
+                auth_event_ids=[
+                    *historical_base_auth_event_ids,
+                    as_membership_event.event_id,
+                ],
                 state_event_ids=historical_state_event_ids,
                 depth=inherited_depth,
             )
@@ -1036,11 +1085,14 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
             create_event(
                 self.hs,
                 room_id=room_id,
-                sender=room_creator,
+                sender=maria_mxid,
                 type=EventTypes.Message,
                 content={"body": "Historical message", "msgtype": "m.text"},
                 prev_event_ids=[insertion_event.event_id],
-                auth_event_ids=historical_auth_event_ids,
+                auth_event_ids=[
+                    *historical_base_auth_event_ids,
+                    maria_membership_event.event_id,
+                ],
                 depth=inherited_depth,
             )
         )
@@ -1056,7 +1108,10 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
                     EventContentFields.MSC2716_HISTORICAL: True,
                 },
                 prev_event_ids=[historical_message_event.event_id],
-                auth_event_ids=historical_auth_event_ids,
+                auth_event_ids=[
+                    *historical_base_auth_event_ids,
+                    as_membership_event.event_id,
+                ],
                 depth=inherited_depth,
             )
         )
@@ -1072,7 +1127,10 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
                     EventContentFields.MSC2716_HISTORICAL: True,
                 },
                 prev_event_ids=[event_before.event_id],
-                auth_event_ids=historical_auth_event_ids,
+                auth_event_ids=[
+                    *historical_base_auth_event_ids,
+                    as_membership_event.event_id,
+                ],
                 state_event_ids=historical_state_event_ids,
                 depth=inherited_depth,
             )
@@ -1215,7 +1273,7 @@ class FederationEventHandlerTests(unittest.FederatingHomeserverTestCase):
             if event.event_id in event_id_extra
         ]
         assertion_message = (
-            "Actual events missing from expected list: %s\nActual events contain %d additional events compared to expected: %s\nExpected event order: %s\nActual event order: %s"
+            "Debug info:\nActual events missing from expected list: %s\nActual events contain %d additional events compared to expected: %s\nExpected event order: %s\nActual event order: %s"
             % (
                 json.dumps(
                     [_debug_event_string(event) for event in event_diff_ordered],