Skip to content

Commit

Permalink
Fix backfilling (#3117)
Browse files Browse the repository at this point in the history
This should fix two issues with backfilling:
1. right after creating and joining a room over federation, we are doing
a `/backfill` request, which would return redacted events, because the
`authEvents` are empty. Even though the spec states that, in the absence
of a history visibility event, it should be handled as `shared`.
2. `gomatrixserverlib: unsupported room version ''` - because, well, we
were never setting the `roomInfo` field..
  • Loading branch information
S7evinK committed Jun 20, 2023
1 parent d13466c commit a734b11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 0 additions & 4 deletions roomserver/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func IsServerAllowed(
serverCurrentlyInRoom bool,
authEvents []gomatrixserverlib.PDU,
) bool {
// In practice should not happen, but avoids unneeded CPU cycles
if serverName == "" || len(authEvents) == 0 {
return false
}
historyVisibility := HistoryVisibilityForRoom(authEvents)

// 1. If the history_visibility was set to world_readable, allow.
Expand Down
12 changes: 5 additions & 7 deletions roomserver/internal/perform/perform_backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
if info == nil || info.IsStub() {
return fmt.Errorf("backfillViaFederation: missing room info for room %s", req.RoomID)
}
requester := newBackfillRequester(r.DB, r.FSAPI, r.Querier, req.VirtualHost, r.IsLocalServerName, req.BackwardsExtremities, r.PreferServers)
requester := newBackfillRequester(r.DB, r.FSAPI, r.Querier, req.VirtualHost, r.IsLocalServerName, req.BackwardsExtremities, r.PreferServers, info.RoomVersion)
// 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
Expand Down Expand Up @@ -265,7 +265,7 @@ type backfillRequester struct {
eventIDToBeforeStateIDs map[string][]string
eventIDMap map[string]gomatrixserverlib.PDU
historyVisiblity gomatrixserverlib.HistoryVisibility
roomInfo types.RoomInfo
roomVersion gomatrixserverlib.RoomVersion
}

func newBackfillRequester(
Expand All @@ -274,6 +274,7 @@ func newBackfillRequester(
virtualHost spec.ServerName,
isLocalServerName func(spec.ServerName) bool,
bwExtrems map[string][]string, preferServers []spec.ServerName,
roomVersion gomatrixserverlib.RoomVersion,
) *backfillRequester {
preferServer := make(map[spec.ServerName]bool)
for _, p := range preferServers {
Expand All @@ -290,6 +291,7 @@ func newBackfillRequester(
bwExtrems: bwExtrems,
preferServer: preferServer,
historyVisiblity: gomatrixserverlib.HistoryVisibilityShared,
roomVersion: roomVersion,
}
}

Expand Down Expand Up @@ -537,15 +539,11 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion,
}
eventNIDs := make([]types.EventNID, len(nidMap))
i := 0
roomNID := b.roomInfo.RoomNID
for _, nid := range nidMap {
eventNIDs[i] = nid.EventNID
i++
if roomNID == 0 {
roomNID = nid.RoomNID
}
}
eventsWithNids, err := b.db.Events(ctx, b.roomInfo.RoomVersion, eventNIDs)
eventsWithNids, err := b.db.Events(ctx, b.roomVersion, eventNIDs)
if err != nil {
logrus.WithError(err).WithField("event_nids", eventNIDs).Error("Failed to load events")
return nil, err
Expand Down

0 comments on commit a734b11

Please sign in to comment.