-
Notifications
You must be signed in to change notification settings - Fork 503
MSC4242: State DAGs (CSAPI) #19424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
MSC4242: State DAGs (CSAPI) #19424
Changes from 3 commits
48e1e73
dc3db60
fc4975f
b69986d
c561c0d
3dff3ac
aa46122
2f82a5b
606ce6b
7311f92
85fa59e
332fd2d
4ea71e0
7a1be81
d96737b
c9d8d9f
2f8fece
bc91229
6ecf821
ecc9860
a0711ef
85fc75c
f790d3a
206c77a
0b155b7
cdf9054
3a51f74
d59f31a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add experimental support for MSC4242: State DAGs. Excludes federation support. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,7 +61,7 @@ | |||||
| RoomVersion, | ||||||
| RoomVersions, | ||||||
| ) | ||||||
| from synapse.events import is_creator | ||||||
| from synapse.events import FrozenEventVMSC4242, is_creator | ||||||
| from synapse.state import CREATE_KEY | ||||||
| from synapse.storage.databases.main.events_worker import EventRedactBehaviour | ||||||
| from synapse.types import ( | ||||||
|
|
@@ -186,6 +186,70 @@ async def check_state_independent_auth_rules( | |||||
| # 1.5 Otherwise, allow | ||||||
| return | ||||||
|
|
||||||
| # State DAGs 2. Considering the event's prev_state_events: | ||||||
kegsay marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if event.room_version.msc4242_state_dags: | ||||||
| prev_state_events_ids = set(cast(FrozenEventVMSC4242, event).prev_state_events) | ||||||
| needed_prev_state_event_ids = { | ||||||
| event_id | ||||||
| for event_id in prev_state_events_ids | ||||||
| if not batched_auth_events or event_id not in batched_auth_events | ||||||
| } | ||||||
| prev_state_events = ( | ||||||
| {} | ||||||
| if not batched_auth_events | ||||||
| else { | ||||||
| e: batched_auth_events[e] | ||||||
| for e in prev_state_events_ids - needed_prev_state_event_ids | ||||||
| } | ||||||
| ) | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| if len(needed_prev_state_event_ids) > 0: | ||||||
| needed_prev_state_events = await store.get_events( | ||||||
| needed_prev_state_event_ids, | ||||||
| redact_behaviour=EventRedactBehaviour.as_is, | ||||||
| allow_rejected=True, | ||||||
| ) | ||||||
| prev_state_events.update(needed_prev_state_events) | ||||||
| if len(prev_state_events) != len(prev_state_events_ids): | ||||||
| # we should have all the prev state events by now, so if we do not, that suggests | ||||||
|
Contributor
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.
Suggested change
|
||||||
| # a synapse programming error | ||||||
|
Contributor
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.
Suggested change
|
||||||
| known_prev_state_event_ids = set(prev_state_events) | ||||||
| raise RuntimeError( | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| f"Event {event.event_id} has unknown prev state events " | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| + f"{len(prev_state_events)} != {len(prev_state_events_ids)} " | ||||||
|
Contributor
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. To avoid some of the jumble of output we can group this together better with a description.
Suggested change
|
||||||
| + f"{prev_state_events_ids - known_prev_state_event_ids} missing " | ||||||
| + f"out of {prev_state_events_ids}" | ||||||
| ) | ||||||
| for prev_state_event in prev_state_events.values(): | ||||||
| # 2.1 If there are entries which do not belong in the same room, reject. | ||||||
| if prev_state_event.room_id != event.room_id: | ||||||
| raise AuthError( | ||||||
| 403, | ||||||
| "During auth for event %s in room %s, found event %s in prev state events " | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| "which is in room %s" | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| % ( | ||||||
| event.event_id, | ||||||
| event.room_id, | ||||||
| prev_state_event.event_id, | ||||||
| prev_state_event.room_id, | ||||||
| ), | ||||||
| ) | ||||||
| # 2.2 If there are entries which do not have a state_key, reject. | ||||||
| if not prev_state_event.is_state(): | ||||||
| raise AuthError( | ||||||
| 403, | ||||||
| f"During auth for event {event.event_id} in room {event.room_id}, event has a " | ||||||
| + f"prev_state_event which is not state: {prev_state_event.event_id}", | ||||||
| ) | ||||||
| # 2.3 If there are entries which were themselves rejected under the checks performed on | ||||||
| # receipt of a PDU, reject. | ||||||
| if prev_state_event.rejected_reason is not None: | ||||||
| raise AuthError( | ||||||
| 403, | ||||||
| f"During auth for event {event.event_id} in room {event.room_id}, event has a " | ||||||
| + f"prev_state_event which is rejected ({prev_state_event.rejected_reason}): " | ||||||
| + f"{prev_state_event.event_id}", | ||||||
| ) | ||||||
|
|
||||||
| # 2. Reject if event has auth_events that: ... | ||||||
| auth_events: ChainMap[str, EventBase] = ChainMap() | ||||||
| if batched_auth_events: | ||||||
|
|
@@ -471,6 +535,13 @@ def _check_create(event: "EventBase") -> None: | |||||
| if event.prev_event_ids(): | ||||||
| raise AuthError(403, "Create event has prev events") | ||||||
|
|
||||||
| # State DAGs 1.2 If it has any prev_state_events, reject. | ||||||
| if ( | ||||||
| event.room_version.msc4242_state_dags | ||||||
| and cast(FrozenEventVMSC4242, event).prev_state_events | ||||||
kegsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ): | ||||||
| raise AuthError(403, "Create event has prev state events") | ||||||
|
|
||||||
| if event.room_version.msc4291_room_ids_as_hashes: | ||||||
| # 1.2 If the create event has a room_id, reject | ||||||
| if "room_id" in event: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.