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
Ensure (room_id, next_batch_id)
is unique to avoid cross-talk/conflicts between batches (MSC2716)
#10877
Merged
MadLittleMods
merged 7 commits into
develop
from
madlittlemods/ensure-unique-next-batch-id
Sep 29, 2021
Merged
Ensure (room_id, next_batch_id)
is unique to avoid cross-talk/conflicts between batches (MSC2716)
#10877
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff32a57
Ensure (room_id, next_batch_id) is unique to avoid cross-talk/conflic…
MadLittleMods 1f3946e
Add changelog
MadLittleMods fd32072
Fix lint
MadLittleMods 8daa576
Add punctuation to changelog
MadLittleMods 21200f8
Stop people from sending duplicate insertion events
MadLittleMods b22c9fa
Also check insertion events from room creators in existing room versions
MadLittleMods ffa31e0
Fix lint
MadLittleMods 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 @@ | ||
Ensure `(room_id, next_batch_id)` is unique across [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) insertion events in rooms to avoid cross-talk/conflicts between batches. | ||
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
# limitations under the License. | ||
import logging | ||
import random | ||
from http import HTTPStatus | ||
from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Tuple | ||
|
||
from canonicaljson import encode_canonical_json | ||
|
@@ -1461,6 +1462,41 @@ async def persist_and_notify_client_event( | |
if prev_state_ids: | ||
raise AuthError(403, "Changing the room create event is forbidden") | ||
|
||
if event.type == EventTypes.MSC2716_INSERTION: | ||
room_version = await self.store.get_room_version_id(event.room_id) | ||
room_version_obj = KNOWN_ROOM_VERSIONS[room_version] | ||
|
||
create_event = await self.store.get_create_event_for_room( | ||
event.room_id | ||
) | ||
room_creator = create_event.content.get(EventContentFields.ROOM_CREATOR) | ||
|
||
# Only check an insertion event if the room version | ||
# supports it or the event is from the room creator. | ||
if room_version_obj.msc2716_historical or ( | ||
self._config.experimental.msc2716_enabled | ||
and event.sender == room_creator | ||
): | ||
next_batch_id = event.content.get( | ||
EventContentFields.MSC2716_NEXT_BATCH_ID | ||
) | ||
conflicting_insertion_event_id = ( | ||
await self.store.get_insertion_event_by_batch_id( | ||
event.room_id, next_batch_id | ||
) | ||
) | ||
if conflicting_insertion_event_id is not None: | ||
# The current insertion event that we're processing is invalid | ||
# because an insertion event already exists in the room with the | ||
# same next_batch_id. We can't allow multiple because the batch | ||
# pointing will get weird, e.g. we can't determine which insertion | ||
# event the batch event is pointing to. | ||
raise SynapseError( | ||
HTTPStatus.BAD_REQUEST, | ||
"Another insertion event already exists with the same next_batch_id", | ||
errcode=Codes.INVALID_PARAM, | ||
) | ||
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. When we receive events over federation, should we ignore duplicate insertion events? In a previous iteration of this PR, I ignored duplicate conflicting insertion events that came over federation but really wanted to reject/soft_fail instead (felt more right). I can't add a conflict database lookup in Maybe it's better to just let them do what they want and we can just stop this from the |
||
|
||
# Mark any `m.historical` messages as backfilled so they don't appear | ||
# in `/sync` and have the proper decrementing `stream_ordering` as we import | ||
backfilled = False | ||
|
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.
@erikjohnston If possible, but you shied away from it in #10245 (comment)
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.
Oh lols. I'm not sure I agree with myself there, but haven't really thought about it. Anyway, doesn't need to block this PR.