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

Refactor _update_auth_events_and_context_for_auth #6343

Merged
merged 6 commits into from
Nov 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,8 +2040,10 @@ def do_auth(self, origin, event, context, auth_events):
auth_events (dict[(str, str)->synapse.events.EventBase]):
Map from (event_type, state_key) to event

What we expect the event's auth_events to be, based on the event's
position in the dag. I think? maybe??
Normally, our calculated auth_events based on the state of the room
at the event's position in the DAG, though occasionally (eg if the
event is an outlier), may be the auth events claimed by the remote
server.

Also NB that this function adds entries to it.
Returns:
Expand Down Expand Up @@ -2091,25 +2093,35 @@ def _update_auth_events_and_context_for_auth(
origin (str):
event (synapse.events.EventBase):
context (synapse.events.snapshot.EventContext):

auth_events (dict[(str, str)->synapse.events.EventBase]):
Map from (event_type, state_key) to event

Normally, our calculated auth_events based on the state of the room
at the event's position in the DAG, though occasionally (eg if the
event is an outlier), may be the auth events claimed by the remote
server.

Also NB that this function adds entries to it.

Returns:
defer.Deferred[EventContext]: updated context
"""
event_auth_events = set(event.auth_event_ids())

# if the event's auth_events refers to events which are not in our
# calculated auth_events, we need to fetch those events from somewhere.
#
# we start by fetching them from the store, and then try calling /event_auth/.
# missing_auth is the set of the event's auth_events which we don't yet have
# in auth_events.
missing_auth = event_auth_events.difference(
e.event_id for e in auth_events.values()
)

# if we have missing events, we need to fetch those events from somewhere.
#
# we start by checking if they are in the store, and then try calling /event_auth/.
if missing_auth:
# TODO: can we use store.have_seen_events here instead?
have_events = yield self.store.get_seen_events_with_rejections(missing_auth)
logger.debug("Got events %s from store", have_events)
logger.debug("Found events %s in the store", have_events)
missing_auth.difference_update(have_events.keys())
else:
have_events = {}
Expand Down Expand Up @@ -2164,15 +2176,23 @@ def _update_auth_events_and_context_for_auth(
event.auth_event_ids()
)
except Exception:
# FIXME:
logger.exception("Failed to get auth chain")

if event.internal_metadata.is_outlier():
# XXX: given that, for an outlier, we'll be working with the
# event's *claimed* auth events rather than those we calculated:
# (a) is there any point in this test, since different_auth below will
# obviously be empty
# (b) alternatively, why don't we do it earlier?
logger.info("Skipping auth_event fetch for outlier")
return context

# FIXME: Assumes we have and stored all the state for all the
# prev_events
#
# FIXME: what does the fixme above mean? where do prev_events come into
babolivier marked this conversation as resolved.
Show resolved Hide resolved
# it, why do we care about the state for those events, and what does "have and
# stored" mean? Seems erik wrote it in c1d860870b
different_auth = event_auth_events.difference(
e.event_id for e in auth_events.values()
)
Expand All @@ -2186,6 +2206,9 @@ def _update_auth_events_and_context_for_auth(
different_auth,
)

# now we state-resolve between our own idea of the auth events, and the remote's
# idea of them.

room_version = yield self.store.get_room_version(event.room_id)

different_events = yield make_deferred_yieldable(
Expand Down