matrix-org / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://matrix-org.github.io/dendrite/
Apache License 2.0
5.63k stars 663 forks source link

Inform syncapi about holes in DAGs #1006

Open kegsay opened 4 years ago

kegsay commented 4 years ago

Problem context

Servers send other servers events. These events have prev_events. It's possible for a receiving server to be missing those prev_events, creating a hole in the DAG (aka an outlier). In an attempt to fill this hole, there's the API /get_missing_events which takes the latest event IDs and the earliest event IDs and gives you events walking back from latest and ignoring anything in earliest (don't be conned into thinking it returns events "between" the two lists, it doesn't have to in the case of forks).

In the happy case:

If we cannot obtain the prev_events, we can request the /state of the room at the event and continue on.

There are many bad cases:

We can try to guard against lies by forcing the server who sent us the event to cough up the prev_events or else their transaction will be rejected.

In addition, the client needs to be informed of a new hole in the DAG, or else they will never hit /messages (and hence backfill) the hole, resulting in a gap in message history e.g due to lost connectivity on the server (this is exacerbated for p2p nodes). We need to send a limited sync to reset the client in this scenario.

kegsay commented 4 years ago

The quick fix (which doesn't really fix everything):

The proper fix:

kegsay commented 4 years ago

This is mostly resolved now, but: