Don't wait for 10 seconds when connecting to the network

This commit is contained in:
Zahary Karadjov 2020-02-19 12:45:34 +02:00
parent 55886ff0ac
commit 880b981a0a
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 12 additions and 6 deletions

View File

@ -156,7 +156,7 @@ when networkBackend in [libp2p, libp2pDaemon]:
# are running behind a NAT).
var switch = newStandardSwitch(some keys.seckey, hostAddress,
triggerSelf = true, gossip = false)
result = Eth2Node.init(conf, switch, keys.seckey.skkey)
result = Eth2Node.init(conf, switch, keys.seckey.asEthKey)
else:
let keyFile = conf.ensureNetworkIdFile
@ -227,10 +227,13 @@ when networkBackend in [libp2p, libp2pDaemon]:
node.addKnownPeer bootstrapNode
await node.start()
await sleepAsync(10.seconds)
if bootstrapEnrs.len > 0 and libp2p_successful_dials.value == 0:
fatal "Failed to connect to any bootstrap node. Quitting", bootstrapEnrs
quit 1
proc checkIfConnectedToBootstrapNode {.async.} =
await sleepAsync(10.seconds)
if bootstrapEnrs.len > 0 and libp2p_successful_dials.value == 0:
fatal "Failed to connect to any bootstrap node. Quitting", bootstrapEnrs
quit 1
traceAsyncErrors checkIfConnectedToBootstrapNode()
proc saveConnectionAddressFile*(node: Eth2Node, filename: string) =
when networkBackend == libp2p:

View File

@ -182,12 +182,15 @@ proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo =
return r.get.toPeerInfo
proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} =
debug "Dialing peer", peer = $peerInfo
logScope: peer = $peerInfo
debug "Dialing peer"
discard await node.switch.dial(peerInfo)
var peer = node.getPeer(peerInfo)
peer.wasDialed = true
await initializeConnection(peer)
inc libp2p_successful_dials
debug "Network handshakes completed"
proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
debug "Starting discovery loop"