Skip to content

Commit

Permalink
Local sim finalizes with native LibP2P
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Dec 10, 2019
1 parent 6ae4070 commit 10e6d48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion beacon_chain/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions beacon_chain/sync_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-eth
2 changes: 1 addition & 1 deletion vendor/nim-libp2p

0 comments on commit 10e6d48

Please sign in to comment.