fix: isolate activity backup restore slices - #1171
Draft
jvsena42 wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1167
This PR applies the three Core-owned slices of an activity backup independently on restore, so one rejected record can no longer discard the others.
Follow-up to #1163, and the app half of synonymdev/bitkit-core#134.
Description
The activity restore upserted activities, tags and closed channels inside a single
runCatching. Core fails a bulk write as a whole, so the first slice to throw aborted the calls after it. A single tag whose parent activity was missing therefore cost the activities and the closed channels too, and an entire restored category was lost from one bad record. This was reproduced on regtest while building #1163, whereactivity_tagswent from one row to zero and closed channels were skipped entirely:#1163 removed the hardware wallet trigger by carrying those tags as pre-activity metadata, so this is no longer easy to hit, but it is not impossible. The backup envelope is assembled from three separate Core reads rather than one snapshot, so a tag written against a brand-new activity between the first and the third read lands in the envelope without its parent, in the default wallet scope, with no hardware wallet involved. The window is narrow, the blast radius is not.
Each slice now runs in its own
runSuspendCatching, and every failure is logged with the slice it came from. The overall result is still a failure when any slice failed, which matters because the VSS rewrite is gated on the restore succeeding: a partial restore must not be treated as authoritative, or it would overwrite a good backup with incomplete state.Two smaller changes come with it. Slices that did apply now notify observers even when a later slice failed, so restored activities reach the UI instead of waiting for the next sync. And moving from
runCatchingtorunSuspendCatchingmeans a cancelled restore propagates instead of being swallowed as a failed slice.Core keeping the valid records within a single bulk write is tracked separately in synonymdev/bitkit-core#134. The two are complementary: Core limits the loss to the bad record, this limits the loss to the affected slice. Neither depends on the other.
Preview
N/A
QA Notes
Reaching the failing-slice path by hand needs a tag whose parent activity is missing from the envelope, which #1163 made hard to produce, so the isolation contract is covered by unit tests instead and manual QA is a restore regression pass.
Manual Tests
regression:Wallet with tagged activity and a closed channel → wipe wallet → restore from seed → Home: activities and their tags are present.regression:Settings → Lightning Connections → Closed: the closed channel is present.regression:Restore the same wallet a second time → Settings → Data Backups: Transaction Log is not re-uploaded.Automated Checks
ActivityRepoTest.kt. One case per failing slice asserts the other two were still applied and that the overall result is a failure, alongside an all-slices-succeed case and a cancellation case pinning therunSuspendCatchingswitch.BackupRepoTest.ktis unchanged and still green, includingactivity backup is not rewritten when core restore fails, which pins the VSS rewrite gate this PR depends on.just compile,just test file ActivityRepoTest,just test file BackupRepoTestandjust lintpass.