From 80e015a7e8cfd1b70a23c9125beac5a70c7ba810 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 25 Jan 2022 18:41:21 +0000 Subject: [PATCH] Remember to send outliers for state returned from /gme --- roomserver/internal/input/input_missing.go | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/roomserver/internal/input/input_missing.go b/roomserver/internal/input/input_missing.go index 3eea9dd53..7eed98c8f 100644 --- a/roomserver/internal/input/input_missing.go +++ b/roomserver/internal/input/input_missing.go @@ -136,12 +136,6 @@ func (t *missingStateReq) processEventWithMissingState( } } - // First of all, send the backward extremity into the roomserver with the - // newly resolved state. This marks the "oldest" point in the backfill and - // sets the baseline state for any new events after this. We'll make a - // copy of the hadEvents map so that it can be taken downstream without - // worrying about concurrent map reads/writes, since t.hadEvents is meant - // to be protected by a mutex. hadEvents := map[string]bool{} t.hadEventsMutex.Lock() for k, v := range t.hadEvents { @@ -149,6 +143,33 @@ func (t *missingStateReq) processEventWithMissingState( } t.hadEventsMutex.Unlock() + // Send outliers first so we can send the new backwards extremity without causing errors + outliers, err := resolvedState.Events() + if err != nil { + return err + } + var outlierRoomEvents []api.InputRoomEvent + for _, outlier := range outliers { + if hadEvents[outlier.EventID()] { + continue + } + outlierRoomEvents = append(outlierRoomEvents, api.InputRoomEvent{ + Kind: api.KindOutlier, + Event: outlier.Headered(roomVersion), + Origin: t.origin, + AuthEventIDs: outlier.AuthEventIDs(), + }) + } + // TODO: we could do this concurrently? + for _, ire := range outlierRoomEvents { + if err = t.inputer.processRoomEvent(ctx, &ire); err != nil { + return fmt.Errorf("t.inputer.processRoomEvent[outlier]: %w", err) + } + } + + // Now send the backward extremity into the roomserver with the + // newly resolved state. This marks the "oldest" point in the backfill and + // sets the baseline state for any new events after this. stateIDs := make([]string, 0, len(resolvedState.StateEvents)) for _, event := range resolvedState.StateEvents { stateIDs = append(stateIDs, event.EventID())