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

Refactor state module to support multiple room versions #3673

Merged
merged 9 commits into from
Aug 22, 2018

Conversation

erikjohnston
Copy link
Member

This lays the ground work for supporting different state resolution algorithms depending on room version.

The two big changes are:

  1. Move and split state.py into state/__init__.py and state/v1.py, where the latter contains only the v1 state resolution algorithm.
  2. Make the state handler aware of room versions and choose the algorithm used based on that.

The reason for checking the room version so late is because large amounts of code assume that if the state handler is given a bunch of event_ids it doesn't have, it'll return an empty state rather than throwing an error. (In particular, a lot of client APIs don't check if the room exists before trying to create the events, and instead rely on the event auth to throw a 403 on empty state). This is not great and should be fixed, but I don't really want to try and block implementing v2 state resolution on fixing that.

There should be no behavioural change here.

@erikjohnston erikjohnston force-pushed the erikj/refactor_state_handler branch from 035d4c4 to 5075e44 Compare August 9, 2018 13:59
@erikjohnston erikjohnston requested a review from a team August 9, 2018 13:59
@@ -341,9 +341,10 @@ def _update_membership(
prev_events_and_hashes = yield self.store.get_prev_events_for_room(
room_id,
)
latest_event_ids = (
latest_event_ids = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this used to be a required change but no longer. Will change it back for simplicity of PR

@@ -365,8 +378,13 @@ def resolve_state_groups_for_events(self, room_id, event_ids):
delta_ids=delta_ids,
))

room_version = explicit_room_version
if not room_version:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surely we should never get here for an m.room.create, because we should never have to do state resolution?

In other words: explicit_room_version seems redundant.

@@ -390,14 +409,18 @@ def resolve_events(self, state_sets, event):
for ev in st
}

room_version = yield self.store.get_room_version(event.room_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks redundant, since it's passed as an arg.

@richvdh
Copy link
Member

richvdh commented Aug 17, 2018

I'm assuming that the stuff in synapse/state/v1.py has just moved out of synapse/state.py - it's hard to check this. Generally I'd have preferred this to be split into one PR which makes the state handler aware of room versions, and another to move the v1 stuff out.

@erikjohnston erikjohnston force-pushed the erikj/refactor_state_handler branch from 34982f4 to 3f6013d Compare August 20, 2018 13:27
@erikjohnston erikjohnston force-pushed the erikj/refactor_state_handler branch from 3f6013d to 4d66427 Compare August 20, 2018 13:53
@erikjohnston
Copy link
Member Author

I'm assuming that the stuff in synapse/state/v1.py has just moved out of synapse/state.py - it's hard to check this.

Yup, its just a copy and paste.

Generally I'd have preferred this to be split into one PR which makes the state handler aware of room versions, and another to move the v1 stuff out.

Ah sorry. FWIW I did the split up in the first commit and then changed it to make it version aware.

@erikjohnston erikjohnston assigned richvdh and unassigned erikjohnston Aug 20, 2018
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -262,14 +262,9 @@ def compute_event_context(self, event, old_state=None):
defer.returnValue(context)

logger.debug("calling resolve_state_groups from compute_event_context")
if event.type == EventTypes.Create:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could explicitly assert that event.type != EventTypes.Create here to give a slightly more comprehensible failure if/when it happens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creation events will happily reach that point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. why would we ever be doing state res on create events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, but we do call compute_event_context, and that gets nooped in resolve_state_groups_for_events since it has not prev events

@richvdh richvdh assigned erikjohnston and unassigned richvdh Aug 21, 2018
@erikjohnston erikjohnston merged commit 3bf8bab into develop Aug 22, 2018
@erikjohnston erikjohnston deleted the erikj/refactor_state_handler branch September 20, 2018 13:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants