From eff348bb69a55f840ccb8cbe2284257158607573 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Jan 2022 09:47:53 +0000 Subject: [PATCH] Check missing state if not an outlier before storing the event --- roomserver/internal/input/input_events.go | 49 ++++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index 669d606ef..6ca549a3c 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -82,6 +82,11 @@ func (r *Inputer) processRoomEvent( "room_id": event.RoomID(), "type": event.Type(), }) + + if input.Origin == "" { + input.Origin = event.Origin() + } + logger.Println("XXX: Processing event") // if we have already got this event then do not process it again, if the input kind is an outlier. @@ -166,6 +171,26 @@ func (r *Inputer) processRoomEvent( } } + if input.Kind != api.KindOutlier && len(missingRes.MissingPrevEventIDs) > 0 { + missingState := missingStateReq{ + origin: input.Origin, + inputer: r, + queryer: r.Queryer, + db: r.DB, + federation: r.FSAPI, + keys: r.KeyRing, + roomsMu: internal.NewMutexByRoom(), + servers: []gomatrixserverlib.ServerName{input.Origin}, + hadEvents: map[string]bool{}, + haveEvents: map[string]*gomatrixserverlib.HeaderedEvent{}, + } + if err = missingState.processEventWithMissingState(ctx, input.Event.Unwrap(), input.Event.RoomVersion); err != nil { + //return fmt.Errorf("r.checkForMissingPrevEvents: %w", err) + softfail = true + rejectionErr = fmt.Errorf("missingState.processEventWithMissingState: %w", err) + } + } + // Store the event. _, _, stateAtEvent, redactionEvent, redactedEventID, err := r.DB.StoreEvent(ctx, event, authEventNIDs, isRejected) if err != nil { @@ -197,30 +222,6 @@ func (r *Inputer) processRoomEvent( return fmt.Errorf("r.DB.RoomInfo missing for room %s", event.RoomID()) } - if input.Origin == "" { - input.Origin = event.Origin() - } - - if len(missingRes.MissingPrevEventIDs) > 0 { - missingState := missingStateReq{ - origin: input.Origin, - inputer: r, - queryer: r.Queryer, - db: r.DB, - federation: r.FSAPI, - keys: r.KeyRing, - roomsMu: internal.NewMutexByRoom(), - servers: []gomatrixserverlib.ServerName{input.Origin}, - hadEvents: map[string]bool{}, - haveEvents: map[string]*gomatrixserverlib.HeaderedEvent{}, - } - if err = missingState.processEventWithMissingState(ctx, input.Event.Unwrap(), roomInfo.RoomVersion); err != nil { - // return fmt.Errorf("r.checkForMissingPrevEvents: %w", err) - softfail = true - rejectionErr = fmt.Errorf("event %s has missing state %+v due to error: %s", input.Event.EventID(), missingRes.MissingPrevEventIDs, err) - } - } - if stateAtEvent.BeforeStateSnapshotNID == 0 { // We haven't calculated a state for this event yet. // Lets calculate one.