Skip to content

Commit b63749d

Browse files
committed
multiple endpoints in config
1 parent 321289c commit b63749d

File tree

3 files changed

+57
-32
lines changed

3 files changed

+57
-32
lines changed

nimbus_verified_proxy/json_lc_backend.nim

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ func new*(
4141
): LCRestClient =
4242
LCRestClient(cfg: cfg, forkDigests: forkDigests, peers: @[])
4343

44-
proc addEndpoint*(client: LCRestClient, endpoint: string) {.raises: [ValueError].} =
45-
if endpoint in client.urls:
46-
raise newException(ValueError, "Endpoint already added")
44+
proc addEndpoints*(client: LCRestClient, urlList: UrlList) {.raises: [ValueError].} =
45+
for endpoint in urlList.urls:
46+
if endpoint in client.urls:
47+
continue
4748

48-
let restClient = RestClientRef.new(endpoint).valueOr:
49-
raise newException(ValueError, $error)
49+
let restClient = RestClientRef.new(endpoint).valueOr:
50+
raise newException(ValueError, $error)
5051

51-
client.peers.add(LCRestPeer(score: 0, restClient: restClient))
52-
client.urls.add(endpoint)
52+
client.peers.add(LCRestPeer(score: 0, restClient: restClient))
53+
client.urls.add(endpoint)
5354

5455
proc closeAll*(client: LCRestClient) {.async: (raises: []).} =
5556
for peer in client.peers:

nimbus_verified_proxy/nimbus_verified_proxy.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ proc run*(
160160
# REST client for json LC updates
161161
lcRestClient = LCRestClient.new(cfg, forkDigests)
162162

163-
debugEcho config.lcEndpoint
164-
165163
# add endpoints to the client
166-
lcRestClient.addEndpoint(config.lcEndpoint)
164+
lcRestClient.addEndpoints(config.lcEndpoints)
167165
lightClient.setBackend(lcRestClient.getEthLCBackend())
168166

169167
# verify chain id that the proxy is connected to

nimbus_verified_proxy/nimbus_verified_proxy_conf.nim

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import
1212
json_rpc/rpcproxy, # must be early (compilation annoyance)
1313
json_serialization/std/net,
1414
beacon_chain/conf_light_client,
15-
beacon_chain/nimbus_binary_common
15+
beacon_chain/nimbus_binary_common,
16+
std/strutils
1617

1718
export net
1819

@@ -25,37 +26,45 @@ type
2526
kind*: Web3UrlKind
2627
web3Url*: string
2728

29+
UrlList* = object
30+
urls*: seq[string]
31+
2832
#!fmt: off
2933
type VerifiedProxyConf* = object
3034
# Config
3135
configFile* {.
32-
desc: "Loads the configuration from a TOML file"
33-
name: "config-file" .}: Option[InputFile]
36+
desc: "Loads the configuration from a TOML file",
37+
name: "config-file"
38+
.}: Option[InputFile]
3439

3540
# Logging
3641
logLevel* {.
37-
desc: "Sets the log level"
38-
defaultValue: "INFO"
39-
name: "log-level" .}: string
42+
desc: "Sets the log level",
43+
defaultValue: "INFO",
44+
name: "log-level"
45+
.}: string
4046

4147
logStdout* {.
42-
hidden
43-
desc: "Specifies what kind of logs should be written to stdout (auto, colors, nocolors, json)"
44-
defaultValueDesc: "auto"
45-
defaultValue: StdoutLogKind.Auto
46-
name: "log-format" .}: StdoutLogKind
48+
hidden,
49+
desc: "Specifies what kind of logs should be written to stdout (auto, colors, nocolors, json)",
50+
defaultValueDesc: "auto",
51+
defaultValue: StdoutLogKind.Auto,
52+
name: "log-format"
53+
.}: StdoutLogKind
4754

4855
# Storage
4956
dataDirFlag* {.
50-
desc: "The directory where nimbus will store all blockchain data"
51-
abbr: "d"
52-
name: "data-dir" .}: Option[OutDir]
57+
desc: "The directory where nimbus will store all blockchain data",
58+
abbr: "d",
59+
name: "data-dir"
60+
.}: Option[OutDir]
5361

5462
# Network
5563
eth2Network* {.
56-
desc: "The Eth2 network to join"
57-
defaultValueDesc: "mainnet"
58-
name: "network" .}: Option[string]
64+
desc: "The Eth2 network to join",
65+
defaultValueDesc: "mainnet",
66+
name: "network"
67+
.}: Option[string]
5968

6069
accountCacheLen* {.
6170
hidden,
@@ -95,8 +104,9 @@ type VerifiedProxyConf* = object
95104
# Consensus light sync
96105
# No default - Needs to be provided by the user
97106
trustedBlockRoot* {.
98-
desc: "Recent trusted finalized block root to initialize light client from"
99-
name: "trusted-block-root" .}: Eth2Digest
107+
desc: "Recent trusted finalized block root to initialize light client from",
108+
name: "trusted-block-root"
109+
.}: Eth2Digest
100110

101111
# (Untrusted) web3 provider
102112
# No default - Needs to be provided by the user
@@ -116,10 +126,10 @@ type VerifiedProxyConf* = object
116126

117127
# (Untrusted) web3 provider
118128
# No default - Needs to be provided by the user
119-
lcEndpoint* {.
129+
lcEndpoints* {.
120130
desc: "command seperated URLs of the light client data provider",
121-
name: "lc-endpoint"
122-
.}: string
131+
name: "lc-endpoints"
132+
.}: UrlList
123133

124134
#!fmt: on
125135

@@ -137,9 +147,25 @@ proc parseCmdArg*(T: type Web3Url, p: string): T {.raises: [ValueError].} =
137147
ValueError, "Web3 url should have defined scheme (http/https/ws/wss)"
138148
)
139149

150+
proc parseCmdArg*(T: type UrlList, p: string): T {.raises: [ValueError].} =
151+
let urls = p.split(',')
152+
153+
for u in urls:
154+
let
155+
parsed = parseUri(u)
156+
normalizedScheme = parsed.scheme.toLowerAscii()
157+
158+
if not (normalizedScheme == "http" or normalizedScheme == "https"):
159+
raise newException(ValueError, "Light Client Endpoint should be a http(s) url")
160+
161+
UrlList(urls: urls)
162+
140163
proc completeCmdArg*(T: type Web3Url, val: string): seq[string] =
141164
return @[]
142165

166+
proc completeCmdArg*(T: type UrlList, val: string): seq[string] =
167+
return @[]
168+
143169
# TODO: Cannot use ClientConfig in VerifiedProxyConf due to the fact that
144170
# it contain `set[TLSFlags]` which does not have proper toml serialization
145171
func asClientConfig*(url: Web3Url): ClientConfig =

0 commit comments

Comments
 (0)