From 379deee4c66b64014fde13b894c410b5454c6d92 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Fri, 16 Jan 2026 14:42:23 -0300 Subject: [PATCH 1/4] fix: sync exception not caught --- .../main/java/to/bitkit/repositories/LightningRepo.kt | 6 +++++- .../main/java/to/bitkit/viewmodels/WalletViewModel.kt | 10 +++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt index fa6b3229e..9caf1fda2 100644 --- a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt @@ -321,7 +321,11 @@ class LightningRepo @Inject constructor( do { syncPending.set(false) _lightningState.update { it.copy(isSyncingWallet = true) } - lightningService.sync() + runCatching { + lightningService.sync() + }.onFailure { + return@executeWhenNodeRunning Result.failure(it) + } refreshChannelCache() syncState() if (syncPending.get()) delay(MS_SYNC_LOOP_DEBOUNCE) diff --git a/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt b/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt index 471fce9d5..f1ff4dda6 100644 --- a/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt +++ b/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt @@ -276,7 +276,15 @@ class WalletViewModel @Inject constructor( walletRepo.syncNodeAndWallet() .onFailure { Logger.error("Failed to refresh state: ${it.message}", it) - if (it is CancellationException || it.isTxSyncTimeout()) return@onFailure + if (it is CancellationException) return@onFailure + if (it.isTxSyncTimeout()) { + ToastEventBus.send( + type = Toast.ToastType.ERROR, + title = context.getString(R.string.wallet__ldk_sync_error_title), + description = context.getString(R.string.wallet__ldk_sync_error_body), + ) + return@onFailure + } ToastEventBus.send(it) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 54f5d0b3c..ccbe6f98b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1099,6 +1099,7 @@ Select Range Received Instant Bitcoin Lightning Startup Error + Unable to sync with the network. Please try again later. Lightning Sync Error Maximum amount Pay Bitcoin From 6785c5b1bd3316e684818b45797e8ddcb6de7957 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Sun, 18 Jan 2026 12:51:43 -0300 Subject: [PATCH 2/4] fix: sync was thrown even with sart success, triggering the retry with node running --- app/src/main/java/to/bitkit/repositories/LightningRepo.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt index 9caf1fda2..b88d0bdd3 100644 --- a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt @@ -249,9 +249,12 @@ class LightningRepo @Inject constructor( connectToTrustedPeers().onFailure { Logger.error("Failed to connect to trusted peers", it, context = TAG) } - sync().getOrThrow().also { - scope.launch { registerForNotifications() } + + sync().onFailure { e -> + Logger.warn("Initial sync failed, event-driven sync will retry", e, context = TAG) } + scope.launch { registerForNotifications() } + Unit }.onFailure { e -> if (shouldRetry) { val retryDelay = 2.seconds @@ -271,6 +274,7 @@ class LightningRepo @Inject constructor( _lightningState.update { it.copy(nodeLifecycleState = NodeLifecycleState.ErrorStarting(e)) } + return@withContext Result.failure(e) } } } From 20cc013adfbfa863f8c949af6a7dfd44af5b3e6d Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Mon, 19 Jan 2026 14:10:50 -0300 Subject: [PATCH 3/4] chore: remove toast --- .../main/java/to/bitkit/viewmodels/WalletViewModel.kt | 10 +--------- app/src/main/res/values/strings.xml | 1 - 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt b/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt index f1ff4dda6..471fce9d5 100644 --- a/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt +++ b/app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt @@ -276,15 +276,7 @@ class WalletViewModel @Inject constructor( walletRepo.syncNodeAndWallet() .onFailure { Logger.error("Failed to refresh state: ${it.message}", it) - if (it is CancellationException) return@onFailure - if (it.isTxSyncTimeout()) { - ToastEventBus.send( - type = Toast.ToastType.ERROR, - title = context.getString(R.string.wallet__ldk_sync_error_title), - description = context.getString(R.string.wallet__ldk_sync_error_body), - ) - return@onFailure - } + if (it is CancellationException || it.isTxSyncTimeout()) return@onFailure ToastEventBus.send(it) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index abbbfabbd..4eec55d59 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1100,7 +1100,6 @@ Select Range Received Instant Bitcoin Lightning Startup Error - Unable to sync with the network. Please try again later. Lightning Sync Error Maximum amount Pay Bitcoin From 2faf744a9730c134a044a09987c01e3edd8079e9 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Mon, 19 Jan 2026 14:29:50 -0300 Subject: [PATCH 4/4] fix: remove unnecessary runCatching from sync --- app/src/main/java/to/bitkit/repositories/LightningRepo.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt index b88d0bdd3..d0c4c2ee5 100644 --- a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt @@ -325,11 +325,7 @@ class LightningRepo @Inject constructor( do { syncPending.set(false) _lightningState.update { it.copy(isSyncingWallet = true) } - runCatching { - lightningService.sync() - }.onFailure { - return@executeWhenNodeRunning Result.failure(it) - } + lightningService.sync() refreshChannelCache() syncState() if (syncPending.get()) delay(MS_SYNC_LOOP_DEBOUNCE)