From 9558946df40a2dfcecaae4785c02dde67ecb2a90 Mon Sep 17 00:00:00 2001
From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com>
Date: Tue, 23 Mar 2021 15:10:17 +0900
Subject: [PATCH] Expose gossip direct peers (#2246)
* Expose gossip direct peers
* direct-peer fixes
* add explicit info about direct peer
* build fixes wip
---
beacon_chain/conf.nim | 4 ++++
beacon_chain/networking/eth2_network.nim | 20 +++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim
index 14b396b15..050d90c1b 100644
--- a/beacon_chain/conf.nim
+++ b/beacon_chain/conf.nim
@@ -273,6 +273,10 @@ type
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
name: "dump" }: bool
+ directPeers* {.
+ desc: "The list of priviledged, secure and known peers to connect and maintain the connection to, this requires a not random netkey-file. In the complete multiaddress format like: /ip4/
/tcp//p2p/. Peering agreements are established out of band and must be reciprocal."
+ name: "direct-peer" .}: seq[string]
+
doppelgangerDetection* {.
defaultValue: true
desc: "Whether to detect whether another validator is be running the same validator keys (default true)"
diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim
index 4db7be3a1..7669032dc 100644
--- a/beacon_chain/networking/eth2_network.nim
+++ b/beacon_chain/networking/eth2_network.nim
@@ -10,13 +10,13 @@ import
faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
json_serialization, json_serialization/std/[net, options],
chronos, chronicles, metrics,
- libp2p/[switch, peerinfo,
+ libp2p/[switch, peerinfo, multicodec,
multiaddress, crypto/crypto, crypto/secp,
protocols/identify, protocols/protocol],
libp2p/muxers/muxer, libp2p/muxers/mplex/mplex,
libp2p/transports/[transport, tcptransport],
libp2p/protocols/secure/[secure, noise],
- libp2p/protocols/pubsub/[pubsub, rpc/message, rpc/messages],
+ libp2p/protocols/pubsub/[pubsub, gossipsub, rpc/message, rpc/messages],
libp2p/transports/tcptransport,
libp2p/stream/connection,
eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl,
@@ -28,8 +28,6 @@ import
../validators/keystore_management,
./eth2_discovery, ./peer_pool, ./libp2p_json_serialization
-import libp2p/protocols/pubsub/gossipsub
-
when chronicles.enabledLogLevel == LogLevel.TRACE:
import std/sequtils
@@ -1541,7 +1539,19 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
ipColocationFactorThreshold: 3.0,
behaviourPenaltyWeight: -15.9,
behaviourPenaltyDecay: 0.986,
- disconnectBadPeers: true
+ disconnectBadPeers: true,
+ directPeers:
+ block:
+ var res = initTable[PeerId, seq[MultiAddress]]()
+ if config.directPeers.len > 0:
+ for s in config.directPeers:
+ let
+ maddress = MultiAddress.init(s).tryGet()
+ mpeerId = maddress[multiCodec("p2p")].tryGet()
+ peerId = PeerID.init(mpeerId.protoAddress().tryGet()).tryGet()
+ res.mGetOrPut(peerId, @[]).add(maddress)
+ info "Adding priviledged direct peer", peerId, address = maddress
+ res
)
pubsub = GossipSub.init(
switch = switch,