@@ -51,6 +51,7 @@ import to.bitkit.di.BgDispatcher
5151import to.bitkit.env.Env
5252import to.bitkit.ext.getSatsPerVByteFor
5353import to.bitkit.ext.nowTimestamp
54+ import to.bitkit.ext.of
5455import to.bitkit.ext.toPeerDetailsList
5556import to.bitkit.models.CoinSelectionPreference
5657import to.bitkit.models.NodeLifecycleState
@@ -64,6 +65,7 @@ import to.bitkit.services.LnurlChannelResponse
6465import to.bitkit.services.LnurlService
6566import to.bitkit.services.LnurlWithdrawResponse
6667import to.bitkit.services.LspNotificationsService
68+ import to.bitkit.services.MigrationService
6769import to.bitkit.services.NodeEventHandler
6870import to.bitkit.utils.AppError
6971import to.bitkit.utils.Logger
@@ -73,6 +75,7 @@ import java.util.concurrent.ConcurrentHashMap
7375import java.util.concurrent.atomic.AtomicBoolean
7476import java.util.concurrent.atomic.AtomicReference
7577import javax.inject.Inject
78+ import javax.inject.Provider
7679import javax.inject.Singleton
7780import kotlin.coroutines.cancellation.CancellationException
7881import kotlin.time.Duration
@@ -94,6 +97,7 @@ class LightningRepo @Inject constructor(
9497 private val preActivityMetadataRepo : PreActivityMetadataRepo ,
9598 private val connectivityRepo : ConnectivityRepo ,
9699 private val vssBackupClientLdk : VssBackupClientLdk ,
100+ private val migrationServiceProvider : Provider <MigrationService >,
97101) {
98102 private val _lightningState = MutableStateFlow (LightningState ())
99103 val lightningState = _lightningState .asStateFlow()
@@ -348,6 +352,7 @@ class LightningRepo @Inject constructor(
348352 connectToTrustedPeers().onFailure {
349353 Logger .error(" Failed to connect to trusted peers" , it, context = TAG )
350354 }
355+ connectMigrationPeers()
351356
352357 sync().onFailure { e ->
353358 Logger .warn(" Initial sync failed, event-driven sync will retry" , e, context = TAG )
@@ -666,6 +671,18 @@ class LightningRepo @Inject constructor(
666671 runCatching { lightningService.connectToTrustedPeers() }
667672 }
668673
674+ private suspend fun connectMigrationPeers () {
675+ val peerUris = migrationServiceProvider.get().tryFetchMigrationPeersFromBackup()
676+ for (uri in peerUris) {
677+ runCatching {
678+ val peer = PeerDetails .of(uri)
679+ lightningService.connectPeer(peer)
680+ }.onFailure {
681+ Logger .error(" Failed to connect migration peer: $uri " , it, context = TAG )
682+ }
683+ }
684+ }
685+
669686 suspend fun connectPeer (peer : PeerDetails ): Result <Unit > = executeWhenNodeRunning(" connectPeer" ) {
670687 lightningService.connectPeer(peer).map {
671688 syncState()
0 commit comments