-
Notifications
You must be signed in to change notification settings - Fork 107
/
nimbus_verified_proxy_conf.nim
227 lines (193 loc) · 6.85 KB
/
nimbus_verified_proxy_conf.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# nimbus_verified_proxy
# Copyright (c) 2022-2024 Status Research & Development GmbH
# 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.
{.push raises: [].}
import
std/os,
json_rpc/rpcproxy, # must be early (compilation annoyance)
json_serialization/std/net,
beacon_chain/conf_light_client,
beacon_chain/conf
export net, conf
proc defaultVerifiedProxyDataDir*(): string =
let dataDir =
when defined(windows):
"AppData" / "Roaming" / "NimbusVerifiedProxy"
elif defined(macosx):
"Library" / "Application Support" / "NimbusVerifiedProxy"
else:
".cache" / "nimbus-verified-proxy"
getHomeDir() / dataDir
const defaultDataVerifiedProxyDirDesc* = defaultVerifiedProxyDataDir()
type
Web3UrlKind* = enum
HttpUrl
WsUrl
Web3Url* = object
kind*: Web3UrlKind
web3Url*: string
type VerifiedProxyConf* = object # Config
configFile* {.desc: "Loads the configuration from a TOML file", name: "config-file".}:
Option[InputFile]
# Logging
logLevel* {.desc: "Sets the log level", defaultValue: "INFO", name: "log-level".}:
string
logStdout* {.
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
# Storage
dataDir* {.
desc: "The directory where nimbus_verified_proxy will store all data",
defaultValue: defaultVerifiedProxyDataDir(),
defaultValueDesc: $defaultDataVerifiedProxyDirDesc,
abbr: "d",
name: "data-dir"
.}: OutDir
# Network
eth2Network* {.
desc: "The Eth2 network to join", defaultValueDesc: "mainnet", name: "network"
.}: Option[string]
# Consensus light sync
# No default - Needs to be provided by the user
trustedBlockRoot* {.
desc:
"Recent trusted finalized block root to initialize the consensus light client from",
name: "trusted-block-root"
.}: Eth2Digest
# (Untrusted) web3 provider
# No default - Needs to be provided by the user
web3url* {.desc: "URL of the web3 data provider", name: "web3-url".}: Web3Url
# Local JSON-RPC server
rpcAddress* {.
desc: "Listening address of the JSON-RPC server",
defaultValue: defaultAdminListenAddress,
defaultValueDesc: $defaultAdminListenAddressDesc,
name: "rpc-address"
.}: IpAddress
rpcPort* {.
desc: "Listening port of the JSON-RPC server", defaultValue: 8545, name: "rpc-port"
.}: Port
# Libp2p
bootstrapNodes* {.
desc: "Specifies one or more bootstrap nodes to use when connecting to the network",
abbr: "b",
name: "bootstrap-node"
.}: seq[string]
bootstrapNodesFile* {.
desc: "Specifies a line-delimited file of bootstrap Ethereum network addresses",
defaultValue: "",
name: "bootstrap-file"
.}: InputFile
listenAddress* {.
desc: "Listening address for the Ethereum LibP2P and Discovery v5 traffic",
name: "listen-address"
.}: Option[IpAddress]
tcpPort* {.
desc: "Listening TCP port for Ethereum LibP2P traffic",
defaultValue: defaultEth2TcpPort,
defaultValueDesc: $defaultEth2TcpPortDesc,
name: "tcp-port"
.}: Port
udpPort* {.
desc: "Listening UDP port for node discovery",
defaultValue: defaultEth2TcpPort,
defaultValueDesc: $defaultEth2TcpPortDesc,
name: "udp-port"
.}: Port
# TODO: Select a lower amount of peers.
maxPeers* {.
desc: "The target number of peers to connect to",
defaultValue: 160, # 5 (fanout) * 64 (subnets) / 2 (subs) for a healthy mesh
name: "max-peers"
.}: int
hardMaxPeers* {.
desc: "The maximum number of peers to connect to. Defaults to maxPeers * 1.5",
name: "hard-max-peers"
.}: Option[int]
nat* {.
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
enrAutoUpdate* {.
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",
defaultValue: false,
name: "enr-auto-update"
.}: bool
agentString* {.
defaultValue: "nimbus",
desc: "Node agent string which is used as identifier in the LibP2P network",
name: "agent-string"
.}: string
discv5Enabled* {.desc: "Enable Discovery v5", defaultValue: true, name: "discv5".}:
bool
directPeers* {.
desc:
"The list of priviledged, secure and known peers to connect and" &
"maintain the connection to, this requires a not random netkey-file." &
"In the complete multiaddress format like:" &
"/ip4/<address>/tcp/<port>/p2p/<peerId-public-key>." &
"Peering agreements are established out of band and must be reciprocal",
name: "direct-peer"
.}: seq[string]
proc parseCmdArg*(T: type Web3Url, p: string): T {.raises: [ValueError].} =
let
url = parseUri(p)
normalizedScheme = url.scheme.toLowerAscii()
if (normalizedScheme == "http" or normalizedScheme == "https"):
Web3Url(kind: HttpUrl, web3Url: p)
elif (normalizedScheme == "ws" or normalizedScheme == "wss"):
Web3Url(kind: WsUrl, web3Url: p)
else:
raise newException(
ValueError, "Web3 url should have defined scheme (http/https/ws/wss)"
)
proc completeCmdArg*(T: type Web3Url, val: string): seq[string] =
return @[]
func asLightClientConf*(pc: VerifiedProxyConf): LightClientConf =
return LightClientConf(
configFile: pc.configFile,
logLevel: pc.logLevel,
logStdout: pc.logStdout,
logFile: none(OutFile),
dataDir: pc.dataDir,
eth2Network: pc.eth2Network,
bootstrapNodes: pc.bootstrapNodes,
bootstrapNodesFile: pc.bootstrapNodesFile,
listenAddress: pc.listenAddress,
tcpPort: pc.tcpPort,
udpPort: pc.udpPort,
maxPeers: pc.maxPeers,
hardMaxPeers: pc.hardMaxPeers,
nat: pc.nat,
enrAutoUpdate: pc.enrAutoUpdate,
agentString: pc.agentString,
discv5Enabled: pc.discv5Enabled,
directPeers: pc.directPeers,
trustedBlockRoot: pc.trustedBlockRoot,
web3Urls: @[EngineApiUrlConfigValue(url: pc.web3url.web3Url)],
jwtSecret: none(InputFile),
stopAtEpoch: 0,
)
# TODO: Cannot use ClientConfig in VerifiedProxyConf due to the fact that
# it contain `set[TLSFlags]` which does not have proper toml serialization
func asClientConfig*(url: Web3Url): ClientConfig =
case url.kind
of HttpUrl:
getHttpClientConfig(url.web3Url)
of WsUrl:
getWebSocketClientConfig(url.web3Url, flags = {})