@@ -909,12 +909,18 @@ async def _process_received_pdu(
909
909
context = await self ._state_handler .compute_event_context (
910
910
event , old_state = state
911
911
)
912
- await self ._auth_and_persist_event (
913
- origin , event , context , state = state , backfilled = backfilled
912
+ context = await self ._check_event_auth (
913
+ origin ,
914
+ event ,
915
+ context ,
916
+ state = state ,
917
+ backfilled = backfilled ,
914
918
)
915
919
except AuthError as e :
916
920
raise FederationError ("ERROR" , e .code , e .msg , affected = event .event_id )
917
921
922
+ await self ._run_push_actions_and_persist_event (event , context , backfilled )
923
+
918
924
if backfilled :
919
925
return
920
926
@@ -1239,51 +1245,6 @@ async def prep(ev_info: _NewEventInfo):
1239
1245
],
1240
1246
)
1241
1247
1242
- async def _auth_and_persist_event (
1243
- self ,
1244
- origin : str ,
1245
- event : EventBase ,
1246
- context : EventContext ,
1247
- state : Optional [Iterable [EventBase ]] = None ,
1248
- claimed_auth_event_map : Optional [StateMap [EventBase ]] = None ,
1249
- backfilled : bool = False ,
1250
- ) -> None :
1251
- """
1252
- Process an event by performing auth checks and then persisting to the database.
1253
-
1254
- Args:
1255
- origin: The host the event originates from.
1256
- event: The event itself.
1257
- context:
1258
- The event context.
1259
-
1260
- state:
1261
- The state events used to check the event for soft-fail. If this is
1262
- not provided the current state events will be used.
1263
-
1264
- claimed_auth_event_map:
1265
- A map of (type, state_key) => event for the event's claimed auth_events.
1266
- Possibly incomplete, and possibly including events that are not yet
1267
- persisted, or authed, or in the right room.
1268
-
1269
- Only populated when populating outliers.
1270
-
1271
- backfilled: True if the event was backfilled.
1272
- """
1273
- # claimed_auth_event_map should be given iff the event is an outlier
1274
- assert bool (claimed_auth_event_map ) == event .internal_metadata .outlier
1275
-
1276
- context = await self ._check_event_auth (
1277
- origin ,
1278
- event ,
1279
- context ,
1280
- state = state ,
1281
- claimed_auth_event_map = claimed_auth_event_map ,
1282
- backfilled = backfilled ,
1283
- )
1284
-
1285
- await self ._run_push_actions_and_persist_event (event , context , backfilled )
1286
-
1287
1248
async def _check_event_auth (
1288
1249
self ,
1289
1250
origin : str ,
@@ -1558,39 +1519,45 @@ async def _update_auth_events_and_context_for_auth(
1558
1519
event .room_id , [e .event_id for e in remote_auth_chain ]
1559
1520
)
1560
1521
1561
- for e in remote_auth_chain :
1562
- if e .event_id in seen_remotes :
1522
+ for auth_event in remote_auth_chain :
1523
+ if auth_event .event_id in seen_remotes :
1563
1524
continue
1564
1525
1565
- if e .event_id == event .event_id :
1526
+ if auth_event .event_id == event .event_id :
1566
1527
continue
1567
1528
1568
1529
try :
1569
- auth_ids = e .auth_event_ids ()
1530
+ auth_ids = auth_event .auth_event_ids ()
1570
1531
auth = {
1571
1532
(e .type , e .state_key ): e
1572
1533
for e in remote_auth_chain
1573
1534
if e .event_id in auth_ids or e .type == EventTypes .Create
1574
1535
}
1575
- e .internal_metadata .outlier = True
1536
+ auth_event .internal_metadata .outlier = True
1576
1537
1577
1538
logger .debug (
1578
1539
"_check_event_auth %s missing_auth: %s" ,
1579
1540
event .event_id ,
1580
- e .event_id ,
1541
+ auth_event .event_id ,
1581
1542
)
1582
1543
missing_auth_event_context = (
1583
- await self ._state_handler .compute_event_context (e )
1544
+ await self ._state_handler .compute_event_context (auth_event )
1584
1545
)
1585
- await self ._auth_and_persist_event (
1546
+
1547
+ missing_auth_event_context = await self ._check_event_auth (
1586
1548
origin ,
1587
- e ,
1549
+ auth_event ,
1588
1550
missing_auth_event_context ,
1589
1551
claimed_auth_event_map = auth ,
1590
1552
)
1553
+ await self .persist_events_and_notify (
1554
+ event .room_id , [(auth_event , missing_auth_event_context )]
1555
+ )
1591
1556
1592
- if e .event_id in event_auth_events :
1593
- auth_events [(e .type , e .state_key )] = e
1557
+ if auth_event .event_id in event_auth_events :
1558
+ auth_events [
1559
+ (auth_event .type , auth_event .state_key )
1560
+ ] = auth_event
1594
1561
except AuthError :
1595
1562
pass
1596
1563
@@ -1733,10 +1700,13 @@ async def _run_push_actions_and_persist_event(
1733
1700
context: The event context.
1734
1701
backfilled: True if the event was backfilled.
1735
1702
"""
1703
+ # this method should not be called on outliers (those code paths call
1704
+ # persist_events_and_notify directly.)
1705
+ assert not event .internal_metadata .outlier
1706
+
1736
1707
try :
1737
1708
if (
1738
- not event .internal_metadata .is_outlier ()
1739
- and not backfilled
1709
+ not backfilled
1740
1710
and not context .rejected
1741
1711
and (await self ._store .get_min_depth (event .room_id )) <= event .depth
1742
1712
):
0 commit comments