make FederationHandler._persist_auth_tree async

This commit is contained in:
Richard van der Hoff 2020-02-03 16:14:58 +00:00
parent ebd6a15af3
commit dbdf843012

View File

@ -1852,15 +1852,14 @@ class FederationHandler(BaseHandler):
backfilled=backfilled, backfilled=backfilled,
) )
@defer.inlineCallbacks async def _persist_auth_tree(
def _persist_auth_tree(
self, self,
origin: str, origin: str,
auth_events: List[EventBase], auth_events: List[EventBase],
state: List[EventBase], state: List[EventBase],
event: EventBase, event: EventBase,
room_version: RoomVersion, room_version: RoomVersion,
): ) -> None:
"""Checks the auth chain is valid (and passes auth checks) for the """Checks the auth chain is valid (and passes auth checks) for the
state and event. Then persists the auth chain and state atomically. state and event. Then persists the auth chain and state atomically.
Persists the event separately. Notifies about the persisted events Persists the event separately. Notifies about the persisted events
@ -1875,14 +1874,11 @@ class FederationHandler(BaseHandler):
event event
room_version: The room version we expect this room to have, and room_version: The room version we expect this room to have, and
will raise if it doesn't match the version in the create event. will raise if it doesn't match the version in the create event.
Returns:
Deferred
""" """
events_to_context = {} events_to_context = {}
for e in itertools.chain(auth_events, state): for e in itertools.chain(auth_events, state):
e.internal_metadata.outlier = True e.internal_metadata.outlier = True
ctx = yield self.state_handler.compute_event_context(e) ctx = await self.state_handler.compute_event_context(e)
events_to_context[e.event_id] = ctx events_to_context[e.event_id] = ctx
event_map = { event_map = {
@ -1914,7 +1910,7 @@ class FederationHandler(BaseHandler):
missing_auth_events.add(e_id) missing_auth_events.add(e_id)
for e_id in missing_auth_events: for e_id in missing_auth_events:
m_ev = yield self.federation_client.get_pdu( m_ev = await self.federation_client.get_pdu(
[origin], [origin],
e_id, e_id,
room_version=room_version.identifier, room_version=room_version.identifier,
@ -1950,18 +1946,18 @@ class FederationHandler(BaseHandler):
raise raise
events_to_context[e.event_id].rejected = RejectedReason.AUTH_ERROR events_to_context[e.event_id].rejected = RejectedReason.AUTH_ERROR
yield self.persist_events_and_notify( await self.persist_events_and_notify(
[ [
(e, events_to_context[e.event_id]) (e, events_to_context[e.event_id])
for e in itertools.chain(auth_events, state) for e in itertools.chain(auth_events, state)
] ]
) )
new_event_context = yield self.state_handler.compute_event_context( new_event_context = await self.state_handler.compute_event_context(
event, old_state=state event, old_state=state
) )
yield self.persist_events_and_notify([(event, new_event_context)]) await self.persist_events_and_notify([(event, new_event_context)])
async def _prep_event( async def _prep_event(
self, self,