Add option to `connectToNetwork` return without waiting for peers

The new sync code wants to start without waiting.  We can `discard` the async
result but there is no need for a background task polling and running a timer
for no clear benefit.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-07-30 03:09:38 +01:00 committed by Zahary Karadjov
parent 9a28ed7ef5
commit 83e5638212
1 changed files with 3 additions and 2 deletions

View File

@ -93,7 +93,8 @@ proc startListening*(node: EthereumNode) {.raises: [CatchableError, Defect].} =
proc connectToNetwork*(node: EthereumNode,
bootstrapNodes: seq[ENode],
startListening = true,
enableDiscovery = true) {.async.} =
enableDiscovery = true,
waitForPeers = true) {.async.} =
doAssert node.connectionState == ConnectionState.None
node.connectionState = Connecting
@ -112,7 +113,7 @@ proc connectToNetwork*(node: EthereumNode,
else:
info "Discovery disabled"
while node.peerPool.connectedNodes.len == 0:
while node.peerPool.connectedNodes.len == 0 and waitForPeers:
trace "Waiting for more peers", peers = node.peerPool.connectedNodes.len
await sleepAsync(500.milliseconds)