@@ -1542,37 +1542,9 @@ async def _check_event_auth(
15421542 calculated_auth_events = await self ._store .get_events_as_list (
15431543 calculated_auth_event_ids
15441544 )
1545- calculated_auth_event_map = {
1546- (e .type , e .state_key ): e for e in calculated_auth_events
1547- }
15481545
15491546 try :
1550- updated_auth_events = await self ._update_auth_events_for_auth (
1551- event ,
1552- calculated_auth_event_map = calculated_auth_event_map ,
1553- )
1554- except Exception :
1555- # We don't really mind if the above fails, so lets not fail
1556- # processing if it does. However, it really shouldn't fail so
1557- # let's still log as an exception since we'll still want to fix
1558- # any bugs.
1559- logger .exception (
1560- "Failed to double check auth events for %s with remote. "
1561- "Ignoring failure and continuing processing of event." ,
1562- event .event_id ,
1563- )
1564- updated_auth_events = None
1565-
1566- if updated_auth_events :
1567- context = await self ._update_context_for_auth_events (
1568- event , context , updated_auth_events
1569- )
1570- auth_events_for_auth = updated_auth_events
1571- else :
1572- auth_events_for_auth = calculated_auth_event_map
1573-
1574- try :
1575- check_state_dependent_auth_rules (event , auth_events_for_auth .values ())
1547+ check_state_dependent_auth_rules (event , calculated_auth_events )
15761548 except AuthError as e :
15771549 logger .warning ("Failed auth resolution for %r because %s" , event , e )
15781550 context .rejected = RejectedReason .AUTH_ERROR
@@ -1688,93 +1660,6 @@ async def _check_for_soft_fail(
16881660 soft_failed_event_counter .inc ()
16891661 event .internal_metadata .soft_failed = True
16901662
1691- async def _update_auth_events_for_auth (
1692- self ,
1693- event : EventBase ,
1694- calculated_auth_event_map : StateMap [EventBase ],
1695- ) -> Optional [StateMap [EventBase ]]:
1696- """Helper for _check_event_auth. See there for docs.
1697-
1698- Checks whether a given event has the expected auth events. If it
1699- doesn't then we talk to the remote server to compare state to see if
1700- we can come to a consensus (e.g. if one server missed some valid
1701- state).
1702-
1703- This attempts to resolve any potential divergence of state between
1704- servers, but is not essential and so failures should not block further
1705- processing of the event.
1706-
1707- Args:
1708- event:
1709-
1710- calculated_auth_event_map:
1711- Our calculated auth_events based on the state of the room
1712- at the event's position in the DAG.
1713-
1714- Returns:
1715- updated auth event map, or None if no changes are needed.
1716-
1717- """
1718- assert not event .internal_metadata .outlier
1719-
1720- # check for events which are in the event's claimed auth_events, but not
1721- # in our calculated event map.
1722- event_auth_events = set (event .auth_event_ids ())
1723- different_auth = event_auth_events .difference (
1724- e .event_id for e in calculated_auth_event_map .values ()
1725- )
1726-
1727- if not different_auth :
1728- return None
1729-
1730- logger .info (
1731- "auth_events refers to events which are not in our calculated auth "
1732- "chain: %s" ,
1733- different_auth ,
1734- )
1735-
1736- # XXX: currently this checks for redactions but I'm not convinced that is
1737- # necessary?
1738- different_events = await self ._store .get_events_as_list (different_auth )
1739-
1740- # double-check they're all in the same room - we should already have checked
1741- # this but it doesn't hurt to check again.
1742- for d in different_events :
1743- assert (
1744- d .room_id == event .room_id
1745- ), f"Event { event .event_id } refers to auth_event { d .event_id } which is in a different room"
1746-
1747- # now we state-resolve between our own idea of the auth events, and the remote's
1748- # idea of them.
1749-
1750- local_state = calculated_auth_event_map .values ()
1751- remote_auth_events = dict (calculated_auth_event_map )
1752- remote_auth_events .update ({(d .type , d .state_key ): d for d in different_events })
1753- remote_state = remote_auth_events .values ()
1754-
1755- room_version = await self ._store .get_room_version_id (event .room_id )
1756- new_state = await self ._state_handler .resolve_events (
1757- room_version , (local_state , remote_state ), event
1758- )
1759- different_state = {
1760- (d .type , d .state_key ): d
1761- for d in new_state .values ()
1762- if calculated_auth_event_map .get ((d .type , d .state_key )) != d
1763- }
1764- if not different_state :
1765- logger .info ("State res returned no new state" )
1766- return None
1767-
1768- logger .info (
1769- "After state res: updating auth_events with new state %s" ,
1770- different_state .values (),
1771- )
1772-
1773- # take a copy of calculated_auth_event_map before we modify it.
1774- auth_events = dict (calculated_auth_event_map )
1775- auth_events .update (different_state )
1776- return auth_events
1777-
17781663 async def _load_or_fetch_auth_events_for_event (
17791664 self , destination : str , event : EventBase
17801665 ) -> Collection [EventBase ]:
@@ -1872,61 +1757,6 @@ async def _get_remote_auth_chain_for_event(
18721757
18731758 await self ._auth_and_persist_outliers (room_id , remote_auth_events )
18741759
1875- async def _update_context_for_auth_events (
1876- self , event : EventBase , context : EventContext , auth_events : StateMap [EventBase ]
1877- ) -> EventContext :
1878- """Update the state_ids in an event context after auth event resolution,
1879- storing the changes as a new state group.
1880-
1881- Args:
1882- event: The event we're handling the context for
1883-
1884- context: initial event context
1885-
1886- auth_events: Events to update in the event context.
1887-
1888- Returns:
1889- new event context
1890- """
1891- # exclude the state key of the new event from the current_state in the context.
1892- if event .is_state ():
1893- event_key : Optional [Tuple [str , str ]] = (event .type , event .state_key )
1894- else :
1895- event_key = None
1896- state_updates = {
1897- k : a .event_id for k , a in auth_events .items () if k != event_key
1898- }
1899-
1900- current_state_ids = await context .get_current_state_ids ()
1901- current_state_ids = dict (current_state_ids ) # type: ignore
1902-
1903- current_state_ids .update (state_updates )
1904-
1905- prev_state_ids = await context .get_prev_state_ids ()
1906- prev_state_ids = dict (prev_state_ids )
1907-
1908- prev_state_ids .update ({k : a .event_id for k , a in auth_events .items ()})
1909-
1910- # create a new state group as a delta from the existing one.
1911- prev_group = context .state_group
1912- state_group = await self ._state_storage_controller .store_state_group (
1913- event .event_id ,
1914- event .room_id ,
1915- prev_group = prev_group ,
1916- delta_ids = state_updates ,
1917- current_state_ids = current_state_ids ,
1918- )
1919-
1920- return EventContext .with_state (
1921- storage = self ._storage_controllers ,
1922- state_group = state_group ,
1923- state_group_before_event = context .state_group_before_event ,
1924- state_delta_due_to_event = state_updates ,
1925- prev_group = prev_group ,
1926- delta_ids = state_updates ,
1927- partial_state = context .partial_state ,
1928- )
1929-
19301760 async def _run_push_actions_and_persist_event (
19311761 self , event : EventBase , context : EventContext , backfilled : bool = False
19321762 ) -> None :
0 commit comments