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

Commit 2e05f5d

Browse files
authored
Merge pull request #2025 from matrix-org/rav/no_reset_state_on_rejections
Avoid resetting state on rejected events
2 parents 2abe85d + 0c01f82 commit 2e05f5d

6 files changed

Lines changed: 278 additions & 84 deletions

File tree

synapse/events/snapshot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@
1515

1616

1717
class EventContext(object):
18+
"""
19+
Attributes:
20+
current_state_ids (dict[(str, str), str]):
21+
The current state map including the current event.
22+
(type, state_key) -> event_id
23+
24+
prev_state_ids (dict[(str, str), str]):
25+
The current state map excluding the current event.
26+
(type, state_key) -> event_id
27+
28+
state_group (int): state group id
29+
rejected (bool|str): A rejection reason if the event was rejected, else
30+
False
31+
32+
push_actions (list[(str, list[object])]): list of (user_id, actions)
33+
tuples
34+
35+
prev_group (int): Previously persisted state group. ``None`` for an
36+
outlier.
37+
delta_ids (dict[(str, str), str]): Delta from ``prev_group``.
38+
(type, state_key) -> event_id. ``None`` for an outlier.
39+
40+
prev_state_events (?): XXX: is this ever set to anything other than
41+
the empty list?
42+
"""
43+
1844
__slots__ = [
1945
"current_state_ids",
2046
"prev_state_ids",

synapse/handlers/federation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,17 @@ def _persist_auth_tree(self, origin, auth_events, state, event):
15371537

15381538
@defer.inlineCallbacks
15391539
def _prep_event(self, origin, event, state=None, auth_events=None):
1540+
"""
1541+
1542+
Args:
1543+
origin:
1544+
event:
1545+
state:
1546+
auth_events:
15401547
1548+
Returns:
1549+
Deferred, which resolves to synapse.events.snapshot.EventContext
1550+
"""
15411551
context = yield self.state_handler.compute_event_context(
15421552
event, old_state=state,
15431553
)

synapse/state.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,12 @@ def get_current_user_in_room(self, room_id, latest_event_ids=None):
177177

178178
@defer.inlineCallbacks
179179
def compute_event_context(self, event, old_state=None):
180-
""" Fills out the context with the `current state` of the graph. The
181-
`current state` here is defined to be the state of the event graph
182-
just before the event - i.e. it never includes `event`
183-
184-
If `event` has `auth_events` then this will also fill out the
185-
`auth_events` field on `context` from the `current_state`.
180+
"""Build an EventContext structure for the event.
186181
187182
Args:
188-
event (EventBase)
183+
event (synapse.events.EventBase):
189184
Returns:
190-
an EventContext
185+
synapse.events.snapshot.EventContext:
191186
"""
192187
context = EventContext()
193188

synapse/storage/event_federation.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,19 @@ def _get_min_depth_interaction(self, txn, room_id):
201201
def _update_min_depth_for_room_txn(self, txn, room_id, depth):
202202
min_depth = self._get_min_depth_interaction(txn, room_id)
203203

204-
do_insert = depth < min_depth if min_depth else True
204+
if min_depth and depth >= min_depth:
205+
return
205206

206-
if do_insert:
207-
self._simple_upsert_txn(
208-
txn,
209-
table="room_depth",
210-
keyvalues={
211-
"room_id": room_id,
212-
},
213-
values={
214-
"min_depth": depth,
215-
},
216-
)
207+
self._simple_upsert_txn(
208+
txn,
209+
table="room_depth",
210+
keyvalues={
211+
"room_id": room_id,
212+
},
213+
values={
214+
"min_depth": depth,
215+
},
216+
)
217217

218218
def _handle_mult_prev_events(self, txn, events):
219219
"""

0 commit comments

Comments
 (0)