Expose gossip direct peers (#2246)

* Expose gossip direct peers

* direct-peer fixes

* add explicit info about direct peer

* build fixes wip
This commit is contained in:
Giovanni Petrantoni 2021-03-23 15:10:17 +09:00 committed by GitHub
parent 5fd82ddaf5
commit 9558946df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -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/<address>/tcp/<port>/p2p/<peerId-public-key>. 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)"

View File

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