summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-10-07 14:08:55 +0100
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-10-07 14:50:46 +0100
commitd711196db876082aa64407f272ac958ebaebbc2a (patch)
tree1a3d1e9b362a171612c57d18ad2734cbcb0290e3
parentAdd a txn and non-txn for getting prev_events no matter the scenario (diff)
downloadsynapse-d711196db876082aa64407f272ac958ebaebbc2a.tar.xz
Decide which kind of prev_events we care about
-rw-r--r--synapse/federation/sender/per_destination_queue.py10
-rw-r--r--synapse/handlers/message.py10
-rw-r--r--synapse/storage/databases/main/event_federation.py4
-rw-r--r--tests/handlers/test_sync.py2
-rw-r--r--tests/storage/test_event_chain.py2
-rw-r--r--tests/storage/test_event_federation.py2
-rw-r--r--tests/storage/test_events.py2
-rw-r--r--tests/storage/test_room_search.py4
8 files changed, 26 insertions, 10 deletions
diff --git a/synapse/federation/sender/per_destination_queue.py b/synapse/federation/sender/per_destination_queue.py
index 084c45a95c..71301ab526 100644
--- a/synapse/federation/sender/per_destination_queue.py
+++ b/synapse/federation/sender/per_destination_queue.py
@@ -470,8 +470,14 @@ class PerDestinationQueue:
                 # servers, but the remote will correctly deduplicate them and
                 # handle it only once.
 
-                # Step 1, fetch the current extremities
-                extrems = await self._store.get_prev_events_for_room(pdu.room_id)
+                # Step 1, fetch some of the current extremities
+                # For partial state rooms, we intentionally restrict ourselves
+                # to only using our own events here, since we shouldn't divulge
+                # other servers' events to servers which we can't know,
+                # with certainty, whether they are in the room or not.
+                extrems = await self._store.get_prev_events_for_creating_event_in_room(
+                    pdu.room_id
+                )
 
                 if pdu.event_id in extrems:
                     # If the event is in the extremities, then great! We can just
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index da1acea275..90ce3f3032 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -1121,7 +1121,11 @@ class EventCreationHandler:
                 len(prev_event_ids),
             )
         else:
-            prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
+            prev_event_ids = (
+                await self.store.get_prev_events_for_creating_event_in_room(
+                    builder.room_id
+                )
+            )
 
         # Do a quick sanity check here, rather than waiting until we've created the
         # event and then try to auth it (which fails with a somewhat confusing "No
@@ -2061,7 +2065,9 @@ class EventCreationHandler:
 
         # modules can send new state events, so we re-calculate the auth events just in
         # case.
-        prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
+        prev_event_ids = await self.store.get_prev_events_for_creating_event_in_room(
+            builder.room_id
+        )
 
         event = await builder.build(
             prev_event_ids=prev_event_ids,
diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py
index 00958f15e4..e17aecf546 100644
--- a/synapse/storage/databases/main/event_federation.py
+++ b/synapse/storage/databases/main/event_federation.py
@@ -1062,7 +1062,9 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas
 
             return min_depth_event_id, current_min_depth
 
-    async def get_prev_events_for_creating_event_in_room(self, room_id: str) -> List[str]:
+    async def get_prev_events_for_creating_event_in_room(
+        self, room_id: str
+    ) -> List[str]:
         """
         Gets up to 10 event IDs which are suitable for use as `prev_events`
         when creating an event in the given room.
diff --git a/tests/handlers/test_sync.py b/tests/handlers/test_sync.py
index ab5c101eb7..0268ed23a3 100644
--- a/tests/handlers/test_sync.py
+++ b/tests/handlers/test_sync.py
@@ -249,7 +249,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
         # precede the join.
         mocked_get_prev_events = patch.object(
             self.hs.get_datastores().main,
-            "get_prev_events_for_room",
+            "get_prev_events_for_creating_event_in_room",
             new_callable=MagicMock,
             return_value=make_awaitable([last_room_creation_event_id]),
         )
diff --git a/tests/storage/test_event_chain.py b/tests/storage/test_event_chain.py
index de9f4af2de..fe42ac44ae 100644
--- a/tests/storage/test_event_chain.py
+++ b/tests/storage/test_event_chain.py
@@ -515,7 +515,7 @@ class EventChainBackgroundUpdateTestCase(HomeserverTestCase):
         # Create a fork in the DAG with different events.
         event_handler = self.hs.get_event_creation_handler()
         latest_event_ids = self.get_success(
-            self.store.get_prev_events_for_room(room_id)
+            self.store.get_prev_events_for_full_state_room(room_id)
         )
         event, context = self.get_success(
             event_handler.create_event(
diff --git a/tests/storage/test_event_federation.py b/tests/storage/test_event_federation.py
index 59b8910907..81498af1eb 100644
--- a/tests/storage/test_event_federation.py
+++ b/tests/storage/test_event_federation.py
@@ -77,7 +77,7 @@ class EventFederationWorkerStoreTestCase(tests.unittest.HomeserverTestCase):
             )
 
         # this should get the last ten
-        r = self.get_success(self.store.get_prev_events_for_room(room_id))
+        r = self.get_success(self.store.get_prev_events_for_full_state_room(room_id))
         self.assertEqual(10, len(r))
         for i in range(0, 10):
             self.assertEqual("$event_%i:local" % (19 - i), r[i])
diff --git a/tests/storage/test_events.py b/tests/storage/test_events.py
index 3ce4f35cb7..a2a112ce1f 100644
--- a/tests/storage/test_events.py
+++ b/tests/storage/test_events.py
@@ -81,7 +81,7 @@ class ExtremPruneTestCase(HomeserverTestCase):
     def assert_extremities(self, expected_extremities):
         """Assert the current extremities for the room"""
         extremities = self.get_success(
-            self.store.get_prev_events_for_room(self.room_id)
+            self.store.get_prev_events_for_full_state_room(self.room_id)
         )
         self.assertCountEqual(extremities, expected_extremities)
 
diff --git a/tests/storage/test_room_search.py b/tests/storage/test_room_search.py
index e747c6b50e..7bfa60e0ba 100644
--- a/tests/storage/test_room_search.py
+++ b/tests/storage/test_room_search.py
@@ -96,7 +96,9 @@ class EventSearchInsertionTest(HomeserverTestCase):
         # Construct a message with a numeric body to be received over federation
         # The message can't be sent using the client API, since Synapse's event
         # validation will reject it.
-        prev_event_ids = self.get_success(store.get_prev_events_for_room(room_id))
+        prev_event_ids = self.get_success(
+            store.get_prev_events_for_full_state_room(room_id)
+        )
         prev_event = self.get_success(store.get_event(prev_event_ids[0]))
         prev_state_map = self.get_success(
             self.hs.get_storage_controllers().state.get_state_ids_for_event(