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

Fix a bug where redactions were not being sent over federation if we did not have the original event. #13813

Merged
merged 16 commits into from
Oct 11, 2022

Conversation

H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Sep 14, 2022

Prior to this change, redactions were not sent over federation if the sending server hadn't received the original event. Fixes #12795. Per the discussion on #12795, this is achieved by making the function EventsWorkerStore._get_events_from_cache_or_db public and using that rather than EventsWorkerStore.get_events_as_list, which drops redaction events if the original event isn't present. I wrote a test to verify that this change works, you can see it here: https://github.com/matrix-org/complement/actions/runs/3055371487/jobs/4929450057

@H-Shay H-Shay requested a review from a team as a code owner September 14, 2022 17:43
@H-Shay H-Shay marked this pull request as draft September 14, 2022 17:43
@H-Shay H-Shay marked this pull request as ready for review September 14, 2022 21:00
@DMRobertson
Copy link
Contributor

Complement test is matrix-org/complement#462

@H-Shay H-Shay requested a review from DMRobertson September 19, 2022 22:47
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

The changes look good, but coming back to this with fresher eyes I'm a bit worried about the bigger picture.

We now have get_events_from_cache_or_db and get_events_as_list which both sound like they do the same thing but have different behaviour with regard to redaction events. I think we now have two duplicates of this snippet of source too? I'm just worried that the fix might make it harder to reason about the source in the future.

if get_prev_content:
if "replaces_state" in event.unsigned:
prev = await self.get_event(
event.unsigned["replaces_state"],
get_prev_content=False,
allow_none=True,
)
if prev:
event.unsigned = dict(event.unsigned)
event.unsigned["prev_content"] = prev.content
event.unsigned["prev_sender"] = prev.sender

Perhaps @richvdh can advise when he gets back?

synapse/storage/databases/main/events_worker.py Outdated Show resolved Hide resolved
@richvdh
Copy link
Member

richvdh commented Sep 22, 2022

We now have get_events_from_cache_or_db and get_events_as_list which both sound like they do the same thing but have different behaviour with regard to redaction events.

I don't disagree, and it's basically the point I made on #12795:

having lots of similar-but-different entry points makes a component hard to use correctly.

Still, I can't think of a better solution here. What we could do is try to find names that better describe the functionality (maybe s/get_events_from_cache_or_db/get_unredacted_events? other suggestions welcome) and spell out the differences between the entry points in the docstrings.

@H-Shay H-Shay requested a review from richvdh September 27, 2022 22:49
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 good to me in general, but a few comments

synapse/storage/databases/main/events_worker.py Outdated Show resolved Hide resolved
synapse/federation/sender/__init__.py Outdated Show resolved Hide resolved
synapse/storage/databases/main/stream.py Outdated Show resolved Hide resolved
@richvdh richvdh self-requested a review September 30, 2022 11:02
synapse/federation/sender/__init__.py Outdated Show resolved Hide resolved
@H-Shay H-Shay requested a review from richvdh October 3, 2022 17:05
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.

Nearly!

(with all this talk of relying on the ordering of event_entries, I'm wondering if we should have a test that checks that behaviour is correct if get_unredacted_events_from_cache_or_db returns them in a different order. But... it looks like we don't have any useful tests for this bit of FederationSender currently, so that sounds like a bit of a big job, so I guess we better leave it.)

synapse/federation/sender/__init__.py Show resolved Hide resolved
now = self.clock.time_msec()
ts = event_to_received_ts[events[-1].event_id]
last_id = list(event_entries.keys())[-1]
Copy link
Member

Choose a reason for hiding this comment

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

this is still assuming an ordering in event_entries. You could use event_ids here instead. Alternatively, you could maintain a last_event_ts as you iterate over event_ids above.

(Aside: for this operation, it's nice to avoid copying the whole thing to a list just to get the last entry. next(reversed(event_entries.keys())) will do the job I think.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that insight, I knew that lists are a little expensive so I appreciate the workaround.

@H-Shay H-Shay requested a review from richvdh October 5, 2022 04:58
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.

lgtm!

(sorry for the glacial review speed!)

@H-Shay H-Shay merged commit a86b2f6 into develop Oct 11, 2022
@H-Shay H-Shay deleted the shay/no_redact branch October 11, 2022 18:18
@H-Shay
Copy link
Contributor Author

H-Shay commented Oct 11, 2022

Merged #13813 into develop, thanks for the explanations and the review!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

redactions are not sent over federation if we do not have the original event
3 participants