|
| 1 | +# MSC3706: Extensions to `/_matrix/federation/v2/send_join/{roomId}/{eventId}` for partial state |
| 2 | + |
| 3 | +## Background |
| 4 | + |
| 5 | +It is well known that joining large rooms over federation can be very slow (see, |
| 6 | +for example, [synapse#1211](https://github.com/matrix-org/synapse/issues/1211)). |
| 7 | + |
| 8 | +Much of the reason for this is the large number of events which are returned by |
| 9 | +the [`/send_join`](https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv2send_joinroomideventid) |
| 10 | +API, and must be validated and stored. |
| 11 | + |
| 12 | +[MSC3902](https://github.com/matrix-org/matrix-doc/pull/3902) gives an overview |
| 13 | +of changes to the matrix protocol to improve this situation. This MSC focuses |
| 14 | +on a specific aspect of those suggestions by proposing specific changes to the |
| 15 | +`/send_join` API. |
| 16 | + |
| 17 | +## Proposal |
| 18 | + |
| 19 | +[`PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`](https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv2send_joinroomideventid) |
| 20 | +is extended to support "partial state" in its responses. This involves the |
| 21 | +following changes. |
| 22 | + |
| 23 | +### New query parameter |
| 24 | + |
| 25 | +`omit_members` is added as a new query parameter. This can take the values |
| 26 | +`true` or `false`; other values should be rejected with an HTTP 400 error with |
| 27 | +matrix error code `M_INVALID_PARAM`. |
| 28 | + |
| 29 | +Calling servers use this parameter to indicate support for partial state in |
| 30 | +`send_join`. If it is not set to `true`, receiving servers continue to behave |
| 31 | +as they do today. |
| 32 | + |
| 33 | +### Changes to the response |
| 34 | + |
| 35 | +Receiving servers are not obliged to implement partial state: they are also |
| 36 | +free to support it for some rooms and not others. |
| 37 | + |
| 38 | +The following changes are made to the response: |
| 39 | + |
| 40 | + * `members_omitted`: a new boolean field is added. This should be set to `true` |
| 41 | + to indicate that `m.room.member` events have been omitted from the response. |
| 42 | + It must otherwise be set to `false` or omitted. |
| 43 | + |
| 44 | + * `state`: if partial state is being returned, then state events with event |
| 45 | + type `m.room.member` are omitted from the response. All other room state is |
| 46 | + returned as normal. (See 'Alternatives' for discussion on why only |
| 47 | + `m.room.member` events are omitted.) |
| 48 | + |
| 49 | + * `auth_chain`: The spec currently defines this as "The auth chain for the |
| 50 | + entire current room state". We instead rephrase this as: |
| 51 | + |
| 52 | + > All events in the auth chain for the returned join event, as well as |
| 53 | + > those in the auth chains for any events returned in `state`. |
| 54 | +
|
| 55 | + (Note that in the case that full state is being returned, the two |
| 56 | + definitions are equivalent.) |
| 57 | + |
| 58 | + * If the `omit_members` query parameter was set, we make a further |
| 59 | + optimisation to `auth_chain`: |
| 60 | + |
| 61 | + > Any events returned within `state` can be omitted from `auth_chain`. |
| 62 | +
|
| 63 | + For example: the `m.room.create` event is part of the room state, so |
| 64 | + must be included in `state`. However, it also forms part of the auth chain |
| 65 | + for all of the returned events, so in the current spec, must *also* be |
| 66 | + included in `auth_chain`. However, this is redundant, so we should omit it |
| 67 | + for calling servers which opt into that via the `omit_members` query param. |
| 68 | + |
| 69 | + * `servers_in_room`: A new field of type `[string]`, listing the servers |
| 70 | + active in the room (ie, those with joined members) before the join. |
| 71 | + |
| 72 | + This is to be used by the joining server to send outgoing federation |
| 73 | + transactions while it synchronises the full state, as outlined in [MSC3902](https://github.com/matrix-org/matrix-spec-proposals/pull/3902). |
| 74 | + |
| 75 | + This field is **required** if the `members_omitted` response field is true; it |
| 76 | + is otherwise optional. |
| 77 | + |
| 78 | +## Potential issues |
| 79 | + |
| 80 | +None at present. |
| 81 | + |
| 82 | +## Alternatives |
| 83 | + |
| 84 | + * In future, the list of event types to omit could be expanded. (Some rooms |
| 85 | + may have large numbers of other state events). |
| 86 | + |
| 87 | + Currently, `m.room.member` events are by far the biggest problem. For |
| 88 | + example, a `/send_join` request for Matrix HQ returns approximately 85000 |
| 89 | + events in `state`, of which all but 44 are `m.room.member`. |
| 90 | + |
| 91 | + Additionally: the client-server API already provides a mechanism for |
| 92 | + omitting `m.room.member` events from the `/sync` response, via |
| 93 | + [lazy loading](https://spec.matrix.org/v1.4/client-server-api/#lazy-loading-room-members), |
| 94 | + which means that this change can be implemented without changes to the |
| 95 | + client-server API. Extending the list of event types to be omitted would |
| 96 | + require changes to the client-server API and therefore be significantly more |
| 97 | + involved. |
| 98 | + |
| 99 | + In order to reduce the scope of the change, we have therefore decided to |
| 100 | + focus on `m.room.member` events for now. Future MSCs might provide a |
| 101 | + mechanism for omitting other event types. |
| 102 | + |
| 103 | +## Security considerations |
| 104 | + |
| 105 | +No security issues are currently foreseen with this specific MSC, though the |
| 106 | +larger topic of incremental synchronisation of state has several concerns; |
| 107 | +these will be discussed in other MSCs such as MSC3902. |
| 108 | + |
| 109 | +## Unstable prefix |
| 110 | + |
| 111 | +The following mapping will be used for identifiers in this MSC during |
| 112 | +development: |
| 113 | + |
| 114 | +Proposed final identifier | Purpose | Development identifier |
| 115 | +------------------------- | --------------- | ---- |
| 116 | +`omit_members` | query parameter | `org.matrix.msc3706.partial_state` |
| 117 | +`members_omitted` | response field | `org.matrix.msc3706.partial_state` |
| 118 | +`servers_in_room` | response field | `org.matrix.msc3706.servers_in_room` |
| 119 | + |
| 120 | +## Dependencies |
| 121 | + |
| 122 | +This MSC does not build on any existing unaccepted MSCs. |
0 commit comments