Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7c2a78b

Browse files
Marker events as state - MSC2716 (#12718)
Sending marker events as state now so they are always able to be seen by homeservers (not lost in some timeline gap). Part of [MSC2716](matrix-org/matrix-spec-proposals#2716) Complement tests: matrix-org/complement#371 As initially discussed at matrix-org/matrix-spec-proposals#2716 (comment) and matrix-org/matrix-spec-proposals#2716 (comment) When someone joins a room, process all of the marker events we see in the current state. Marker events should be sent with a unique `state_key` so that they can all resolve in the current state to easily be discovered. Marker events as state - If we re-use the same `state_key` (like `""`), then we would have to fetch previous snapshots of state up through time to find all of the marker events. This way we can avoid all of that. This PR was originally doing this but then thought of the smarter way to tackle in an [out of band discussion with @erikjohnston](https://docs.google.com/document/d/1JJDuPfcPNX75fprdTWlxlaKjWOdbdJylbpZ03hzo638/edit#bookmark=id.sm92fqyq7vpp). - Also avoids state resolution conflicts where only one of the marker events win As a homeserver, when we see new marker state, we know there is new history imported somewhere back in time and should process it to fetch the insertion event where the historical messages are and set it as an insertion extremity. This way we know where to backfill more messages when someone asks for scrollback.
1 parent 28199e9 commit 7c2a78b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

changelog.d/12718.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update [MSC2716](https://github.com/matrix-org/matrix-spec-proposals/pull/2716) implementation to process marker events from the current state to avoid markers being lost in timeline gaps for federated servers which would cause the imported history to be undiscovered.

synapse/handlers/federation_event.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,23 @@ async def process_remote_join(
477477
# and discover that we do not have it.
478478
event.internal_metadata.proactively_send = False
479479

480-
return await self.persist_events_and_notify(room_id, [(event, context)])
480+
stream_id_after_persist = await self.persist_events_and_notify(
481+
room_id, [(event, context)]
482+
)
483+
484+
# If we're joining the room again, check if there is new marker
485+
# state indicating that there is new history imported somewhere in
486+
# the DAG. Multiple markers can exist in the current state with
487+
# unique state_keys.
488+
#
489+
# Do this after the state from the remote join was persisted (via
490+
# `persist_events_and_notify`). Otherwise we can run into a
491+
# situation where the create event doesn't exist yet in the
492+
# `current_state_events`
493+
for e in state:
494+
await self._handle_marker_event(origin, e)
495+
496+
return stream_id_after_persist
481497

482498
async def update_state_for_partial_state_event(
483499
self, destination: str, event: EventBase
@@ -1230,6 +1246,14 @@ async def _handle_marker_event(self, origin: str, marker_event: EventBase) -> No
12301246
# Nothing to retrieve then (invalid marker)
12311247
return
12321248

1249+
already_seen_insertion_event = await self._store.have_seen_event(
1250+
marker_event.room_id, insertion_event_id
1251+
)
1252+
if already_seen_insertion_event:
1253+
# No need to process a marker again if we have already seen the
1254+
# insertion event that it was pointing to
1255+
return
1256+
12331257
logger.debug(
12341258
"_handle_marker_event: backfilling insertion event %s", insertion_event_id
12351259
)

0 commit comments

Comments
 (0)