matrix-org / matrix-org/matrix-spec
Kahn's algorithm variation in v2 state resolution not specified
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 330
- Forks
- 150
- Avg merge
- 2h 21m
- Merged PRs (30d)
- 3
Description
From [the spec](https://matrix.org/docs/spec/rooms/v2#definitions):
> The reverse topological power ordering can be found by sorting the events using Kahn's algorithm for topological sorting, and at each step selecting, among all the candidate vertices, the smallest vertex using the above comparison relation.
... however, Kahn's algorithm doesn't *have* a candidate selection step; the standard implementation simply adds discovered nodes to a queue and processes them in order, irrespective of their relation to other nodes.
Presumably a modified version of Kahn's algorithm was used here; but it is not specified what the exact semantics of that modified version would be. For example, I can think of two modified versions with potentially different outcomes:
1. For every 'process a node from the queue' step, scan the entire queue for the node which at that moment is lexicographically smallest, regardless of its depth in the DAG.
2. For every 'depth bracket' (ie. first depth 0, then depth 1, ...), process the queue at that depth in lexicographically smallest order, before moving on to the next depth bracket.
Which would be the correct semantics, or would there be a third option that applies here? @uhoreg suggested on IRC that 2 is the correct option, but wasn't entirely certain. Either way this should be added to the spec explicitly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the v2 state resolution definitions in the Matrix specification and review the Kahn's algorithm wording quoted in the issue. Resolve which candidate-selection semantics are intended, then update that specification section to state the algorithm explicitly and verify that the revised wording removes the ambiguity.
Written by the indexing model from the issue text.
Assessment
- Domain
- distributed-systems, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100