From 260e69d138fb82003b0a7e77aeb5cac6b3281777 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Tue, 19 May 2020 18:42:55 +0100 Subject: [PATCH] Make "Outbound federation can backfill events" pass sytest (#1049) - Use a backfill limit of 100 regardless of what was asked. - Special case the create event for `StateIDsBeforeEvent` - Trim to the limit in `syncapi` --- roomserver/internal/query.go | 7 ++++++- roomserver/internal/query_backfill.go | 6 ++++++ syncapi/routing/messages.go | 9 ++++++++- sytest-whitelist | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/roomserver/internal/query.go b/roomserver/internal/query.go index 8a8c8e7d..8043746c 100644 --- a/roomserver/internal/query.go +++ b/roomserver/internal/query.go @@ -535,9 +535,14 @@ func (r *RoomserverInternalAPI) backfillViaFederation(ctx context.Context, req * return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err) } requester := newBackfillRequester(r.DB, r.FedClient, r.ServerName) + // Request 100 items regardless of what the query asks for. + // We don't want to go much higher than this. + // We can't honour exactly the limit as some sytests rely on requesting more for tests to pass + // (so we don't need to hit /state_ids which the test has no listener for) + // Specifically the test "Outbound federation can backfill events" events, err := gomatrixserverlib.RequestBackfill( ctx, requester, - r.KeyRing, req.RoomID, roomVer, req.EarliestEventsIDs, req.Limit) + r.KeyRing, req.RoomID, roomVer, req.EarliestEventsIDs, 100) if err != nil { return err } diff --git a/roomserver/internal/query_backfill.go b/roomserver/internal/query_backfill.go index d42038e7..82f7238d 100644 --- a/roomserver/internal/query_backfill.go +++ b/roomserver/internal/query_backfill.go @@ -7,6 +7,7 @@ import ( "github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/util" "github.com/sirupsen/logrus" ) @@ -37,6 +38,11 @@ func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok { return ids, nil } + if len(targetEvent.PrevEventIDs()) == 0 && targetEvent.Type() == "m.room.create" && targetEvent.StateKeyEquals("") { + util.GetLogger(ctx).WithField("room_id", targetEvent.RoomID()).Info("Backfilled to the beginning of the room") + b.eventIDToBeforeStateIDs[targetEvent.EventID()] = []string{} + return nil, nil + } // if we have exactly 1 prev event and we know the state of the room at that prev event, then just roll forward the prev event. // Else, we have to hit /state_ids because either we don't know the state at all at this event (new backwards extremity) or // we don't know the result of state res to merge forks (2 or more prev_events) diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go index 67de6df7..811188cc 100644 --- a/syncapi/routing/messages.go +++ b/syncapi/routing/messages.go @@ -412,7 +412,14 @@ func (r *messagesReq) backfill(roomID string, fromEventIDs []string, limit int) } } - return res.Events, nil + // we may have got more than the requested limit so resize now + events := res.Events + if len(events) > limit { + // last `limit` events + events = events[len(events)-limit:] + } + + return events, nil } // setToDefault returns the default value for the "to" query parameter of a diff --git a/sytest-whitelist b/sytest-whitelist index 035b9b36..4a8af13a 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -279,3 +279,4 @@ Inbound federation can return missing events for invite visibility Inbound federation can get public room list An event which redacts itself should be ignored A pair of events which redact each other should be ignored +Outbound federation can backfill events