Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Refactor create_new_client_event to use a new parameter, state_event_ids, which accurately describes the usage with MSC2716 instead of abusing auth_event_ids #12083

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Feb 25, 2022

Refactor create_new_client_event to use a new parameter, state_event_ids, which accurately describes the usage with MSC2716 instead of abusing auth_event_ids.

Spawned from #10975 (comment)

Part of MSC2716

Dev notes

Relevant call stacks (MSC2716 -> create_new_client_event)

# For events
RoomBatchSendEventRestServlet.on_POST
handle_batch_of_events
persist_historical_events
create_event
create_new_client_event

# For `m.room.member` state events
RoomBatchSendEventRestServlet.on_POST
persist_state_events_at_start
update_membership
update_membership_locked
_local_membership_update
create_event
create_new_client_event

# For non `m.room.member` state events
RoomBatchSendEventRestServlet.on_POST
persist_state_events_at_start
create_and_send_nonmember_event
create_event
create_new_client_event

MSC2716 Complement tests are passing ✅

$ COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestImportHistoricalMessages
...
--- PASS: TestImportHistoricalMessages (21.11s)
    --- PASS: TestImportHistoricalMessages/parallel (7.37s)
        --- SKIP: TestImportHistoricalMessages/parallel/TODO:_Trying_to_send_insertion_event_with_same_`next_batch_id`_will_reject (0.00s)
        --- SKIP: TestImportHistoricalMessages/parallel/TODO:_What_happens_when_you_point_multiple_batches_at_the_same_insertion_event? (0.00s)
        --- PASS: TestImportHistoricalMessages/parallel/Federation (0.00s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_joining_on_federated_server_-_auto-generated_base_insertion_event (4.05s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_joining_on_federated_server_-_pre-made_insertion_event (4.57s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_already_joined_on_federated_server (5.56s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/When_messages_have_already_been_scrolled_back_through,_new_historical_messages_are_visible_in_next_scroll_back_on_federated_server (6.41s)
        --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions (0.00s)
            --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions/Not_allowed_to_redact_MSC2716_insertion,_batch,_marker_events (0.87s)
            --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions/Room_creator_can_send_MSC2716_events (0.95s)
        --- PASS: TestImportHistoricalMessages/parallel/Unrecognised_prev_event_ID_will_throw_an_error (1.43s)
        --- PASS: TestImportHistoricalMessages/parallel/Duplicate_next_batch_id_on_insertion_event_will_be_rejected (2.12s)
        --- PASS: TestImportHistoricalMessages/parallel/Normal_users_aren't_allowed_to_batch_send_historical_messages (2.26s)
        --- PASS: TestImportHistoricalMessages/parallel/Unrecognised_batch_id_will_throw_an_error (2.26s)
        --- PASS: TestImportHistoricalMessages/parallel/Batch_send_endpoint_only_returns_state_events_that_we_passed_in_via_state_events_at_start (2.72s)
        --- PASS: TestImportHistoricalMessages/parallel/Should_be_able_to_send_a_batch_without_any_state_events_at_start_-_user_already_joined_in_the_current_room_state (2.99s)
        --- PASS: TestImportHistoricalMessages/parallel/Should_be_able_to_batch_send_historical_messages_into_private_room (3.28s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_from_multiple_users_in_the_same_batch (3.34s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_resolve_in_the_correct_order (3.98s)
        --- PASS: TestImportHistoricalMessages/parallel/should_resolve_member_state_events_for_historical_events (4.00s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_from_batch_send_do_not_come_down_in_an_incremental_sync (4.12s)
PASS
ok  	github.com/matrix-org/complement/tests	23.012s

Dev notes

SYNAPSE_POSTGRES=1 SYNAPSE_TEST_LOG_LEVEL=INFO python -m twisted.trial tests.rest.client.test_room_batch

synapse/handlers/message.py -> create_event (by the create_new_client_event call)

        logger.info(
            "create_new_client_event %s event=%s state_group=%s",
            event.type,
            event.event_id,
            context._state_group,
        )
Before After
create_new_client_event org.matrix.msc2716.insertion event=$y08_OT7wtMscqZbvauBvqWfXEjwM-hLX57_MT-71uNk state_group=7
create_new_client_event org.matrix.msc2716.insertion event=$3-4GMFlhZg6soJ5X3sZj8_hX2U7SrkFXn6TpKSBAZQ0 state_group=8
create_new_client_event m.room.message event=$JfDqQ6dWTMUrO7OC0K5MQhV0GiHIqGf6Ptzq-O74xQk state_group=8
create_new_client_event m.room.message event=$mKx6r9PikAI1GfmA6B-dV6AnzhOBJikfveKlk-HJTpY state_group=8
create_new_client_event m.room.message event=$32YuJxDCy8noF5q_Yb_wYm6-94taEjlRlNArpyrrmkM state_group=8
create_new_client_event org.matrix.msc2716.batch event=$I7GeKSYMTLNnoyWyWZTXFHVE9QmDWMFt1I-JzLsX83c state_group=8
same

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

Instead of abusing and re-using auth_event_ids which should only contain state
event ids which are used to auth the given event.

Spawned from #10975 (comment)
@MadLittleMods MadLittleMods added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Feb 25, 2022
@MadLittleMods MadLittleMods requested a review from a team as a code owner February 25, 2022 02:50
@MadLittleMods MadLittleMods marked this pull request as draft February 25, 2022 02:50
auth_event_ids = await self.room_batch_handler.get_most_recent_auth_event_ids_from_event_id_list(
# find the most recent state events that allowed that message to be
# sent. We will use that as a base to auth our historical messages
# against.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this comment more accurate

old_state = await self.store.get_events_as_list(full_state_ids_at_event)
# Add explicit state to the insertion event so the rest of the batch
# can inherit the same state and state_group
old_state = await self.store.get_events_as_list(state_event_ids)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some nice context for why we're doing this that was only a PR review comment previously, #10975 (comment)

allowed that message to be sent. We will use this as a base
to auth our historical messages against.
"""Find the most recent event_id and grab the full state at that event.
We will use this as a base to auth our historical messages against.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this comment more accurate

@@ -272,6 +272,7 @@ async def _local_membership_update(
allow_no_prev_events: bool = False,
prev_event_ids: Optional[List[str]] = None,
auth_event_ids: Optional[List[str]] = None,
Copy link
Contributor Author

@MadLittleMods MadLittleMods Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now using the new state_event_ids parameter to do all of the heavy lifting. I think we can remove any spots where we plumbed auth_event_ids just for MSC2716 things in https://github.com/matrix-org/synapse/pull/9247/files. This assumes that no one else started using those parameters outside of MSC2716 and I would need to check for sure while doing this removal. This includes the following functions:

  • create_and_send_nonmember_event
  • _local_membership_update
  • update_membership
  • update_membership_locked

We do need to keep prev_event_ids as that's still important and separate from the state/auth.

Should I do this as part of this PR or is it okay to split that out to another PR as a fast follow-up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to keep it separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #12304 to take care of this ⏩

```
synapse/handlers/message.py:964: error: Argument "prev_event_ids" to "build" of "EventBuilder" has incompatible type "Optional[List[str]]"; expected "List[str]"  [arg-type]
```
@MadLittleMods MadLittleMods removed the request for review from a team February 25, 2022 07:15
@MadLittleMods MadLittleMods changed the title Draft: Refactor create_new_client_event to use full state parameter instead of abusing auth_event_ids Refactor create_new_client_event to use a new parameter, state_event_ids, which accurately describes the usage with MSC2716 instead of abusing auth_event_ids Feb 25, 2022
@MadLittleMods MadLittleMods marked this pull request as ready for review February 25, 2022 07:57
@tulir
Copy link
Member

tulir commented Feb 28, 2022

It looks like batch sending is completely broken in 1.53, so would be nice to get this merged quickly :3

@@ -71,4 +71,4 @@ fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like batch sending is completely broken in 1.53, so would be nice to get this merged quickly :3

-- @tulir, #12083 (comment)

What's broken about it?

This PR doesn't fix anything (just refactors a parameter differently)

Here are the Complement tests passing on v1.53.0 Synapse tag. The only thing broken is Complement itself which is being fixed in matrix-org/complement#324

$ cd complement
# checkout https://github.com/matrix-org/complement/pull/324
$ git checkout madlittlemods/fix-unrecognised-appservice-access-token

$ cd synapse
$ git checkout v1.53.0
$ COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestImportHistoricalMessages

--- PASS: TestImportHistoricalMessages (19.46s)
    --- PASS: TestImportHistoricalMessages/parallel (6.28s)
        --- SKIP: TestImportHistoricalMessages/parallel/TODO:_Trying_to_send_insertion_event_with_same_`next_batch_id`_will_reject (0.00s)
        --- SKIP: TestImportHistoricalMessages/parallel/TODO:_What_happens_when_you_point_multiple_batches_at_the_same_insertion_event? (0.00s)
        --- PASS: TestImportHistoricalMessages/parallel/Federation (0.00s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_joining_on_federated_server_-_auto-generated_base_insertion_event (4.12s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_joining_on_federated_server_-_pre-made_insertion_event (4.67s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/Historical_messages_are_visible_when_already_joined_on_federated_server (5.33s)
            --- PASS: TestImportHistoricalMessages/parallel/Federation/When_messages_have_already_been_scrolled_back_through,_new_historical_messages_are_visible_in_next_scroll_back_on_federated_server (5.38s)
        --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions (0.00s)
            --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions/Not_allowed_to_redact_MSC2716_insertion,_batch,_marker_events (0.82s)
            --- PASS: TestImportHistoricalMessages/parallel/Existing_room_versions/Room_creator_can_send_MSC2716_events (0.90s)
        --- PASS: TestImportHistoricalMessages/parallel/Unrecognised_prev_event_ID_will_throw_an_error (1.34s)
        --- PASS: TestImportHistoricalMessages/parallel/Duplicate_next_batch_id_on_insertion_event_will_be_rejected (1.94s)
        --- PASS: TestImportHistoricalMessages/parallel/Normal_users_aren't_allowed_to_batch_send_historical_messages (2.05s)
        --- PASS: TestImportHistoricalMessages/parallel/Unrecognised_batch_id_will_throw_an_error (2.06s)
        --- PASS: TestImportHistoricalMessages/parallel/Batch_send_endpoint_only_returns_state_events_that_we_passed_in_via_state_events_at_start (2.52s)
        --- PASS: TestImportHistoricalMessages/parallel/Should_be_able_to_send_a_batch_without_any_state_events_at_start_-_user_already_joined_in_the_current_room_state (2.79s)
        --- PASS: TestImportHistoricalMessages/parallel/Should_be_able_to_batch_send_historical_messages_into_private_room (3.07s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_from_multiple_users_in_the_same_batch (3.11s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_resolve_in_the_correct_order (3.57s)
        --- PASS: TestImportHistoricalMessages/parallel/should_resolve_member_state_events_for_historical_events (3.62s)
        --- PASS: TestImportHistoricalMessages/parallel/Historical_events_from_batch_send_do_not_come_down_in_an_incremental_sync (3.72s)
PASS
ok  	github.com/matrix-org/complement/tests	21.795s

Copy link
Member

@tulir tulir Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to always throw

AssertionError: Attempting to create a non-m.room.create event with no prev_events

Happened on 1.53, so I tested this branch and it worked, then I tried plain develop and it failed again

Maybe specific to event creation workers again? Did Complement ever get worker support?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack trace (I think this was from develop):

2022-02-28 22:09:26,425 - synapse.http.server - 100 - ERROR - POST-702 - Failed handle request via 'RoomBatchSendEventRestServlet': <XForwardedForRequest at 0x7f1cec068910 method='POST' uri='/_matrix/client/unstable/org.matrix.msc2716/rooms/%21luiLbOOYPPuupTkaHC:pc.mau.dev/batch_send?prev_event_id=$sOyl_xFS22jWSD0Tczo_fQ1c4aFc0vB809kYQj5tJ2c&user_id=@_tulir_whatsapp_<redacted>:pc.mau.dev&com.beeper.also_allow_user=@tulir:pc.mau.dev' clientproto='HTTP/1.1' site='8008'>
Traceback (most recent call last):
  File "synapse/http/server.py", line 269, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "synapse/http/server.py", line 471, in _async_render
    callback_return = await raw_callback_return
  File "synapse/rest/client/room_batch.py", line 148, in on_POST
    await self.room_batch_handler.persist_state_events_at_start(
  File "synapse/handlers/room_batch.py", line 240, in persist_state_events_at_start
    ) = await self.event_creation_handler.create_and_send_nonmember_event(
  File "synapse/handlers/message.py", line 857, in create_and_send_nonmember_event
    event, context = await self.create_event(
  File "synapse/handlers/message.py", line 611, in create_event
    event, context = await self.create_new_client_event(
  File "synapse/util/metrics.py", line 106, in measured_func
    r = await func(self, *args, **kwargs)
  File "synapse/handlers/message.py", line 977, in create_new_client_event
    assert (
AssertionError: Attempting to create a non-m.room.create event with no prev_events
2022-02-28 22:09:26,429 - synapse.access.http.8008 - 427 - INFO - POST-702 - 127.0.0.1 - 8008 - {@_tulir_whatsapp_<redacted>:pc.mau.dev} Processed request: 0.004sec/0.003sec (0.001sec, 0.000sec) (0.000sec/0.001sec/2) 55B 500 "POST /_matrix/client/unstable/org.matrix.msc2716/rooms/%21luiLbOOYPPuupTkaHC:pc.mau.dev/batch_send?prev_event_id=$sOyl_xFS22jWSD0Tczo_fQ1c4aFc0vB809kYQj5tJ2c&user_id=@_tulir_whatsapp_<redacted>:pc.mau.dev&com.beeper.also_allow_user=@tulir:pc.mau.dev HTTP/1.1" "mautrix-whatsapp/0.2.4+dev.3479e1cc mautrix-go/v0.10.11" [0 dbevts]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And of course a simple batch send with curl doesn't reproduce it, while the bridge does consistently on every attempt 🙃

Copy link
Member

@tulir tulir Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was able to reproduce it with curl by sending a non-member event in state_events_at_start. Happens on develop and 1.53.0, doesn't happen after merging this PR on top of develop. Doesn't happen on 1.52.0

Is non-member state events included in complement tests? I've stopped sending them from the bridge now (it only sent a dummy event as a workaround for #11188), but it should probably be tested (or rejected with a proper error, if it's not supposed to be allowed in state_events_at_start)

Copy link
Contributor Author

@MadLittleMods MadLittleMods Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-member event in state_events_at_start

😫 Ayee, that's one area I haven't really used yet.

Relevant code: synapse/handlers/room_batch.py#L232-L253

Feel free to create a separate issue to track this and will create a fix shortly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the specific issue seems to go away with this PR. No idea why, but that's why I thought this was the fix. Anyway, I made #12110 for either adding tests or removing the branch.

tulir added a commit to mautrix/whatsapp that referenced this pull request Feb 28, 2022
It's not needed anymore as the relevant PR was merged, and Synapse 1.53
seems to include a regression which breaks sending non-member state events
(which seems to be fixed by matrix-org/synapse#12083).
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks generally plausible to me, but I'm going to bump this over to @erikjohnston as I think he has more context here.

@@ -856,8 +878,10 @@ async def create_and_send_nonmember_event(
requester,
event_dict,
txn_id=txn_id,
allow_no_prev_events=allow_no_prev_events,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the previous omission of this a bug?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could we get rid of allow_no_prev_events and just allow there to be no prev events when state_event_ids is given?)

Copy link
Contributor Author

@MadLittleMods MadLittleMods Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the previous omission of this a bug?

Yes and seems to be why this PR fixes @tulir's issue, #12083 (comment)

(could we get rid of allow_no_prev_events and just allow there to be no prev events when state_event_ids is given?)

I'm leaning to no although technically yes probably.

The assertion nature of allow_no_prev_events disallowing the case for the majority of normal event sending cases is nice.

Also in our case, we only want the first event to have no prev_event_ids. The rest in the chain using state_event_ids should have prev_event_ids pointing at the event before it in the chain.

state_event_ids is really just used to derive auth_event_ids. Although I do see how they're related, auth_event_ids explicitly set by state_event_ids or derived from prev_event_ids in normal cases.

Copy link
Member

@erikjohnston erikjohnston Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context: we see a fair few "can't create event with no prev events" errors already, so having an allow_no_prev_events flag should hopefully make it easier to reason about what is going on when investigating that issue.

@@ -272,6 +272,7 @@ async def _local_membership_update(
allow_no_prev_events: bool = False,
prev_event_ids: Optional[List[str]] = None,
auth_event_ids: Optional[List[str]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to keep it separate.

@@ -176,7 +177,7 @@ async def persist_state_events_at_start(
assert app_service_requester.app_service

state_event_ids_at_start = []
auth_event_ids = initial_auth_event_ids.copy()
state_event_ids = initial_state_ids_at_event.copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Side note: all these copies will be expensive for rooms with a lot of state, which will affect how quickly we can batch insert history.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how exactly to side-step this.

state_event_ids is an ongoing list where we add to as we persist state_events_at_start. Then return the full list at the end.

And we state_event_ids.copy() to snapshot the state in the loop and pass it to the event creation functions. Otherwise, the signatures integrity checks go out of whack because we modified the list in place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference on why we have to define state_event_ids here:

# Since each state event is marked as an outlier, the
# `EventContext.for_outlier()` won't have any `state_ids`
# set and therefore can't derive any state even though the
# prev_events are set. Also since the first event in the
# state chain is floating with no `prev_events`, it can't
# derive state from anywhere automatically. So we need to
# set some state explicitly.

necessary to auth a given event and set as the auth_event_ids. For
insertion events, we will add all of these state events as the explicit
state so the rest of the historical batch can inherit the same state and
state_group.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. We probably don't actually want this behaviour, instead we want to only set the state for the insertion event and allow subsequent events to inherit the state from their prev event. When just sending messages this doesn't matter, but if we send state events in the batch then the current behaviour means that the state event won't become part of the state.

For example, if a user joins half way through the batch and they won't be able to send the message (assuming they weren't added as part of state_events_at_start).

I think its trivial to change, that we only set state_event_ids for the initial insertion event, i.e. when the prev_events are empty.

Or am I forgetting how this works yet again?

Copy link
Contributor Author

@MadLittleMods MadLittleMods Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead we want to only set the state for the insertion event and allow subsequent events to inherit the state from their prev event.

This is what currently is happening. And as far as I can tell, the comment explains it that way too.

For non-insertion events, we only use state_event_ids to derive auth_event_ids to set.

For insertion events, we set the state as state_event_ids

For example, if a user joins half way through the batch and they won't be able to send the message (assuming they weren't added as part of state_events_at_start).

It's not expected to have any state events in the batch of events (or at least processed to auth further messages). Any messages being sent should have m.room.member already in the state for that point in time where we are inserting at or added to state_events_at_start.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know why I get confused about this every time. Ah well.

From the doc-comment:

We share the same state across the whole historical batch.

Ok, so I think is what is getting me. I think what you mean is that the state for the historical batch is all derived from the state at the insertion event? My reading of it was "all events in the batch have the same state", which is not true?

For non-insertion events, we only use state_event_ids to derive auth_event_ids to set.

Why do we need this for non-insertion events? Can't we just let the code derive it as normal from the state? That way the only special case is handling the insertion event.

It's not expected to have any state events in the batch of events (or at least processed to auth further messages). Any messages being sent should have m.room.member already in the state for that point in time where we are inserting at or added to state_events_at_start.

This means that the timeline will never see when a user joins/leaves, which may be fine for the Gitter use case, but we probably want to support it more generally than other use cases. I think we get this for free though, if we stop specifying the auth events directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this for non-insertion events? Can't we just let the code derive it as normal from the state? That way the only special case is handling the insertion event.

Ahh, this does work and is a good simplification! Updated comments to be more nuanced here too ⏩

I also tried doing something similar for the state_events_at_start chain to avoid the copies but since each state event is an outlier which uses EventContext.for_outlier() and has no state_ids to derive from, we have to explicitly set the state for each and can't avoid it as far as I can tell. I also commented the code with these details.

Overall, more understanding of why things are the way they are from this prompt to change 👍

This means that the timeline will never see when a user joins/leaves, which may be fine for the Gitter use case, but we probably want to support it more generally than other use cases. I think we get this for free though, if we stop specifying the auth events directly.

The problem is that the events are persisted in reverse-chronological order so they have the correct stream_ordering while being backfilled which decrements.

As an example of why this fails, if we /batch_send -> events: [messageFromA, memberEventB, messageFromB], it will first try to persist messageFromB which will fail because memberEventB hasn't been processed yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the events are persisted in reverse-chronological order so they have the correct stream_ordering while being backfilled which decrements.

As an example of why this fails, if we /batch_send -> events: [messageFromA, memberEventB, messageFromB], it will first try to persist messageFromB which will fail because memberEventB hasn't been processed yet.

Oh yes, nyargh. I think we want to fix that, but not in this PR I guess. My hunch is that we want to try and persist the entire batch of events all in one go, rather than doing them one-by-one in reverse order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own reference, here is a Complement test around adding state in the middle of the events batch (it fails for reason outlined above).

Complement test for "State in the middle of the events batch resolves for subsequent events"
t.Run("State in the middle of the events batch resolves for subsequent events", func(t *testing.T) {
	t.Parallel()

	roomID := as.CreateRoom(t, createPublicRoomOpts)
	alice.JoinRoom(t, roomID, nil)

	// Create the "live" event we are going to import our historical events next to
	eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
	eventIdBefore := eventIDsBefore[0]
	timeAfterEventBefore := time.Now()

	events := createMessageEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore, 1)

	// Add some events from Ricky who joined in the middle of the events batch
	virtualUserID2 := "@ricky:hs1"
	ensureVirtualUserRegistered(t, as, "ricky")
	events = append(
		events,
		createJoinStateEventsForBatchSendRequest([]string{virtualUserID2}, timeAfterEventBefore)...,
	)
	events = append(
		events,
		createMessageEventsForBatchSendRequest([]string{virtualUserID2}, timeAfterEventBefore, 1)...,
	)

	// Import a historical event
	batchSendHistoricalMessages(
		t,
		as,
		roomID,
		eventIdBefore,
		"",
		createJoinStateEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore),
		events,
		// Status
		200,
	)
})

@MadLittleMods MadLittleMods merged commit 14662d3 into develop Mar 25, 2022
@MadLittleMods MadLittleMods deleted the madlittlemods/10975-r813183430-refactor-to-full-state-parameter branch March 25, 2022 14:21
@MadLittleMods
Copy link
Contributor Author

Thanks for the review @richvdh, @erikjohnston , and @tulir for trying it out 🦓

MadLittleMods added a commit that referenced this pull request Mar 26, 2022
Follow-up to #12083

Since we are now using the new `state_event_ids` parameter to do all of the heavy lifting.
We can remove any spots where we plumbed `auth_event_ids` just for MSC2716 things in
https://github.com/matrix-org/synapse/pull/9247/files.

Removing `auth_event_ids` from following functions:

 - `create_and_send_nonmember_event`
 - `_local_membership_update`
 - `update_membership`
 - `update_membership_locked`
erikjohnston pushed a commit that referenced this pull request Mar 29, 2022
Follow-up to #12083

Since we are now using the new `state_event_ids` parameter to do all of the heavy lifting.
We can remove any spots where we plumbed `auth_event_ids` just for MSC2716 things in
https://github.com/matrix-org/synapse/pull/9247/files.

Removing `auth_event_ids` from following functions:

 - `create_and_send_nonmember_event`
 - `_local_membership_update`
 - `update_membership`
 - `update_membership_locked`
richvdh added a commit that referenced this pull request Apr 5, 2022
Synapse 1.56.0rc1 (2022-03-29)
==============================

Features
--------

- Allow modules to store already existing 3PID associations. ([\#12195](#12195))
- Allow registering server administrators using the module API. Contributed by Famedly. ([\#12250](#12250))

Bugfixes
--------

- Fix a long-standing bug which caused the `/_matrix/federation/v1/state` and `/_matrix/federation/v1/state_ids` endpoints to return incorrect or invalid data when called for an event which we have stored as an "outlier". ([\#12087](#12087))
- Fix a long-standing bug where events from ignored users would still be considered for relations. ([\#12227](#12227), [\#12232](#12232), [\#12285](#12285))
- Fix a bug introduced in Synapse 1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads. ([\#12228](#12228))
- Fix a bug introduced in Synapse 1.52.0 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars. ([\#12261](#12261))

Improved Documentation
----------------------

- Fix the link to the module documentation in the legacy spam checker warning message. ([\#12231](#12231))
- Remove incorrect prefixes in the worker documentation for some endpoints. ([\#12243](#12243))
- Correct `check_username_for_spam` annotations and docs. ([\#12246](#12246))
- Correct Authentik OpenID typo, and add notes on troubleshooting. Contributed by @IronTooch. ([\#12275](#12275))
- HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh. ([\#12279](#12279))

Internal Changes
----------------

- Rename `shared_rooms` to `mutual_rooms` ([MSC2666](matrix-org/matrix-spec-proposals#2666)), as per proposal changes. ([\#12036](#12036))
- Remove check on `update_user_directory` for shared rooms handler ([MSC2666](matrix-org/matrix-spec-proposals#2666)), and update/expand documentation. ([\#12038](#12038))
- Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](matrix-org/matrix-spec-proposals#2716) instead of abusing `auth_event_ids`. ([\#12083](#12083), [\#12304](#12304))
- Refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config flag `enable_registration_without_verification` is set. ([\#12091](#12091))
- Add tests for database transaction callbacks. ([\#12198](#12198))
- Handle cancellation in `DatabasePool.runInteraction`. ([\#12199](#12199))
- Add missing type hints for cache storage. ([\#12216](#12216))
- Add missing type hints for storage. ([\#12248](#12248), [\#12255](#12255))
- Add type hints to tests files. ([\#12224](#12224), [\#12240](#12240), [\#12256](#12256))
- Use type stubs for `psycopg2`. ([\#12269](#12269))
- Improve type annotations for `execute_values`. ([\#12311](#12311))
- Clean-up logic around rebasing URLs for URL image previews. ([\#12219](#12219))
- Use the `ignored_users` table in additional places instead of re-parsing the account data. ([\#12225](#12225))
- Refactor the relations endpoints to add a `RelationsHandler`. ([\#12237](#12237))
- Generate announcement links in the release script. ([\#12242](#12242))
- Improve error message when dependencies check finds a broken installation. ([\#12244](#12244))
- Compress metrics HTTP resource when enabled. Contributed by Nick @ Beeper. ([\#12258](#12258))
- Refuse to start if the PostgreSQL database has a non-`C` locale, unless the config flag `allow_unsafe_db_locale` is set to true. ([\#12262](#12262), [\#12288](#12288))
- Optionally include account validity expiration information to experimental [MSC3720](matrix-org/matrix-spec-proposals#3720) account status responses. ([\#12266](#12266))
- Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms. ([\#12272](#12272))
- Re-enable Complement concurrency in CI. ([\#12283](#12283))
- Remove unused test utilities. ([\#12291](#12291))
- Enhance logging for inbound federation events. ([\#12301](#12301))
- Fix compatibility with the recently-released Jinja 3.1. ([\#12313](#12313))
- Avoid trying to calculate the state at outlier events. ([\#12314](#12314))
chagai95 pushed a commit to chagai95/synapse that referenced this pull request Apr 9, 2022
…ing-modules-for-ansible-self-build

Synapse 1.56.0 (2022-04-05)
===========================

Synapse will now refuse to start up if open registration is enabled, in order to help mitigate
abuse across the federation. If you would like
to provide registration to anyone, consider adding [email](https://github.com/matrix-org/synapse/blob/8a519f8abc6de772167c2cca101d22ee2052fafc/docs/sample_config.yaml#L1285),
[recaptcha](https://matrix-org.github.io/synapse/v1.56/CAPTCHA_SETUP.html)
or [token-based](https://matrix-org.github.io/synapse/v1.56/usage/administration/admin_api/registration_tokens.html) verification
in order to prevent automated registration from bad actors.
This check can be disabled by setting the `enable_registration_without_verification` option in your
homeserver configuration file to `true`. More details are available in the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade.html#open-registration-without-verification-is-now-disabled-by-default).

Synapse will additionally now refuse to start when using PostgreSQL with a non-`C` values for `COLLATE` and `CTYPE`, unless
the config flag `allow_unsafe_locale`, found in the database section of the configuration file, is set to `true`. See the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade#change-in-behaviour-for-postgresql-databases-with-unsafe-locale)
for details.

Internal Changes
----------------

- Bump the version of `black` for compatibility with the latest `click` release. ([\matrix-org#12320](matrix-org#12320))

Synapse 1.56.0rc1 (2022-03-29)
==============================

Features
--------

- Allow modules to store already existing 3PID associations. ([\matrix-org#12195](matrix-org#12195))
- Allow registering server administrators using the module API. Contributed by Famedly. ([\matrix-org#12250](matrix-org#12250))

Bugfixes
--------

- Fix a long-standing bug which caused the `/_matrix/federation/v1/state` and `/_matrix/federation/v1/state_ids` endpoints to return incorrect or invalid data when called for an event which we have stored as an "outlier". ([\matrix-org#12087](matrix-org#12087))
- Fix a long-standing bug where events from ignored users would still be considered for relations. ([\matrix-org#12227](matrix-org#12227), [\matrix-org#12232](matrix-org#12232), [\matrix-org#12285](matrix-org#12285))
- Fix a bug introduced in Synapse 1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads. ([\matrix-org#12228](matrix-org#12228))
- Fix a bug introduced in Synapse 1.52.0 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars. ([\matrix-org#12261](matrix-org#12261))

Improved Documentation
----------------------

- Fix the link to the module documentation in the legacy spam checker warning message. ([\matrix-org#12231](matrix-org#12231))
- Remove incorrect prefixes in the worker documentation for some endpoints. ([\matrix-org#12243](matrix-org#12243))
- Correct `check_username_for_spam` annotations and docs. ([\matrix-org#12246](matrix-org#12246))
- Correct Authentik OpenID typo, and add notes on troubleshooting. Contributed by @IronTooch. ([\matrix-org#12275](matrix-org#12275))
- HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh. ([\matrix-org#12279](matrix-org#12279))

Internal Changes
----------------

- Rename `shared_rooms` to `mutual_rooms` ([MSC2666](matrix-org/matrix-spec-proposals#2666)), as per proposal changes. ([\matrix-org#12036](matrix-org#12036))
- Remove check on `update_user_directory` for shared rooms handler ([MSC2666](matrix-org/matrix-spec-proposals#2666)), and update/expand documentation. ([\matrix-org#12038](matrix-org#12038))
- Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](matrix-org/matrix-spec-proposals#2716) instead of abusing `auth_event_ids`. ([\matrix-org#12083](matrix-org#12083), [\matrix-org#12304](matrix-org#12304))
- Refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config flag `enable_registration_without_verification` is set to `true`. ([\matrix-org#12091](matrix-org#12091), [\matrix-org#12322](matrix-org#12322))
- Add tests for database transaction callbacks. ([\matrix-org#12198](matrix-org#12198))
- Handle cancellation in `DatabasePool.runInteraction`. ([\matrix-org#12199](matrix-org#12199))
- Add missing type hints for cache storage. ([\matrix-org#12216](matrix-org#12216))
- Add missing type hints for storage. ([\matrix-org#12248](matrix-org#12248), [\matrix-org#12255](matrix-org#12255))
- Add type hints to tests files. ([\matrix-org#12224](matrix-org#12224), [\matrix-org#12240](matrix-org#12240), [\matrix-org#12256](matrix-org#12256))
- Use type stubs for `psycopg2`. ([\matrix-org#12269](matrix-org#12269))
- Improve type annotations for `execute_values`. ([\matrix-org#12311](matrix-org#12311))
- Clean-up logic around rebasing URLs for URL image previews. ([\matrix-org#12219](matrix-org#12219))
- Use the `ignored_users` table in additional places instead of re-parsing the account data. ([\matrix-org#12225](matrix-org#12225))
- Refactor the relations endpoints to add a `RelationsHandler`. ([\matrix-org#12237](matrix-org#12237))
- Generate announcement links in the release script. ([\matrix-org#12242](matrix-org#12242))
- Improve error message when dependencies check finds a broken installation. ([\matrix-org#12244](matrix-org#12244))
- Compress metrics HTTP resource when enabled. Contributed by Nick @ Beeper. ([\matrix-org#12258](matrix-org#12258))
- Refuse to start if the PostgreSQL database has a non-`C` locale, unless the config flag `allow_unsafe_db_locale` is set to true. ([\matrix-org#12262](matrix-org#12262), [\matrix-org#12288](matrix-org#12288))
- Optionally include account validity expiration information to experimental [MSC3720](matrix-org/matrix-spec-proposals#3720) account status responses. ([\matrix-org#12266](matrix-org#12266))
- Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms. ([\matrix-org#12272](matrix-org#12272))
- Re-enable Complement concurrency in CI. ([\matrix-org#12283](matrix-org#12283))
- Remove unused test utilities. ([\matrix-org#12291](matrix-org#12291))
- Enhance logging for inbound federation events. ([\matrix-org#12301](matrix-org#12301))
- Fix compatibility with the recently-released Jinja 3.1. ([\matrix-org#12313](matrix-org#12313))
- Avoid trying to calculate the state at outlier events. ([\matrix-org#12314](matrix-org#12314))
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Apr 17, 2022
Synapse 1.56.0 (2022-04-05)
===========================

Synapse will now refuse to start up if open registration is enabled, in order to help mitigate
abuse across the federation. If you would like
to provide registration to anyone, consider adding [email](https://github.com/matrix-org/synapse/blob/8a519f8abc6de772167c2cca101d22ee2052fafc/docs/sample_config.yaml#L1285),
[recaptcha](https://matrix-org.github.io/synapse/v1.56/CAPTCHA_SETUP.html)
or [token-based](https://matrix-org.github.io/synapse/v1.56/usage/administration/admin_api/registration_tokens.html) verification
in order to prevent automated registration from bad actors.
This check can be disabled by setting the `enable_registration_without_verification` option in your
homeserver configuration file to `true`. More details are available in the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade.html#open-registration-without-verification-is-now-disabled-by-default).

Synapse will additionally now refuse to start when using PostgreSQL with a non-`C` values for `COLLATE` and `CTYPE`, unless
the config flag `allow_unsafe_locale`, found in the database section of the configuration file, is set to `true`. See the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade#change-in-behaviour-for-postgresql-databases-with-unsafe-locale)
for details.

Internal Changes
----------------

- Bump the version of `black` for compatibility with the latest `click` release. ([\#12320](matrix-org/synapse#12320))


Synapse 1.56.0rc1 (2022-03-29)
==============================

Features
--------

- Allow modules to store already existing 3PID associations. ([\#12195](matrix-org/synapse#12195))
- Allow registering server administrators using the module API. Contributed by Famedly. ([\#12250](matrix-org/synapse#12250))


Bugfixes
--------

- Fix a long-standing bug which caused the `/_matrix/federation/v1/state` and `/_matrix/federation/v1/state_ids` endpoints to return incorrect or invalid data when called for an event which we have stored as an "outlier". ([\#12087](matrix-org/synapse#12087))
- Fix a long-standing bug where events from ignored users would still be considered for relations. ([\#12227](matrix-org/synapse#12227), [\#12232](matrix-org/synapse#12232), [\#12285](matrix-org/synapse#12285))
- Fix a bug introduced in Synapse 1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads. ([\#12228](matrix-org/synapse#12228))
- Fix a bug introduced in Synapse 1.52.0 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars. ([\#12261](matrix-org/synapse#12261))


Improved Documentation
----------------------

- Fix the link to the module documentation in the legacy spam checker warning message. ([\#12231](matrix-org/synapse#12231))
- Remove incorrect prefixes in the worker documentation for some endpoints. ([\#12243](matrix-org/synapse#12243))
- Correct `check_username_for_spam` annotations and docs. ([\#12246](matrix-org/synapse#12246))
- Correct Authentik OpenID typo, and add notes on troubleshooting. Contributed by @IronTooch. ([\#12275](matrix-org/synapse#12275))
- HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh. ([\#12279](matrix-org/synapse#12279))


Internal Changes
----------------

- Rename `shared_rooms` to `mutual_rooms` ([MSC2666](matrix-org/matrix-spec-proposals#2666)), as per proposal changes. ([\#12036](matrix-org/synapse#12036))
- Remove check on `update_user_directory` for shared rooms handler ([MSC2666](matrix-org/matrix-spec-proposals#2666)), and update/expand documentation. ([\#12038](matrix-org/synapse#12038))
- Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](matrix-org/matrix-spec-proposals#2716) instead of abusing `auth_event_ids`. ([\#12083](matrix-org/synapse#12083), [\#12304](matrix-org/synapse#12304))
- Refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config flag `enable_registration_without_verification` is set to `true`. ([\#12091](matrix-org/synapse#12091), [\#12322](matrix-org/synapse#12322))
- Add tests for database transaction callbacks. ([\#12198](matrix-org/synapse#12198))
- Handle cancellation in `DatabasePool.runInteraction`. ([\#12199](matrix-org/synapse#12199))
- Add missing type hints for cache storage. ([\#12216](matrix-org/synapse#12216))
- Add missing type hints for storage. ([\#12248](matrix-org/synapse#12248), [\#12255](matrix-org/synapse#12255))
- Add type hints to tests files. ([\#12224](matrix-org/synapse#12224), [\#12240](matrix-org/synapse#12240), [\#12256](matrix-org/synapse#12256))
- Use type stubs for `psycopg2`. ([\#12269](matrix-org/synapse#12269))
- Improve type annotations for `execute_values`. ([\#12311](matrix-org/synapse#12311))
- Clean-up logic around rebasing URLs for URL image previews. ([\#12219](matrix-org/synapse#12219))
- Use the `ignored_users` table in additional places instead of re-parsing the account data. ([\#12225](matrix-org/synapse#12225))
- Refactor the relations endpoints to add a `RelationsHandler`. ([\#12237](matrix-org/synapse#12237))
- Generate announcement links in the release script. ([\#12242](matrix-org/synapse#12242))
- Improve error message when dependencies check finds a broken installation. ([\#12244](matrix-org/synapse#12244))
- Compress metrics HTTP resource when enabled. Contributed by Nick @ Beeper. ([\#12258](matrix-org/synapse#12258))
- Refuse to start if the PostgreSQL database has a non-`C` locale, unless the config flag `allow_unsafe_db_locale` is set to true. ([\#12262](matrix-org/synapse#12262), [\#12288](matrix-org/synapse#12288))
- Optionally include account validity expiration information to experimental [MSC3720](matrix-org/matrix-spec-proposals#3720) account status responses. ([\#12266](matrix-org/synapse#12266))
- Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms. ([\#12272](matrix-org/synapse#12272))
- Re-enable Complement concurrency in CI. ([\#12283](matrix-org/synapse#12283))
- Remove unused test utilities. ([\#12291](matrix-org/synapse#12291))
- Enhance logging for inbound federation events. ([\#12301](matrix-org/synapse#12301))
- Fix compatibility with the recently-released Jinja 3.1. ([\#12313](matrix-org/synapse#12313))
- Avoid trying to calculate the state at outlier events. ([\#12314](matrix-org/synapse#12314))


Synapse 1.55.2 (2022-03-24)
===========================

This patch version reverts the earlier fixes from Synapse 1.55.1, which could cause problems in certain deployments, and instead adds a cap to the version of Jinja to be installed. Again, this is to fix an incompatibility with version 3.1.0 of the [Jinja](https://pypi.org/project/Jinja2/) library, and again, deployments of Synapse using the `matrixdotorg/synapse` Docker image or Debian packages from packages.matrix.org are not affected.

Internal Changes
----------------

- Pin Jinja to <3.1.0, as Synapse fails to start with Jinja 3.1.0. ([\#12297](matrix-org/synapse#12297))
- Revert changes from 1.55.1 as they caused problems with older versions of Jinja ([\#12296](matrix-org/synapse#12296))


Synapse 1.55.1 (2022-03-24)
===========================

This is a patch release that fixes an incompatibility with version 3.1.0 of the [Jinja](https://pypi.org/project/Jinja2/) library, released on March 24th, 2022. Deployments of Synapse using the `matrixdotorg/synapse` Docker image or Debian packages from packages.matrix.org are not affected.

Internal Changes
----------------

- Remove uses of the long-deprecated `jinja2.Markup` which would prevent Synapse from starting with Jinja 3.1.0 or above installed. ([\#12289](matrix-org/synapse#12289))


Synapse 1.55.0 (2022-03-22)
===========================

This release removes a workaround introduced in Synapse 1.50.0 for Mjolnir compatibility. **This breaks compatibility with Mjolnir 1.3.1 and earlier. ([\#11700](matrix-org/synapse#11700; Mjolnir users should upgrade Mjolnir before upgrading Synapse to this version.

This release also moves the location of the `synctl` script; see the [upgrade notes](https://github.com/matrix-org/synapse/blob/develop/docs/upgrade.md#synctl-script-has-been-moved) for more details.


Internal Changes
----------------

- Tweak copy for default Single Sign-On account details template to better adhere to mobile app store guidelines. ([\#12265](matrix-org/synapse#12265), [\#12260](matrix-org/synapse#12260))


Synapse 1.55.0rc1 (2022-03-15)
==============================

Features
--------

- Add third-party rules callbacks `check_can_shutdown_room` and `check_can_deactivate_user`. ([\#12028](matrix-org/synapse#12028))
- Improve performance of logging in for large accounts. ([\#12132](matrix-org/synapse#12132))
- Add experimental env var `SYNAPSE_ASYNC_IO_REACTOR` that causes Synapse to use the asyncio reactor for Twisted. ([\#12135](matrix-org/synapse#12135))
- Support the stable identifiers from [MSC3440](matrix-org/matrix-spec-proposals#3440): threads. ([\#12151](matrix-org/synapse#12151))
- Add a new Jinja2 template filter to extract the local part of an email address. ([\#12212](matrix-org/synapse#12212))


Bugfixes
--------

- Use the proper serialization format for bundled thread aggregations. The bug has existed since Synapse v1.48.0. ([\#12090](matrix-org/synapse#12090))
- Fix a long-standing bug when redacting events with relations. ([\#12113](matrix-org/synapse#12113), [\#12121](matrix-org/synapse#12121), [\#12130](matrix-org/synapse#12130), [\#12189](matrix-org/synapse#12189))
- Fix a bug introduced in Synapse 1.7.2 whereby background updates are never run with the default background batch size. ([\#12157](matrix-org/synapse#12157))
- Fix a bug where non-standard information was returned from the `/hierarchy` API. Introduced in Synapse v1.41.0. ([\#12175](matrix-org/synapse#12175))
- Fix a bug introduced in Synapse 1.54.0 that broke background updates on sqlite homeservers while search was disabled. ([\#12215](matrix-org/synapse#12215))
- Fix a long-standing bug when a `filter` argument with `event_fields` which did not include the `unsigned` field could result in a 500 error on `/sync`. ([\#12234](matrix-org/synapse#12234))


Improved Documentation
----------------------

- Fix complexity checking config example in [Resource Constrained Devices](https://matrix-org.github.io/synapse/v1.54/other/running_synapse_on_single_board_computers.html) docs page. ([\#11998](matrix-org/synapse#11998))
- Improve documentation for demo scripts. ([\#12143](matrix-org/synapse#12143))
- Updates to the Room DAG concepts development document. ([\#12179](matrix-org/synapse#12179))
- Document that the `typing`, `to_device`, `account_data`, `receipts`, and `presence` stream writer can only be used on a single worker. ([\#12196](matrix-org/synapse#12196))
- Document that contributors can sign off privately by email. ([\#12204](matrix-org/synapse#12204))


Deprecations and Removals
-------------------------

- **Remove workaround introduced in Synapse 1.50.0 for Mjolnir compatibility. Breaks compatibility with Mjolnir 1.3.1 and earlier. ([\#11700](matrix-org/synapse#11700
- **`synctl` has been moved into into `synapse._scripts` and is exposed as an entry point; see [upgrade notes](https://github.com/matrix-org/synapse/blob/develop/docs/upgrade.md#synctl-script-has-been-moved). ([\#12140](matrix-org/synapse#12140))
- Remove backwards compatibilty with pagination tokens from the `/relations` and `/aggregations` endpoints generated from Synapse < v1.52.0. ([\#12138](matrix-org/synapse#12138))
- The groups/communities feature in Synapse has been deprecated. ([\#12200](matrix-org/synapse#12200))


Internal Changes
----------------

- Simplify the `ApplicationService` class' set of public methods related to interest checking. ([\#11915](matrix-org/synapse#11915))
- Add config settings for background update parameters. ([\#11980](matrix-org/synapse#11980))
- Correct type hints for txredis. ([\#12042](matrix-org/synapse#12042))
- Limit the size of `aggregation_key` on annotations. ([\#12101](matrix-org/synapse#12101))
- Add type hints to tests files. ([\#12108](matrix-org/synapse#12108), [\#12146](matrix-org/synapse#12146), [\#12207](matrix-org/synapse#12207), [\#12208](matrix-org/synapse#12208))
- Move scripts to Synapse package and expose as setuptools entry points. ([\#12118](matrix-org/synapse#12118))
- Add support for cancellation to `ReadWriteLock`. ([\#12120](matrix-org/synapse#12120))
- Fix data validation to compare to lists, not sequences. ([\#12128](matrix-org/synapse#12128))
- Fix CI not attaching source distributions and wheels to the GitHub releases. ([\#12131](matrix-org/synapse#12131))
- Remove unused mocks from `test_typing`. ([\#12136](matrix-org/synapse#12136))
- Give `scripts-dev` scripts suffixes for neater CI config. ([\#12137](matrix-org/synapse#12137))
- Move the snapcraft configuration file to `contrib`. ([\#12142](matrix-org/synapse#12142))
- Enable [MSC3030](matrix-org/matrix-spec-proposals#3030) Complement tests in CI. ([\#12144](matrix-org/synapse#12144))
- Enable [MSC2716](matrix-org/matrix-spec-proposals#2716) Complement tests in CI. ([\#12145](matrix-org/synapse#12145))
- Add test for `ObservableDeferred`'s cancellation behaviour. ([\#12149](matrix-org/synapse#12149))
- Use `ParamSpec` in type hints for `synapse.logging.context`. ([\#12150](matrix-org/synapse#12150))
- Prune unused jobs from `tox` config. ([\#12152](matrix-org/synapse#12152))
- Move CI checks out of tox, to facilitate a move to using poetry. ([\#12153](matrix-org/synapse#12153))
- Avoid generating state groups for local out-of-band leaves. ([\#12154](matrix-org/synapse#12154))
- Avoid trying to calculate the state at outlier events. ([\#12155](matrix-org/synapse#12155), [\#12173](matrix-org/synapse#12173), [\#12202](matrix-org/synapse#12202))
- Fix some type annotations. ([\#12156](matrix-org/synapse#12156))
- Add type hints for `ObservableDeferred` attributes. ([\#12159](matrix-org/synapse#12159))
- Use a prebuilt Action for the `tests-done` CI job. ([\#12161](matrix-org/synapse#12161))
- Reduce number of DB queries made during processing of `/sync`. ([\#12163](matrix-org/synapse#12163))
- Add `delay_cancellation` utility function, which behaves like `stop_cancellation` but waits until the original `Deferred` resolves before raising a `CancelledError`. ([\#12180](matrix-org/synapse#12180))
- Retry HTTP replication failures, this should prevent 502's when restarting stateful workers (main, event persisters, stream writers). Contributed by Nick @ Beeper. ([\#12182](matrix-org/synapse#12182))
- Add cancellation support to `@cached` and `@cachedList` decorators. ([\#12183](matrix-org/synapse#12183))
- Remove unused variables. ([\#12187](matrix-org/synapse#12187))
- Add combined test for HTTP pusher and push rule. Contributed by Nick @ Beeper. ([\#12188](matrix-org/synapse#12188))
- Rename `HomeServer.get_tcp_replication` to `get_replication_command_handler`. ([\#12192](matrix-org/synapse#12192))
- Remove some dead code. ([\#12197](matrix-org/synapse#12197))
- Fix a misleading comment in the function `check_event_for_spam`. ([\#12203](matrix-org/synapse#12203))
- Remove unnecessary `pass` statements. ([\#12206](matrix-org/synapse#12206))
- Update the SSO username picker template to comply with SIWA guidelines. ([\#12210](matrix-org/synapse#12210))
- Improve code documentation for the typing stream over replication. ([\#12211](matrix-org/synapse#12211))
Fizzadar added a commit to Fizzadar/synapse that referenced this pull request Apr 25, 2022
Synapse 1.56.0 (2022-04-05)
===========================

Synapse will now refuse to start up if open registration is enabled, in order to help mitigate
abuse across the federation. If you would like
to provide registration to anyone, consider adding [email](https://github.com/matrix-org/synapse/blob/8a519f8abc6de772167c2cca101d22ee2052fafc/docs/sample_config.yaml#L1285),
[recaptcha](https://matrix-org.github.io/synapse/v1.56/CAPTCHA_SETUP.html)
or [token-based](https://matrix-org.github.io/synapse/v1.56/usage/administration/admin_api/registration_tokens.html) verification
in order to prevent automated registration from bad actors.
This check can be disabled by setting the `enable_registration_without_verification` option in your
homeserver configuration file to `true`. More details are available in the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade.html#open-registration-without-verification-is-now-disabled-by-default).

Synapse will additionally now refuse to start when using PostgreSQL with a non-`C` values for `COLLATE` and `CTYPE`, unless
the config flag `allow_unsafe_locale`, found in the database section of the configuration file, is set to `true`. See the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade#change-in-behaviour-for-postgresql-databases-with-unsafe-locale)
for details.

Internal Changes
----------------

- Bump the version of `black` for compatibility with the latest `click` release. ([\matrix-org#12320](matrix-org#12320))

Synapse 1.56.0rc1 (2022-03-29)
==============================

Features
--------

- Allow modules to store already existing 3PID associations. ([\matrix-org#12195](matrix-org#12195))
- Allow registering server administrators using the module API. Contributed by Famedly. ([\matrix-org#12250](matrix-org#12250))

Bugfixes
--------

- Fix a long-standing bug which caused the `/_matrix/federation/v1/state` and `/_matrix/federation/v1/state_ids` endpoints to return incorrect or invalid data when called for an event which we have stored as an "outlier". ([\matrix-org#12087](matrix-org#12087))
- Fix a long-standing bug where events from ignored users would still be considered for relations. ([\matrix-org#12227](matrix-org#12227), [\matrix-org#12232](matrix-org#12232), [\matrix-org#12285](matrix-org#12285))
- Fix a bug introduced in Synapse 1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads. ([\matrix-org#12228](matrix-org#12228))
- Fix a bug introduced in Synapse 1.52.0 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars. ([\matrix-org#12261](matrix-org#12261))

Improved Documentation
----------------------

- Fix the link to the module documentation in the legacy spam checker warning message. ([\matrix-org#12231](matrix-org#12231))
- Remove incorrect prefixes in the worker documentation for some endpoints. ([\matrix-org#12243](matrix-org#12243))
- Correct `check_username_for_spam` annotations and docs. ([\matrix-org#12246](matrix-org#12246))
- Correct Authentik OpenID typo, and add notes on troubleshooting. Contributed by @IronTooch. ([\matrix-org#12275](matrix-org#12275))
- HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh. ([\matrix-org#12279](matrix-org#12279))

Internal Changes
----------------

- Rename `shared_rooms` to `mutual_rooms` ([MSC2666](matrix-org/matrix-spec-proposals#2666)), as per proposal changes. ([\matrix-org#12036](matrix-org#12036))
- Remove check on `update_user_directory` for shared rooms handler ([MSC2666](matrix-org/matrix-spec-proposals#2666)), and update/expand documentation. ([\matrix-org#12038](matrix-org#12038))
- Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](matrix-org/matrix-spec-proposals#2716) instead of abusing `auth_event_ids`. ([\matrix-org#12083](matrix-org#12083), [\matrix-org#12304](matrix-org#12304))
- Refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config flag `enable_registration_without_verification` is set to `true`. ([\matrix-org#12091](matrix-org#12091), [\matrix-org#12322](matrix-org#12322))
- Add tests for database transaction callbacks. ([\matrix-org#12198](matrix-org#12198))
- Handle cancellation in `DatabasePool.runInteraction`. ([\matrix-org#12199](matrix-org#12199))
- Add missing type hints for cache storage. ([\matrix-org#12216](matrix-org#12216))
- Add missing type hints for storage. ([\matrix-org#12248](matrix-org#12248), [\matrix-org#12255](matrix-org#12255))
- Add type hints to tests files. ([\matrix-org#12224](matrix-org#12224), [\matrix-org#12240](matrix-org#12240), [\matrix-org#12256](matrix-org#12256))
- Use type stubs for `psycopg2`. ([\matrix-org#12269](matrix-org#12269))
- Improve type annotations for `execute_values`. ([\matrix-org#12311](matrix-org#12311))
- Clean-up logic around rebasing URLs for URL image previews. ([\matrix-org#12219](matrix-org#12219))
- Use the `ignored_users` table in additional places instead of re-parsing the account data. ([\matrix-org#12225](matrix-org#12225))
- Refactor the relations endpoints to add a `RelationsHandler`. ([\matrix-org#12237](matrix-org#12237))
- Generate announcement links in the release script. ([\matrix-org#12242](matrix-org#12242))
- Improve error message when dependencies check finds a broken installation. ([\matrix-org#12244](matrix-org#12244))
- Compress metrics HTTP resource when enabled. Contributed by Nick @ Beeper. ([\matrix-org#12258](matrix-org#12258))
- Refuse to start if the PostgreSQL database has a non-`C` locale, unless the config flag `allow_unsafe_db_locale` is set to true. ([\matrix-org#12262](matrix-org#12262), [\matrix-org#12288](matrix-org#12288))
- Optionally include account validity expiration information to experimental [MSC3720](matrix-org/matrix-spec-proposals#3720) account status responses. ([\matrix-org#12266](matrix-org#12266))
- Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms. ([\matrix-org#12272](matrix-org#12272))
- Re-enable Complement concurrency in CI. ([\matrix-org#12283](matrix-org#12283))
- Remove unused test utilities. ([\matrix-org#12291](matrix-org#12291))
- Enhance logging for inbound federation events. ([\matrix-org#12301](matrix-org#12301))
- Fix compatibility with the recently-released Jinja 3.1. ([\matrix-org#12313](matrix-org#12313))
- Avoid trying to calculate the state at outlier events. ([\matrix-org#12314](matrix-org#12314))
babolivier added a commit to matrix-org/synapse-dinsic that referenced this pull request Apr 28, 2022
Synapse 1.56.0 (2022-04-05)
===========================

Synapse will now refuse to start up if open registration is enabled, in order to help mitigate
abuse across the federation. If you would like
to provide registration to anyone, consider adding [email](https://github.com/matrix-org/synapse/blob/8a519f8abc6de772167c2cca101d22ee2052fafc/docs/sample_config.yaml#L1285),
[recaptcha](https://matrix-org.github.io/synapse/v1.56/CAPTCHA_SETUP.html)
or [token-based](https://matrix-org.github.io/synapse/v1.56/usage/administration/admin_api/registration_tokens.html) verification
in order to prevent automated registration from bad actors.
This check can be disabled by setting the `enable_registration_without_verification` option in your
homeserver configuration file to `true`. More details are available in the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade.html#open-registration-without-verification-is-now-disabled-by-default).

Synapse will additionally now refuse to start when using PostgreSQL with a non-`C` values for `COLLATE` and `CTYPE`, unless
the config flag `allow_unsafe_locale`, found in the database section of the configuration file, is set to `true`. See the
[upgrade notes](https://matrix-org.github.io/synapse/v1.56/upgrade#change-in-behaviour-for-postgresql-databases-with-unsafe-locale)
for details.

Internal Changes
----------------

- Bump the version of `black` for compatibility with the latest `click` release. ([\#12320](matrix-org/synapse#12320))

Synapse 1.56.0rc1 (2022-03-29)
==============================

Features
--------

- Allow modules to store already existing 3PID associations. ([\#12195](matrix-org/synapse#12195))
- Allow registering server administrators using the module API. Contributed by Famedly. ([\#12250](matrix-org/synapse#12250))

Bugfixes
--------

- Fix a long-standing bug which caused the `/_matrix/federation/v1/state` and `/_matrix/federation/v1/state_ids` endpoints to return incorrect or invalid data when called for an event which we have stored as an "outlier". ([\#12087](matrix-org/synapse#12087))
- Fix a long-standing bug where events from ignored users would still be considered for relations. ([\#12227](matrix-org/synapse#12227), [\#12232](matrix-org/synapse#12232), [\#12285](matrix-org/synapse#12285))
- Fix a bug introduced in Synapse 1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads. ([\#12228](matrix-org/synapse#12228))
- Fix a bug introduced in Synapse 1.52.0 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars. ([\#12261](matrix-org/synapse#12261))

Improved Documentation
----------------------

- Fix the link to the module documentation in the legacy spam checker warning message. ([\#12231](matrix-org/synapse#12231))
- Remove incorrect prefixes in the worker documentation for some endpoints. ([\#12243](matrix-org/synapse#12243))
- Correct `check_username_for_spam` annotations and docs. ([\#12246](matrix-org/synapse#12246))
- Correct Authentik OpenID typo, and add notes on troubleshooting. Contributed by @IronTooch. ([\#12275](matrix-org/synapse#12275))
- HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh. ([\#12279](matrix-org/synapse#12279))

Internal Changes
----------------

- Rename `shared_rooms` to `mutual_rooms` ([MSC2666](matrix-org/matrix-spec-proposals#2666)), as per proposal changes. ([\#12036](matrix-org/synapse#12036))
- Remove check on `update_user_directory` for shared rooms handler ([MSC2666](matrix-org/matrix-spec-proposals#2666)), and update/expand documentation. ([\#12038](matrix-org/synapse#12038))
- Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](matrix-org/matrix-spec-proposals#2716) instead of abusing `auth_event_ids`. ([\#12083](matrix-org/synapse#12083), [\#12304](matrix-org/synapse#12304))
- Refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config flag `enable_registration_without_verification` is set to `true`. ([\#12091](matrix-org/synapse#12091), [\#12322](matrix-org/synapse#12322))
- Add tests for database transaction callbacks. ([\#12198](matrix-org/synapse#12198))
- Handle cancellation in `DatabasePool.runInteraction`. ([\#12199](matrix-org/synapse#12199))
- Add missing type hints for cache storage. ([\#12216](matrix-org/synapse#12216))
- Add missing type hints for storage. ([\#12248](matrix-org/synapse#12248), [\#12255](matrix-org/synapse#12255))
- Add type hints to tests files. ([\#12224](matrix-org/synapse#12224), [\#12240](matrix-org/synapse#12240), [\#12256](matrix-org/synapse#12256))
- Use type stubs for `psycopg2`. ([\#12269](matrix-org/synapse#12269))
- Improve type annotations for `execute_values`. ([\#12311](matrix-org/synapse#12311))
- Clean-up logic around rebasing URLs for URL image previews. ([\#12219](matrix-org/synapse#12219))
- Use the `ignored_users` table in additional places instead of re-parsing the account data. ([\#12225](matrix-org/synapse#12225))
- Refactor the relations endpoints to add a `RelationsHandler`. ([\#12237](matrix-org/synapse#12237))
- Generate announcement links in the release script. ([\#12242](matrix-org/synapse#12242))
- Improve error message when dependencies check finds a broken installation. ([\#12244](matrix-org/synapse#12244))
- Compress metrics HTTP resource when enabled. Contributed by Nick @ Beeper. ([\#12258](matrix-org/synapse#12258))
- Refuse to start if the PostgreSQL database has a non-`C` locale, unless the config flag `allow_unsafe_db_locale` is set to true. ([\#12262](matrix-org/synapse#12262), [\#12288](matrix-org/synapse#12288))
- Optionally include account validity expiration information to experimental [MSC3720](matrix-org/matrix-spec-proposals#3720) account status responses. ([\#12266](matrix-org/synapse#12266))
- Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms. ([\#12272](matrix-org/synapse#12272))
- Re-enable Complement concurrency in CI. ([\#12283](matrix-org/synapse#12283))
- Remove unused test utilities. ([\#12291](matrix-org/synapse#12291))
- Enhance logging for inbound federation events. ([\#12301](matrix-org/synapse#12301))
- Fix compatibility with the recently-released Jinja 3.1. ([\#12313](matrix-org/synapse#12313))
- Avoid trying to calculate the state at outlier events. ([\#12314](matrix-org/synapse#12314))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants