Skip to content

Commit 9a93bee

Browse files
committed
Fix LN sync issue
1 parent 9ebdfae commit 9a93bee

2 files changed

Lines changed: 8 additions & 30 deletions

File tree

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import kotlinx.coroutines.flow.update
4646
import kotlinx.coroutines.launch
4747
import kotlinx.coroutines.withContext
4848
import kotlinx.coroutines.withTimeout
49-
import org.lightningdevkit.ldknode.ChannelDataMigration
5049
import org.lightningdevkit.ldknode.Event
5150
import org.lightningdevkit.ldknode.PaymentId
5251
import org.lightningdevkit.ldknode.SpendableUtxo
@@ -359,14 +358,6 @@ class AppViewModel @Inject constructor(
359358
migrationService.setShowingMigrationLoading(false)
360359
}
361360

362-
private fun buildChannelMigrationIfAvailable(): ChannelDataMigration? {
363-
val migration = migrationService.peekPendingChannelMigration() ?: return null
364-
return ChannelDataMigration(
365-
channelManager = migration.channelManager.map { it.toUByte() },
366-
channelMonitors = migration.channelMonitors.map { monitor -> monitor.map { it.toUByte() } },
367-
)
368-
}
369-
370361
private suspend fun completeMigration() {
371362
if (isCompletingMigration) return
372363
isCompletingMigration = true
@@ -379,26 +370,13 @@ class AppViewModel @Inject constructor(
379370
}
380371
activityRepo.markAllUnseenActivitiesAsSeen()
381372

382-
val channelMigration = buildChannelMigrationIfAvailable()
383-
lightningRepo.stop().onFailure {
384-
Logger.error("Failed to stop node during migration restart", it, context = TAG)
385-
}
386-
delay(MIGRATION_NODE_RESTART_DELAY_MS)
387-
lightningRepo.start(channelMigration = channelMigration, shouldRetry = false)
388-
.onSuccess {
389-
migrationService.consumePendingChannelMigration()
390-
walletRepo.syncNodeAndWallet()
391-
.onSuccess {
392-
finishMigrationSuccessfully()
393-
}
394-
.onFailure { e ->
395-
Logger.warn("Sync failed after restart during migration: $e", e, context = TAG)
396-
finishMigrationWithFallbackSync()
397-
}
398-
}
373+
migrationService.consumePendingChannelMigration()
374+
375+
walletRepo.syncNodeAndWallet()
376+
.onSuccess { finishMigrationSuccessfully() }
399377
.onFailure { e ->
400-
Logger.error("Failed to restart node after migration: $e", e, context = TAG)
401-
finishMigrationWithError()
378+
Logger.warn("Sync failed during migration: $e", e, context = TAG)
379+
finishMigrationWithFallbackSync()
402380
}
403381
} catch (e: Exception) {
404382
Logger.error("Migration completion error: $e", e, context = TAG)
@@ -1992,7 +1970,6 @@ class AppViewModel @Inject constructor(
19921970
private const val MAX_FEE_AMOUNT_RATIO = 0.5
19931971
private const val SCREEN_TRANSITION_DELAY_MS = 300L
19941972
private const val MIGRATION_LOADING_TIMEOUT_MS = 300_000L
1995-
private const val MIGRATION_NODE_RESTART_DELAY_MS = 500L
19961973
private const val MIGRATION_AUTH_RESET_DELAY_MS = 500L
19971974
private const val AUTH_CHECK_INITIAL_DELAY_MS = 1000L
19981975
private const val AUTH_CHECK_SPLASH_DELAY_MS = 500L

app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class WalletViewModel @Inject constructor(
122122
walletExists = walletRepo.walletExists()
123123
loadCacheIfWalletExists()
124124
if (walletExists) {
125-
startNode(0, channelMigration = null)
125+
val channelMigration = buildChannelMigrationIfAvailable()
126+
startNode(0, channelMigration)
126127
} else {
127128
migrationService.setShowingMigrationLoading(false)
128129
}

0 commit comments

Comments
 (0)