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

Marker events as state - MSC2716 #12718

Merged
merged 10 commits into from
May 24, 2022
1 change: 1 addition & 0 deletions changelog.d/12718.feature
Original file line number Diff line number Diff line change
@@ -0,0 +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.
26 changes: 25 additions & 1 deletion synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,23 @@ async def process_remote_join(
# and discover that we do not have it.
event.internal_metadata.proactively_send = False

return await self.persist_events_and_notify(room_id, [(event, context)])
stream_id_after_persist = await self.persist_events_and_notify(
room_id, [(event, context)]
)

# If we're joining the room again, check if there is new marker
# state indicating that there is new history imported somewhere in
# the DAG. Multiple markers can exist in the current state with
# unique state_keys.
#
# Do this after the state from the remote join was persisted (via
# `persist_events_and_notify`). Otherwise we can run into a
# situation where the create event doesn't exist yet in the
# `current_state_events`
for e in state:
await self._handle_marker_event(origin, e)

return stream_id_after_persist

async def update_state_for_partial_state_event(
self, destination: str, event: EventBase
Expand Down Expand Up @@ -1228,6 +1244,14 @@ async def _handle_marker_event(self, origin: str, marker_event: EventBase) -> No
# Nothing to retrieve then (invalid marker)
return

already_seen_insertion_event = await self._store.have_seen_event(
marker_event.room_id, insertion_event_id
)
if already_seen_insertion_event:
# No need to process a marker again if we have already seen the
# insertion event that it was pointing to
return

logger.debug(
"_handle_marker_event: backfilling insertion event %s", insertion_event_id
)
Expand Down