Use the latest LibP2P

This commit is contained in:
Zahary Karadjov 2020-06-05 18:08:50 +03:00
parent 32bc4d9096
commit 0c78fc39e7
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
13 changed files with 52 additions and 43 deletions

View File

@ -44,7 +44,7 @@ type
# this needs to be global, so it can be set in the Ctrl+C signal handler
var status = BeaconNodeStatus.Starting
template init(T: type RpcHttpServer, ip: IpAddress, port: Port): T =
template init(T: type RpcHttpServer, ip: ValidIpAddress, port: Port): T =
newRpcHttpServer([initTAddress(ip, port)])
# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#interop-metrics

View File

@ -78,7 +78,7 @@ type
libp2pAddress* {.
defaultValue: defaultListenAddress(config)
desc: "Listening address for the Ethereum LibP2P traffic."
name: "listen-address"}: IpAddress
name: "listen-address" }: ValidIpAddress
tcpPort* {.
defaultValue: defaultEth2TcpPort
@ -140,7 +140,7 @@ type
metricsAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Listening address of the metrics server."
name: "metrics-address" }: IpAddress
name: "metrics-address" }: ValidIpAddress
metricsPort* {.
defaultValue: 8008
@ -173,7 +173,7 @@ type
rpcAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Listening address of the RPC server"
name: "rpc-address" }: IpAddress
name: "rpc-address" }: ValidIpAddress
dumpEnabled* {.
defaultValue: false
@ -201,9 +201,9 @@ type
name: "last-user-validator" }: uint64
bootstrapAddress* {.
defaultValue: parseIpAddress("127.0.0.1")
defaultValue: ValidIpAddress.init("127.0.0.1")
desc: "The public IP address that will be advertised as a bootstrap node for the testnet."
name: "bootstrap-address" }: IpAddress
name: "bootstrap-address" }: ValidIpAddress
bootstrapPort* {.
defaultValue: defaultEth2TcpPort
@ -290,7 +290,7 @@ type
rpcAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Address of the server to connect to for RPC."
name: "rpc-address" }: IpAddress
name: "rpc-address" }: ValidIpAddress
validators* {.
required
@ -330,13 +330,13 @@ func localValidatorsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
func databaseDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
conf.dataDir / "db"
func defaultListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): IpAddress =
func defaultListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
return static: parseIpAddress("0.0.0.0")
(static ValidIpAddress.init("0.0.0.0"))
func defaultAdminListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): IpAddress =
return static: parseIpAddress("127.0.0.1")
func defaultAdminListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
(static ValidIpAddress.init("127.0.0.1"))
iterator validatorKeys*(conf: BeaconNodeConf|ValidatorClientConf): ValidatorPrivKey =
for validatorKeyFile in conf.validators:

View File

