feat: Add timestamp to event endpoint backed by a timestamp index #2332
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Continuwuity/Web Interface
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2332
Loading…
Reference in a new issue
No description provided.
Delete branch "eleboucher/continuwuity:feat/timestamp-to-event-index"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Brings back /timestamp_to_event (MSC3030) using a new per-room timestamp index (roomts_pduid), so each lookup is a single database seek instead of a scan, remote events are indexed by when we received them, local and backfilled events by origin_server_ts, and older events are indexed by a background migration.
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
conceptually lgtm, just a couple style comments and also that compliance issue I'd like input on
@ -942,6 +975,38 @@ async fn unembed_unsigned_info(info!(elapsed=?start.elapsed(), total_migrated_pdus=total_migrated, "Finished migration.");}const ROOMTS_UNTIL: &str = "populate_roomts_pduid_until";async fn populate_roomts_pduid(db: Arc<Database>, until: u64) {nit: this probably wants to go below
drop_server_signingkeys@ -398,9 +398,17 @@ impl super::Service {let count2 = PduCount::Normal(self.services.globals.next_count().unwrap());let pdu_id: RawPduId = PduId { shortroomid, shorteventid: count2 }.into();// Remote timestamps are untrusted, so index remote events by when we// received themI'd like to get the team's thoughts on this: personally I don't fw the idea of disregarding the spec (which explicitly states that this functionality is based on
origin_server_ts) just because that field can be lied about. After some thought, I don't personally see "malicious server lies about its own timestamp" to be a problem that actually matters.cc @Jade @ginger
In this case it's not because of a security issue, but because our timeline is ordered based on the timestamp that is received and this endpoint seems to be primarily used for jump to date - meaning that jumping to the closest
origin_server_tsmay jump to a completely different place in the timeline to what was actually intendedHmm, I guess that usually makes sense, but what about if a server is offline for a month (e.g. due to a VPS provider outage) and as such it receives that month's events late? The user will have to account for an extra month's offset, which isn't very intuitive, and is contrary to what their client will end up actually displaying (the origin time)
That's a good (annoying) point. I don't have an answer right now, maybe once I've not got a headache
ofc, no rush. Maybe we could compromise and trust the origin timestamp if it's within, say, 12 hours of our local time? I originally went to say 1hr, but that might not account for clock skew
Actually no, that doesn't solve my problem. Perhaps the inverse? Or maybe I should just think about this after a night's rest lmao
Clock skew shouldn't be more than like 30 seconds, but that doesn't fix the issue you raised. I was gonna say something like trusting it if it's not before a previous event timestamp we received? Which would work as long as we get events in order?
Several bugs I've fixed since the last release have been caused by receiving events hilariously out of order :(
Not like on a macro scale but on a micro scale - like we process the ones we have in order, if we get a transaction with many.
@ -269,6 +279,48 @@ impl Data {.try_flatten_stream()}pub(super) fn pdus_by_ts<'a>(nit:
pdus_by_timestampis more intuitive@ -272,0 +282,4 @@pub(super) fn pdus_by_ts<'a>(&'a self,room_id: &'a RoomId,ts: MilliSecondsSinceUnixEpoch,nit: this could also just be
timestamp@ -255,0 +258,4 @@pub fn pdus_by_timestamp<'a>(&'a self,room_id: &'a RoomId,ts: MilliSecondsSinceUnixEpoch,nit: could be
timestampNeeds main merging, lgtm to merge after
8ab0af0bf9ececd3ea2dececd3ea2de98ae850782026-11-19T05:26:54.038579Z INFO conduwuit_service::migrations: Finished indexing PDUs by timestamp. elapsed=763.608827795s
not bad!
Considering this good enough ✅
@ -0,0 +36,4 @@.timeline.pdus_by_timestamp(room_id, body.ts, body.dir).ignore_err().take(MAX_CANDIDATES);So uh I think this will technically cause an incorrect result when we have limited history visibility. Low prio bug tho