2023-11-23 10:44:57 +00:00
|
|
|
# Fluffy
|
2024-02-16 22:38:58 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2021-06-16 19:18:45 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
{.push raises: [].}
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
import
|
2024-03-05 12:45:48 +00:00
|
|
|
std/[os, strutils],
|
2024-02-28 17:31:45 +00:00
|
|
|
uri,
|
|
|
|
confutils,
|
|
|
|
confutils/std/net,
|
|
|
|
chronicles,
|
2024-10-04 21:21:26 +00:00
|
|
|
eth/common/keys,
|
2024-02-28 17:31:45 +00:00
|
|
|
eth/p2p/discoveryv5/[enr, node, routing_table],
|
2022-12-27 14:57:10 +00:00
|
|
|
nimcrypto/hash,
|
|
|
|
stew/byteutils,
|
2023-08-04 11:10:09 +00:00
|
|
|
eth/net/nat, # must be late (compilation annoyance)
|
2023-04-19 15:01:01 +00:00
|
|
|
./logging,
|
2022-05-12 16:04:37 +00:00
|
|
|
./network/wire/portal_protocol_config
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2021-09-29 11:58:55 +00:00
|
|
|
proc defaultDataDir*(): string =
|
2024-02-28 17:31:45 +00:00
|
|
|
let dataDir =
|
|
|
|
when defined(windows):
|
|
|
|
"AppData" / "Roaming" / "Fluffy"
|
|
|
|
elif defined(macosx):
|
|
|
|
"Library" / "Application Support" / "Fluffy"
|
|
|
|
else:
|
|
|
|
".cache" / "fluffy"
|
2021-09-29 11:58:55 +00:00
|
|
|
|
|
|
|
getHomeDir() / dataDir
|
|
|
|
|
2021-06-16 19:18:45 +00:00
|
|
|
const
|
2023-11-10 18:38:11 +00:00
|
|
|
defaultListenAddress* = (static parseIpAddress("0.0.0.0"))
|
|
|
|
defaultAdminListenAddress* = (static parseIpAddress("127.0.0.1"))
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2021-12-08 10:54:22 +00:00
|
|
|
defaultListenAddressDesc = $defaultListenAddress
|
|
|
|
defaultAdminListenAddressDesc = $defaultAdminListenAddress
|
|
|
|
defaultDataDirDesc = defaultDataDir()
|
2023-11-10 16:16:15 +00:00
|
|
|
defaultStorageCapacity* = 2000'u32 # 2 GB default
|
|
|
|
defaultStorageCapacityDesc* = $defaultStorageCapacity
|
2021-09-29 11:58:55 +00:00
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultTableIpLimitDesc* = $defaultPortalProtocolConfig.tableIpLimits.tableIpLimit
|
|
|
|
defaultBucketIpLimitDesc* = $defaultPortalProtocolConfig.tableIpLimits.bucketIpLimit
|
|
|
|
defaultBitsPerHopDesc* = $defaultPortalProtocolConfig.bitsPerHop
|
2024-09-25 07:15:20 +00:00
|
|
|
defaultMaxGossipNodesDesc* = $defaultPortalProtocolConfig.maxGossipNodes
|
2024-09-25 14:44:46 +00:00
|
|
|
defaultRpcApis* = @["eth", "portal"]
|
|
|
|
defaultRpcApisDesc* = "eth,portal"
|
2023-01-02 15:37:22 +00:00
|
|
|
|
2021-06-16 19:18:45 +00:00
|
|
|
type
|
2024-09-25 14:44:46 +00:00
|
|
|
RpcFlag* {.pure.} = enum
|
|
|
|
eth
|
|
|
|
debug
|
|
|
|
portal
|
|
|
|
portal_debug
|
|
|
|
discovery
|
|
|
|
|
2022-12-27 14:57:10 +00:00
|
|
|
TrustedDigest* = MDigest[32 * 8]
|
|
|
|
|
2021-06-16 19:18:45 +00:00
|
|
|
PortalCmd* = enum
|
|
|
|
noCommand
|
|
|
|
|
|
|
|
PortalConf* = object
|
|
|
|
logLevel* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Sets the log level for process and topics (e.g. \"DEBUG; TRACE:discv5,portal_wire; REQUIRED:none; DISABLED:none\")",
|
|
|
|
defaultValue: "INFO",
|
|
|
|
name: "log-level"
|
|
|
|
.}: string
|
2023-04-19 15:01:01 +00:00
|
|
|
|
|
|
|
logStdout* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc:
|
|
|
|
"Specifies what kind of logs should be written to stdout (auto, colors, nocolors, json)",
|
|
|
|
defaultValueDesc: "auto",
|
|
|
|
defaultValue: StdoutLogKind.Auto,
|
|
|
|
name: "log-format"
|
|
|
|
.}: StdoutLogKind
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
udpPort* {.defaultValue: 9009, desc: "UDP listening port", name: "udp-port".}:
|
|
|
|
uint16
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
listenAddress* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: defaultListenAddress,
|
|
|
|
defaultValueDesc: $defaultListenAddressDesc,
|
|
|
|
desc: "Listening address for the Discovery v5 traffic",
|
|
|
|
name: "listen-address"
|
|
|
|
.}: IpAddress
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-06-18 07:32:57 +00:00
|
|
|
network* {.
|
2022-03-17 17:39:24 +00:00
|
|
|
desc:
|
2023-01-02 15:37:22 +00:00
|
|
|
"Select which Portal network to join. This will set the " &
|
2024-03-05 12:45:48 +00:00
|
|
|
"Portal network specific bootstrap nodes automatically",
|
2024-05-22 15:10:31 +00:00
|
|
|
defaultValue: PortalNetwork.mainnet,
|
2024-06-18 07:32:57 +00:00
|
|
|
name: "network"
|
2024-02-28 17:31:45 +00:00
|
|
|
.}: PortalNetwork
|
2022-03-17 17:39:24 +00:00
|
|
|
|
2024-06-18 07:32:57 +00:00
|
|
|
portalSubnetworks* {.
|
2024-03-05 12:45:48 +00:00
|
|
|
desc: "Select which networks (Portal sub-protocols) to enable",
|
2024-10-30 22:26:49 +00:00
|
|
|
defaultValue:
|
|
|
|
{PortalSubnetwork.history, PortalSubnetwork.state, PortalSubnetwork.beacon},
|
2024-06-18 07:32:57 +00:00
|
|
|
name: "portal-subnetworks"
|
|
|
|
.}: set[PortalSubnetwork]
|
2024-03-05 12:45:48 +00:00
|
|
|
|
2021-12-13 08:06:29 +00:00
|
|
|
# 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.
|
2021-11-24 11:12:25 +00:00
|
|
|
bootstrapNodes* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"ENR URI of node to bootstrap Discovery v5 and the Portal networks from. Argument may be repeated",
|
|
|
|
name: "bootstrap-node"
|
|
|
|
.}: seq[Record]
|
2021-11-24 11:12:25 +00:00
|
|
|
|
|
|
|
bootstrapNodesFile* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Specifies a line-delimited file of ENR URIs to bootstrap Discovery v5 and Portal networks from",
|
|
|
|
defaultValue: "",
|
|
|
|
name: "bootstrap-file"
|
|
|
|
.}: InputFile
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
nat* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Specify method to use for determining public address. " &
|
|
|
|
"Must be one of: any, none, upnp, pmp, extip:<IP>",
|
|
|
|
defaultValue: NatConfig(hasExtIp: false, nat: NatAny),
|
|
|
|
defaultValueDesc: "any",
|
|
|
|
name: "nat"
|
|
|
|
.}: NatConfig
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
enrAutoUpdate* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: false,
|
|
|
|
desc:
|
|
|
|
"Discovery can automatically update its ENR with the IP address " &
|
|
|
|
"and UDP port as seen by other nodes it communicates with. " &
|
|
|
|
"This option allows to enable/disable this functionality",
|
|
|
|
name: "enr-auto-update"
|
|
|
|
.}: bool
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2021-09-28 17:58:41 +00:00
|
|
|
dataDir* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc: "The directory where fluffy will store the content data",
|
|
|
|
defaultValue: defaultDataDir(),
|
|
|
|
defaultValueDesc: $defaultDataDirDesc,
|
|
|
|
name: "data-dir"
|
|
|
|
.}: OutDir
|
2021-09-28 17:58:41 +00:00
|
|
|
|
2022-02-17 13:13:39 +00:00
|
|
|
networkKeyFile* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc: "Source of network (secp256k1) private key file",
|
2022-02-17 13:13:39 +00:00
|
|
|
defaultValue: config.dataDir / "netkey",
|
2024-02-28 17:31:45 +00:00
|
|
|
name: "netkey-file"
|
|
|
|
.}: string
|
2022-02-17 13:13:39 +00:00
|
|
|
|
|
|
|
networkKey* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
2022-02-17 13:13:39 +00:00
|
|
|
desc: "Private key (secp256k1) for the p2p network, hex encoded.",
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: none(PrivateKey),
|
|
|
|
defaultValueDesc: "none",
|
|
|
|
name: "netkey-unsafe"
|
|
|
|
.}: Option[PrivateKey]
|
2022-02-17 13:13:39 +00:00
|
|
|
|
2022-08-01 19:00:21 +00:00
|
|
|
accumulatorFile* {.
|
|
|
|
desc:
|
2022-10-17 18:38:51 +00:00
|
|
|
"Get the master accumulator snapshot from a file containing an " &
|
2024-02-28 17:31:45 +00:00
|
|
|
"pre-build SSZ encoded master accumulator.",
|
|
|
|
defaultValue: none(InputFile),
|
|
|
|
defaultValueDesc: "none",
|
|
|
|
name: "accumulator-file"
|
|
|
|
.}: Option[InputFile]
|
2022-08-01 19:00:21 +00:00
|
|
|
|
2021-06-16 19:18:45 +00:00
|
|
|
metricsEnabled* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: false, desc: "Enable the metrics server", name: "metrics"
|
|
|
|
.}: bool
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
metricsAddress* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: defaultAdminListenAddress,
|
|
|
|
defaultValueDesc: $defaultAdminListenAddressDesc,
|
|
|
|
desc: "Listening address of the metrics server",
|
|
|
|
name: "metrics-address"
|
|
|
|
.}: IpAddress
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
metricsPort* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: 8008,
|
|
|
|
desc: "Listening HTTP port of the metrics server",
|
|
|
|
name: "metrics-port"
|
|
|
|
.}: Port
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-09-18 13:27:24 +00:00
|
|
|
rpcEnabled* {.
|
|
|
|
desc: "Enable the HTTP JSON-RPC server", defaultValue: false, name: "rpc"
|
|
|
|
.}: bool
|
2021-06-16 19:18:45 +00:00
|
|
|
|
|
|
|
rpcAddress* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc: "Listening address of the RPC server",
|
|
|
|
defaultValue: defaultAdminListenAddress,
|
|
|
|
defaultValueDesc: $defaultAdminListenAddressDesc,
|
|
|
|
name: "rpc-address"
|
|
|
|
.}: IpAddress
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-09-25 14:44:46 +00:00
|
|
|
rpcPort* {.
|
|
|
|
desc: "Port for the HTTP JSON-RPC server", defaultValue: 8545, name: "rpc-port"
|
|
|
|
.}: Port
|
|
|
|
|
|
|
|
rpcApi* {.
|
|
|
|
desc:
|
|
|
|
"Enable specific set of RPC APIs (available: eth, debug, portal, portal_debug, discovery)",
|
|
|
|
defaultValue: defaultRpcApis,
|
|
|
|
defaultValueDesc: $defaultRpcApisDesc,
|
|
|
|
name: "rpc-api"
|
|
|
|
.}: seq[string]
|
|
|
|
|
2024-09-18 13:27:24 +00:00
|
|
|
wsEnabled* {.
|
|
|
|
desc: "Enable the WebSocket JSON-RPC server", defaultValue: false, name: "ws"
|
|
|
|
.}: bool
|
|
|
|
|
|
|
|
wsPort* {.
|
|
|
|
desc: "Port for the WebSocket JSON-RPC server",
|
|
|
|
defaultValue: 8546,
|
|
|
|
name: "ws-port"
|
|
|
|
.}: Port
|
|
|
|
|
|
|
|
wsCompression* {.
|
|
|
|
desc: "Enable compression for the WebSocket JSON-RPC server",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "ws-compression"
|
|
|
|
.}: bool
|
|
|
|
|
2022-01-18 08:01:22 +00:00
|
|
|
tableIpLimit* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc:
|
|
|
|
"Maximum amount of nodes with the same IP in the routing table. " &
|
|
|
|
"This option is currently required as many nodes are running from " &
|
2024-07-10 15:26:30 +00:00
|
|
|
"the same machines. The option might be removed/adjusted in the future",
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: defaultPortalProtocolConfig.tableIpLimits.tableIpLimit,
|
|
|
|
defaultValueDesc: $defaultTableIpLimitDesc,
|
|
|
|
name: "table-ip-limit"
|
|
|
|
.}: uint
|
2022-01-18 08:01:22 +00:00
|
|
|
|
|
|
|
bucketIpLimit* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc:
|
|
|
|
"Maximum amount of nodes with the same IP in the routing table's buckets. " &
|
|
|
|
"This option is currently required as many nodes are running from " &
|
2024-07-10 15:26:30 +00:00
|
|
|
"the same machines. The option might be removed/adjusted in the future",
|
2024-02-28 17:31:45 +00:00
|
|
|
defaultValue: defaultPortalProtocolConfig.tableIpLimits.bucketIpLimit,
|
|
|
|
defaultValueDesc: $defaultBucketIpLimitDesc,
|
|
|
|
name: "bucket-ip-limit"
|
|
|
|
.}: uint
|
2022-01-18 08:01:22 +00:00
|
|
|
|
|
|
|
bitsPerHop* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc: "Kademlia's b variable, increase for less hops per lookup",
|
|
|
|
defaultValue: defaultPortalProtocolConfig.bitsPerHop,
|
|
|
|
defaultValueDesc: $defaultBitsPerHopDesc,
|
|
|
|
name: "bits-per-hop"
|
|
|
|
.}: int
|
2022-01-18 08:01:22 +00:00
|
|
|
|
2024-09-25 07:15:20 +00:00
|
|
|
maxGossipNodes* {.
|
|
|
|
hidden,
|
|
|
|
desc: "The maximum number of nodes to send content to during gossip",
|
|
|
|
defaultValue: defaultPortalProtocolConfig.maxGossipNodes,
|
|
|
|
defaultValueDesc: $defaultMaxGossipNodesDesc,
|
|
|
|
name: "max-gossip-nodes"
|
|
|
|
.}: int
|
|
|
|
|
2022-05-12 16:04:37 +00:00
|
|
|
radiusConfig* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Radius configuration for a fluffy node. Radius can be either `dynamic` " &
|
|
|
|
"where the node adjusts the radius based on `storage-size` option, " &
|
|
|
|
"or `static:<logRadius>` where the node has a hardcoded logarithmic radius value. " &
|
|
|
|
"Warning: `static:<logRadius>` disables `storage-size` limits and " &
|
|
|
|
"makes the node store a fraction of the network based on set radius.",
|
|
|
|
defaultValue: defaultRadiusConfig,
|
|
|
|
defaultValueDesc: $defaultRadiusConfigDesc,
|
|
|
|
name: "radius"
|
|
|
|
.}: RadiusConfig
|
2022-05-12 16:04:37 +00:00
|
|
|
|
2022-05-09 15:18:57 +00:00
|
|
|
# TODO maybe it is worth defining minimal storage size and throw error if
|
|
|
|
# value provided is smaller than minimum
|
2023-11-10 16:16:15 +00:00
|
|
|
storageCapacityMB* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Maximum amount (in megabytes) of content which will be stored " &
|
|
|
|
"in the local database.",
|
|
|
|
defaultValue: defaultStorageCapacity,
|
|
|
|
defaultValueDesc: $defaultStorageCapacityDesc,
|
|
|
|
name: "storage-capacity"
|
|
|
|
.}: uint64
|
2022-05-09 15:18:57 +00:00
|
|
|
|
2022-12-27 14:57:10 +00:00
|
|
|
trustedBlockRoot* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
desc:
|
|
|
|
"Recent trusted finalized block root to initialize the consensus light client from. " &
|
|
|
|
"If not provided by the user, portal light client will be disabled.",
|
|
|
|
defaultValue: none(TrustedDigest),
|
|
|
|
name: "trusted-block-root"
|
|
|
|
.}: Option[TrustedDigest]
|
2022-12-27 14:57:10 +00:00
|
|
|
|
2023-11-21 15:16:15 +00:00
|
|
|
forcePrune* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc:
|
|
|
|
"Force the pruning of the database. This should be used when the " &
|
|
|
|
"database is decreased in size, e.g. when a lower static radius " &
|
|
|
|
"or a lower storage capacity is set.",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "force-prune"
|
|
|
|
.}: bool
|
2023-11-21 15:16:15 +00:00
|
|
|
|
2024-10-25 07:15:01 +00:00
|
|
|
contentRequestRetries* {.
|
|
|
|
hidden,
|
|
|
|
desc: "Max number of retries when requesting content over the network.",
|
|
|
|
defaultValue: 1,
|
|
|
|
name: "debug-content-request-retries"
|
|
|
|
.}: uint
|
|
|
|
|
2024-10-16 13:05:39 +00:00
|
|
|
contentCacheSize* {.
|
|
|
|
hidden,
|
|
|
|
desc:
|
|
|
|
"Size of the in memory local content cache. This is the max number " &
|
|
|
|
"of content values that can be stored in the cache.",
|
|
|
|
defaultValue: defaultPortalProtocolConfig.contentCacheSize,
|
|
|
|
name: "content-cache-size"
|
|
|
|
.}: int
|
|
|
|
|
|
|
|
disableContentCache* {.
|
|
|
|
hidden,
|
|
|
|
desc: "Disable the in memory local content cache",
|
|
|
|
defaultValue: defaultPortalProtocolConfig.disableContentCache,
|
|
|
|
name: "disable-content-cache"
|
|
|
|
.}: bool
|
|
|
|
|
2023-08-30 08:01:00 +00:00
|
|
|
disablePoke* {.
|
2024-02-28 17:31:45 +00:00
|
|
|
hidden,
|
|
|
|
desc: "Disable POKE functionality for gossip mechanisms testing",
|
|
|
|
defaultValue: defaultDisablePoke,
|
|
|
|
defaultValueDesc: $defaultDisablePoke,
|
|
|
|
name: "disable-poke"
|
|
|
|
.}: bool
|
2023-08-30 08:01:00 +00:00
|
|
|
|
2024-06-11 13:01:35 +00:00
|
|
|
disableStateRootValidation* {.
|
|
|
|
hidden,
|
|
|
|
desc: "Disables state root validation for content received by the state network.",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "disable-state-root-validation"
|
|
|
|
.}: bool
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
case cmd* {.command, defaultValue: noCommand.}: PortalCmd
|
2021-06-16 19:18:45 +00:00
|
|
|
of noCommand:
|
|
|
|
discard
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
func parseCmdArg*(T: type TrustedDigest, input: string): T {.raises: [ValueError].} =
|
2022-12-27 14:57:10 +00:00
|
|
|
TrustedDigest.fromHex(input)
|
|
|
|
|
|
|
|
func completeCmdArg*(T: type TrustedDigest, input: string): seq[string] =
|
|
|
|
return @[]
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} =
|
2024-06-27 15:59:08 +00:00
|
|
|
let res = enr.Record.fromURI(p)
|
|
|
|
if res.isErr():
|
|
|
|
raise newException(ValueError, "Invalid ENR: " & $res.error)
|
|
|
|
res.value
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
proc completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
2021-06-16 19:18:45 +00:00
|
|
|
return @[]
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
proc parseCmdArg*(T: type Node, p: string): T {.raises: [ValueError].} =
|
2024-06-27 15:59:08 +00:00
|
|
|
let res = enr.Record.fromURI(p)
|
|
|
|
if res.isErr():
|
|
|
|
raise newException(ValueError, "Invalid ENR: " & $res.error)
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-06-27 15:59:08 +00:00
|
|
|
let n = Node.fromRecord(res.value)
|
|
|
|
if n.address.isNone():
|
2023-08-04 12:43:30 +00:00
|
|
|
raise newException(ValueError, "ENR without address")
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2024-06-27 15:59:08 +00:00
|
|
|
n
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
proc completeCmdArg*(T: type Node, val: string): seq[string] =
|
2021-06-16 19:18:45 +00:00
|
|
|
return @[]
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
proc parseCmdArg*(T: type PrivateKey, p: string): T {.raises: [ValueError].} =
|
2021-06-16 19:18:45 +00:00
|
|
|
try:
|
2023-01-31 12:38:08 +00:00
|
|
|
result = PrivateKey.fromHex(p).tryGet()
|
2021-06-16 19:18:45 +00:00
|
|
|
except CatchableError:
|
2023-08-04 12:43:30 +00:00
|
|
|
raise newException(ValueError, "Invalid private key")
|
2021-06-16 19:18:45 +00:00
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
proc completeCmdArg*(T: type PrivateKey, val: string): seq[string] =
|
2021-06-16 19:18:45 +00:00
|
|
|
return @[]
|
2021-08-05 06:14:25 +00:00
|
|
|
|
2024-06-18 07:32:57 +00:00
|
|
|
proc parseCmdArg*(
|
|
|
|
T: type set[PortalSubnetwork], p: string
|
|
|
|
): T {.raises: [ValueError].} =
|
|
|
|
var res: set[PortalSubnetwork] = {}
|
2024-03-05 12:45:48 +00:00
|
|
|
let values = p.split({' ', ','})
|
|
|
|
for value in values:
|
|
|
|
let stripped = value.strip()
|
|
|
|
let network =
|
|
|
|
try:
|
2024-06-18 07:32:57 +00:00
|
|
|
parseEnum[PortalSubnetwork](stripped)
|
2024-03-05 12:45:48 +00:00
|
|
|
except ValueError:
|
|
|
|
raise newException(ValueError, "Invalid network: " & stripped)
|
|
|
|
|
|
|
|
res.incl(network)
|
|
|
|
res
|
|
|
|
|
2024-06-18 07:32:57 +00:00
|
|
|
proc completeCmdArg*(T: type set[PortalSubnetwork], val: string): seq[string] =
|
2024-03-05 12:45:48 +00:00
|
|
|
return @[]
|
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
chronicles.formatIt(InputDir):
|
|
|
|
$it
|
|
|
|
chronicles.formatIt(OutDir):
|
|
|
|
$it
|
|
|
|
chronicles.formatIt(InputFile):
|
|
|
|
$it
|
2024-09-25 14:44:46 +00:00
|
|
|
|
|
|
|
func processList(v: string, o: var seq[string]) =
|
|
|
|
## Process comma-separated list of strings.
|
|
|
|
if len(v) > 0:
|
|
|
|
for n in v.split({' ', ','}):
|
|
|
|
if len(n) > 0:
|
|
|
|
o.add(n)
|
|
|
|
|
|
|
|
iterator repeatingList(listOfList: openArray[string]): string =
|
|
|
|
for strList in listOfList:
|
|
|
|
var list = newSeq[string]()
|
|
|
|
processList(strList, list)
|
|
|
|
for item in list:
|
|
|
|
yield item
|
|
|
|
|
|
|
|
proc getRpcFlags*(rpcApis: openArray[string]): set[RpcFlag] =
|
|
|
|
if rpcApis.len == 0:
|
|
|
|
error "No RPC APIs specified"
|
|
|
|
quit QuitFailure
|
|
|
|
|
|
|
|
var rpcFlags: set[RpcFlag]
|
|
|
|
for apiStr in rpcApis.repeatingList():
|
|
|
|
case apiStr.toLowerAscii()
|
|
|
|
of "eth":
|
|
|
|
rpcFlags.incl RpcFlag.eth
|
|
|
|
of "debug":
|
|
|
|
rpcFlags.incl RpcFlag.debug
|
|
|
|
of "portal":
|
|
|
|
rpcFlags.incl RpcFlag.portal
|
|
|
|
of "portal_debug":
|
|
|
|
rpcFlags.incl RpcFlag.portal_debug
|
|
|
|
of "discovery":
|
|
|
|
rpcFlags.incl RpcFlag.discovery
|
|
|
|
else:
|
|
|
|
error "Unknown RPC API: ", name = apiStr
|
|
|
|
quit QuitFailure
|
|
|
|
|
|
|
|
rpcFlags
|