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
Add rooms.room_version
column
#6729
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b6be4b
Have `make_membership_event` return room version
erikjohnston f01d0d5
Check room_version from make_join matches returned state.
erikjohnston a42b675
Use RoomVersion consistently throughout room upgrade
erikjohnston 963237f
Add rooms.room_version column and populate it in store_room
erikjohnston e7618af
Read room version from rooms table.
erikjohnston 0bb025a
Newsfile
erikjohnston 892bab9
Add background update
erikjohnston 70be703
Correctly raise exception if unknown room version
erikjohnston ced73b3
Add comment
erikjohnston 53a75fa
Use explicit is not None
erikjohnston e825fd0
Add comments about paranoia
erikjohnston 1474a49
Correctly handle and document UnsupportedRoomVersionError
erikjohnston 126599e
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/ro…
erikjohnston 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Record room versions in the `rooms` table. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,10 @@ | |
StoreError, | ||
SynapseError, | ||
) | ||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersions | ||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions | ||
from synapse.crypto.event_signing import compute_event_signature | ||
from synapse.event_auth import auth_types_for_event | ||
from synapse.events import EventBase | ||
from synapse.events import EventBase, room_version_to_event_format | ||
from synapse.events.snapshot import EventContext | ||
from synapse.events.validator import EventValidator | ||
from synapse.logging.context import ( | ||
|
@@ -703,8 +703,20 @@ async def _process_received_pdu( | |
|
||
if not room: | ||
try: | ||
prev_state_ids = await context.get_prev_state_ids() | ||
create_event = await self.store.get_event( | ||
prev_state_ids[(EventTypes.Create, "")] | ||
) | ||
|
||
room_version_id = create_event.content.get( | ||
"room_version", RoomVersions.V1.identifier | ||
) | ||
|
||
await self.store.store_room( | ||
room_id=room_id, room_creator_user_id="", is_public=False | ||
room_id=room_id, | ||
room_creator_user_id="", | ||
is_public=False, | ||
room_version=KNOWN_ROOM_VERSIONS[room_version_id], | ||
) | ||
except StoreError: | ||
logger.exception("Failed to store room.") | ||
|
@@ -1186,7 +1198,7 @@ def do_invite_join(self, target_hosts, room_id, joinee, content): | |
""" | ||
logger.debug("Joining %s to %s", joinee, room_id) | ||
|
||
origin, event, event_format_version = yield self._make_and_verify_event( | ||
origin, event, room_version = yield self._make_and_verify_event( | ||
target_hosts, | ||
room_id, | ||
joinee, | ||
|
@@ -1214,6 +1226,8 @@ def do_invite_join(self, target_hosts, room_id, joinee, content): | |
target_hosts.insert(0, origin) | ||
except ValueError: | ||
pass | ||
|
||
event_format_version = room_version_to_event_format(room_version.identifier) | ||
ret = yield self.federation_client.send_join( | ||
target_hosts, event, event_format_version | ||
) | ||
|
@@ -1234,13 +1248,18 @@ def do_invite_join(self, target_hosts, room_id, joinee, content): | |
|
||
try: | ||
yield self.store.store_room( | ||
room_id=room_id, room_creator_user_id="", is_public=False | ||
room_id=room_id, | ||
room_creator_user_id="", | ||
is_public=False, | ||
room_version=room_version, | ||
) | ||
except Exception: | ||
# FIXME | ||
pass | ||
|
||
yield self._persist_auth_tree(origin, auth_chain, state, event) | ||
yield self._persist_auth_tree( | ||
origin, auth_chain, state, event, room_version | ||
) | ||
|
||
# Check whether this room is the result of an upgrade of a room we already know | ||
# about. If so, migrate over user information | ||
|
@@ -1486,7 +1505,7 @@ def on_invite_request(self, origin, pdu): | |
|
||
@defer.inlineCallbacks | ||
def do_remotely_reject_invite(self, target_hosts, room_id, user_id, content): | ||
origin, event, event_format_version = yield self._make_and_verify_event( | ||
origin, event, room_version = yield self._make_and_verify_event( | ||
target_hosts, room_id, user_id, "leave", content=content | ||
) | ||
# Mark as outlier as we don't have any state for this event; we're not | ||
|
@@ -1513,7 +1532,11 @@ def do_remotely_reject_invite(self, target_hosts, room_id, user_id, content): | |
def _make_and_verify_event( | ||
self, target_hosts, room_id, user_id, membership, content={}, params=None | ||
): | ||
origin, event, format_ver = yield self.federation_client.make_membership_event( | ||
( | ||
origin, | ||
event, | ||
room_version, | ||
) = yield self.federation_client.make_membership_event( | ||
target_hosts, room_id, user_id, membership, content, params=params | ||
) | ||
|
||
|
@@ -1525,7 +1548,7 @@ def _make_and_verify_event( | |
assert event.user_id == user_id | ||
assert event.state_key == user_id | ||
assert event.room_id == room_id | ||
return origin, event, format_ver | ||
return origin, event, room_version | ||
|
||
@defer.inlineCallbacks | ||
@log_function | ||
|
@@ -1810,7 +1833,14 @@ def prep(ev_info: _NewEventInfo): | |
) | ||
|
||
@defer.inlineCallbacks | ||
def _persist_auth_tree(self, origin, auth_events, state, event): | ||
def _persist_auth_tree( | ||
self, | ||
origin: str, | ||
auth_events: List[EventBase], | ||
state: List[EventBase], | ||
event: EventBase, | ||
room_version: RoomVersion, | ||
erikjohnston marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
"""Checks the auth chain is valid (and passes auth checks) for the | ||
state and event. Then persists the auth chain and state atomically. | ||
Persists the event separately. Notifies about the persisted events | ||
|
@@ -1819,10 +1849,12 @@ def _persist_auth_tree(self, origin, auth_events, state, event): | |
Will attempt to fetch missing auth events. | ||
|
||
Args: | ||
origin (str): Where the events came from | ||
auth_events (list) | ||
state (list) | ||
event (Event) | ||
origin: Where the events came from | ||
auth_events | ||
state | ||
event | ||
room_version: The room version we expect this room to have, and | ||
will raise if it doesn't match the version in the create event. | ||
|
||
Returns: | ||
Deferred | ||
|
@@ -1848,10 +1880,13 @@ def _persist_auth_tree(self, origin, auth_events, state, event): | |
# invalid, and it would fail auth checks anyway. | ||
raise SynapseError(400, "No create event in state") | ||
|
||
room_version = create_event.content.get( | ||
room_version_id = create_event.content.get( | ||
"room_version", RoomVersions.V1.identifier | ||
) | ||
|
||
if room_version.identifier != room_version_id: | ||
raise SynapseError(400, "Room version mismatch") | ||
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. I'm not sure that 400 is the right response code when the remote server lies to us, but 🤷♂️ 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. It's the closest error code to "please bugger off and never sully our doors with that request again" that I know of :) |
||
|
||
missing_auth_events = set() | ||
for e in itertools.chain(auth_events, state, [event]): | ||
for e_id in e.auth_event_ids(): | ||
|
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
Oops, something went wrong.
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.
this could conceivably return
None
? in which case that should be documented in the docstring?Or it should be changed to
KNOWN_ROOM_VERSIONS[room_version_id]
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.
It now raises an
UnsupportedRoomVersionError
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.
could probably do with putting that in the docstring too.