This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix bug in state group storage #2649
Merged
+58
−33
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1706,6 +1706,17 @@ def on_get_missing_events(self, origin, room_id, earliest_events, | |
@defer.inlineCallbacks | ||
@log_function | ||
def do_auth(self, origin, event, context, auth_events): | ||
""" | ||
|
||
Args: | ||
origin (str): | ||
event (synapse.events.FrozenEvent): | ||
context (synapse.events.snapshot.EventContext): | ||
auth_events (dict[(str, str)->str]): | ||
|
||
Returns: | ||
defer.Deferred[None] | ||
""" | ||
# Check if we have all the auth events. | ||
current_state = set(e.event_id for e in auth_events.values()) | ||
event_auth_events = set(e_id for e_id, _ in event.auth_events) | ||
|
@@ -1817,16 +1828,9 @@ def do_auth(self, origin, event, context, auth_events): | |
current_state = set(e.event_id for e in auth_events.values()) | ||
different_auth = event_auth_events - current_state | ||
|
||
context.current_state_ids = dict(context.current_state_ids) | ||
context.current_state_ids.update({ | ||
k: a.event_id for k, a in auth_events.items() | ||
if k != event_key | ||
}) | ||
context.prev_state_ids = dict(context.prev_state_ids) | ||
context.prev_state_ids.update({ | ||
k: a.event_id for k, a in auth_events.items() | ||
}) | ||
context.state_group = self.store.get_next_state_group() | ||
self._update_context_for_auth_events( | ||
context, auth_events, event_key, | ||
) | ||
|
||
if different_auth and not event.internal_metadata.is_outlier(): | ||
logger.info("Different auth after resolution: %s", different_auth) | ||
|
@@ -1906,23 +1910,45 @@ def do_auth(self, origin, event, context, auth_events): | |
# 4. Look at rejects and their proofs. | ||
# TODO. | ||
|
||
context.current_state_ids = dict(context.current_state_ids) | ||
context.current_state_ids.update({ | ||
k: a.event_id for k, a in auth_events.items() | ||
if k != event_key | ||
}) | ||
context.prev_state_ids = dict(context.prev_state_ids) | ||
context.prev_state_ids.update({ | ||
k: a.event_id for k, a in auth_events.items() | ||
}) | ||
context.state_group = self.store.get_next_state_group() | ||
self._update_context_for_auth_events( | ||
context, auth_events, event_key, | ||
) | ||
|
||
try: | ||
self.auth.check(event, auth_events=auth_events) | ||
except AuthError as e: | ||
logger.warn("Failed auth resolution for %r because %s", event, e) | ||
raise e | ||
|
||
def _update_context_for_auth_events(self, context, auth_events, | ||
event_key): | ||
"""Update the state_ids in an event context after auth event resolution | ||
|
||
Args: | ||
context (synapse.events.snapshot.EventContext): event context | ||
to be updated | ||
|
||
auth_events (dict[(str, str)->str]): Events to update in the event | ||
context. | ||
|
||
event_key ((str, str)): (type, state_key) for the current event. | ||
this will not be included in the current_state in the context. | ||
""" | ||
state_updates = { | ||
k: a.event_id for k, a in auth_events.items() | ||
if k != event_key | ||
} | ||
context.current_state_ids = dict(context.current_state_ids) | ||
context.current_state_ids.update(state_updates) | ||
if context.delta_ids is not None: | ||
context.delta_ids = dict(context.delta_ids) | ||
context.delta_ids.update(state_updates) | ||
context.prev_state_ids = dict(context.prev_state_ids) | ||
context.prev_state_ids.update({ | ||
k: a.event_id for k, a in auth_events.items() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
}) | ||
context.state_group = self.store.get_next_state_group() | ||
|
||
@defer.inlineCallbacks | ||
def construct_auth_difference(self, local_auth, remote_auth): | ||
""" Given a local and remote auth chain, find the differences. This | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.iteritems()
would be nice