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

Commit 2a017da

Browse files
committed
Rip out auth-event reconciliation code
This code attempts to update our reconcile our state with the remote's auth events. The spec says nothing about this, and it doesn't really seem like the right thing to do.
1 parent c2f2bad commit 2a017da

File tree

1 file changed

+1
-173
lines changed

1 file changed

+1
-173
lines changed

synapse/handlers/federation_event.py

Lines changed: 1 addition & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,39 +1539,9 @@ async def _check_event_auth(
15391539
calculated_auth_events = await self._store.get_events_as_list(
15401540
calculated_auth_event_ids
15411541
)
1542-
calculated_auth_event_map = {
1543-
(e.type, e.state_key): e for e in calculated_auth_events
1544-
}
15451542

15461543
try:
1547-
updated_auth_events = await self._update_auth_events_for_auth(
1548-
event,
1549-
calculated_auth_event_map=calculated_auth_event_map,
1550-
)
1551-
except Exception:
1552-
# We don't really mind if the above fails, so lets not fail
1553-
# processing if it does. However, it really shouldn't fail so
1554-
# let's still log as an exception since we'll still want to fix
1555-
# any bugs.
1556-
logger.exception(
1557-
"Failed to double check auth events for %s with remote. "
1558-
"Ignoring failure and continuing processing of event.",
1559-
event.event_id,
1560-
)
1561-
updated_auth_events = None
1562-
1563-
if updated_auth_events:
1564-
context = await self._update_context_for_auth_events(
1565-
event, context, updated_auth_events
1566-
)
1567-
auth_events_for_auth = updated_auth_events
1568-
else:
1569-
auth_events_for_auth = calculated_auth_event_map
1570-
1571-
try:
1572-
check_auth_rules_for_event(
1573-
room_version_obj, event, auth_events_for_auth.values()
1574-
)
1544+
check_auth_rules_for_event(room_version_obj, event, calculated_auth_events)
15751545
except AuthError as e:
15761546
logger.warning("Failed auth resolution for %r because %s", event, e)
15771547
context.rejected = RejectedReason.AUTH_ERROR
@@ -1681,93 +1651,6 @@ async def _check_for_soft_fail(
16811651
soft_failed_event_counter.inc()
16821652
event.internal_metadata.soft_failed = True
16831653

1684-
async def _update_auth_events_for_auth(
1685-
self,
1686-
event: EventBase,
1687-
calculated_auth_event_map: StateMap[EventBase],
1688-
) -> Optional[StateMap[EventBase]]:
1689-
"""Helper for _check_event_auth. See there for docs.
1690-
1691-
Checks whether a given event has the expected auth events. If it
1692-
doesn't then we talk to the remote server to compare state to see if
1693-
we can come to a consensus (e.g. if one server missed some valid
1694-
state).
1695-
1696-
This attempts to resolve any potential divergence of state between
1697-
servers, but is not essential and so failures should not block further
1698-
processing of the event.
1699-
1700-
Args:
1701-
event:
1702-
1703-
calculated_auth_event_map:
1704-
Our calculated auth_events based on the state of the room
1705-
at the event's position in the DAG.
1706-
1707-
Returns:
1708-
updated auth event map, or None if no changes are needed.
1709-
1710-
"""
1711-
assert not event.internal_metadata.outlier
1712-
1713-
# check for events which are in the event's claimed auth_events, but not
1714-
# in our calculated event map.
1715-
event_auth_events = set(event.auth_event_ids())
1716-
different_auth = event_auth_events.difference(
1717-
e.event_id for e in calculated_auth_event_map.values()
1718-
)
1719-
1720-
if not different_auth:
1721-
return None
1722-
1723-
logger.info(
1724-
"auth_events refers to events which are not in our calculated auth "
1725-
"chain: %s",
1726-
different_auth,
1727-
)
1728-
1729-
# XXX: currently this checks for redactions but I'm not convinced that is
1730-
# necessary?
1731-
different_events = await self._store.get_events_as_list(different_auth)
1732-
1733-
# double-check they're all in the same room - we should already have checked
1734-
# this but it doesn't hurt to check again.
1735-
for d in different_events:
1736-
assert (
1737-
d.room_id == event.room_id
1738-
), f"Event {event.event_id} refers to auth_event {d.event_id} which is in a different room"
1739-
1740-
# now we state-resolve between our own idea of the auth events, and the remote's
1741-
# idea of them.
1742-
1743-
local_state = calculated_auth_event_map.values()
1744-
remote_auth_events = dict(calculated_auth_event_map)
1745-
remote_auth_events.update({(d.type, d.state_key): d for d in different_events})
1746-
remote_state = remote_auth_events.values()
1747-
1748-
room_version = await self._store.get_room_version_id(event.room_id)
1749-
new_state = await self._state_handler.resolve_events(
1750-
room_version, (local_state, remote_state), event
1751-
)
1752-
different_state = {
1753-
(d.type, d.state_key): d
1754-
for d in new_state.values()
1755-
if calculated_auth_event_map.get((d.type, d.state_key)) != d
1756-
}
1757-
if not different_state:
1758-
logger.info("State res returned no new state")
1759-
return None
1760-
1761-
logger.info(
1762-
"After state res: updating auth_events with new state %s",
1763-
different_state.values(),
1764-
)
1765-
1766-
# take a copy of calculated_auth_event_map before we modify it.
1767-
auth_events = dict(calculated_auth_event_map)
1768-
auth_events.update(different_state)
1769-
return auth_events
1770-
17711654
async def _load_or_fetch_auth_events_for_event(
17721655
self, destination: str, event: EventBase
17731656
) -> Collection[EventBase]:
@@ -1865,61 +1748,6 @@ async def _get_remote_auth_chain_for_event(
18651748

18661749
await self._auth_and_persist_outliers(room_id, remote_auth_events)
18671750

1868-
async def _update_context_for_auth_events(
1869-
self, event: EventBase, context: EventContext, auth_events: StateMap[EventBase]
1870-
) -> EventContext:
1871-
"""Update the state_ids in an event context after auth event resolution,
1872-
storing the changes as a new state group.
1873-
1874-
Args:
1875-
event: The event we're handling the context for
1876-
1877-
context: initial event context
1878-
1879-
auth_events: Events to update in the event context.
1880-
1881-
Returns:
1882-
new event context
1883-
"""
1884-
# exclude the state key of the new event from the current_state in the context.
1885-
if event.is_state():
1886-
event_key: Optional[Tuple[str, str]] = (event.type, event.state_key)
1887-
else:
1888-
event_key = None
1889-
state_updates = {
1890-
k: a.event_id for k, a in auth_events.items() if k != event_key
1891-
}
1892-
1893-
current_state_ids = await context.get_current_state_ids()
1894-
current_state_ids = dict(current_state_ids) # type: ignore
1895-
1896-
current_state_ids.update(state_updates)
1897-
1898-
prev_state_ids = await context.get_prev_state_ids()
1899-
prev_state_ids = dict(prev_state_ids)
1900-
1901-
prev_state_ids.update({k: a.event_id for k, a in auth_events.items()})
1902-
1903-
# create a new state group as a delta from the existing one.
1904-
prev_group = context.state_group
1905-
state_group = await self._state_storage_controller.store_state_group(
1906-
event.event_id,
1907-
event.room_id,
1908-
prev_group=prev_group,
1909-
delta_ids=state_updates,
1910-
current_state_ids=current_state_ids,
1911-
)
1912-
1913-
return EventContext.with_state(
1914-
storage=self._storage_controllers,
1915-
state_group=state_group,
1916-
state_group_before_event=context.state_group_before_event,
1917-
state_delta_due_to_event=state_updates,
1918-
prev_group=prev_group,
1919-
delta_ids=state_updates,
1920-
partial_state=context.partial_state,
1921-
)
1922-
19231751
async def _run_push_actions_and_persist_event(
19241752
self, event: EventBase, context: EventContext, backfilled: bool = False
19251753
) -> None:

0 commit comments

Comments
 (0)