From 10e6d4842fa4987293d318303290bf009321fd56 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 10 Dec 2019 01:04:35 +0200 Subject: [PATCH] Local sim finalizes with native LibP2P --- beacon_chain/eth2_network.nim | 3 ++- beacon_chain/sync_protocol.nim | 10 ++++++++++ vendor/nim-eth | 2 +- vendor/nim-libp2p | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index 91dfff7971..41b62a2a37 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -222,7 +222,8 @@ else: # TODO nim-libp2p still doesn't have support for announcing addresses # that are different from the host address (this is relevant when we # are running behind a NAT). - result = Eth2Node.init newStandardSwitch(some keys.seckey, hostAddress) + result = Eth2Node.init newStandardSwitch(some keys.seckey, hostAddress, + triggerSelf = true, gossip = true) await result.start() else: let keyFile = conf.ensureNetworkIdFile diff --git a/beacon_chain/sync_protocol.nim b/beacon_chain/sync_protocol.nim index c3d1453c83..b9c95b49f3 100644 --- a/beacon_chain/sync_protocol.nim +++ b/beacon_chain/sync_protocol.nim @@ -7,6 +7,8 @@ import when networkBackend == rlpx: import eth/rlp/options as rlpOptions template libp2pProtocol*(name: string, version: int) {.pragma.} +elif networkBackend == libp2p: + import libp2p/switch declarePublicGauge libp2p_peers, "Number of libp2p peers" @@ -162,6 +164,14 @@ proc handleInitialStatus(peer: Peer, state: BeaconSyncNetworkState, ourStatus: StatusMsg, theirStatus: StatusMsg) {.async, gcsafe.} = + when networkBackend == libp2p: + # TODO: This doesn't seem like an appropraite place for this call, + # but it's hard to pick a better place at the moment. + # nim-libp2p plans to add a general `onPeerConnected` callback which + # will allow us to implement the subscription earlier. + # The root of the problem is that both sides must call `subscribeToPeer` + # before any GossipSub traffic will flow between them. + await peer.network.switch.subscribeToPeer(peer.info) if theirStatus.forkVersion != state.forkVersion: notice "Irrelevant peer", diff --git a/vendor/nim-eth b/vendor/nim-eth index 3f721e7ef6..5bd7baaf9c 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 3f721e7ef66bb6e6004cd49202fcf23b29d2ff9d +Subproject commit 5bd7baaf9c1a0232822f467af85ed3a18fa6c033 diff --git a/vendor/nim-libp2p b/vendor/nim-libp2p index 454f658ba8..77e866d29a 160000 --- a/vendor/nim-libp2p +++ b/vendor/nim-libp2p @@ -1 +1 @@ -Subproject commit 454f658ba8aae8050bc0ffd800f1014cd68dbcb2 +Subproject commit 77e866d29a58ad6cfefaf9c8a8ee7159a43bcfe5