From c2d55eed84b4cae3880099397fca0644a5ed2d88 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 6 Jun 2022 13:48:13 +0100 Subject: [PATCH] Rework the mainline ordering more dramatically. This has undergone a fairly large rework, so needs careful inspection. --- content/rooms/fragments/v2-state-res.md | 35 +++++++++++++++---------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/content/rooms/fragments/v2-state-res.md b/content/rooms/fragments/v2-state-res.md index d130c149..f470e4bd 100644 --- a/content/rooms/fragments/v2-state-res.md +++ b/content/rooms/fragments/v2-state-res.md @@ -88,28 +88,35 @@ Starting with *i* = 0, repeatedly fetch *P**i*+1, the Increment *i* and repeat until *Pi* has no `m.room.power_levels` event in its `auth_events`. The *mainline of P*0 is the list of events - [*P*n , ... , *P*1, *P*0]. + [*P*n , ... , *P*1, *P*0], +ordered from oldest to newest. -Given another event *e* = *e0* we can compute a similar list of -`m.room.power_levels` events - [*e*0, *e*1, ...], +Let *e* = *e0* be another event (possibly another +`m.room.power_levels` event). We can compute a similar list of events + [*e*1, ..., *em*], where *e*j* + 1* is the `m.room.power_levels` event in the -`auth_events` of *ej*. The *closest mainline event to e* -is the first event *ej* which belongs to the mainline of *P*. -If no event *ej* belongs to the mainline of *P*, then the closest -mainline event to *e* can be considered to be a dummy event that is -before any other event in the mainline of *P* for the purposes of -condition 1 below. +`auth_events` of *ej*, and where *em* has no +`m.room.power_levels` event in its `auth_events`. (Note that this second list +may be empty, because *e* may not cite an `m.room.power_levels` event in its +`auth_events` at all.) + +Now compare these two lists as follows. +* Find the smallest index *j* ≥1 for which *ej* belongs to the + mainline of *P*. +* If *j* exists, then *ej* = *Pi* for some unique index + *i* ≥ 0. Otherwise set *i* = ∞, where ∞ is a sentinel value greater + than any integer. +* In both cases, the *position of e in the mainline of P* is *i*. The *mainline ordering based on* *P* of a set of events is the ordering, from smallest to largest, using the following comparison relation on events: for events *x* and *y*, *x* < *y* if -1. the closest mainline event to *x* appears *before* the closest - mainline event to *y*; or -2. the closest mainline events are the same, but *x*'s +1. the position of *x* in *P*'s mainline is **greater** than + the position of *y* in *P*'s mainline. +2. the positions of the events are the same, but *x*'s `origin_server_ts` is *less* than *y*'s `origin_server_ts`; or -3. the closest mainline events are the same and the events have the +3. the positions of the events are the same and the events have the same `origin_server_ts`, but *x*'s `event_id` is *less* than *y*'s `event_id`.