Skip to content

Commit 0063b96

Browse files
committed
ETCM-168: Add enrollInBackground option to DiscoveryService
1 parent 6eac5aa commit 0063b96

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scalanet/discovery/src/io/iohk/scalanet/discovery/ethereum/v4/DiscoveryService.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ object DiscoveryService {
6868
node: Node,
6969
config: DiscoveryConfig,
7070
network: DiscoveryNetwork[A],
71-
toAddress: Node.Address => A
71+
toAddress: Node.Address => A,
72+
enrollInBackground: Boolean = false
7273
)(
7374
implicit sigalg: SigAlg,
7475
enrCodec: Codec[EthereumNodeRecord.Content],
@@ -88,9 +89,15 @@ object DiscoveryService {
8889
// Start handling requests, we need them during enrolling so the peers can ping and bond with us.
8990
cancelToken <- network.startHandling(service)
9091
// Contact the bootstrap nodes.
91-
_ <- service.enroll()
92+
enroll = service.enroll()
9293
// Periodically discover new nodes.
93-
discoveryFiber <- service.lookupRandom().delayExecution(config.discoveryPeriod).loopForever.start
94+
discover = service.lookupRandom().delayExecution(config.discoveryPeriod).loopForever
95+
// Enrollment can be run in the background if it takes very long.
96+
discoveryFiber <- if (enrollInBackground) {
97+
(enroll >> discover).start
98+
} else {
99+
enroll >> discover.start
100+
}
94101
} yield (service, cancelToken, discoveryFiber)
95102
} {
96103
case (_, cancelToken, discoveryFiber) =>

0 commit comments

Comments
 (0)