Use one bootstrap nodes argument for discv5 and Portal (#911)

Currently bootstrap nodes for discv5 and for the Portal nodes
were provided through separate cli arguments. This is however
confusing and cumbersome as typically when (currently) testing
a node will have both discv5 and the Portal networks enabled.
We merge them into one argument.

If a node happens not to support a Portal network, it will be
removed after message request failure.

Commit also contains additional clean-up and nim-eth bump.
This commit is contained in:
Kim De Mey 2021-12-13 09:06:29 +01:00 committed by GitHub
parent d5082df5d8
commit 70625bc02c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 52 deletions

View File

@ -56,12 +56,15 @@ type
desc: "Listening address for the Discovery v5 traffic"
name: "listen-address" }: ValidIpAddress
# Note: This will add bootstrap nodes for both Discovery v5 network and each
# enabled Portal network. No distinction is made on bootstrap nodes per
# specific network.
bootstrapNodes* {.
desc: "ENR URI of node to bootstrap Discovery v5 from. Argument may be repeated"
desc: "ENR URI of node to bootstrap Discovery v5 and the Portal networks from. Argument may be repeated"
name: "bootstrap-node" .}: seq[Record]
bootstrapNodesFile* {.
desc: "Specifies a line-delimited file of ENR URIs to bootstrap Discovery v5 from"
desc: "Specifies a line-delimited file of ENR URIs to bootstrap Discovery v5 and Portal networks from"
defaultValue: ""
name: "bootstrap-file" }: InputFile
@ -91,17 +94,6 @@ type
defaultValueDesc: $defaultDataDirDesc
name: "data-dir" }: OutDir
# Note: This will add bootstrap nodes for each enabled Portal network.
# No distinction is being made on bootstrap nodes for a specific network.
portalBootstrapNodes* {.
desc: "ENR URI of node to bootstrap the Portal networks from. Argument may be repeated"
name: "portal-bootstrap-node" .}: seq[Record]
portalBootstrapNodesFile* {.
desc: "Specifies a line-delimited file of ENR URIs to bootstrap the Portal networks from"
defaultValue: ""
name: "portal-bootstrap-file" }: InputFile
metricsEnabled* {.
defaultValue: false
desc: "Enable the metrics server"

View File

@ -52,12 +52,13 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
loadBootstrapFile(string config.bootstrapNodesFile, bootstrapRecords)
bootstrapRecords.add(config.bootstrapNodes)
let d = newProtocol(config.nodeKey,
extIp, none(Port), extUdpPort,
bootstrapRecords = bootstrapRecords,
bindIp = bindIp, bindPort = udpPort,
enrAutoUpdate = config.enrAutoUpdate,
rng = rng)
let d = newProtocol(
config.nodeKey,
extIp, none(Port), extUdpPort,
bootstrapRecords = bootstrapRecords,
bindIp = bindIp, bindPort = udpPort,
enrAutoUpdate = config.enrAutoUpdate,
rng = rng)
d.open()
@ -68,15 +69,9 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
ContentDB.new(config.dataDir / "db" / "contentdb_" &
d.localNode.id.toByteArrayBE().toOpenArray(0, 8).toHex())
var portalBootstrapRecords: seq[Record]
loadBootstrapFile(string config.portalBootstrapNodesFile, portalBootstrapRecords)
portalBootstrapRecords.add(config.portalBootstrapNodes)
let
stateNetwork = StateNetwork.new(d, db,
bootstrapRecords = portalBootstrapRecords)
historyNetwork = HistoryNetwork.new(d, db,
bootstrapRecords = portalBootstrapRecords)
stateNetwork = StateNetwork.new(d, db, bootstrapRecords = bootstrapRecords)
historyNetwork = HistoryNetwork.new(d, db, bootstrapRecords = bootstrapRecords)
# TODO: If no new network key is generated then we should first check if an
# enr file exists, and in the case it does read out the seqNum from it and

View File

@ -58,7 +58,7 @@ proc getContent*(n: HistoryNetwork, key: ContentKey):
proc new*(T: type HistoryNetwork, baseProtocol: protocol.Protocol,
contentDB: ContentDB , dataRadius = UInt256.high(),
bootstrapRecords: openarray[Record] = []): T =
bootstrapRecords: openArray[Record] = []): T =
let portalProtocol = PortalProtocol.new(
baseProtocol, historyProtocolId, getHandler(contentDB), dataRadius,
bootstrapRecords)

View File

@ -61,7 +61,7 @@ proc getContent*(n: StateNetwork, key: ContentKey):
proc new*(T: type StateNetwork, baseProtocol: protocol.Protocol,
contentDB: ContentDB , dataRadius = UInt256.high(),
bootstrapRecords: openarray[Record] = []): T =
bootstrapRecords: openArray[Record] = []): T =
let portalProtocol = PortalProtocol.new(
baseProtocol, stateProtocolId, getHandler(contentDB), dataRadius,
bootstrapRecords, stateDistanceCalculator)

View File

@ -136,7 +136,7 @@ func encodeMessage*[T: SomeMessage](m: T): seq[byte] =
elif T is OfferMessage: SSZ.encode(Message(kind: offer, offer: m))
elif T is AcceptMessage: SSZ.encode(Message(kind: accept, accept: m))
func decodeMessage*(body: openarray[byte]): Result[Message, cstring] =
func decodeMessage*(body: openArray[byte]): Result[Message, cstring] =
try:
if body.len < 1: # TODO: This check should probably move a layer down
return err("No message data, peer might not support this talk protocol")

