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

Commit

Permalink
Skip attempt to get state at backwards-extremities
Browse files Browse the repository at this point in the history
We don't *have* the state at a backwards-extremity, so this is never going to
do anything useful.
  • Loading branch information
richvdh committed Mar 7, 2022
1 parent 00a67f8 commit bcf97ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 57 deletions.
1 change: 1 addition & 0 deletions changelog.d/12173.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge remote-tracking branch 'origin/release-v1.54' into develop
60 changes: 3 additions & 57 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from signedjson.sign import verify_signed_json
from unpaddedbase64 import decode_base64

from twisted.internet import defer

from synapse import event_auth
from synapse.api.constants import EventContentFields, EventTypes, Membership
from synapse.api.errors import (
Expand All @@ -45,11 +43,7 @@
from synapse.events.validator import EventValidator
from synapse.federation.federation_client import InvalidResponseError
from synapse.http.servlet import assert_params_in_dict
from synapse.logging.context import (
make_deferred_yieldable,
nested_logging_context,
preserve_fn,
)
from synapse.logging.context import nested_logging_context
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.replication.http.federation import (
ReplicationCleanRoomRestServlet,
Expand Down Expand Up @@ -355,56 +349,8 @@ async def try_backfill(domains: List[str]) -> bool:
if success:
return True

# Huh, well *those* domains didn't work out. Lets try some domains
# from the time.

tried_domains = set(likely_domains)
tried_domains.add(self.server_name)

event_ids = list(extremities.keys())

logger.debug("calling resolve_state_groups in _maybe_backfill")
resolve = preserve_fn(self.state_handler.resolve_state_groups_for_events)
states_list = await make_deferred_yieldable(
defer.gatherResults(
[resolve(room_id, [e]) for e in event_ids], consumeErrors=True
)
)

# A map from event_id to state map of event_ids.
state_ids: Dict[str, StateMap[str]] = dict(
zip(event_ids, [s.state for s in states_list])
)

state_map = await self.store.get_events(
[e_id for ids in state_ids.values() for e_id in ids.values()],
get_prev_content=False,
)

# A map from event_id to state map of events.
state_events: Dict[str, StateMap[EventBase]] = {
key: {
k: state_map[e_id]
for k, e_id in state_dict.items()
if e_id in state_map
}
for key, state_dict in state_ids.items()
}

for e_id in event_ids:
likely_extremeties_domains = get_domains_from_state(state_events[e_id])

success = await try_backfill(
[
dom
for dom, _ in likely_extremeties_domains
if dom not in tried_domains
]
)
if success:
return True

tried_domains.update(dom for dom, _ in likely_extremeties_domains)
# TODO: we could also try servers which were previously in the room, but
# are no longer.

return False

Expand Down

0 comments on commit bcf97ea

Please sign in to comment.