test_state.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. # Copyright 2014-2016 OpenMarket Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Collection, Dict, List, Optional
  15. from unittest.mock import Mock
  16. from twisted.internet import defer
  17. from synapse.api.auth import Auth
  18. from synapse.api.constants import EventTypes, Membership
  19. from synapse.api.room_versions import RoomVersions
  20. from synapse.events import make_event_from_dict
  21. from synapse.events.snapshot import EventContext
  22. from synapse.state import StateHandler, StateResolutionHandler
  23. from tests import unittest
  24. from .utils import MockClock, default_config
  25. _next_event_id = 1000
  26. def create_event(
  27. name=None,
  28. type=None,
  29. state_key=None,
  30. depth=2,
  31. event_id=None,
  32. prev_events: Optional[List[str]] = None,
  33. **kwargs,
  34. ):
  35. global _next_event_id
  36. if not event_id:
  37. _next_event_id += 1
  38. event_id = "$%s:test" % (_next_event_id,)
  39. if not name:
  40. if state_key is not None:
  41. name = "<%s-%s, %s>" % (type, state_key, event_id)
  42. else:
  43. name = "<%s, %s>" % (type, event_id)
  44. d = {
  45. "event_id": event_id,
  46. "type": type,
  47. "sender": "@user_id:example.com",
  48. "room_id": "!room_id:example.com",
  49. "depth": depth,
  50. "prev_events": prev_events or [],
  51. }
  52. if state_key is not None:
  53. d["state_key"] = state_key
  54. d.update(kwargs)
  55. event = make_event_from_dict(d)
  56. return event
  57. class _DummyStore:
  58. def __init__(self):
  59. self._event_to_state_group = {}
  60. self._group_to_state = {}
  61. self._event_id_to_event = {}
  62. self._next_group = 1
  63. async def get_state_groups_ids(self, room_id, event_ids):
  64. groups = {}
  65. for event_id in event_ids:
  66. group = self._event_to_state_group.get(event_id)
  67. if group:
  68. groups[group] = self._group_to_state[group]
  69. return groups
  70. async def store_state_group(
  71. self, event_id, room_id, prev_group, delta_ids, current_state_ids
  72. ):
  73. state_group = self._next_group
  74. self._next_group += 1
  75. self._group_to_state[state_group] = dict(current_state_ids)
  76. return state_group
  77. async def get_events(self, event_ids, **kwargs):
  78. return {
  79. e_id: self._event_id_to_event[e_id]
  80. for e_id in event_ids
  81. if e_id in self._event_id_to_event
  82. }
  83. async def get_partial_state_events(
  84. self, event_ids: Collection[str]
  85. ) -> Dict[str, bool]:
  86. return {e: False for e in event_ids}
  87. async def get_state_group_delta(self, name):
  88. return None, None
  89. def register_events(self, events):
  90. for e in events:
  91. self._event_id_to_event[e.event_id] = e
  92. def register_event_context(self, event, context):
  93. self._event_to_state_group[event.event_id] = context.state_group
  94. def register_event_id_state_group(self, event_id, state_group):
  95. self._event_to_state_group[event_id] = state_group
  96. async def get_room_version_id(self, room_id):
  97. return RoomVersions.V1.identifier
  98. class DictObj(dict):
  99. def __init__(self, **kwargs):
  100. super().__init__(kwargs)
  101. self.__dict__ = self
  102. class Graph:
  103. def __init__(self, nodes, edges):
  104. events = {}
  105. clobbered = set(events.keys())
  106. for event_id, fields in nodes.items():
  107. refs = edges.get(event_id)
  108. if refs:
  109. clobbered.difference_update(refs)
  110. prev_events = [(r, {}) for r in refs]
  111. else:
  112. prev_events = []
  113. events[event_id] = create_event(
  114. event_id=event_id, prev_events=prev_events, **fields
  115. )
  116. self._leaves = clobbered
  117. self._events = sorted(events.values(), key=lambda e: e.depth)
  118. def walk(self):
  119. return iter(self._events)
  120. def get_leaves(self):
  121. return (self._events[i] for i in self._leaves)
  122. class StateTestCase(unittest.TestCase):
  123. def setUp(self):
  124. self.dummy_store = _DummyStore()
  125. storage = Mock(main=self.dummy_store, state=self.dummy_store)
  126. hs = Mock(
  127. spec_set=[
  128. "config",
  129. "get_datastores",
  130. "get_storage",
  131. "get_auth",
  132. "get_state_handler",
  133. "get_clock",
  134. "get_state_resolution_handler",
  135. "get_account_validity_handler",
  136. "hostname",
  137. ]
  138. )
  139. hs.config = default_config("tesths", True)
  140. hs.get_datastores.return_value = Mock(main=self.dummy_store)
  141. hs.get_state_handler.return_value = None
  142. hs.get_clock.return_value = MockClock()
  143. hs.get_auth.return_value = Auth(hs)
  144. hs.get_state_resolution_handler = lambda: StateResolutionHandler(hs)
  145. hs.get_storage.return_value = storage
  146. self.state = StateHandler(hs)
  147. self.event_id = 0
  148. @defer.inlineCallbacks
  149. def test_branch_no_conflict(self):
  150. graph = Graph(
  151. nodes={
  152. "START": DictObj(
  153. type=EventTypes.Create, state_key="", content={}, depth=1
  154. ),
  155. "A": DictObj(type=EventTypes.Message, depth=2),
  156. "B": DictObj(type=EventTypes.Message, depth=3),
  157. "C": DictObj(type=EventTypes.Name, state_key="", depth=3),
  158. "D": DictObj(type=EventTypes.Message, depth=4),
  159. },
  160. edges={"A": ["START"], "B": ["A"], "C": ["A"], "D": ["B", "C"]},
  161. )
  162. self.dummy_store.register_events(graph.walk())
  163. context_store: dict[str, EventContext] = {}
  164. for event in graph.walk():
  165. context = yield defer.ensureDeferred(
  166. self.state.compute_event_context(event)
  167. )
  168. self.dummy_store.register_event_context(event, context)
  169. context_store[event.event_id] = context
  170. ctx_c = context_store["C"]
  171. ctx_d = context_store["D"]
  172. prev_state_ids = yield defer.ensureDeferred(ctx_d.get_prev_state_ids())
  173. self.assertEqual(2, len(prev_state_ids))
  174. self.assertEqual(ctx_c.state_group, ctx_d.state_group_before_event)
  175. self.assertEqual(ctx_d.state_group_before_event, ctx_d.state_group)
  176. @defer.inlineCallbacks
  177. def test_branch_basic_conflict(self):
  178. graph = Graph(
  179. nodes={
  180. "START": DictObj(
  181. type=EventTypes.Create,
  182. state_key="",
  183. content={"creator": "@user_id:example.com"},
  184. depth=1,
  185. ),
  186. "A": DictObj(
  187. type=EventTypes.Member,
  188. state_key="@user_id:example.com",
  189. content={"membership": Membership.JOIN},
  190. membership=Membership.JOIN,
  191. depth=2,
  192. ),
  193. "B": DictObj(type=EventTypes.Name, state_key="", depth=3),
  194. "C": DictObj(type=EventTypes.Name, state_key="", depth=4),
  195. "D": DictObj(type=EventTypes.Message, depth=5),
  196. },
  197. edges={"A": ["START"], "B": ["A"], "C": ["A"], "D": ["B", "C"]},
  198. )
  199. self.dummy_store.register_events(graph.walk())
  200. context_store = {}
  201. for event in graph.walk():
  202. context = yield defer.ensureDeferred(
  203. self.state.compute_event_context(event)
  204. )
  205. self.dummy_store.register_event_context(event, context)
  206. context_store[event.event_id] = context
  207. # C ends up winning the resolution between B and C
  208. ctx_c = context_store["C"]
  209. ctx_d = context_store["D"]
  210. prev_state_ids = yield defer.ensureDeferred(ctx_d.get_prev_state_ids())
  211. self.assertSetEqual({"START", "A", "C"}, set(prev_state_ids.values()))
  212. self.assertEqual(ctx_c.state_group, ctx_d.state_group_before_event)
  213. self.assertEqual(ctx_d.state_group_before_event, ctx_d.state_group)
  214. @defer.inlineCallbacks
  215. def test_branch_have_banned_conflict(self):
  216. graph = Graph(
  217. nodes={
  218. "START": DictObj(
  219. type=EventTypes.Create,
  220. state_key="",
  221. content={"creator": "@user_id:example.com"},
  222. depth=1,
  223. ),
  224. "A": DictObj(
  225. type=EventTypes.Member,
  226. state_key="@user_id:example.com",
  227. content={"membership": Membership.JOIN},
  228. membership=Membership.JOIN,
  229. depth=2,
  230. ),
  231. "B": DictObj(type=EventTypes.Name, state_key="", depth=3),
  232. "C": DictObj(
  233. type=EventTypes.Member,
  234. state_key="@user_id_2:example.com",
  235. content={"membership": Membership.BAN},
  236. membership=Membership.BAN,
  237. depth=4,
  238. ),
  239. "D": DictObj(
  240. type=EventTypes.Name,
  241. state_key="",
  242. depth=4,
  243. sender="@user_id_2:example.com",
  244. ),
  245. "E": DictObj(type=EventTypes.Message, depth=5),
  246. },
  247. edges={"A": ["START"], "B": ["A"], "C": ["B"], "D": ["B"], "E": ["C", "D"]},
  248. )
  249. self.dummy_store.register_events(graph.walk())
  250. context_store = {}
  251. for event in graph.walk():
  252. context = yield defer.ensureDeferred(
  253. self.state.compute_event_context(event)
  254. )
  255. self.dummy_store.register_event_context(event, context)
  256. context_store[event.event_id] = context
  257. # C ends up winning the resolution between C and D because bans win over other
  258. # changes
  259. ctx_c = context_store["C"]
  260. ctx_e = context_store["E"]
  261. prev_state_ids = yield defer.ensureDeferred(ctx_e.get_prev_state_ids())
  262. self.assertSetEqual({"START", "A", "B", "C"}, set(prev_state_ids.values()))
  263. self.assertEqual(ctx_c.state_group, ctx_e.state_group_before_event)
  264. self.assertEqual(ctx_e.state_group_before_event, ctx_e.state_group)
  265. @defer.inlineCallbacks
  266. def test_branch_have_perms_conflict(self):
  267. userid1 = "@user_id:example.com"
  268. userid2 = "@user_id2:example.com"
  269. nodes = {
  270. "A1": DictObj(
  271. type=EventTypes.Create,
  272. state_key="",
  273. content={"creator": userid1},
  274. depth=1,
  275. ),
  276. "A2": DictObj(
  277. type=EventTypes.Member,
  278. state_key=userid1,
  279. content={"membership": Membership.JOIN},
  280. membership=Membership.JOIN,
  281. ),
  282. "A3": DictObj(
  283. type=EventTypes.Member,
  284. state_key=userid2,
  285. content={"membership": Membership.JOIN},
  286. membership=Membership.JOIN,
  287. ),
  288. "A4": DictObj(
  289. type=EventTypes.PowerLevels,
  290. state_key="",
  291. content={
  292. "events": {"m.room.name": 50},
  293. "users": {userid1: 100, userid2: 60},
  294. },
  295. ),
  296. "A5": DictObj(type=EventTypes.Name, state_key=""),
  297. "B": DictObj(
  298. type=EventTypes.PowerLevels,
  299. state_key="",
  300. content={"events": {"m.room.name": 50}, "users": {userid2: 30}},
  301. ),
  302. "C": DictObj(type=EventTypes.Name, state_key="", sender=userid2),
  303. "D": DictObj(type=EventTypes.Message),
  304. }
  305. edges = {
  306. "A2": ["A1"],
  307. "A3": ["A2"],
  308. "A4": ["A3"],
  309. "A5": ["A4"],
  310. "B": ["A5"],
  311. "C": ["A5"],
  312. "D": ["B", "C"],
  313. }
  314. self._add_depths(nodes, edges)
  315. graph = Graph(nodes, edges)
  316. self.dummy_store.register_events(graph.walk())
  317. context_store = {}
  318. for event in graph.walk():
  319. context = yield defer.ensureDeferred(
  320. self.state.compute_event_context(event)
  321. )
  322. self.dummy_store.register_event_context(event, context)
  323. context_store[event.event_id] = context
  324. # B ends up winning the resolution between B and C because power levels
  325. # win over other changes.
  326. ctx_b = context_store["B"]
  327. ctx_d = context_store["D"]
  328. prev_state_ids = yield defer.ensureDeferred(ctx_d.get_prev_state_ids())
  329. self.assertSetEqual({"A1", "A2", "A3", "A5", "B"}, set(prev_state_ids.values()))
  330. self.assertEqual(ctx_b.state_group, ctx_d.state_group_before_event)
  331. self.assertEqual(ctx_d.state_group_before_event, ctx_d.state_group)
  332. def _add_depths(self, nodes, edges):
  333. def _get_depth(ev):
  334. node = nodes[ev]
  335. if "depth" not in node:
  336. prevs = edges[ev]
  337. depth = max(_get_depth(prev) for prev in prevs) + 1
  338. node["depth"] = depth
  339. return node["depth"]
  340. for n in nodes:
  341. _get_depth(n)
  342. @defer.inlineCallbacks
  343. def test_annotate_with_old_message(self):
  344. event = create_event(type="test_message", name="event")
  345. old_state = [
  346. create_event(type="test1", state_key="1"),
  347. create_event(type="test1", state_key="2"),
  348. create_event(type="test2", state_key=""),
  349. ]
  350. context = yield defer.ensureDeferred(
  351. self.state.compute_event_context(event, old_state=old_state)
  352. )
  353. prev_state_ids = yield defer.ensureDeferred(context.get_prev_state_ids())
  354. self.assertCountEqual((e.event_id for e in old_state), prev_state_ids.values())
  355. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  356. self.assertCountEqual(
  357. (e.event_id for e in old_state), current_state_ids.values()
  358. )
  359. self.assertIsNotNone(context.state_group_before_event)
  360. self.assertEqual(context.state_group_before_event, context.state_group)
  361. @defer.inlineCallbacks
  362. def test_annotate_with_old_state(self):
  363. event = create_event(type="state", state_key="", name="event")
  364. old_state = [
  365. create_event(type="test1", state_key="1"),
  366. create_event(type="test1", state_key="2"),
  367. create_event(type="test2", state_key=""),
  368. ]
  369. context = yield defer.ensureDeferred(
  370. self.state.compute_event_context(event, old_state=old_state)
  371. )
  372. prev_state_ids = yield defer.ensureDeferred(context.get_prev_state_ids())
  373. self.assertCountEqual((e.event_id for e in old_state), prev_state_ids.values())
  374. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  375. self.assertCountEqual(
  376. (e.event_id for e in old_state + [event]), current_state_ids.values()
  377. )
  378. self.assertIsNotNone(context.state_group_before_event)
  379. self.assertNotEqual(context.state_group_before_event, context.state_group)
  380. self.assertEqual(context.state_group_before_event, context.prev_group)
  381. self.assertEqual({("state", ""): event.event_id}, context.delta_ids)
  382. @defer.inlineCallbacks
  383. def test_trivial_annotate_message(self):
  384. prev_event_id = "prev_event_id"
  385. event = create_event(
  386. type="test_message", name="event2", prev_events=[(prev_event_id, {})]
  387. )
  388. old_state = [
  389. create_event(type="test1", state_key="1"),
  390. create_event(type="test1", state_key="2"),
  391. create_event(type="test2", state_key=""),
  392. ]
  393. group_name = yield defer.ensureDeferred(
  394. self.dummy_store.store_state_group(
  395. prev_event_id,
  396. event.room_id,
  397. None,
  398. None,
  399. {(e.type, e.state_key): e.event_id for e in old_state},
  400. )
  401. )
  402. self.dummy_store.register_event_id_state_group(prev_event_id, group_name)
  403. context = yield defer.ensureDeferred(self.state.compute_event_context(event))
  404. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  405. self.assertEqual(
  406. {e.event_id for e in old_state}, set(current_state_ids.values())
  407. )
  408. self.assertEqual(group_name, context.state_group)
  409. @defer.inlineCallbacks
  410. def test_trivial_annotate_state(self):
  411. prev_event_id = "prev_event_id"
  412. event = create_event(
  413. type="state", state_key="", name="event2", prev_events=[(prev_event_id, {})]
  414. )
  415. old_state = [
  416. create_event(type="test1", state_key="1"),
  417. create_event(type="test1", state_key="2"),
  418. create_event(type="test2", state_key=""),
  419. ]
  420. group_name = yield defer.ensureDeferred(
  421. self.dummy_store.store_state_group(
  422. prev_event_id,
  423. event.room_id,
  424. None,
  425. None,
  426. {(e.type, e.state_key): e.event_id for e in old_state},
  427. )
  428. )
  429. self.dummy_store.register_event_id_state_group(prev_event_id, group_name)
  430. context = yield defer.ensureDeferred(self.state.compute_event_context(event))
  431. prev_state_ids = yield defer.ensureDeferred(context.get_prev_state_ids())
  432. self.assertEqual({e.event_id for e in old_state}, set(prev_state_ids.values()))
  433. self.assertIsNotNone(context.state_group)
  434. @defer.inlineCallbacks
  435. def test_resolve_message_conflict(self):
  436. prev_event_id1 = "event_id1"
  437. prev_event_id2 = "event_id2"
  438. event = create_event(
  439. type="test_message",
  440. name="event3",
  441. prev_events=[(prev_event_id1, {}), (prev_event_id2, {})],
  442. )
  443. creation = create_event(type=EventTypes.Create, state_key="")
  444. old_state_1 = [
  445. creation,
  446. create_event(type="test1", state_key="1"),
  447. create_event(type="test1", state_key="2"),
  448. create_event(type="test2", state_key=""),
  449. ]
  450. old_state_2 = [
  451. creation,
  452. create_event(type="test1", state_key="1"),
  453. create_event(type="test3", state_key="2"),
  454. create_event(type="test4", state_key=""),
  455. ]
  456. self.dummy_store.register_events(old_state_1)
  457. self.dummy_store.register_events(old_state_2)
  458. context = yield self._get_context(
  459. event, prev_event_id1, old_state_1, prev_event_id2, old_state_2
  460. )
  461. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  462. self.assertEqual(len(current_state_ids), 6)
  463. self.assertIsNotNone(context.state_group)
  464. @defer.inlineCallbacks
  465. def test_resolve_state_conflict(self):
  466. prev_event_id1 = "event_id1"
  467. prev_event_id2 = "event_id2"
  468. event = create_event(
  469. type="test4",
  470. state_key="",
  471. name="event",
  472. prev_events=[(prev_event_id1, {}), (prev_event_id2, {})],
  473. )
  474. creation = create_event(type=EventTypes.Create, state_key="")
  475. old_state_1 = [
  476. creation,
  477. create_event(type="test1", state_key="1"),
  478. create_event(type="test1", state_key="2"),
  479. create_event(type="test2", state_key=""),
  480. ]
  481. old_state_2 = [
  482. creation,
  483. create_event(type="test1", state_key="1"),
  484. create_event(type="test3", state_key="2"),
  485. create_event(type="test4", state_key=""),
  486. ]
  487. store = _DummyStore()
  488. store.register_events(old_state_1)
  489. store.register_events(old_state_2)
  490. self.dummy_store.get_events = store.get_events
  491. context = yield self._get_context(
  492. event, prev_event_id1, old_state_1, prev_event_id2, old_state_2
  493. )
  494. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  495. self.assertEqual(len(current_state_ids), 6)
  496. self.assertIsNotNone(context.state_group)
  497. @defer.inlineCallbacks
  498. def test_standard_depth_conflict(self):
  499. prev_event_id1 = "event_id1"
  500. prev_event_id2 = "event_id2"
  501. event = create_event(
  502. type="test4",
  503. name="event",
  504. prev_events=[(prev_event_id1, {}), (prev_event_id2, {})],
  505. )
  506. member_event = create_event(
  507. type=EventTypes.Member,
  508. state_key="@user_id:example.com",
  509. content={"membership": Membership.JOIN},
  510. )
  511. power_levels = create_event(
  512. type=EventTypes.PowerLevels,
  513. state_key="",
  514. content={"users": {"@foo:bar": "100", "@user_id:example.com": "100"}},
  515. )
  516. creation = create_event(
  517. type=EventTypes.Create, state_key="", content={"creator": "@foo:bar"}
  518. )
  519. old_state_1 = [
  520. creation,
  521. power_levels,
  522. member_event,
  523. create_event(type="test1", state_key="1", depth=1),
  524. ]
  525. old_state_2 = [
  526. creation,
  527. power_levels,
  528. member_event,
  529. create_event(type="test1", state_key="1", depth=2),
  530. ]
  531. store = _DummyStore()
  532. store.register_events(old_state_1)
  533. store.register_events(old_state_2)
  534. self.dummy_store.get_events = store.get_events
  535. context = yield self._get_context(
  536. event, prev_event_id1, old_state_1, prev_event_id2, old_state_2
  537. )
  538. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  539. self.assertEqual(old_state_2[3].event_id, current_state_ids[("test1", "1")])
  540. # Reverse the depth to make sure we are actually using the depths
  541. # during state resolution.
  542. old_state_1 = [
  543. creation,
  544. power_levels,
  545. member_event,
  546. create_event(type="test1", state_key="1", depth=2),
  547. ]
  548. old_state_2 = [
  549. creation,
  550. power_levels,
  551. member_event,
  552. create_event(type="test1", state_key="1", depth=1),
  553. ]
  554. store.register_events(old_state_1)
  555. store.register_events(old_state_2)
  556. context = yield self._get_context(
  557. event, prev_event_id1, old_state_1, prev_event_id2, old_state_2
  558. )
  559. current_state_ids = yield defer.ensureDeferred(context.get_current_state_ids())
  560. self.assertEqual(old_state_1[3].event_id, current_state_ids[("test1", "1")])
  561. @defer.inlineCallbacks
  562. def _get_context(
  563. self, event, prev_event_id_1, old_state_1, prev_event_id_2, old_state_2
  564. ):
  565. sg1 = yield defer.ensureDeferred(
  566. self.dummy_store.store_state_group(
  567. prev_event_id_1,
  568. event.room_id,
  569. None,
  570. None,
  571. {(e.type, e.state_key): e.event_id for e in old_state_1},
  572. )
  573. )
  574. self.dummy_store.register_event_id_state_group(prev_event_id_1, sg1)
  575. sg2 = yield defer.ensureDeferred(
  576. self.dummy_store.store_state_group(
  577. prev_event_id_2,
  578. event.room_id,
  579. None,
  580. None,
  581. {(e.type, e.state_key): e.event_id for e in old_state_2},
  582. )
  583. )
  584. self.dummy_store.register_event_id_state_group(prev_event_id_2, sg2)
  585. result = yield defer.ensureDeferred(self.state.compute_event_context(event))
  586. return result