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

Introduce StaticAccountData for ReadOnlyAccount immutable fields #2627

Merged
merged 6 commits into from
Sep 28, 2023

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Sep 26, 2023

This introduces a new data structure, StaticAccountData (we could just call it StaticAccount) that contains all the immutable fields from the ReadOnlyAccount. The ReadOnlyAccount is "cached" in one place, the Store; after #2625 lands, we can put the ReadOnlyAccount in the actual cache.

Then, all the structs storing ReadOnlyAccount are changed according to the following rules:

  • if all uses were only of static data, store a StaticAccountData
  • if there are uses of the actual inner-mutable ReadOnlyAccount fields, refer to the Store's ReadOnlyAccount

The first step was supposed to be carried in small, incremental commits, but I've pulled a thread at some point, and it unraveled lots of uses that could be simplified at once.

This can be reviewed commit by commit. I've left some future work items as TODO(BNJ); can be ideas to try as followups, not guaranteed they'll work fine.

Part of #2624.

@bnjbvr bnjbvr requested a review from poljar September 26, 2023 16:38
@bnjbvr bnjbvr requested a review from a team as a code owner September 26, 2023 16:38
@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (79f408b) 77.94% compared to head (3398dd1) 77.94%.
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2627   +/-   ##
=======================================
  Coverage   77.94%   77.94%           
=======================================
  Files         190      190           
  Lines       19674    19684   +10     
=======================================
+ Hits        15334    15343    +9     
- Misses       4340     4341    +1     
Files Coverage Δ
crates/matrix-sdk-crypto/src/dehydrated_devices.rs 100.00% <100.00%> (ø)
crates/matrix-sdk-crypto/src/gossiping/machine.rs 63.88% <ø> (ø)
crates/matrix-sdk-crypto/src/identities/manager.rs 81.62% <100.00%> (ø)
crates/matrix-sdk-crypto/src/identities/user.rs 86.54% <100.00%> (ø)
crates/matrix-sdk-crypto/src/machine.rs 83.27% <100.00%> (+0.31%) ⬆️
crates/matrix-sdk-crypto/src/olm/signing/mod.rs 84.31% <ø> (ø)
...x-sdk-crypto/src/session_manager/group_sessions.rs 95.53% <ø> (ø)
...s/matrix-sdk-crypto/src/store/integration_tests.rs 100.00% <100.00%> (ø)
crates/matrix-sdk-crypto/src/store/mod.rs 83.54% <100.00%> (+0.37%) ⬆️
...ates/matrix-sdk-crypto/src/verification/machine.rs 73.43% <100.00%> (ø)
... and 11 more

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

Copy link
Contributor

@poljar poljar 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 that this makes sense. Apart from the CI failure of course.

crates/matrix-sdk-crypto/src/olm/account.rs Outdated Show resolved Hide resolved
@@ -111,6 +112,7 @@ impl From<UserIdentity> for UserIdentities {
pub struct OwnUserIdentity {
pub(crate) inner: ReadOnlyOwnUserIdentity,
pub(crate) verification_machine: VerificationMachine,
store: Store,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this? The VerificationMachine already has access to a store type, can't we get things from there?

I guess the point here is that the store inside VerificationMachine doesn't have a ReadOnlyAccount anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need this? The VerificationMachine already has access to a store type, can't we get things from there?

Yes. No, the "store" in the VerificationStore contained in the VerificationMachine was containing the ReadOnlyAccount before, and now it's only containing a StaticAccountData instead.

I guess the point here is that the store inside VerificationMachine doesn't have a ReadOnlyAccount anymore?

So yeah, basically that.

Sorry, this commit is a bit big. What happened is that I've pulled a thread: put a `StaticAccountData` there, look at caller; it seems to use only a
static account too, so keep up.

The only contender was the `OwnUserIdentity` data structure which really wants to sign things. Lucky for us, we could pass it a `ReadOnlyAccount`
from a store, in those cases, since we always had a `Store` hanging around; in the future it'll read it from the store cache, which is somewhat
identical.
And use the `self.store.account()` when we really need the `ReadOnlyAccount`. Also cache the immutable account data in this Account.
@bnjbvr bnjbvr merged commit a1f6e2f into main Sep 28, 2023
36 checks passed
@bnjbvr bnjbvr deleted the static-account-data branch September 28, 2023 15:21
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