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:
parent
11691c33e9
commit
0debf1a122
|
@ -8,7 +8,7 @@
|
|||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/os,
|
||||
std/[os, strutils],
|
||||
uri,
|
||||
confutils,
|
||||
confutils/std/net,
|
||||
|
@ -60,6 +60,12 @@ type
|
|||
none
|
||||
testnet0
|
||||
|
||||
# The networks alias Portal sub-protocols
|
||||
Network* = enum
|
||||
beacon
|
||||
history
|
||||
state
|
||||
|
||||
PortalConf* = object
|
||||
logLevel* {.
|
||||
desc:
|
||||
|
@ -90,11 +96,25 @@ type
|
|||
portalNetwork* {.
|
||||
desc:
|
||||
"Select which Portal network to join. This will set the " &
|
||||
"network specific bootstrap nodes automatically",
|
||||
"Portal network specific bootstrap nodes automatically",
|
||||
defaultValue: PortalNetwork.testnet0,
|
||||
name: "network"
|
||||
name: "portal-network"
|
||||
.}: 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
|
||||
# enabled Portal network. No distinction is made on bootstrap nodes per
|
||||
# specific network.
|
||||
|
@ -278,10 +298,6 @@ type
|
|||
name: "disable-poke"
|
||||
.}: bool
|
||||
|
||||
stateNetworkEnabled* {.
|
||||
hidden, desc: "Enable State Network", defaultValue: false, name: "state"
|
||||
.}: bool
|
||||
|
||||
case cmd* {.command, defaultValue: noCommand.}: PortalCmd
|
||||
of noCommand:
|
||||
discard
|
||||
|
@ -339,6 +355,23 @@ proc parseCmdArg*(T: type ClientConfig, p: string): T {.raises: [ValueError].} =
|
|||
proc completeCmdArg*(T: type ClientConfig, val: string): seq[string] =
|
||||
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):
|
||||
$it
|
||||
chronicles.formatIt(OutDir):
|
||||
|
|
|
@ -13,7 +13,7 @@ which contains nodes of the different clients.
|
|||
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.
|
||||
|
||||
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.
|
||||
|
||||
The `--rpc` option will also enable the different JSON-RPC interfaces through
|
||||
|
|
|
@ -27,5 +27,5 @@ any of the running nodes their ENR.
|
|||
E.g. to manually add a Fluffy node to the local testnet run:
|
||||
|
||||
```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`
|
||||
```
|
||||
|
|
|
@ -100,7 +100,14 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
loadBootstrapFile(string config.bootstrapNodesFile, bootstrapRecords)
|
||||
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:
|
||||
for enrURI in testnet0BootstrapNodes:
|
||||
var record: Record
|
||||
|
@ -183,7 +190,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
streamManager = StreamManager.new(d)
|
||||
|
||||
stateNetwork =
|
||||
if config.stateNetworkEnabled:
|
||||
if Network.state in config.networks:
|
||||
Opt.some(
|
||||
StateNetwork.new(
|
||||
d,
|
||||
|
@ -213,21 +220,25 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
except SszError as err:
|
||||
raiseAssert "Invalid baked-in accumulator: " & err.msg
|
||||
|
||||
historyNetwork = Opt.some(
|
||||
HistoryNetwork.new(
|
||||
d,
|
||||
db,
|
||||
streamManager,
|
||||
accumulator,
|
||||
bootstrapRecords = bootstrapRecords,
|
||||
portalConfig = portalConfig,
|
||||
)
|
||||
)
|
||||
historyNetwork =
|
||||
if Network.history in config.networks:
|
||||
Opt.some(
|
||||
HistoryNetwork.new(
|
||||
d,
|
||||
db,
|
||||
streamManager,
|
||||
accumulator,
|
||||
bootstrapRecords = bootstrapRecords,
|
||||
portalConfig = portalConfig,
|
||||
)
|
||||
)
|
||||
else:
|
||||
Opt.none(HistoryNetwork)
|
||||
|
||||
beaconLightClient =
|
||||
# TODO: Currently disabled by default as it is not sufficiently polished.
|
||||
# Eventually this should be always-on functionality.
|
||||
if config.trustedBlockRoot.isSome():
|
||||
if Network.beacon in config.networks and config.trustedBlockRoot.isSome():
|
||||
let
|
||||
# Portal works only over mainnet data currently
|
||||
networkData = loadNetworkData("mainnet")
|
||||
|
|
|
@ -304,7 +304,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
|
|||
--log-level="${LOG_LEVEL}" \
|
||||
--udp-port=$(( BASE_PORT + NUM_NODE )) \
|
||||
--data-dir="${NODE_DATA_DIR}" \
|
||||
--network="none" \
|
||||
--portal-network="none" \
|
||||
${BOOTSTRAP_ARG} \
|
||||
--rpc \
|
||||
--rpc-address="127.0.0.1" \
|
||||
|
@ -315,7 +315,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
|
|||
--table-ip-limit=1024 \
|
||||
--bucket-ip-limit=24 \
|
||||
--bits-per-hop=1 \
|
||||
--state=1 \
|
||||
--networks:beacon,history,state \
|
||||
${TRUSTED_BLOCK_ROOT_ARG} \
|
||||
${RADIUS_ARG} \
|
||||
${EXTRA_ARGS} \
|
||||
|
|
Loading…
Reference in New Issue