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

Fix FactoryReset to not remove CloudKit related cache #1136

Conversation

GhenadieVP
Copy link
Contributor

@GhenadieVP GhenadieVP commented May 24, 2024

Jira ticket: https://radixdlt.atlassian.net/browse/ABW-3342
Jira ticket: https://radixdlt.atlassian.net/browse/ABW-3340

Description

Our CacheClient did create all of the cache folders/files at the root of caches directory, thus when it was needed to clear the cache on FactoryReset, the whole caches directory was cleared out.

CloudKit is using caches directory for its operations, and it would create specific folders. Thus when performing FactoryReset, those were deleted - this caused the bug of not being able to see the Cloud backups when restoring from backup immediately after FactoryReset.

The error thrown by CloudKit was:

CKError 0x302a87e10: "Internal Error" (1/1000); "Moving downloaded asset failed"

Which correlates well with the CloudKit directories being removed from caches - CloudKit didn't know anymore where to store the temporary assets after downloading those from the container.

The fix is about moving all of the CacheClient's entries under one and the same folder, thus when doing factory reset and calling cacheClient.removeAll(), only the entries created by the CacheClient directly are removed.

Video

RPReplay_Final1716529853.MP4

@@ -152,8 +152,6 @@ extension CloudBackupClient {
}

let savedRecord = try await uploadProfileSnapshotToICloud(profileSnapshot, id: profile.id, existingRecord: backedUpRecord)
// Migration completed, deleting old copy
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kugel3 Before merging this, I want to actually understand the reasoning behind deleting the profile from the secure storage.

IMO, the Wallet should be able to locate the profile in secure storage even after the "backup migration". To me, it is wrong to assume that backup migration means uploading the profile from the Keychain to the cloud container and then deleting it from the Keychain.

The SecureStorage(KeyChain) is the actual local storage of the Profile, and the profile should not be suddenly gone. A more correct interpretation of migration maybe is:

  • Upload the profile from keychain to cloud.
  • Disable keychain sync for the said profile.

Probably I am missing something as you have worked a lot more on this feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't see this comment before, but it was decided last week to not actually delete non-current profiles when they are "migrated". Matt still wants to delete the currently used profile from backup, but it just hit me that I am not sure we even can do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep in mind that this code only applies to non-current profiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting that you mention non-current profiles. In the context of SelectBackup, aren't all profiles non-current? I don't see the migration function to be called from anywhere else than from SelectBackup.

I guess what we have to do to remove the backup from cloud, is to disable iCloud sync of the profile in SecureStorage, which we should do anyway.

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@matiasbzurovski matiasbzurovski left a comment

Choose a reason for hiding this comment

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

Good catch!

@@ -61,7 +61,7 @@ extension CacheClient: DependencyKey {
@Dependency(\.diskPersistenceClient) var diskPersistenceClient

do {
try diskPersistenceClient.removeAll()
try diskPersistenceClient.remove(Entry.root)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we delete the removeAll from DiskPersistenceClient?

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 did choose to still have it, in case we do really need to clear the whole caches directory.

@GhenadieVP GhenadieVP merged commit 3d0a211 into main May 28, 2024
6 checks passed
@GhenadieVP GhenadieVP deleted the fix/ABW-3342-i-os-pre-alpha-1-6-0-31-unable-to-see-cloud-backups-in-the-restore-wallet-from-backup-screen branch May 28, 2024 08:39
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.

None yet

4 participants