@ -1,8 +1,8 @@
{.push raises: [Defect].}
import
os, net, sequtils, strutils,
chronicles, stew/results, eth/keys, eth/trie/db,
os, sequtils, strutils,
chronicles, stew/shims/net, stew/results, eth/keys, eth/trie/db,
eth/p2p/discoveryv5/[enr, protocol, discovery_db, node],
conf
@ -74,7 +74,7 @@ proc loadBootstrapFile*(bootstrapFile: string,
proc new*(T: type Eth2DiscoveryProtocol,
conf: BeaconNodeConf,
ip: Option[IpAddress], tcpPort, udpPort: Port,
ip: Option[ValidIpAddress], tcpPort, udpPort: Port,
rawPrivKeyBytes: openarray[byte],
enrFields: openarray[(string, seq[byte])]):
T {.raises: [Exception, Defect].} =

View File

@ -1,10 +1,11 @@
import
# Std lib
typetraits, strutils, os, random, algorithm, sequtils,
options as stdOptions, net as stdNet,
options as stdOptions,
# Status libs
stew/[varints, base58, endians2, results, byteutils],
stew/shims/net as stewNet,
stew/shims/[macros, tables],
faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
json_serialization, json_serialization/std/[net, options],
@ -656,17 +657,15 @@ proc toPeerInfo*(r: enr.TypedRecord): PeerInfo =
var addresses = newSeq[MultiAddress]()
if r.ip.isSome and r.tcp.isSome:
let ip = IpAddress(family: IpAddressFamily.IPv4,
address_v4: r.ip.get)
addresses.add MultiAddress.init(ip, TCP, Port r.tcp.get)
let ip = ipv4(r.ip.get)
addresses.add MultiAddress.init(ip, tcpProtocol, Port r.tcp.get)
if r.ip6.isSome:
let ip = IpAddress(family: IpAddressFamily.IPv6,
address_v6: r.ip6.get)
let ip = ipv6(r.ip6.get)
if r.tcp6.isSome:
addresses.add MultiAddress.init(ip, TCP, Port r.tcp6.get)
addresses.add MultiAddress.init(ip, tcpProtocol, Port r.tcp6.get)
elif r.tcp.isSome:
addresses.add MultiAddress.init(ip, TCP, Port r.tcp.get)
addresses.add MultiAddress.init(ip, tcpProtocol, Port r.tcp.get)
else:
discard
@ -781,7 +780,7 @@ proc getPersistentNetMetadata*(conf: BeaconNodeConf): Eth2Metadata =
result = Json.loadFile(metadataPath, Eth2Metadata)
proc init*(T: type Eth2Node, conf: BeaconNodeConf, enrForkId: ENRForkID,
switch: Switch, ip: Option[IpAddress], tcpPort, udpPort: Port,
switch: Switch, ip: Option[ValidIpAddress], tcpPort, udpPort: Port,
privKey: keys.PrivateKey): T =
new result
result.switch = switch
@ -986,7 +985,7 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend =
result.implementProtocolInit = proc (p: P2PProtocol): NimNode =
return newCall(initProtocol, newLit(p.name), p.peerInit, p.netInit)
proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[IpAddress],
proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[ValidIpAddress],
tcpPort: Port,
udpPort: Port] {.gcsafe.} =
# defaults
@ -1004,17 +1003,22 @@ proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[IpAddress],
of "pmp":
nat = NatPmp
else:
if conf.nat.startsWith("extip:") and isIpAddress(conf.nat[6..^1]):
if conf.nat.startsWith("extip:"):
try:
# any required port redirection is assumed to be done by hand
result.ip = some(parseIpAddress(conf.nat[6..^1]))
result.ip = some(ValidIpAddress.init(conf.nat[6..^1]))
nat = NatNone
except ValueError:
error "nor a valid IP address", address = conf.nat[6..^1]
quit QuitFailure
else:
error "not a valid NAT mechanism, nor a valid IP address", value = conf.nat
quit(QuitFailure)
error "not a valid NAT mechanism", value = conf.nat
quit QuitFailure
if nat != NatNone:
result.ip = getExternalIP(nat)
if result.ip.isSome:
let extIp = getExternalIP(nat)
if extIP.isSome:
result.ip = some(ValidIpAddress.init extIp.get)
# TODO redirectPorts in considered a gcsafety violation
# because it obtains the address of a non-gcsafe proc?
let extPorts = ({.gcsafe.}:
@ -1039,7 +1043,7 @@ proc initAddress*(T: type MultiAddress, str: string): T =
"Invalid bootstrap node multi-address")
template tcpEndPoint(address, port): auto =
MultiAddress.init(address, Protocol.IPPROTO_TCP, port)
MultiAddress.init(address, tcpProtocol, port)
proc getPersistentNetKeys*(conf: BeaconNodeConf): KeyPair =
let
@ -1079,7 +1083,7 @@ proc createEth2Node*(conf: BeaconNodeConf, enrForkId: ENRForkID): Future[Eth2Nod
keys.seckey.asEthKey)
proc getPersistenBootstrapAddr*(conf: BeaconNodeConf,
ip: IpAddress, port: Port): EnrResult[enr.Record] =
ip: ValidIpAddress, port: Port): EnrResult[enr.Record] =
let pair = getPersistentNetKeys(conf)
return enr.Record.init(1'u64, # sequence number
pair.seckey.asEthKey,

View File

@ -11,5 +11,9 @@ proc writeValue*(writer: var JsonWriter, value: MultiAddress) {.inline.} =
writer.writeValue $value
proc readValue*(reader: var JsonReader, value: var MultiAddress) {.inline.} =
value = MultiAddress.init reader.readValue(string)
let addressRes = MultiAddress.init reader.readValue(string)
if addressRes.isOk:
value = addressRes.value
else:
raiseUnexpectedValue(reader, "Invalid MultiAddress value")

View File

@ -155,7 +155,7 @@ BOOTSTRAP_IP="127.0.0.1"
--output-bootstrap-file="${NETWORK_DIR}/bootstrap_nodes.txt" \
--bootstrap-address=${BOOTSTRAP_IP} \
--bootstrap-port=${BASE_PORT} \
--genesis-offset=5 # Delay in seconds
--genesis-offset=30 # Delay in seconds
if [[ "$ENABLE_GRAFANA" == "1" ]]; then
# Prometheus config

View File

@ -153,7 +153,7 @@ if [ ! -f "${SNAPSHOT_FILE}" ]; then
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=$(( BASE_P2P_PORT + MASTER_NODE )) \
--genesis-offset=5 # Delay in seconds
--genesis-offset=15 # Delay in seconds
fi
fi

View File

@ -1,5 +1,6 @@
import
unittest, os,
stew/shims/net,
chronos, confutils,
../beacon_chain/[conf, eth2_network]
@ -17,7 +18,7 @@ asyncTest "connect two nodes":
c1.nat = "none"
var n1PersistentAddress = c1.getPersistenBootstrapAddr(
parseIpAddress("127.0.0.1"), Port c1.tcpPort)
ValidIpAddress.init("127.0.0.1"), Port c1.tcpPort)
var n1 = await createEth2Node(c1, ENRForkID())

@ -1 +1 @@
Subproject commit 6e5d570490989c753d4645ba9173ef9358d302bb
Subproject commit 26667818be48d428892b26be9535c1f0a98d1510

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit d53cebcf5dd35728c27088d9c95923d7baad4ac4
Subproject commit 617f5d8c13fcf025cb0b135db3b67f6c0f3f7f04

@ -1 +1 @@
Subproject commit 8d4c31f7c2f56e17ec3325ec054fe15ccf4e89d4
Subproject commit c478b7bbbab6ee298a25c29c7357783d94aaecaa

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 7b6e1c06888a831d61d7019a07d2d59d5bd079ea
Subproject commit 2aebae56c03cb1dd14cdf9f2fa16ca921b217ff2

2
vendor/nim-stew vendored

@ -1 +1 @@
Subproject commit 86ac01122c29119cd585e400e85396b6bd3cceb6
Subproject commit bb2221ba8c8ea2d3fbbcfdb8d28796f8d3eff348