Introduce --networks and --portal-network cli options (#2061)

The --networks option is to select the networks alias the Portal
sub-protocols.
The --network option is deprecated and replaced with the
--portal-network option to avoid confusion with --networks option.

This commit also remove the --state flag which was a temporary
quick-fix.
This commit is contained in:
Kim De Mey 2024-03-05 13:45:48 +01:00 committed by GitHub
parent 11691c33e9
commit 0debf1a122
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 68 additions and 24 deletions

View File

@ -8,7 +8,7 @@
{.push raises: [].} {.push raises: [].}
import import
std/os, std/[os, strutils],
uri, uri,
confutils, confutils,
confutils/std/net, confutils/std/net,
@ -60,6 +60,12 @@ type
none none
testnet0 testnet0
# The networks alias Portal sub-protocols
Network* = enum
beacon
history
state
PortalConf* = object PortalConf* = object
logLevel* {. logLevel* {.
desc: desc:
@ -90,11 +96,25 @@ type
portalNetwork* {. portalNetwork* {.
desc: desc:
"Select which Portal network to join. This will set the " & "Select which Portal network to join. This will set the " &
"network specific bootstrap nodes automatically", "Portal network specific bootstrap nodes automatically",
defaultValue: PortalNetwork.testnet0, defaultValue: PortalNetwork.testnet0,
name: "network" name: "portal-network"
.}: PortalNetwork .}: PortalNetwork
portalNetworkDeprecated* {.
hidden,
desc:
"DEPRECATED: The --network flag will be removed in the future, please use the drop in replacement --portal-network flag instead",
defaultValue: none(PortalNetwork),
name: "network"
.}: Option[PortalNetwork.testnet0]
networks* {.
desc: "Select which networks (Portal sub-protocols) to enable",
defaultValue: {Network.history},
name: "networks"
.}: set[Network]
# Note: This will add bootstrap nodes for both Discovery v5 network and each # Note: This will add bootstrap nodes for both Discovery v5 network and each
# enabled Portal network. No distinction is made on bootstrap nodes per # enabled Portal network. No distinction is made on bootstrap nodes per
# specific network. # specific network.
@ -278,10 +298,6 @@ type
name: "disable-poke" name: "disable-poke"
.}: bool .}: bool
stateNetworkEnabled* {.
hidden, desc: "Enable State Network", defaultValue: false, name: "state"
.}: bool
case cmd* {.command, defaultValue: noCommand.}: PortalCmd case cmd* {.command, defaultValue: noCommand.}: PortalCmd
of noCommand: of noCommand:
discard discard
@ -339,6 +355,23 @@ proc parseCmdArg*(T: type ClientConfig, p: string): T {.raises: [ValueError].} =
proc completeCmdArg*(T: type ClientConfig, val: string): seq[string] = proc completeCmdArg*(T: type ClientConfig, val: string): seq[string] =
return @[] return @[]
proc parseCmdArg*(T: type set[Network], p: string): T {.raises: [ValueError].} =
var res: set[Network] = {}
let values = p.split({' ', ','})
for value in values:
let stripped = value.strip()
let network =
try:
parseEnum[Network](stripped)
except ValueError:
raise newException(ValueError, "Invalid network: " & stripped)
res.incl(network)
res
proc completeCmdArg*(T: type set[Network], val: string): seq[string] =
return @[]
chronicles.formatIt(InputDir): chronicles.formatIt(InputDir):
$it $it
chronicles.formatIt(OutDir): chronicles.formatIt(OutDir):

View File

@ -13,7 +13,7 @@ which contains nodes of the different clients.
Default the Fluffy node will connect to the Default the Fluffy node will connect to the
[bootstrap nodes](https://github.com/ethereum/portal-network-specs/blob/master/testnet.md#bootnodes) of the public testnet. [bootstrap nodes](https://github.com/ethereum/portal-network-specs/blob/master/testnet.md#bootnodes) of the public testnet.
When testing locally the `--network:none` option can be provided to avoid When testing locally the `--portal-network:none` option can be provided to avoid
connecting to any of the testnet bootstrap nodes. connecting to any of the testnet bootstrap nodes.
The `--rpc` option will also enable the different JSON-RPC interfaces through The `--rpc` option will also enable the different JSON-RPC interfaces through

View File

@ -27,5 +27,5 @@ any of the running nodes their ENR.
E.g. to manually add a Fluffy node to the local testnet run: E.g. to manually add a Fluffy node to the local testnet run:
```bash ```bash
./build/fluffy --rpc --network:none --udp-port:9010 --nat:extip:127.0.0.1 --bootstrap-node:`cat ./local_testnet_data/node0/fluffy_node.enr` ./build/fluffy --rpc --portal-network:none --udp-port:9010 --nat:extip:127.0.0.1 --bootstrap-node:`cat ./local_testnet_data/node0/fluffy_node.enr`
``` ```

View File

@ -100,7 +100,14 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
loadBootstrapFile(string config.bootstrapNodesFile, bootstrapRecords) loadBootstrapFile(string config.bootstrapNodesFile, bootstrapRecords)
bootstrapRecords.add(config.bootstrapNodes) bootstrapRecords.add(config.bootstrapNodes)
case config.portalNetwork var portalNetwork: PortalNetwork
if config.portalNetworkDeprecated.isSome():
warn "DEPRECATED: The --network flag will be removed in the future, please use the drop in replacement --portal-network flag instead"
portalNetwork = config.portalNetworkDeprecated.get()
else:
portalNetwork = config.portalNetwork
case portalNetwork
of testnet0: of testnet0:
for enrURI in testnet0BootstrapNodes: for enrURI in testnet0BootstrapNodes:
var record: Record var record: Record
@ -183,7 +190,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
streamManager = StreamManager.new(d) streamManager = StreamManager.new(d)
stateNetwork = stateNetwork =
if config.stateNetworkEnabled: if Network.state in config.networks:
Opt.some( Opt.some(
StateNetwork.new( StateNetwork.new(
d, d,
@ -213,21 +220,25 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
except SszError as err: except SszError as err:
raiseAssert "Invalid baked-in accumulator: " & err.msg raiseAssert "Invalid baked-in accumulator: " & err.msg
historyNetwork = Opt.some( historyNetwork =
HistoryNetwork.new( if Network.history in config.networks:
d, Opt.some(
db, HistoryNetwork.new(
streamManager, d,
accumulator, db,
bootstrapRecords = bootstrapRecords, streamManager,
portalConfig = portalConfig, accumulator,
) bootstrapRecords = bootstrapRecords,
) portalConfig = portalConfig,
)
)
else:
Opt.none(HistoryNetwork)
beaconLightClient = beaconLightClient =
# TODO: Currently disabled by default as it is not sufficiently polished. # TODO: Currently disabled by default as it is not sufficiently polished.
# Eventually this should be always-on functionality. # Eventually this should be always-on functionality.
if config.trustedBlockRoot.isSome(): if Network.beacon in config.networks and config.trustedBlockRoot.isSome():
let let
# Portal works only over mainnet data currently # Portal works only over mainnet data currently
networkData = loadNetworkData("mainnet") networkData = loadNetworkData("mainnet")

View File

@ -304,7 +304,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
--log-level="${LOG_LEVEL}" \ --log-level="${LOG_LEVEL}" \
--udp-port=$(( BASE_PORT + NUM_NODE )) \ --udp-port=$(( BASE_PORT + NUM_NODE )) \
--data-dir="${NODE_DATA_DIR}" \ --data-dir="${NODE_DATA_DIR}" \
--network="none" \ --portal-network="none" \
${BOOTSTRAP_ARG} \ ${BOOTSTRAP_ARG} \
--rpc \ --rpc \
--rpc-address="127.0.0.1" \ --rpc-address="127.0.0.1" \
@ -315,7 +315,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
--table-ip-limit=1024 \ --table-ip-limit=1024 \
--bucket-ip-limit=24 \ --bucket-ip-limit=24 \
--bits-per-hop=1 \ --bits-per-hop=1 \
--state=1 \ --networks:beacon,history,state \
${TRUSTED_BLOCK_ROOT_ARG} \ ${TRUSTED_BLOCK_ROOT_ARG} \
${RADIUS_ARG} \ ${RADIUS_ARG} \
${EXTRA_ARGS} \ ${EXTRA_ARGS} \