Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a8f0810
fix: preserve pending backups across restart
ben-kaufman Oct 25, 2026
e585fcc
fix: retain backup changes while restart drains
ben-kaufman Oct 25, 2026
c255458
Merge restore recovery parent into backup lifecycle fix
ben-kaufman Oct 26, 2026
a102e0e
fix: recognize native backup request transport failures
ben-kaufman Oct 26, 2026
49e9a99
fix: retain explicit backup retry ownership
ben-kaufman Oct 26, 2026
5fca5cd
fix: integrate current restore recovery parent
ben-kaufman Oct 28, 2026
e80ca3f
Merge updated restore identity parent into backup lifecycle
ben-kaufman Oct 29, 2026
9a837a6
fix: keep recovery callbacks ahead of backup debounce
ben-kaufman Oct 29, 2026
1d3ba14
Merge current identity recovery parent into backup observers
ben-kaufman Oct 29, 2026
9cfe052
Merge restore metadata guards into backup observer lifecycle
ben-kaufman Oct 30, 2026
cfe7daf
Merge validated identity restore parent
ben-kaufman Nov 1, 2026
9226253
Merge restored-identity allowance admission
ben-kaufman Nov 1, 2026
a3693b0
Merge stable allowance activation into backup observation
ben-kaufman Nov 1, 2026
2eb0c49
Merge guarded identity and allowance recovery parent
ben-kaufman Nov 1, 2026
f068aba
Merge current allowance resume fix into recovery branch
ben-kaufman Nov 1, 2026
439b5d0
merge: include identity recovery diagnostics
ben-kaufman Nov 1, 2026
add2c04
merge: integrate current identity recovery
ben-kaufman Nov 3, 2026
8727da0
fix: initialize cold explicit backup retries
ben-kaufman Nov 3, 2026
e7fb0ac
fix: retry backup authentication transport failures
ben-kaufman Nov 3, 2026
1a6048a
fix: retain backup ownership across wallet transitions
ben-kaufman Nov 4, 2026
2fa4098
merge: compose queued backup status
ben-kaufman Nov 4, 2026
1cf5d39
merge: compose admitted backup status
ben-kaufman Nov 4, 2026
a60add9
Merge the current restore identity branch into backup observation
ben-kaufman Nov 9, 2026
be4e1ba
fix: retry wallet and USDT recovery uploads after VSS setup times out
ben-kaufman Nov 9, 2026
f8b2ffc
Preserve full activity uploads across backup observation
ben-kaufman Nov 9, 2026
534b3d8
Preserve Spark backups in admitted observation lifecycle
ben-kaufman Nov 11, 2026
9f60111
fix: compose spark restore backup recovery
ben-kaufman Nov 11, 2026
e0d2598
fix: preserve explicit profile deletion recovery
ben-kaufman Nov 11, 2026
c53a459
fix: preserve profile ownership during recovery
ben-kaufman Nov 11, 2026
62c8cf2
fix: retain recovery guards in the composed parent
ben-kaufman Nov 12, 2026
66ba140
fix: retain recovery with spark balance updates
ben-kaufman Nov 12, 2026
4024e8b
fix: preserve recovery with startup cache loading
ben-kaufman Nov 12, 2026
ac1549f
fix: preserve recovery with node timeout balance updates
ben-kaufman Nov 12, 2026
afb4f06
fix: preserve recovery across parent changes
ben-kaufman Nov 12, 2026
43e314c
fix: preserve recovery with finished-exit balance updates
ben-kaufman Nov 12, 2026
9330e24
fix: retry consumed backup marks after storage failures
ben-kaufman Nov 13, 2026
7fac7ab
fix: retain backup marks before wallet retirement
ben-kaufman Nov 13, 2026
78d65fe
fix: resume backups after cancelled wallet wipe
ben-kaufman Nov 14, 2026
dca0a5b
test: retain backup wipe controls with swap cleanup dependency
ben-kaufman Nov 14, 2026
a24e8a5
chore: merge restore identity background into backup observer lifecycle
ovitrif Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/to/bitkit/data/WalletConnectionRecovery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class WalletConnectionRecovery @Inject constructor(
/** Drains original owners before credentials, settings or the SDK wipe barrier can change. */
suspend fun <T> withIdentityChange(
isStillNeeded: suspend () -> Boolean = { true },
beforeClientsSuspend: suspend () -> Unit = {},
block: suspend () -> T,
): T {
check(currentCoroutineContext()[ReceiptOperation] == null) { "Wallet replacement cannot drain itself" }
Expand All @@ -156,6 +157,8 @@ class WalletConnectionRecovery @Inject constructor(
currentCoroutineContext().ensureActive()
beginWipe()
currentCoroutineContext().ensureActive()
beforeClientsSuspend()
currentCoroutineContext().ensureActive()
vssClients.withSuspendedClients { block() }
} finally {
storeIdProvider.clearCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UsdtRecoveryBackupStore(
) {
constructor(client: VssBackupClient) : this(
put = { key, data ->
client.setup().getOrThrow()
client.ensureSetupForUpload()
client.putObject(key, data).getOrThrow()
},
keys = {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import to.bitkit.data.keychain.Keychain
import to.bitkit.di.IoDispatcher
import to.bitkit.env.Env
import to.bitkit.ext.runSuspendCatching
import to.bitkit.utils.AppError
import to.bitkit.utils.Logger
import to.bitkit.utils.ServiceError
import javax.inject.Inject
Expand All @@ -28,6 +29,17 @@ import kotlin.time.Duration.Companion.seconds

class MnemonicNotAvailableException : Exception("Mnemonic not available")

internal class BackupClientSetupTimeout(cause: TimeoutCancellationException) :
AppError("Backup client setup timed out", cause)

internal suspend fun VssBackupClient.ensureSetupForUpload() {
val result = setup()
currentCoroutineContext().ensureActive()
val error = result.exceptionOrNull()
if (error is TimeoutCancellationException) throw BackupClientSetupTimeout(error)
result.getOrThrow()
}

@Singleton
class VssBackupClient @Inject constructor(
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
Expand Down
1,131 changes: 720 additions & 411 deletions app/src/main/java/to/bitkit/repositories/BackupRepo.kt

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions app/src/main/java/to/bitkit/usecases/WipeWalletUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ class WipeWalletUseCase @Inject constructor(
var credentialsMayBeErased = false
val result = try {
runSuspendCatching {
connectionRecovery.withIdentityChange(isStillNeeded = {
expectedPendingAttemptId?.let { profileRemovalStore.requirePendingWalletReset(it) }
backupRepo.setWiping(true)
lightningRepo.setWiping(true)
wipeAdmitted = true
true
}) {
connectionRecovery.withIdentityChange(
isStillNeeded = {
expectedPendingAttemptId?.let { profileRemovalStore.requirePendingWalletReset(it) }
backupRepo.setWiping(true)
lightningRepo.setWiping(true)
wipeAdmitted = true
true
},
beforeClientsSuspend = { backupRepo.reset() },
) {
expectedPendingAttemptId?.let { profileRemovalStore.requirePendingWalletReset(it) }
contactPaymentSettingsRepo.get().withWalletWipe(pubkyRepo::withWalletWipeAdmission) {
paykitSdkService.withWalletWipe {
Expand All @@ -89,7 +92,7 @@ class WipeWalletUseCase @Inject constructor(
val attemptId = pending.attemptId ?: UUID.randomUUID().toString()
profileRemovalStore.withAccess(attemptId, ProfileRemovalScope.WALLET_WIPE) {
privatePaykitRepo.get().withProfileDeletionPaused { pause ->
stopNode().getOrThrow()
lightningRepo.stop().getOrThrow()
profileRemovalStore.begin(attemptId)
if (pending.scope != ProfileRemovalScope.WALLET_WIPE) cleanupRemote()
wipeLocal(walletIndex, pause) { credentialsMayBeErased = true }.getOrThrow()
Expand All @@ -109,22 +112,17 @@ class WipeWalletUseCase @Inject constructor(
if (wipeAdmitted) {
lightningRepo.setWiping(false)
backupRepo.setWiping(false)
if (lightningRepo.lightningState.value.nodeLifecycleState.isRunning()) {
backupRepo.startObservingBackups()
}
}
wipeMutex.unlock()
}
return result.onFailure {
Logger.error("Failed to wipe wallet", it, context = TAG)
if (wipeAdmitted && lightningRepo.lightningState.value.nodeLifecycleState.isRunning()) {
backupRepo.startObservingBackups()
}
}
}

private suspend fun stopNode(): Result<Unit> {
backupRepo.reset()
return lightningRepo.stop()
}

private suspend fun cleanupRemote() {
step("remove Paykit published endpoints") { privatePaykitRepo.get().removePublishedEndpointsForCleanup(TAG) }
step("remove Bitkit payment endpoints") { pubkyRepo.removeBitkitPaymentEndpoints() }
Expand Down
25 changes: 25 additions & 0 deletions app/src/test/java/to/bitkit/data/WalletConnectionRecoveryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,31 @@ class WalletConnectionRecoveryTest : BaseUnitTest() {
assertTrue(result.exceptionOrNull() is CancellationException)
}

@Test
fun `cancellation during local drain preserves native owner and skips identity change`() = test {
val original = vssClients.owners.value
val draining = CompletableDeferred<Unit>()
val release = CompletableDeferred<Unit>()
var replaced = false
val replacement = launch {
sut.withIdentityChange(beforeClientsSuspend = {
withContext(NonCancellable) {
draining.complete(Unit)
release.await()
}
}) { replaced = true }
}
draining.await()
replacement.cancel()
runCurrent()
assertFalse(replacement.isCompleted)
release.complete(Unit)
replacement.join()
assertFalse(replaced)
assertEquals(original, vssClients.owners.value)
vssClients.withWallet { }
}

@Test
fun `rejected conditional migration preserves the current wallet admission`() = test {
val owner = sut.captureOwner()
Expand Down
Loading
Loading