Advertise the TCP port of the bootstrap node properly

This commit is contained in:
Zahary Karadjov 2020-02-18 01:35:24 +02:00 committed by zah
parent 2a3e40e298
commit b2d5aba749
7 changed files with 18 additions and 8 deletions

View File

@ -1116,7 +1116,9 @@ when isMainModule:
networkKeys = getPersistentNetKeys(config) networkKeys = getPersistentNetKeys(config)
bootstrapAddress = enode.Address( bootstrapAddress = enode.Address(
ip: parseIpAddress(config.bootstrapAddress), ip: parseIpAddress(config.bootstrapAddress),
tcpPort: Port config.bootstrapPort,
udpPort: Port config.bootstrapPort) udpPort: Port config.bootstrapPort)
bootstrapEnr = enr.Record.init(1, networkKeys.seckey, bootstrapAddress) bootstrapEnr = enr.Record.init(1, networkKeys.seckey, bootstrapAddress)
writeFile(bootstrapFile, bootstrapEnr.toURI) writeFile(bootstrapFile, bootstrapEnr.toURI)
echo "Wrote ", bootstrapFile echo "Wrote ", bootstrapFile

View File

@ -24,7 +24,7 @@ proc new*(T: type Eth2DiscoveryProtocol,
pk = initPrivateKey(rawPrivKeyBytes) pk = initPrivateKey(rawPrivKeyBytes)
db = DiscoveryDB.init(newMemoryDB()) db = DiscoveryDB.init(newMemoryDB())
newProtocol(pk, db, Port conf.udpPort) newProtocol(pk, db, Port conf.tcpPort, Port conf.udpPort)
proc toENode*(a: MultiAddress): Result[ENode, cstring] = proc toENode*(a: MultiAddress): Result[ENode, cstring] =
if not IPFS.match(a): if not IPFS.match(a):

View File

@ -232,7 +232,7 @@ when networkBackend in [libp2p, libp2pDaemon]:
await node.start() await node.start()
await sleepAsync(10.seconds) await sleepAsync(10.seconds)
if libp2p_peers.value == 0: if libp2p_successful_dials.value == 0:
fatal "Failed to connect to any bootstrap node. Quitting" fatal "Failed to connect to any bootstrap node. Quitting"
quit 1 quit 1

View File

@ -30,7 +30,6 @@ type
discovery*: Eth2DiscoveryProtocol discovery*: Eth2DiscoveryProtocol
wantedPeers*: int wantedPeers*: int
peers*: Table[PeerID, Peer] peers*: Table[PeerID, Peer]
peersByDiscoveryId*: Table[Eth2DiscoveryId, Peer]
protocolStates*: seq[RootRef] protocolStates*: seq[RootRef]
libp2pTransportLoops*: seq[Future[void]] libp2pTransportLoops*: seq[Future[void]]
@ -153,7 +152,11 @@ include libp2p_backends_common
proc toPeerInfo*(r: enr.TypedRecord): PeerInfo = proc toPeerInfo*(r: enr.TypedRecord): PeerInfo =
if r.secp256k1.isSome: if r.secp256k1.isSome:
var peerId = PeerID.init r.secp256k1.get var pubKey: keys.PublicKey
if recoverPublicKey(r.secp256k1.get, pubKey) != EthKeysStatus.Success:
return # TODO
let peerId = PeerID.init crypto.PublicKey(scheme: Secp256k1, skkey: pubKey)
var addresses = newSeq[MultiAddress]() var addresses = newSeq[MultiAddress]()
if r.ip.isSome and r.tcp.isSome: if r.ip.isSome and r.tcp.isSome:
@ -184,6 +187,7 @@ proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} =
var peer = node.getPeer(peerInfo) var peer = node.getPeer(peerInfo)
peer.wasDialed = true peer.wasDialed = true
await initializeConnection(peer) await initializeConnection(peer)
inc libp2p_successful_dials
proc runDiscoveryLoop*(node: Eth2Node) {.async.} = proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
debug "Starting discovery loop" debug "Starting discovery loop"
@ -202,7 +206,7 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
# TODO do this in parallel # TODO do this in parallel
await node.dialPeer(peerInfo) await node.dialPeer(peerInfo)
except CatchableError as err: except CatchableError as err:
debug "Failed to connect to peer", peer = $peer debug "Failed to connect to peer", peer = $peer, err = err.msg
except CatchableError as err: except CatchableError as err:
debug "Failure in discovery", err = err.msg debug "Failure in discovery", err = err.msg

View File

@ -25,7 +25,11 @@ const
logScope: logScope:
topics = "libp2p" topics = "libp2p"
declarePublicGauge libp2p_peers, "Number of libp2p peers" declarePublicGauge libp2p_successful_dials,
"Number of successfully dialed peers"
declarePublicGauge libp2p_peers,
"Number of active libp2p peers"
template libp2pProtocol*(name: string, version: int) {.pragma.} template libp2pProtocol*(name: string, version: int) {.pragma.}

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit e3ced62d4ba06b7ff638f6784e782046b1fadc70 Subproject commit a9ed7e4f3fda41f0649e9e0fe21ab00c03ec368f

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 31a4e8f959c1ce7de0ef5544753009d3b6b46e25 Subproject commit cfdb26db4097b078f02db172534977bd47e0e6c3