Check missing state if not an outlier before storing the event

This commit is contained in:
Neil Alexander 2022-01-07 09:47:53 +00:00
parent 110ab7b8f3
commit eff348bb69
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -82,6 +82,11 @@ func (r *Inputer) processRoomEvent(
"room_id": event.RoomID(), "room_id": event.RoomID(),
"type": event.Type(), "type": event.Type(),
}) })
if input.Origin == "" {
input.Origin = event.Origin()
}
logger.Println("XXX: Processing event") 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. // 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. // Store the event.
_, _, stateAtEvent, redactionEvent, redactedEventID, err := r.DB.StoreEvent(ctx, event, authEventNIDs, isRejected) _, _, stateAtEvent, redactionEvent, redactedEventID, err := r.DB.StoreEvent(ctx, event, authEventNIDs, isRejected)
if err != nil { if err != nil {
@ -197,30 +222,6 @@ func (r *Inputer) processRoomEvent(
return fmt.Errorf("r.DB.RoomInfo missing for room %s", event.RoomID()) 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 { if stateAtEvent.BeforeStateSnapshotNID == 0 {
// We haven't calculated a state for this event yet. // We haven't calculated a state for this event yet.
// Lets calculate one. // Lets calculate one.