From b2d5aba749435b465ddb7633ca33cbc4f0a3216a Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 18 Feb 2020 01:35:24 +0200 Subject: [PATCH] Advertise the TCP port of the bootstrap node properly --- beacon_chain/beacon_node.nim | 2 ++ beacon_chain/eth2_discovery.nim | 2 +- beacon_chain/eth2_network.nim | 2 +- beacon_chain/libp2p_backend.nim | 10 +++++++--- beacon_chain/libp2p_backends_common.nim | 6 +++++- vendor/nim-chronos | 2 +- vendor/nim-eth | 2 +- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 50f894214..9b266f821 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -1116,7 +1116,9 @@ when isMainModule: networkKeys = getPersistentNetKeys(config) bootstrapAddress = enode.Address( ip: parseIpAddress(config.bootstrapAddress), + tcpPort: Port config.bootstrapPort, udpPort: Port config.bootstrapPort) + bootstrapEnr = enr.Record.init(1, networkKeys.seckey, bootstrapAddress) writeFile(bootstrapFile, bootstrapEnr.toURI) echo "Wrote ", bootstrapFile diff --git a/beacon_chain/eth2_discovery.nim b/beacon_chain/eth2_discovery.nim index dc8cc8199..6ca451033 100644 --- a/beacon_chain/eth2_discovery.nim +++ b/beacon_chain/eth2_discovery.nim @@ -24,7 +24,7 @@ proc new*(T: type Eth2DiscoveryProtocol, pk = initPrivateKey(rawPrivKeyBytes) 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] = if not IPFS.match(a): diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index aa23b709f..4a771dc55 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -232,7 +232,7 @@ when networkBackend in [libp2p, libp2pDaemon]: await node.start() await sleepAsync(10.seconds) - if libp2p_peers.value == 0: + if libp2p_successful_dials.value == 0: fatal "Failed to connect to any bootstrap node. Quitting" quit 1 diff --git a/beacon_chain/libp2p_backend.nim b/beacon_chain/libp2p_backend.nim index f314a3e9a..c92cd8187 100644 --- a/beacon_chain/libp2p_backend.nim +++ b/beacon_chain/libp2p_backend.nim @@ -30,7 +30,6 @@ type discovery*: Eth2DiscoveryProtocol wantedPeers*: int peers*: Table[PeerID, Peer] - peersByDiscoveryId*: Table[Eth2DiscoveryId, Peer] protocolStates*: seq[RootRef] libp2pTransportLoops*: seq[Future[void]] @@ -153,7 +152,11 @@ include libp2p_backends_common proc toPeerInfo*(r: enr.TypedRecord): PeerInfo = 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]() if r.ip.isSome and r.tcp.isSome: @@ -184,6 +187,7 @@ proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} = var peer = node.getPeer(peerInfo) peer.wasDialed = true await initializeConnection(peer) + inc libp2p_successful_dials proc runDiscoveryLoop*(node: Eth2Node) {.async.} = debug "Starting discovery loop" @@ -202,7 +206,7 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} = # TODO do this in parallel await node.dialPeer(peerInfo) 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: debug "Failure in discovery", err = err.msg diff --git a/beacon_chain/libp2p_backends_common.nim b/beacon_chain/libp2p_backends_common.nim index faa567d24..9bd09638b 100644 --- a/beacon_chain/libp2p_backends_common.nim +++ b/beacon_chain/libp2p_backends_common.nim @@ -25,7 +25,11 @@ const logScope: 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.} diff --git a/vendor/nim-chronos b/vendor/nim-chronos index e3ced62d4..a9ed7e4f3 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit e3ced62d4ba06b7ff638f6784e782046b1fadc70 +Subproject commit a9ed7e4f3fda41f0649e9e0fe21ab00c03ec368f diff --git a/vendor/nim-eth b/vendor/nim-eth index 31a4e8f95..cfdb26db4 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 31a4e8f959c1ce7de0ef5544753009d3b6b46e25 +Subproject commit cfdb26db4097b078f02db172534977bd47e0e6c3