@@ -46,6 +46,7 @@ import kotlinx.coroutines.flow.update
4646import kotlinx.coroutines.launch
4747import kotlinx.coroutines.withContext
4848import kotlinx.coroutines.withTimeout
49+ import org.lightningdevkit.ldknode.ChannelDataMigration
4950import org.lightningdevkit.ldknode.Event
5051import org.lightningdevkit.ldknode.PaymentId
5152import org.lightningdevkit.ldknode.SpendableUtxo
@@ -351,13 +352,40 @@ class AppViewModel @Inject constructor(
351352 }
352353
353354 private suspend fun completeRNRemoteBackupRestore () {
355+ val channelMigration = buildChannelMigrationIfAvailable()
356+
357+ if (channelMigration != null ) {
358+ lightningRepo.stop().onFailure {
359+ Logger .error(" Failed to stop node during remote restore restart" , it, context = TAG )
360+ }
361+ delay(REMOTE_RESTORE_NODE_RESTART_DELAY_MS )
362+ lightningRepo.start(channelMigration = channelMigration, shouldRetry = false )
363+ .onSuccess {
364+ migrationService.consumePendingChannelMigration()
365+ walletRepo.syncNodeAndWallet()
366+ walletRepo.syncBalances()
367+ }
368+ .onFailure { e ->
369+ Logger .error(" Failed to restart node after remote restore: $e " , e, context = TAG )
370+ }
371+ }
372+
354373 lightningRepo.getPayments().onSuccess { activityRepo.syncLdkNodePayments(it) }
355374 migrationService.reapplyMetadataAfterSync()
356375 activityRepo.syncActivities()
376+ walletRepo.syncBalances()
357377 migrationService.setRestoringFromRNRemoteBackup(false )
358378 migrationService.setShowingMigrationLoading(false )
359379 }
360380
381+ private fun buildChannelMigrationIfAvailable (): ChannelDataMigration ? {
382+ val migration = migrationService.peekPendingChannelMigration() ? : return null
383+ return ChannelDataMigration (
384+ channelManager = migration.channelManager.map { it.toUByte() },
385+ channelMonitors = migration.channelMonitors.map { monitor -> monitor.map { it.toUByte() } },
386+ )
387+ }
388+
361389 private suspend fun completeMigration () {
362390 if (isCompletingMigration) return
363391 isCompletingMigration = true
@@ -1986,6 +2014,7 @@ class AppViewModel @Inject constructor(
19862014 private const val SCREEN_TRANSITION_DELAY_MS = 300L
19872015 private const val MIGRATION_LOADING_TIMEOUT_MS = 300_000L
19882016 private const val MIGRATION_AUTH_RESET_DELAY_MS = 500L
2017+ private const val REMOTE_RESTORE_NODE_RESTART_DELAY_MS = 500L
19892018 private const val AUTH_CHECK_INITIAL_DELAY_MS = 1000L
19902019 private const val AUTH_CHECK_SPLASH_DELAY_MS = 500L
19912020 }
0 commit comments