@@ -138,7 +138,7 @@ class LightningService @Inject constructor(
138138 )
139139 }
140140
141- @Suppress(" ForbiddenComment" )
141+ @Suppress(" ForbiddenComment" , " LongMethod " )
142142 private suspend fun build (
143143 walletIndex : Int ,
144144 customServerUrl : String? ,
@@ -186,11 +186,34 @@ class LightningService @Inject constructor(
186186 " Building node with \n\t vssUrl: '$vssUrl '\n\t lnurlAuthServerUrl: '$lnurlAuthServerUrl '" ,
187187 context = TAG ,
188188 )
189- if (lnurlAuthServerUrl.isNotEmpty()) {
190- builder.buildWithVssStore(vssUrl, vssStoreId, lnurlAuthServerUrl, fixedHeaders)
191- } else {
192- builder.buildWithVssStoreAndFixedHeaders(vssUrl, vssStoreId, fixedHeaders)
189+
190+ fun buildNode () = runCatching {
191+ if (lnurlAuthServerUrl.isNotEmpty()) {
192+ builder.buildWithVssStore(vssUrl, vssStoreId, lnurlAuthServerUrl, fixedHeaders)
193+ } else {
194+ builder.buildWithVssStoreAndFixedHeaders(vssUrl, vssStoreId, fixedHeaders)
195+ }
193196 }
197+
198+ buildNode().recoverCatching {
199+ if (it !is BuildException .DangerousValue ) throw it
200+ // Handle `DangerousValue` with recovery flow
201+ Logger .warn(
202+ " Build failed with DangerousValue. Retrying with `accept_stale_channel_monitors` for recovery." ,
203+ it,
204+ context = TAG ,
205+ )
206+ builder.setAcceptStaleChannelMonitors(true )
207+ buildNode()
208+ .onFailure { recoveryError ->
209+ Logger .error(
210+ " Error in recovery attempt with `accept_stale_channel_monitors`." ,
211+ recoveryError,
212+ context = TAG ,
213+ )
214+ }
215+ .getOrThrow()
216+ }.getOrThrow()
194217 } catch (e: BuildException ) {
195218 throw LdkError (e)
196219 } finally {
@@ -226,6 +249,7 @@ class LightningService @Inject constructor(
226249 lightningWalletSyncIntervalSecs = Env .walletSyncIntervalSecs,
227250 feeRateCacheUpdateIntervalSecs = Env .walletSyncIntervalSecs,
228251 ),
252+ connectionTimeoutSecs = Env .walletSyncTimeoutSecs, // 10s
229253 ),
230254 )
231255 }
0 commit comments