0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-07-04 18:28:48 +02:00

Don't query auth if the only difference is events that were rejected due to auth.

This commit is contained in:
Erik Johnston 2015-02-06 14:16:50 +00:00
parent c78b5fb1f1
commit e890ce223c

View file

@ -791,12 +791,12 @@ class FederationHandler(BaseHandler):
@log_function
def do_auth(self, origin, event, context, auth_events):
# Check if we have all the auth events.
res = yield self.store.have_events(
have_events = yield self.store.have_events(
[e_id for e_id, _ in event.auth_events]
)
event_auth_events = set(e_id for e_id, _ in event.auth_events)
seen_events = set(res.keys())
seen_events = set(have_events.keys())
missing_auth = event_auth_events - seen_events
@ -839,6 +839,11 @@ class FederationHandler(BaseHandler):
auth_events[(e.type, e.state_key)] = e
except AuthError:
pass
have_events = yield self.store.have_events(
[e_id for e_id, _ in event.auth_events]
)
seen_events = set(have_events.keys())
except:
# FIXME:
logger.exception("Failed to get auth chain")
@ -852,6 +857,16 @@ class FederationHandler(BaseHandler):
# Do auth conflict res.
logger.debug("Different auth: %s", different_auth)
# Only do auth resolution if we have something new to say.
# We can't rove an auth failure.
do_resolution = False
for e_id in different_auth:
if e_id in have_events:
if have_events[e_id] != RejectedReason.AUTH_ERROR:
do_resolution = True
break
if do_resolution:
# 1. Get what we think is the auth chain.
auth_ids = self.auth.compute_auth_events(
event, context.current_state
@ -882,7 +897,8 @@ class FederationHandler(BaseHandler):
try:
auth_ids = [e_id for e_id, _ in ev.auth_events]
auth = {
(e.type, e.state_key): e for e in result["auth_chain"]
(e.type, e.state_key): e
for e in result["auth_chain"]
if e.event_id in auth_ids
}
ev.internal_metadata.outlier = True
@ -1028,9 +1044,9 @@ class FederationHandler(BaseHandler):
for e in base_remote_rejected:
reason = yield self.store.get_rejection_reason(e.event_id)
if reason is None:
# FIXME: ERRR?!
logger.warn("Could not find reason for %s", e.event_id)
raise RuntimeError("Could not find reason for %s" % e.event_id)
# TODO: e is not in the current state, so we should
# construct some proof of that.
continue
reason_map[e.event_id] = reason