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

Add base starting insertion event when no chunk ID is provided (MSC2716) #10250

Merged
merged 5 commits into from
Jul 9, 2021

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Jun 25, 2021

Add base starting insertion event when no chunk ID is provided.

Part of MSC2716: matrix-org/matrix-spec-proposals#2716

This is spawning from #10245 (follow-up to #9247) where I am actually trying to traverse the historical events. I realized we would skip the first chunk of messages if the marker event was pointing to the insertion point at the top of the chunk. Now the marker event can point to this base insertion event and we can traverse up the events and over to the next chunk.

Before After

TARDIS visualization:

Previous diagrams (backup)
Before After

TARDIS visualization:
Screen Shot 2021-06-25 at 12 35 11 AM

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.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

This is so we can have the marker event point to this initial
insertion event and be able to traverse the events in the first chunk.
EventContentFields.MSC2716_CHUNK_ID
] = chunk_id_from_query
# TODO: Verify the chunk_id_from_query corresponds to an insertion event
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need a database index to make this lookup fast. Going to add this in #10245

@MadLittleMods MadLittleMods changed the title Draft: Add base starting insertion point when no chunk ID is provided (MSC2716) Draft: Add base starting insertion event when no chunk ID is provided (MSC2716) Jun 25, 2021
events_to_create.append(base_insertion_event)
chunk_id_to_connect_to = base_insertion_event["content"][
EventContentFields.MSC2716_NEXT_CHUNK_ID
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is where we are creating the base insertion event

@MadLittleMods MadLittleMods changed the title Draft: Add base starting insertion event when no chunk ID is provided (MSC2716) Add base starting insertion event when no chunk ID is provided (MSC2716) Jun 25, 2021
@MadLittleMods MadLittleMods force-pushed the madlittlemods/2716-base-insertion-event branch from 3411d51 to 3083660 Compare June 29, 2021 22:11
@erikjohnston
Copy link
Member

I'm a little bit confused. Shouldn't the marker event be pointing at the next chunk? The same way that the insertion events are pointing at the next chunk?

@erikjohnston
Copy link
Member

I'm a little bit confused. Shouldn't the marker event be pointing at the next chunk? The same way that the insertion events are pointing at the next chunk?

So the way to think about this is that the base insertion event isn't in the first chunk per se, as ideally it would be part of the original DAG when we first created the room. However, we want to support adding historical events even where we don't have insertion events, and so we create a new base insertion event in an ad hoc manner.

@MadLittleMods
Copy link
Contributor Author

MadLittleMods commented Jul 7, 2021

So the way to think about this is that the base insertion event isn't in the first chunk per se, as ideally it would be part of the original DAG when we first created the room. However, we want to support adding historical events even where we don't have insertion events, and so we create a new base insertion event in an ad hoc manner.

It would probably be more accurate if showed the chunk connection from the base insertion point. The insertion event is part of the first chunk currently which made it easy to insert and add.

Perhaps it should float more as you're thinking about. I don't think it affects much being in the first chunk but it would be used in a more consistent manner this way if we made it float.

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

I think this all makes sense

synapse/rest/client/v1/room.py Outdated Show resolved Hide resolved
synapse/rest/client/v1/room.py Outdated Show resolved Hide resolved
synapse/rest/client/v1/room.py Outdated Show resolved Hide resolved
@MadLittleMods MadLittleMods force-pushed the madlittlemods/2716-base-insertion-event branch from b2039a7 to e91c9bb Compare July 8, 2021 04:22
@MadLittleMods MadLittleMods force-pushed the madlittlemods/2716-base-insertion-event branch from e91c9bb to 4dfa4ff Compare July 8, 2021 04:27
auth_event_ids=auth_event_ids,
historical=True,
depth=inherited_depth,
)
Copy link
Contributor Author

@MadLittleMods MadLittleMods Jul 8, 2021

Choose a reason for hiding this comment

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

@erikjohnston I've decided to make the base insertion event float off on its own so its easier to reason about in my head (all of them are hooked up consistently).

@MadLittleMods MadLittleMods merged commit d26094e into develop Jul 9, 2021
@MadLittleMods MadLittleMods deleted the madlittlemods/2716-base-insertion-event branch July 9, 2021 01:26
@MadLittleMods
Copy link
Contributor Author

@erikjohnston Thanks for the review on this one! Really valuable to talk through it to see how we align 🦃

MadLittleMods added a commit that referenced this pull request Jul 9, 2021
See #10250 (comment)

Conflicts:
	synapse/rest/client/v1/room.py
anoadragon453 added a commit that referenced this pull request Jul 20, 2021
Synapse 1.39.0rc1 (2021-07-20)
==============================

The Third-Party Event Rules module interface has been deprecated in favour of the generic module interface introduced in Synapse v1.37.0. Support for the old interface is planned to be removed in September 2021. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information.

Features
--------

