Skip to content

Commit ea8e12c

Browse files
Support for room v11 as the default room version (#858)
--------- Signed-off-by: Thomas Traineau t.traineau@famedly.com
1 parent bb8d0f0 commit ea8e12c

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

federation/server_room.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,20 @@ func InitialRoomEvents(roomVer gomatrixserverlib.RoomVersion, creator string) []
333333
Type: "m.room.create",
334334
StateKey: b.Ptr(""),
335335
Sender: creator,
336-
Content: map[string]interface{}{
337-
"creator": creator,
338-
"room_version": roomVer,
339-
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
340-
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
341-
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
342-
// hashes will not be the same.
343-
"complement_entropy": util.RandomString(18),
344-
},
336+
Content: func() map[string]interface{} {
337+
content := map[string]interface{}{
338+
"room_version": roomVer,
339+
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
340+
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
341+
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
342+
// hashes will not be the same.
343+
"complement_entropy": util.RandomString(18),
344+
}
345+
if gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersion(roomVer)).CreatorInCreateEvent() {
346+
content["creator"] = creator
347+
}
348+
return content
349+
}(),
345350
},
346351
{
347352
Type: "m.room.member",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/docker/go-connections v0.6.0
88
github.com/gorilla/mux v1.8.1
99
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
10-
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744
10+
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353
1111
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
1212
github.com/sirupsen/logrus v1.9.4
1313
github.com/tidwall/gjson v1.18.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8
7373
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
7474
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744 h1:5GvC2FD9O/PhuyY95iJQdNYHbDioEhMWdeMP9maDUL8=
7575
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744/go.mod h1:b6KVfDjXjA5Q7vhpOaMqIhFYvu5BuFVZixlNeTV/CLc=
76+
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353 h1:BdGU/8sF4ZaqGhfYN+eFEzc/whU4LpKvEDdM6i0Oqqs=
77+
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353/go.mod h1:b6KVfDjXjA5Q7vhpOaMqIhFYvu5BuFVZixlNeTV/CLc=
7678
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
7779
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66/go.mod h1:iBI1foelCqA09JJgPV0FYz4qA5dUXYOxMi57FxKBdd4=
7880
github.com/miekg/dns v1.1.66 h1:FeZXOS3VCVsKnEAd+wBkjMC3D2K+ww66Cq3VnCINuJE=

tests/csapi/rooms_state_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/matrix-org/complement/helpers"
1616
"github.com/matrix-org/complement/match"
1717
"github.com/matrix-org/complement/must"
18+
"github.com/matrix-org/gomatrixserverlib"
1819
)
1920

2021
func TestRoomCreationReportsEventsToMyself(t *testing.T) {
@@ -26,6 +27,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
2627
LocalpartSuffix: "bob",
2728
Password: "bobpassword",
2829
})
30+
defaultVer := alice.GetDefaultRoomVersion(t)
2931
roomID := alice.MustCreateRoom(t, map[string]interface{}{})
3032

3133
t.Run("parallel", func(t *testing.T) {
@@ -38,7 +40,10 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
3840
return false
3941
}
4042
must.Equal(t, ev.Get("sender").Str, alice.UserID, "wrong sender")
41-
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
43+
// The creator field was removed in room version 11 (MSC4239).
44+
if gomatrixserverlib.MustGetRoomVersion(defaultVer).CreatorInCreateEvent() {
45+
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
46+
}
4247
return true
4348
}))
4449
})

tests/federation_room_get_missing_events_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,16 @@ func TestOutboundFederationEventSizeGetMissingEvents(t *testing.T) {
497497
}).Methods("POST")
498498

499499
ver := alice.GetDefaultRoomVersion(t)
500+
// This test crafts a "bad" event which state_key is 280 bytes but only 70
501+
// codepoints.
502+
//
503+
// Room version 11 in Synapse switched from using codepoints to using
504+
// bytes. Which means the 280-byte state_key would be rejected immediately.
505+
// Use room version 10 in that case so the codepoint-based limit is in effect.
506+
//
507+
if gomatrixserverlib.MustGetRoomVersion(ver).StrictEventByteLimits() {
508+
ver = gomatrixserverlib.RoomVersion("10")
509+
}
500510
charlie := srv.UserID("charlie")
501511
room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
502512
roomAlias := srv.MakeAliasMapping("flibble", room.RoomID)

0 commit comments

Comments
 (0)