Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor collect_session_recipients in advance of some behavioural changes #3884

Conversation

uhoreg
Copy link
Member

@uhoreg uhoreg commented Aug 22, 2024

This is part of #3662, pulled out to into a separate PR. Recent changes in main made it pretty much impossible to merge this section of code from main into that PR, and Rich wanted to see the refactoring bits separate from the behavioural changes. So I've re-written the refactoring.

Pulls the match on sharing_strategy outside of the for loop, and moves any code that is specific to one strategy into the appropriate branch.

@uhoreg uhoreg requested a review from richvdh August 22, 2024 23:14
@uhoreg uhoreg requested review from a team as code owners August 22, 2024 23:14
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 10 lines in your changes missing coverage. Please review.

Project coverage is 84.14%. Comparing base (2db031c) to head (7ce88fd).
Report is 34 commits behind head on main.

Files Patch % Lines
...c/session_manager/group_sessions/share_strategy.rs 81.81% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3884      +/-   ##
==========================================
+ Coverage   84.10%   84.14%   +0.03%     
==========================================
  Files         266      266              
  Lines       27724    27738      +14     
==========================================
+ Hits        23318    23339      +21     
+ Misses       4406     4399       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

This feels a bit odd because now recipient_devices.unsigned_of_verified_user etc are completely unused in the IdentityBasedStrategy case. We should probably use a different return type for split_recipients_withhelds_for_user_based_on_identity if we're going to do this.


I'd previously seen another PR from Valere making this change, and at the time dismissed it, because it felt like it was adding duplication (eg, we have to do the should_rotate logic twice) without a clear benefit. I appreciate I'm lacking the context from the later PR, so could you give me a one-liner on why you feel that duplicating that logic is a worthwhile tradeoff?

withheld_devices.extend(withheld_recipients);
}
let recipients = recipient_devices.allowed_devices;
let withheld_recipients = recipient_devices.denied_devices_with_code;
Copy link
Member

Choose a reason for hiding this comment

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

consider inlining withheld_recipients

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, this was done in #3662 (along with inlining recipients) so I've added that here now.

@uhoreg
Copy link
Member Author

uhoreg commented Aug 23, 2024

Initially, I was just trying to make #3662 easier to review, so I wasn't looking much into why the refactor was made, but IMHO, it isn't much duplication, and the code looks easier to follow. For example, in this version, it's clearer that unsigned_devices_of_verified_users and verified_users_with_new_identities are only used in the device-based strategy, rather than having to rely on comments to document that.

@uhoreg uhoreg requested a review from richvdh August 23, 2024 20:40
@uhoreg
Copy link
Member Author

uhoreg commented Aug 23, 2024

Actually, looking at #3662 again, it basically also adds the verified_users_with_new_identities check (and we should probably combine them). But I still think the refactor is useful because the check within the loop will still need to be duplicated (because the device-based check only runs if error_on_verified_user_problem is true, while the identity-based check runs all the time), and it will make it clear that the verified_users_with_new_identities check applies to both cases, whereas the unsigned_devices_of_verified_users check only applies to the device-based case.

@uhoreg
Copy link
Member Author

uhoreg commented Aug 23, 2024

And, having mostly re-implemented #3662 on top of this PR, another reason for the refactor is that identity-based collection needs to ensure that the user has cross-signing set up, so we already need to have a check for the collection strategy outside of the for loop, and it may be cleaner to just have the one check in the function, rather than one outside the for loop and one inside.

Actually, looking at #3662 again, it basically also adds the verified_users_with_new_identities check (and we should probably combine them). ...

Which leads to the somewhat awkward result that I need to move some things such as variable definitions back out to their original positions. So I'm somewhat torn as to whether it's better to actually move those things here, with the rationale that the moves make sense for what this PR does, or if it's better to leave those in place, with the rationale that it makes more sense for the end result, even though this PR gets more "trust me, it'll make sense later" thrown into it.

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.

The change looks good to me, so if you're happy that this is progress in the right general direction, suggest you go ahead and land it.

@uhoreg
Copy link
Member Author

uhoreg commented Aug 27, 2024

The change looks good to me, so if you're happy that this is progress in the right general direction, suggest you go ahead and land it.

I'm happy with this, but I don't have permissions to merge. Can you hit the button for me?

BTW, the next bit that builds on top of this PR is #3896 I have some compilation issues to fix and a changelog to write, but it should be ready for review soon.

@richvdh richvdh merged commit 7581719 into matrix-org:main Aug 27, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants