From 48520505cd52e3082d97a7a2c8cc658525b1f19a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 25 Jun 2015 15:18:07 +0100 Subject: Dedupe auth_chain + state --- synapse/federation/federation_client.py | 37 +++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 21b91d2fb8..6f0cc51819 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -30,6 +30,7 @@ import synapse.metrics from synapse.util.retryutils import get_retry_limiter, NotRetryingDestination +import copy import itertools import logging import random @@ -380,14 +381,42 @@ class FederationClient(FederationBase): for p in content.get("auth_chain", []) ] + pdus = { + p.event_id: p + for p in itertools.chain(state, auth_chain) + } + valid_pdus = yield self._check_sigs_and_hash_and_fetch( - destination, state + auth_chain, + destination, pdus.values(), outlier=True, - include_none=True, ) - signed_state = [p for p in valid_pdus[:len(state)] if p] - signed_auth = [p for p in valid_pdus[len(state):] if p] + valid_pdus_map = { + p.event_id: p + for p in valid_pdus + } + + # NB: We *need* to copy to ensure that we don't have multiple + # references being passed on, as that causes... issues. + signed_state = [ + copy.copy(valid_pdus_map[p.event_id]) + for p in state + if p.event_id in valid_pdus_map + ] + + signed_auth = [ + valid_pdus_map[p.event_id] + for p in auth_chain + if p.event_id in valid_pdus_map + ] + + logger.info("signed_state: %r", [p.event_id for p in signed_state]) + logger.info("signed_auth: %r", [p.event_id for p in signed_auth]) + + # NB: We *need* to copy to ensure that we don't have multiple + # references being passed on, as that causes... issues. + for s in signed_state: + s.internal_metadata = copy.deepcopy(s.internal_metadata) auth_chain.sort(key=lambda e: e.depth) -- cgit 1.4.1