@@ -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,29 @@ 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 { error ->
199+ if (error !is BuildException .DangerousValue ) throw error
200+ Logger .warn(
201+ " Retrying build failed with 'DangerousValue' using 'setAcceptStaleChannelMonitors' for recovery." ,
202+ error,
203+ context = TAG ,
204+ )
205+ builder.setAcceptStaleChannelMonitors(true )
206+ buildNode()
207+ .onFailure {
208+ Logger .error(" Failed recovery retry using 'setAcceptStaleChannelMonitors'." , it, context = TAG )
209+ }
210+ .getOrThrow()
211+ }.getOrThrow()
194212 } catch (e: BuildException ) {
195213 throw LdkError (e)
196214 } finally {
@@ -226,6 +244,7 @@ class LightningService @Inject constructor(
226244 lightningWalletSyncIntervalSecs = Env .walletSyncIntervalSecs,
227245 feeRateCacheUpdateIntervalSecs = Env .walletSyncIntervalSecs,
228246 ),
247+ connectionTimeoutSecs = Env .walletSyncTimeoutSecs,
229248 ),
230249 )
231250 }
0 commit comments