Fix backfilling (#3117)

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..
This commit is contained in:
Till 2023-06-20 16:52:29 +02:00 committed by GitHub
parent d13466c1ee
commit a734b112c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View file

@ -30,10 +30,6 @@ func IsServerAllowed(
serverCurrentlyInRoom bool, serverCurrentlyInRoom bool,
authEvents []gomatrixserverlib.PDU, authEvents []gomatrixserverlib.PDU,
) bool { ) bool {
// In practice should not happen, but avoids unneeded CPU cycles
if serverName == "" || len(authEvents) == 0 {
return false
}
historyVisibility := HistoryVisibilityForRoom(authEvents) historyVisibility := HistoryVisibilityForRoom(authEvents)
// 1. If the history_visibility was set to world_readable, allow. // 1. If the history_visibility was set to world_readable, allow.

View file

@ -114,7 +114,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
if info == nil || info.IsStub() { if info == nil || info.IsStub() {
return fmt.Errorf("backfillViaFederation: missing room info for room %s", req.RoomID) 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. // Request 100 items regardless of what the query asks for.
// We don't want to go much higher than this. // 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 // We can't honour exactly the limit as some sytests rely on requesting more for tests to pass
@ -265,7 +265,7 @@ type backfillRequester struct {
eventIDToBeforeStateIDs map[string][]string eventIDToBeforeStateIDs map[string][]string
eventIDMap map[string]gomatrixserverlib.PDU eventIDMap map[string]gomatrixserverlib.PDU
historyVisiblity gomatrixserverlib.HistoryVisibility historyVisiblity gomatrixserverlib.HistoryVisibility
roomInfo types.RoomInfo roomVersion gomatrixserverlib.RoomVersion
} }
func newBackfillRequester( func newBackfillRequester(
@ -274,6 +274,7 @@ func newBackfillRequester(
virtualHost spec.ServerName, virtualHost spec.ServerName,
isLocalServerName func(spec.ServerName) bool, isLocalServerName func(spec.ServerName) bool,
bwExtrems map[string][]string, preferServers []spec.ServerName, bwExtrems map[string][]string, preferServers []spec.ServerName,
roomVersion gomatrixserverlib.RoomVersion,
) *backfillRequester { ) *backfillRequester {
preferServer := make(map[spec.ServerName]bool) preferServer := make(map[spec.ServerName]bool)
for _, p := range preferServers { for _, p := range preferServers {
@ -290,6 +291,7 @@ func newBackfillRequester(
bwExtrems: bwExtrems, bwExtrems: bwExtrems,
preferServer: preferServer, preferServer: preferServer,
historyVisiblity: gomatrixserverlib.HistoryVisibilityShared, historyVisiblity: gomatrixserverlib.HistoryVisibilityShared,
roomVersion: roomVersion,
} }
} }
@ -537,15 +539,11 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion,
} }
eventNIDs := make([]types.EventNID, len(nidMap)) eventNIDs := make([]types.EventNID, len(nidMap))
i := 0 i := 0
roomNID := b.roomInfo.RoomNID
for _, nid := range nidMap { for _, nid := range nidMap {
eventNIDs[i] = nid.EventNID eventNIDs[i] = nid.EventNID
i++ 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 { if err != nil {
logrus.WithError(err).WithField("event_nids", eventNIDs).Error("Failed to load events") logrus.WithError(err).WithField("event_nids", eventNIDs).Error("Failed to load events")
return nil, err return nil, err