Skip to content

Commit

Permalink
Introduce --networks and --portal-network cli options (#2061)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kdeme authored Mar 5, 2024
1 parent 11691c3 commit 0debf1a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
47 changes: 40 additions & 7 deletions fluffy/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{.push raises: [].}

import
std/os,
std/[os, strutils],
uri,
confutils,
confutils/std/net,
Expand Down Expand Up @@ -60,6 +60,12 @@ type
none
testnet0

# The networks alias Portal sub-protocols
Network* = enum
beacon
history
state

PortalConf* = object
logLevel* {.
desc:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion fluffy/docs/the_fluffy_book/docs/connect-to-portal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fluffy/docs/the_fluffy_book/docs/run-local-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
```
37 changes: 24 additions & 13 deletions fluffy/fluffy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions fluffy/scripts/launch_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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} \
Expand Down

0 comments on commit 0debf1a

Please sign in to comment.