View File

@ -222,7 +222,7 @@ proc new*(T: type PortalProtocol,
protocolId: PortalProtocolId,
contentHandler: ContentHandler,
dataRadius = UInt256.high(),
bootstrapRecords: openarray[Record] = [],
bootstrapRecords: openArray[Record] = [],
distanceCalculator: DistanceCalculator = XorDistanceCalculator
): T =
let proto = PortalProtocol(

View File

@ -245,7 +245,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
NODE_DATA_DIR="${DATA_DIR}/node${NUM_NODE}"
if [[ ${NUM_NODE} != ${BOOTSTRAP_NODE} ]]; then
BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR_FILE} --portal-bootstrap-file=${BOOTSTRAP_ENR_FILE}"
BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR_FILE}"
# Wait for the bootstrap node to write out its enr file
START_TIMESTAMP=$(date +%s)

View File

@ -17,8 +17,8 @@ proc localAddress*(port: int): Address =
proc initDiscoveryNode*(rng: ref BrHmacDrbgContext,
privKey: PrivateKey,
address: Address,
bootstrapRecords: openarray[Record] = [],
localEnrFields: openarray[(string, seq[byte])] = [],
bootstrapRecords: openArray[Record] = [],
localEnrFields: openArray[(string, seq[byte])] = [],
previousRecord = none[enr.Record]()): discv5_protocol.Protocol =
# set bucketIpLimit to allow bucket split
let tableIpLimits = TableIpLimits(tableIpLimit: 1000, bucketIpLimit: 24)

View File

@ -13,6 +13,7 @@ import
eth/[keys, net/nat],
eth/p2p/discoveryv5/[enr, node],
eth/p2p/discoveryv5/protocol as discv5_protocol,
../common/common_utils,
../network/wire/[messages, portal_protocol],
../network/state/state_content
@ -30,7 +31,7 @@ type
findnodes
findcontent
DiscoveryConf* = object
PortalCliConf* = object
logLevel* {.
defaultValue: LogLevel.DEBUG
defaultValueDesc: $LogLevel.DEBUG
@ -48,9 +49,17 @@ type
desc: "Listening address for the Discovery v5 traffic"
name: "listen-address" }: ValidIpAddress
bootnodes* {.
desc: "ENR URI of node to bootstrap discovery with. Argument may be repeated"
name: "bootnode" .}: seq[enr.Record]
# Note: This will add bootstrap nodes for both Discovery v5 network and each
# enabled Portal network. No distinction is made on bootstrap nodes per
# specific network.
bootstrapNodes* {.
desc: "ENR URI of node to bootstrap Discovery v5 and the Portal networks from. Argument may be repeated"
name: "bootstrap-node" .}: seq[Record]
bootstrapNodesFile* {.
desc: "Specifies a line-delimited file of ENR URIs to bootstrap Discovery v5 and Portal networks from"
defaultValue: ""
name: "bootstrap-file" }: InputFile
nat* {.
desc: "Specify method to use for determining public address. " &
@ -72,10 +81,6 @@ type
defaultValueDesc: "random"
name: "nodekey" .}: PrivateKey
portalBootnodes* {.
desc: "ENR URI of node to bootstrap the Portal protocol with. Argument may be repeated"
name: "portal-bootnode" .}: seq[Record]
metricsEnabled* {.
defaultValue: false
desc: "Enable the metrics server"
@ -169,7 +174,7 @@ proc testHandler(contentKey: state_content.ByteList): ContentResult =
ContentResult(kind: ContentKeyValidationFailure,
error: "Failed decoding content key")
proc run(config: DiscoveryConf) =
proc run(config: PortalCliConf) =
let
rng = newRng()
bindIp = config.listenAddress
@ -178,18 +183,23 @@ proc run(config: DiscoveryConf) =
(extIp, _, extUdpPort) = setupAddress(config.nat,
config.listenAddress, udpPort, udpPort, "dcli")
let d = newProtocol(config.nodeKey,
extIp, none(Port), extUdpPort,
bootstrapRecords = config.bootnodes,
bindIp = bindIp, bindPort = udpPort,
enrAutoUpdate = config.enrAutoUpdate,
rng = rng)
var bootstrapRecords: seq[Record]
loadBootstrapFile(string config.bootstrapNodesFile, bootstrapRecords)
bootstrapRecords.add(config.bootstrapNodes)
let d = newProtocol(
config.nodeKey,
extIp, none(Port), extUdpPort,
bootstrapRecords = bootstrapRecords,
bindIp = bindIp, bindPort = udpPort,
enrAutoUpdate = config.enrAutoUpdate,
rng = rng)
d.open()
# TODO: Configurable protocol id
let portal = PortalProtocol.new(d, [byte 0x50, 0x0A], testHandler,
bootstrapRecords = config.portalBootnodes)
bootstrapRecords = bootstrapRecords)
if config.metricsEnabled:
let
@ -242,7 +252,7 @@ proc run(config: DiscoveryConf) =
waitfor(discover(d))
when isMainModule:
let config = DiscoveryConf.load()
let config = PortalCliConf.load()
setLogLevel(config.logLevel)

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 6e21b32f0d0569b6bfc527eecd6f9ff65452f271
Subproject commit 2088d7568db0cfe9b13f6244ba413df21d7899b8