- Add the ability to override the account validity feature with a module. ([\#9884](#9884))
- The spaces summary API now returns any joinable rooms, not only rooms which are world-readable. ([\#10298](#10298), [\#10305](#10305))
- Add a new version of the R30 phone-home metric, which removes a false impression of retention given by the old R30 metric. ([\#10332](#10332), [\#10427](#10427))
- Allow providing credentials to `http_proxy`. ([\#10360](#10360))

Bugfixes
--------

- Fix error while dropping locks on shutdown. Introduced in v1.38.0. ([\#10433](#10433))
- Add base starting insertion event when no chunk ID is specified in the historical batch send API. ([\#10250](#10250))
- Fix historical batch send endpoint (MSC2716) rejecting batches with messages from multiple senders. ([\#10276](#10276))
- Fix purging rooms that other homeservers are still sending events for. Contributed by @ilmari. ([\#10317](#10317))
- Fix errors during backfill caused by previously purged redaction events. Contributed by Andreas Rammhold (@andir). ([\#10343](#10343))
- Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. ([\#10344](#10344))
- Fix newly added `synapse_federation_server_oldest_inbound_pdu_in_staging` prometheus metric to measure age rather than timestamp. ([\#10355](#10355))
- Fix PostgreSQL sometimes using table scans for queries against `state_groups_state` table, taking a long time and a large amount of IO. ([\#10359](#10359))
- Fix `make_room_admin` failing for users that have left a private room. ([\#10367](#10367))
- Fix a number of logged errors caused by remote servers being down. ([\#10400](#10400), [\#10414](#10414))
- Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`. ([\#10404](#10404))

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

- Updated installation dependencies for newer macOS versions and ARM Macs. Contributed by Luke Walsh. ([\#9971](#9971))
- Simplify structure of room admin API. ([\#10313](#10313))
- Refresh the logcontext dev documentation. ([\#10353](#10353)), ([\#10337](#10337))
- Add delegation example for caddy in the reverse proxy documentation. Contributed by @moritzdietz. ([\#10368](#10368))
- Fix and clarify some links in `docs` and `contrib`. ([\#10370](#10370)), ([\#10322](#10322)), ([\#10399](#10399))
- Make deprecation notice of the spam checker doc more obvious. ([\#10395](#10395))
- Add instructions on installing Debian packages for release candidates. ([\#10396](#10396))

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

- Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz. ([\#9721](#9721))
- The third-party event rules module interface is deprecated in favour of the generic module interface introduced in Synapse v1.37.0. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information. ([\#10386](#10386))

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

- Convert `room_depth.min_depth` column to a `BIGINT`. ([\#10289](#10289))
- Add tests to characterise the current behaviour of R30 phone-home metrics. ([\#10315](#10315))
- Rebuild event context and auth when processing specific results from `ThirdPartyEventRules` modules. ([\#10316](#10316))
- Minor change to the code that populates `user_daily_visits`. ([\#10324](#10324))
- Re-enable Sytests that were disabled for the 1.37.1 release. ([\#10345](#10345), [\#10357](#10357))
- Run `pyupgrade` on the codebase. ([\#10347](#10347), [\#10348](#10348))
- Switch `application_services_txns.txn_id` database column to `BIGINT`. ([\#10349](#10349))
- Convert internal type variable syntax to reflect wider ecosystem use. ([\#10350](#10350), [\#10380](#10380), [\#10381](#10381), [\#10382](#10382), [\#10418](#10418))
- Make the Github Actions workflow configuration more efficient. ([\#10383](#10383))
- Add type hints to `get_{domain,localpart}_from_id`. ([\#10385](#10385))
- When building Debian packages for prerelease versions, set the Section accordingly. ([\#10391](#10391))
- Add type hints and comments to event auth code. ([\#10393](#10393))
- Stagger sending of presence update to remote servers, reducing CPU spikes caused by starting many connections to remote servers at once. ([\#10398](#10398))
- Remove unused `events_by_room` code (tech debt). ([\#10421](#10421))
- Add a github actions job which records success of other jobs. ([\#10430](#10430))
MadLittleMods added a commit that referenced this pull request Jul 28, 2021
… any scrollback history (MSC2716) (#10245)

* Make historical messages available to federated servers

Part of MSC2716: matrix-org/matrix-spec-proposals#2716

Follow-up to #9247

* Debug message not available on federation

* Add base starting insertion point when no chunk ID is provided

* Fix messages from multiple senders in historical chunk

Follow-up to #9247

Part of MSC2716: matrix-org/matrix-spec-proposals#2716

---

Previously, Synapse would throw a 403,
`Cannot force another user to join.`,
because we were trying to use `?user_id` from a single virtual user
which did not match with messages from other users in the chunk.

* Remove debug lines

* Messing with selecting insertion event extremeties

* Move db schema change to new version

* Add more better comments

* Make a fake requester with just what we need

See #10276 (comment)

* Store insertion events in table

* Make base insertion event float off on its own

See #10250 (comment)

Conflicts:
	synapse/rest/client/v1/room.py

* Validate that the app service can actually control the given user

See #10276 (comment)

Conflicts:
	synapse/rest/client/v1/room.py

* Add some better comments on what we're trying to check for

* Continue debugging

* Share validation logic

* Add inserted historical messages to /backfill response

* Remove debug sql queries

* Some marker event implemntation trials

* Clean up PR

* Rename insertion_event_id to just event_id

* Add some better sql comments

* More accurate description

* Add changelog

* Make it clear what MSC the change is part of

* Add more detail on which insertion event came through

* Address review and improve sql queries

* Only use event_id as unique constraint

* Fix test case where insertion event is already in the normal DAG

* Remove debug changes

* Switch to chunk events so we can auth via power_levels

Previously, we were using `content.chunk_id` to connect one
chunk to another. But these events can be from any `sender`
and we can't tell who should be able to send historical events.
We know we only want the application service to do it but these
events have the sender of a real historical message, not the
application service user ID as the sender. Other federated homeservers
also have no indicator which senders are an application service on
the originating homeserver.

So we want to auth all of the MSC2716 events via power_levels
and have them be sent by the application service with proper
PL levels in the room.

* Switch to chunk events for federation

* Add unstable room version to support new historical PL

* Fix federated events being rejected for no state_groups

Add fix from #10439
until it merges.

* Only connect base insertion event to prev_event_ids

Per discussion with @erikjohnston,
https://matrix.to/#/!UytJQHLQYfvYWsGrGY:jki.re/$12bTUiObDFdHLAYtT7E-BvYRp3k_xv8w0dUQHibasJk?via=jki.re&via=matrix.org

* Make it possible to get the room_version with txn

* Allow but ignore historical events in unsupported room version

See #10245 (comment)

We can't reject historical events on unsupported room versions because homeservers without knowledge of MSC2716 or the new room version don't reject historical events either.

Since we can't rely on the auth check here to stop historical events on unsupported room versions, I've added some additional checks in the processing/persisting code (`synapse/storage/databases/main/events.py` ->  `_handle_insertion_event` and `_handle_chunk_event`). I've had to do some refactoring so there is method to fetch the room version by `txn`.

* Move to unique index syntax

See #10245 (comment)

* High-level document how the insertion->chunk lookup works

* Remove create_event fallback for room_versions

See https://github.com/matrix-org/synapse/pull/10245/files#r677641879

* Use updated method name
@MadLittleMods MadLittleMods added the T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. label Jul 28, 2021
erikjohnston added a commit that referenced this pull request Jul 29, 2021
Synapse 1.39.0 (2021-07-29)
===========================

No significant changes.

Synapse 1.39.0rc3 (2021-07-28)
==============================

Bugfixes
--------

- Fix a bug introduced in Synapse 1.38 which caused an exception at startup when SAML authentication was enabled. ([\#10477](#10477))
- Fix a long-standing bug where Synapse would not inform clients that a device had exhausted its one-time-key pool, potentially causing problems decrypting events. ([\#10485](#10485))
- Fix reporting old R30 stats as R30v2 stats. Introduced in v1.39.0rc1. ([\#10486](#10486))

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

- Fix an error which prevented the Github Actions workflow to build the docker images from running. ([\#10461](#10461))
- Fix release script to correctly version debian changelog when doing RCs. ([\#10465](#10465))

Synapse 1.39.0rc2 (2021-07-22)
==============================

This release also includes the changes in v1.38.1.

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

- Move docker image build to Github Actions. ([\#10416](#10416))

Synapse 1.39.0rc1 (2021-07-20)
==============================

The Third-Party Event Rules module interface has been deprecated in favour of the generic module interface introduced in Synapse v1.37.0. Support for the old interface is planned to be removed in September 2021. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information.

Features
--------

- Add the ability to override the account validity feature with a module. ([\#9884](#9884))
- The spaces summary API now returns any joinable rooms, not only rooms which are world-readable. ([\#10298](#10298), [\#10305](#10305))
- Add a new version of the R30 phone-home metric, which removes a false impression of retention given by the old R30 metric. ([\#10332](#10332), [\#10427](#10427))
- Allow providing credentials to `http_proxy`. ([\#10360](#10360))

Bugfixes
--------

- Fix error while dropping locks on shutdown. Introduced in v1.38.0. ([\#10433](#10433))
- Add base starting insertion event when no chunk ID is specified in the historical batch send API. ([\#10250](#10250))
- Fix historical batch send endpoint (MSC2716) rejecting batches with messages from multiple senders. ([\#10276](#10276))
- Fix purging rooms that other homeservers are still sending events for. Contributed by @ilmari. ([\#10317](#10317))
- Fix errors during backfill caused by previously purged redaction events. Contributed by Andreas Rammhold (@andir). ([\#10343](#10343))
- Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. ([\#10344](#10344))
- Fix newly added `synapse_federation_server_oldest_inbound_pdu_in_staging` prometheus metric to measure age rather than timestamp. ([\#10355](#10355))
- Fix PostgreSQL sometimes using table scans for queries against `state_groups_state` table, taking a long time and a large amount of IO. ([\#10359](#10359))
- Fix `make_room_admin` failing for users that have left a private room. ([\#10367](#10367))
- Fix a number of logged errors caused by remote servers being down. ([\#10400](#10400), [\#10414](#10414))
- Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`. ([\#10404](#10404))

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

- Updated installation dependencies for newer macOS versions and ARM Macs. Contributed by Luke Walsh. ([\#9971](#9971))
- Simplify structure of room admin API. ([\#10313](#10313))
- Refresh the logcontext dev documentation. ([\#10353](#10353)), ([\#10337](#10337))
- Add delegation example for caddy in the reverse proxy documentation. Contributed by @moritzdietz. ([\#10368](#10368))
- Fix and clarify some links in `docs` and `contrib`. ([\#10370](#10370)), ([\#10322](#10322)), ([\#10399](#10399))
- Make deprecation notice of the spam checker doc more obvious. ([\#10395](#10395))
- Add instructions on installing Debian packages for release candidates. ([\#10396](#10396))

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

- Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz. ([\#9721](#9721))
- The third-party event rules module interface is deprecated in favour of the generic module interface introduced in Synapse v1.37.0. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information. ([\#10386](#10386))

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

- Convert `room_depth.min_depth` column to a `BIGINT`. ([\#10289](#10289))
- Add tests to characterise the current behaviour of R30 phone-home metrics. ([\#10315](#10315))
- Rebuild event context and auth when processing specific results from `ThirdPartyEventRules` modules. ([\#10316](#10316))
- Minor change to the code that populates `user_daily_visits`. ([\#10324](#10324))
- Re-enable Sytests that were disabled for the 1.37.1 release. ([\#10345](#10345), [\#10357](#10357))
- Run `pyupgrade` on the codebase. ([\#10347](#10347), [\#10348](#10348))
- Switch `application_services_txns.txn_id` database column to `BIGINT`. ([\#10349](#10349))
- Convert internal type variable syntax to reflect wider ecosystem use. ([\#10350](#10350), [\#10380](#10380), [\#10381](#10381), [\#10382](#10382), [\#10418](#10418))
- Make the Github Actions workflow configuration more efficient. ([\#10383](#10383))
- Add type hints to `get_{domain,localpart}_from_id`. ([\#10385](#10385))
- When building Debian packages for prerelease versions, set the Section accordingly. ([\#10391](#10391))
- Add type hints and comments to event auth code. ([\#10393](#10393))
- Stagger sending of presence update to remote servers, reducing CPU spikes caused by starting many connections to remote servers at once. ([\#10398](#10398))
- Remove unused `events_by_room` code (tech debt). ([\#10421](#10421))
- Add a github actions job which records success of other jobs. ([\#10430](#10430))
aaronraimist added a commit to aaronraimist/synapse that referenced this pull request Jul 29, 2021
Synapse 1.39.0 (2021-07-29)
===========================

No significant changes.

Synapse 1.39.0rc3 (2021-07-28)
==============================

Bugfixes
--------

- Fix a bug introduced in Synapse 1.38 which caused an exception at startup when SAML authentication was enabled. ([\matrix-org#10477](matrix-org#10477))
- Fix a long-standing bug where Synapse would not inform clients that a device had exhausted its one-time-key pool, potentially causing problems decrypting events. ([\matrix-org#10485](matrix-org#10485))
- Fix reporting old R30 stats as R30v2 stats. Introduced in v1.39.0rc1. ([\matrix-org#10486](matrix-org#10486))

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

- Fix an error which prevented the Github Actions workflow to build the docker images from running. ([\matrix-org#10461](matrix-org#10461))
- Fix release script to correctly version debian changelog when doing RCs. ([\matrix-org#10465](matrix-org#10465))

Synapse 1.39.0rc2 (2021-07-22)
==============================

This release also includes the changes in v1.38.1.

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

- Move docker image build to Github Actions. ([\matrix-org#10416](matrix-org#10416))

Synapse 1.39.0rc1 (2021-07-20)
==============================

The Third-Party Event Rules module interface has been deprecated in favour of the generic module interface introduced in Synapse v1.37.0. Support for the old interface is planned to be removed in September 2021. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information.

Features
--------

- Add the ability to override the account validity feature with a module. ([\matrix-org#9884](matrix-org#9884))
- The spaces summary API now returns any joinable rooms, not only rooms which are world-readable. ([\matrix-org#10298](matrix-org#10298), [\matrix-org#10305](matrix-org#10305))
- Add a new version of the R30 phone-home metric, which removes a false impression of retention given by the old R30 metric. ([\matrix-org#10332](matrix-org#10332), [\matrix-org#10427](matrix-org#10427))
- Allow providing credentials to `http_proxy`. ([\matrix-org#10360](matrix-org#10360))

Bugfixes
--------

- Fix error while dropping locks on shutdown. Introduced in v1.38.0. ([\matrix-org#10433](matrix-org#10433))
- Add base starting insertion event when no chunk ID is specified in the historical batch send API. ([\matrix-org#10250](matrix-org#10250))
- Fix historical batch send endpoint (MSC2716) rejecting batches with messages from multiple senders. ([\matrix-org#10276](matrix-org#10276))
- Fix purging rooms that other homeservers are still sending events for. Contributed by @ilmari. ([\matrix-org#10317](matrix-org#10317))
- Fix errors during backfill caused by previously purged redaction events. Contributed by Andreas Rammhold (@andir). ([\matrix-org#10343](matrix-org#10343))
- Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. ([\matrix-org#10344](matrix-org#10344))
- Fix newly added `synapse_federation_server_oldest_inbound_pdu_in_staging` prometheus metric to measure age rather than timestamp. ([\matrix-org#10355](matrix-org#10355))
- Fix PostgreSQL sometimes using table scans for queries against `state_groups_state` table, taking a long time and a large amount of IO. ([\matrix-org#10359](matrix-org#10359))
- Fix `make_room_admin` failing for users that have left a private room. ([\matrix-org#10367](matrix-org#10367))
- Fix a number of logged errors caused by remote servers being down. ([\matrix-org#10400](matrix-org#10400), [\matrix-org#10414](matrix-org#10414))
- Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`. ([\matrix-org#10404](matrix-org#10404))

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

- Updated installation dependencies for newer macOS versions and ARM Macs. Contributed by Luke Walsh. ([\matrix-org#9971](matrix-org#9971))
- Simplify structure of room admin API. ([\matrix-org#10313](matrix-org#10313))
- Refresh the logcontext dev documentation. ([\matrix-org#10353](matrix-org#10353)), ([\matrix-org#10337](matrix-org#10337))
- Add delegation example for caddy in the reverse proxy documentation. Contributed by @moritzdietz. ([\matrix-org#10368](matrix-org#10368))
- Fix and clarify some links in `docs` and `contrib`. ([\matrix-org#10370](matrix-org#10370)), ([\matrix-org#10322](matrix-org#10322)), ([\matrix-org#10399](matrix-org#10399))
- Make deprecation notice of the spam checker doc more obvious. ([\matrix-org#10395](matrix-org#10395))
- Add instructions on installing Debian packages for release candidates. ([\matrix-org#10396](matrix-org#10396))

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

- Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz. ([\matrix-org#9721](matrix-org#9721))
- The third-party event rules module interface is deprecated in favour of the generic module interface introduced in Synapse v1.37.0. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information. ([\matrix-org#10386](matrix-org#10386))

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

- Convert `room_depth.min_depth` column to a `BIGINT`. ([\matrix-org#10289](matrix-org#10289))
- Add tests to characterise the current behaviour of R30 phone-home metrics. ([\matrix-org#10315](matrix-org#10315))
- Rebuild event context and auth when processing specific results from `ThirdPartyEventRules` modules. ([\matrix-org#10316](matrix-org#10316))
- Minor change to the code that populates `user_daily_visits`. ([\matrix-org#10324](matrix-org#10324))
- Re-enable Sytests that were disabled for the 1.37.1 release. ([\matrix-org#10345](matrix-org#10345), [\matrix-org#10357](matrix-org#10357))
- Run `pyupgrade` on the codebase. ([\matrix-org#10347](matrix-org#10347), [\matrix-org#10348](matrix-org#10348))
- Switch `application_services_txns.txn_id` database column to `BIGINT`. ([\matrix-org#10349](matrix-org#10349))
- Convert internal type variable syntax to reflect wider ecosystem use. ([\matrix-org#10350](matrix-org#10350), [\matrix-org#10380](matrix-org#10380), [\matrix-org#10381](matrix-org#10381), [\matrix-org#10382](matrix-org#10382), [\matrix-org#10418](matrix-org#10418))
- Make the Github Actions workflow configuration more efficient. ([\matrix-org#10383](matrix-org#10383))
- Add type hints to `get_{domain,localpart}_from_id`. ([\matrix-org#10385](matrix-org#10385))
- When building Debian packages for prerelease versions, set the Section accordingly. ([\matrix-org#10391](matrix-org#10391))
- Add type hints and comments to event auth code. ([\matrix-org#10393](matrix-org#10393))
- Stagger sending of presence update to remote servers, reducing CPU spikes caused by starting many connections to remote servers at once. ([\matrix-org#10398](matrix-org#10398))
- Remove unused `events_by_room` code (tech debt). ([\matrix-org#10421](matrix-org#10421))
- Add a github actions job which records success of other jobs. ([\matrix-org#10430](matrix-org#10430))
MadLittleMods added a commit that referenced this pull request Aug 4, 2021
* Make historical messages available to federated servers

Part of MSC2716: matrix-org/matrix-spec-proposals#2716

Follow-up to #9247

* Debug message not available on federation

* Add base starting insertion point when no chunk ID is provided

* Fix messages from multiple senders in historical chunk

Follow-up to #9247

Part of MSC2716: matrix-org/matrix-spec-proposals#2716

---

Previously, Synapse would throw a 403,
`Cannot force another user to join.`,
because we were trying to use `?user_id` from a single virtual user
which did not match with messages from other users in the chunk.

* Remove debug lines

* Messing with selecting insertion event extremeties

* Move db schema change to new version

* Add more better comments

* Make a fake requester with just what we need

See #10276 (comment)

* Store insertion events in table

* Make base insertion event float off on its own

See #10250 (comment)

Conflicts:
	synapse/rest/client/v1/room.py

* Validate that the app service can actually control the given user

See #10276 (comment)

Conflicts:
	synapse/rest/client/v1/room.py

* Add some better comments on what we're trying to check for

* Continue debugging

* Share validation logic

* Add inserted historical messages to /backfill response

* Remove debug sql queries

* Some marker event implemntation trials

* Clean up PR

* Rename insertion_event_id to just event_id

* Add some better sql comments

* More accurate description

* Add changelog

* Make it clear what MSC the change is part of

* Add more detail on which insertion event came through

* Address review and improve sql queries

* Only use event_id as unique constraint

* Fix test case where insertion event is already in the normal DAG

* Remove debug changes

* Add support for MSC2716 marker events

* Process markers when we receive it over federation

* WIP: make hs2 backfill historical messages after marker event

* hs2 to better ask for insertion event extremity

But running into the `sqlite3.IntegrityError: NOT NULL constraint failed: event_to_state_groups.state_group`
error

* Add insertion_event_extremities table

* Switch to chunk events so we can auth via power_levels

Previously, we were using `content.chunk_id` to connect one
chunk to another. But these events can be from any `sender`
and we can't tell who should be able to send historical events.
We know we only want the application service to do it but these
events have the sender of a real historical message, not the
application service user ID as the sender. Other federated homeservers
also have no indicator which senders are an application service on
the originating homeserver.

So we want to auth all of the MSC2716 events via power_levels
and have them be sent by the application service with proper
PL levels in the room.

* Switch to chunk events for federation

* Add unstable room version to support new historical PL

* Messy: Fix undefined state_group for federated historical events

```
2021-07-13 02:27:57,810 - synapse.handlers.federation - 1248 - ERROR - GET-4 - Failed to backfill from hs1 because NOT NULL constraint failed: event_to_state_groups.state_group
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/federation.py", line 1216, in try_backfill
    await self.backfill(
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/federation.py", line 1035, in backfill
    await self._auth_and_persist_event(dest, event, context, backfilled=True)
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/federation.py", line 2222, in _auth_and_persist_event
    await self._run_push_actions_and_persist_event(event, context, backfilled)
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/federation.py", line 2244, in _run_push_actions_and_persist_event
    await self.persist_events_and_notify(
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/federation.py", line 3290, in persist_events_and_notify
    events, max_stream_token = await self.storage.persistence.persist_events(
  File "/usr/local/lib/python3.8/site-packages/synapse/logging/opentracing.py", line 774, in _trace_inner
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/persist_events.py", line 320, in persist_events
    ret_vals = await yieldable_gather_results(enqueue, partitioned.items())
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/persist_events.py", line 237, in handle_queue_loop
    ret = await self._per_item_callback(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/persist_events.py", line 577, in _persist_event_batch
    await self.persist_events_store._persist_events_and_state_updates(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/events.py", line 176, in _persist_events_and_state_updates
    await self.db_pool.runInteraction(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 681, in runInteraction
    result = await self.runWithConnection(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 770, in runWithConnection
    return await make_deferred_yieldable(
  File "/usr/local/lib/python3.8/site-packages/twisted/python/threadpool.py", line 238, in inContext
    result = inContext.theWork()  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.8/site-packages/twisted/python/threadpool.py", line 254, in <lambda>
    inContext.theWork = lambda: context.call(  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.8/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/context.py", line 83, in callWithContext
    return func(*args, **kw)
  File "/usr/local/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 293, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/deprecate.py", line 298, in deprecatedFunction
    return function(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/compat.py", line 403, in reraise
    raise exception.with_traceback(traceback)
  File "/usr/local/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 284, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 765, in inner_func
    return func(db_conn, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 549, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/logging/utils.py", line 69, in wrapped
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/events.py", line 385, in _persist_events_txn
    self._store_event_state_mappings_txn(txn, events_and_contexts)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/events.py", line 2065, in _store_event_state_mappings_txn
    self.db_pool.simple_insert_many_txn(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 923, in simple_insert_many_txn
    txn.execute_batch(sql, vals)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 280, in execute_batch
    self.executemany(sql, args)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 300, in executemany
    self._do_execute(self.txn.executemany, sql, *args)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 330, in _do_execute
    return func(sql, *args)
sqlite3.IntegrityError: NOT NULL constraint failed: event_to_state_groups.state_group
```

* Revert "Messy: Fix undefined state_group for federated historical events"

This reverts commit 187ab28.

* Fix federated events being rejected for no state_groups

Add fix from #10439
until it merges.

* Adapting to experimental room version

* Some log cleanup

* Add better comments around extremity fetching code and why

* Rename to be more accurate to what the function returns

* Add changelog

* Ignore rejected events

* Use simplified upsert

* Add Erik's explanation of extra event checks

See #10498 (comment)

* Clarify that the depth is not directly correlated to the backwards extremity that we return

See #10498 (comment)

* lock only matters for sqlite

See #10498 (comment)

* Move new SQL changes to its own delta file

* Clean up upsert docstring

* Bump database schema version (62)
babolivier added a commit to matrix-org/synapse-dinsic that referenced this pull request Sep 1, 2021
Synapse 1.39.0 (2021-07-29)
===========================

No significant changes.

Synapse 1.39.0rc3 (2021-07-28)
==============================

Bugfixes
--------

- Fix a bug introduced in Synapse 1.38 which caused an exception at startup when SAML authentication was enabled. ([\#10477](matrix-org/synapse#10477))
- Fix a long-standing bug where Synapse would not inform clients that a device had exhausted its one-time-key pool, potentially causing problems decrypting events. ([\#10485](matrix-org/synapse#10485))
- Fix reporting old R30 stats as R30v2 stats. Introduced in v1.39.0rc1. ([\#10486](matrix-org/synapse#10486))

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

- Fix an error which prevented the Github Actions workflow to build the docker images from running. ([\#10461](matrix-org/synapse#10461))
- Fix release script to correctly version debian changelog when doing RCs. ([\#10465](matrix-org/synapse#10465))

Synapse 1.39.0rc2 (2021-07-22)
==============================

This release also includes the changes in v1.38.1.

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

- Move docker image build to Github Actions. ([\#10416](matrix-org/synapse#10416))

Synapse 1.39.0rc1 (2021-07-20)
==============================

The Third-Party Event Rules module interface has been deprecated in favour of the generic module interface introduced in Synapse v1.37.0. Support for the old interface is planned to be removed in September 2021. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information.

Features
--------

- Add the ability to override the account validity feature with a module. ([\#9884](matrix-org/synapse#9884))
- The spaces summary API now returns any joinable rooms, not only rooms which are world-readable. ([\#10298](matrix-org/synapse#10298), [\#10305](matrix-org/synapse#10305))
- Add a new version of the R30 phone-home metric, which removes a false impression of retention given by the old R30 metric. ([\#10332](matrix-org/synapse#10332), [\#10427](matrix-org/synapse#10427))
- Allow providing credentials to `http_proxy`. ([\#10360](matrix-org/synapse#10360))

Bugfixes
--------

- Fix error while dropping locks on shutdown. Introduced in v1.38.0. ([\#10433](matrix-org/synapse#10433))
- Add base starting insertion event when no chunk ID is specified in the historical batch send API. ([\#10250](matrix-org/synapse#10250))
- Fix historical batch send endpoint (MSC2716) rejecting batches with messages from multiple senders. ([\#10276](matrix-org/synapse#10276))
- Fix purging rooms that other homeservers are still sending events for. Contributed by @ilmari. ([\#10317](matrix-org/synapse#10317))
- Fix errors during backfill caused by previously purged redaction events. Contributed by Andreas Rammhold (@andir). ([\#10343](matrix-org/synapse#10343))
- Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. ([\#10344](matrix-org/synapse#10344))
- Fix newly added `synapse_federation_server_oldest_inbound_pdu_in_staging` prometheus metric to measure age rather than timestamp. ([\#10355](matrix-org/synapse#10355))
- Fix PostgreSQL sometimes using table scans for queries against `state_groups_state` table, taking a long time and a large amount of IO. ([\#10359](matrix-org/synapse#10359))
- Fix `make_room_admin` failing for users that have left a private room. ([\#10367](matrix-org/synapse#10367))
- Fix a number of logged errors caused by remote servers being down. ([\#10400](matrix-org/synapse#10400), [\#10414](matrix-org/synapse#10414))
- Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`. ([\#10404](matrix-org/synapse#10404))

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

- Updated installation dependencies for newer macOS versions and ARM Macs. Contributed by Luke Walsh. ([\#9971](matrix-org/synapse#9971))
- Simplify structure of room admin API. ([\#10313](matrix-org/synapse#10313))
- Refresh the logcontext dev documentation. ([\#10353](matrix-org/synapse#10353)), ([\#10337](matrix-org/synapse#10337))
- Add delegation example for caddy in the reverse proxy documentation. Contributed by @moritzdietz. ([\#10368](matrix-org/synapse#10368))
- Fix and clarify some links in `docs` and `contrib`. ([\#10370](matrix-org/synapse#10370)), ([\#10322](matrix-org/synapse#10322)), ([\#10399](matrix-org/synapse#10399))
- Make deprecation notice of the spam checker doc more obvious. ([\#10395](matrix-org/synapse#10395))
- Add instructions on installing Debian packages for release candidates. ([\#10396](matrix-org/synapse#10396))

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

- Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz. ([\#9721](matrix-org/synapse#9721))
- The third-party event rules module interface is deprecated in favour of the generic module interface introduced in Synapse v1.37.0. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information. ([\#10386](matrix-org/synapse#10386))

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

- Convert `room_depth.min_depth` column to a `BIGINT`. ([\#10289](matrix-org/synapse#10289))
- Add tests to characterise the current behaviour of R30 phone-home metrics. ([\#10315](matrix-org/synapse#10315))
- Rebuild event context and auth when processing specific results from `ThirdPartyEventRules` modules. ([\#10316](matrix-org/synapse#10316))
- Minor change to the code that populates `user_daily_visits`. ([\#10324](matrix-org/synapse#10324))
- Re-enable Sytests that were disabled for the 1.37.1 release. ([\#10345](matrix-org/synapse#10345), [\#10357](matrix-org/synapse#10357))
- Run `pyupgrade` on the codebase. ([\#10347](matrix-org/synapse#10347), [\#10348](matrix-org/synapse#10348))
- Switch `application_services_txns.txn_id` database column to `BIGINT`. ([\#10349](matrix-org/synapse#10349))
- Convert internal type variable syntax to reflect wider ecosystem use. ([\#10350](matrix-org/synapse#10350), [\#10380](matrix-org/synapse#10380), [\#10381](matrix-org/synapse#10381), [\#10382](matrix-org/synapse#10382), [\#10418](matrix-org/synapse#10418))
- Make the Github Actions workflow configuration more efficient. ([\#10383](matrix-org/synapse#10383))
- Add type hints to `get_{domain,localpart}_from_id`. ([\#10385](matrix-org/synapse#10385))
- When building Debian packages for prerelease versions, set the Section accordingly. ([\#10391](matrix-org/synapse#10391))
- Add type hints and comments to event auth code. ([\#10393](matrix-org/synapse#10393))
- Stagger sending of presence update to remote servers, reducing CPU spikes caused by starting many connections to remote servers at once. ([\#10398](matrix-org/synapse#10398))
- Remove unused `events_by_room` code (tech debt). ([\#10421](matrix-org/synapse#10421))
- Add a github actions job which records success of other jobs. ([\#10430](matrix-org/synapse#10430))
Fizzadar pushed a commit to Fizzadar/synapse that referenced this pull request Oct 26, 2021
Synapse 1.39.0 (2021-07-29)
===========================

No significant changes.

Synapse 1.39.0rc3 (2021-07-28)
==============================

Bugfixes
--------

- Fix a bug introduced in Synapse 1.38 which caused an exception at startup when SAML authentication was enabled. ([\matrix-org#10477](matrix-org#10477))
- Fix a long-standing bug where Synapse would not inform clients that a device had exhausted its one-time-key pool, potentially causing problems decrypting events. ([\matrix-org#10485](matrix-org#10485))
- Fix reporting old R30 stats as R30v2 stats. Introduced in v1.39.0rc1. ([\matrix-org#10486](matrix-org#10486))

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

- Fix an error which prevented the Github Actions workflow to build the docker images from running. ([\matrix-org#10461](matrix-org#10461))
- Fix release script to correctly version debian changelog when doing RCs. ([\matrix-org#10465](matrix-org#10465))

Synapse 1.39.0rc2 (2021-07-22)
==============================

This release also includes the changes in v1.38.1.

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

- Move docker image build to Github Actions. ([\matrix-org#10416](matrix-org#10416))

Synapse 1.39.0rc1 (2021-07-20)
==============================

The Third-Party Event Rules module interface has been deprecated in favour of the generic module interface introduced in Synapse v1.37.0. Support for the old interface is planned to be removed in September 2021. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information.

Features
--------

- Add the ability to override the account validity feature with a module. ([\matrix-org#9884](matrix-org#9884))
- The spaces summary API now returns any joinable rooms, not only rooms which are world-readable. ([\matrix-org#10298](matrix-org#10298), [\matrix-org#10305](matrix-org#10305))
- Add a new version of the R30 phone-home metric, which removes a false impression of retention given by the old R30 metric. ([\matrix-org#10332](matrix-org#10332), [\matrix-org#10427](matrix-org#10427))
- Allow providing credentials to `http_proxy`. ([\matrix-org#10360](matrix-org#10360))

Bugfixes
--------

- Fix error while dropping locks on shutdown. Introduced in v1.38.0. ([\matrix-org#10433](matrix-org#10433))
- Add base starting insertion event when no chunk ID is specified in the historical batch send API. ([\matrix-org#10250](matrix-org#10250))
- Fix historical batch send endpoint (MSC2716) rejecting batches with messages from multiple senders. ([\matrix-org#10276](matrix-org#10276))
- Fix purging rooms that other homeservers are still sending events for. Contributed by @ilmari. ([\matrix-org#10317](matrix-org#10317))
- Fix errors during backfill caused by previously purged redaction events. Contributed by Andreas Rammhold (@andir). ([\matrix-org#10343](matrix-org#10343))
- Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. ([\matrix-org#10344](matrix-org#10344))
- Fix newly added `synapse_federation_server_oldest_inbound_pdu_in_staging` prometheus metric to measure age rather than timestamp. ([\matrix-org#10355](matrix-org#10355))
- Fix PostgreSQL sometimes using table scans for queries against `state_groups_state` table, taking a long time and a large amount of IO. ([\matrix-org#10359](matrix-org#10359))
- Fix `make_room_admin` failing for users that have left a private room. ([\matrix-org#10367](matrix-org#10367))
- Fix a number of logged errors caused by remote servers being down. ([\matrix-org#10400](matrix-org#10400), [\matrix-org#10414](matrix-org#10414))
- Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`. ([\matrix-org#10404](matrix-org#10404))

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

- Updated installation dependencies for newer macOS versions and ARM Macs. Contributed by Luke Walsh. ([\matrix-org#9971](matrix-org#9971))
- Simplify structure of room admin API. ([\matrix-org#10313](matrix-org#10313))
- Refresh the logcontext dev documentation. ([\matrix-org#10353](matrix-org#10353)), ([\matrix-org#10337](matrix-org#10337))
- Add delegation example for caddy in the reverse proxy documentation. Contributed by @moritzdietz. ([\matrix-org#10368](matrix-org#10368))
- Fix and clarify some links in `docs` and `contrib`. ([\matrix-org#10370](matrix-org#10370)), ([\matrix-org#10322](matrix-org#10322)), ([\matrix-org#10399](matrix-org#10399))
- Make deprecation notice of the spam checker doc more obvious. ([\matrix-org#10395](matrix-org#10395))
- Add instructions on installing Debian packages for release candidates. ([\matrix-org#10396](matrix-org#10396))

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

- Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz. ([\matrix-org#9721](matrix-org#9721))
- The third-party event rules module interface is deprecated in favour of the generic module interface introduced in Synapse v1.37.0. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html#upgrading-to-v1390) for more information. ([\matrix-org#10386](matrix-org#10386))

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

- Convert `room_depth.min_depth` column to a `BIGINT`. ([\matrix-org#10289](matrix-org#10289))
- Add tests to characterise the current behaviour of R30 phone-home metrics. ([\matrix-org#10315](matrix-org#10315))
- Rebuild event context and auth when processing specific results from `ThirdPartyEventRules` modules. ([\matrix-org#10316](matrix-org#10316))
- Minor change to the code that populates `user_daily_visits`. ([\matrix-org#10324](matrix-org#10324))
- Re-enable Sytests that were disabled for the 1.37.1 release. ([\matrix-org#10345](matrix-org#10345), [\matrix-org#10357](matrix-org#10357))
- Run `pyupgrade` on the codebase. ([\matrix-org#10347](matrix-org#10347), [\matrix-org#10348](matrix-org#10348))
- Switch `application_services_txns.txn_id` database column to `BIGINT`. ([\matrix-org#10349](matrix-org#10349))
- Convert internal type variable syntax to reflect wider ecosystem use. ([\matrix-org#10350](matrix-org#10350), [\matrix-org#10380](matrix-org#10380), [\matrix-org#10381](matrix-org#10381), [\matrix-org#10382](matrix-org#10382), [\matrix-org#10418](matrix-org#10418))
- Make the Github Actions workflow configuration more efficient. ([\matrix-org#10383](matrix-org#10383))
- Add type hints to `get_{domain,localpart}_from_id`. ([\matrix-org#10385](matrix-org#10385))
- When building Debian packages for prerelease versions, set the Section accordingly. ([\matrix-org#10391](matrix-org#10391))
- Add type hints and comments to event auth code. ([\matrix-org#10393](matrix-org#10393))
- Stagger sending of presence update to remote servers, reducing CPU spikes caused by starting many connections to remote servers at once. ([\matrix-org#10398](matrix-org#10398))
- Remove unused `events_by_room` code (tech debt). ([\matrix-org#10421](matrix-org#10421))
- Add a github actions job which records success of other jobs. ([\matrix-org#10430](matrix-org#10430))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants