Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 2782ae3

Browse files
Fix fetching missing state (#2163)
* Check that we have a populated state snapshot when determining if we closed the gap * Do the same in the query API * Use HasState more opportunistically * Try to avoid falling down the hole of using a trustworthy but empty state snapshot for non-create events * Refactor missing state and make sure that we really solve the problem for the new event * Comments * Review comments * Tweak that check again * Tidy up that create check further * Fix build hopefully * Update sendOutliers to use OrderAuthAndStateEvents * Don't go out of bounds on missingEvents
1 parent 9130156 commit 2782ae3

File tree

6 files changed

+223
-122
lines changed

6 files changed

+223
-122
lines changed

roomserver/internal/input/input_events.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,32 @@ func (r *Inputer) processRoomEvent(
255255
hadEvents: map[string]bool{},
256256
haveEvents: map[string]*gomatrixserverlib.HeaderedEvent{},
257257
}
258-
if err := missingState.processEventWithMissingState(ctx, event, headered.RoomVersion); err != nil {
258+
if stateSnapshot, err := missingState.processEventWithMissingState(ctx, event, headered.RoomVersion); err != nil {
259+
// Something went wrong with retrieving the missing state, so we can't
260+
// really do anything with the event other than reject it at this point.
259261
isRejected = true
260262
rejectionErr = fmt.Errorf("missingState.processEventWithMissingState: %w", err)
263+
} else if stateSnapshot != nil {
264+
// We retrieved some state and we ended up having to call /state_ids for
265+
// the new event in question (probably because closing the gap by using
266+
// /get_missing_events didn't do what we hoped) so we'll instead overwrite
267+
// the state snapshot with the newly resolved state.
268+
missingPrev = false
269+
input.HasState = true
270+
input.StateEventIDs = make([]string, 0, len(stateSnapshot.StateEvents))
271+
for _, e := range stateSnapshot.StateEvents {
272+
input.StateEventIDs = append(input.StateEventIDs, e.EventID())
273+
}
261274
} else {
275+
// We retrieved some state and it would appear that rolling forward the
276+
// state did everything we needed it to do, so we can just resolve the
277+
// state for the event in the normal way.
262278
missingPrev = false
263279
}
264280
} else {
281+
// We're missing prev events or state for the event, but for some reason
282+
// we don't know any servers to ask. In this case we can't do anything but
283+
// reject the event and hope that it gets unrejected later.
265284
isRejected = true
266285
rejectionErr = fmt.Errorf("missing prev events and no other servers to ask")
267286
}
@@ -299,7 +318,7 @@ func (r *Inputer) processRoomEvent(
299318
return rollbackTransaction, fmt.Errorf("updater.RoomInfo missing for room %s", event.RoomID())
300319
}
301320

302-
if !missingPrev && stateAtEvent.BeforeStateSnapshotNID == 0 {
321+
if input.HasState || (!missingPrev && stateAtEvent.BeforeStateSnapshotNID == 0) {
303322
// We haven't calculated a state for this event yet.
304323
// Lets calculate one.
305324
err = r.calculateAndSetState(ctx, updater, input, roomInfo, &stateAtEvent, event, isRejected)

0 commit comments

Comments
 (0)