Local sim finalizes with native LibP2P

This commit is contained in:
Zahary Karadjov 2019-12-10 01:04:35 +02:00 committed by zah
parent 6ae4070d3f
commit 10e6d4842f
4 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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",

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 3f721e7ef66bb6e6004cd49202fcf23b29d2ff9d
Subproject commit 5bd7baaf9c1a0232822f467af85ed3a18fa6c033

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 454f658ba8aae8050bc0ffd800f1014cd68dbcb2
Subproject commit 77e866d29a58ad6cfefaf9c8a8ee7159a43bcfe5