Skip to content

Commit 06ba228

Browse files
authored
fix issue #5665 (#5671)
1 parent 9c6ba7d commit 06ba228

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

beacon_chain/conf.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{.push raises: [].}
99

1010
import
11-
std/[strutils, os, options, unicode, uri],
11+
std/[options, unicode, uri],
1212
metrics,
1313

1414
chronicles, chronicles/options as chroniclesOptions,
@@ -29,6 +29,8 @@ import
2929
./el/el_conf,
3030
./filepath
3131

32+
from std/os import getHomeDir, parentDir, `/`
33+
from std/strutils import parseBiggestUInt, replace
3234
from fork_choice/fork_choice_types
3335
import ForkChoiceVersion
3436
from consensus_object_pools/block_pools_types_light_client
@@ -56,7 +58,7 @@ const
5658

5759
defaultListenAddressDesc* = $defaultListenAddress
5860
defaultAdminListenAddressDesc* = $defaultAdminListenAddress
59-
defaultBeaconNodeDesc* = $defaultBeaconNode
61+
defaultBeaconNodeDesc = $defaultBeaconNode
6062

6163
when defined(windows):
6264
{.pragma: windowsOnly.}
@@ -1433,7 +1435,7 @@ func defaultFeeRecipient*(conf: AnyConf): Opt[Eth1Address] =
14331435
# https://github.com/nim-lang/Nim/issues/19802
14341436
(static(Opt.none Eth1Address))
14351437

1436-
proc loadJwtSecret*(
1438+
proc loadJwtSecret(
14371439
rng: var HmacDrbgContext,
14381440
dataDir: string,
14391441
jwtSecret: Opt[InputFile],
@@ -1468,7 +1470,7 @@ proc engineApiUrls*(config: BeaconNodeConf): seq[EngineApiUrl] =
14681470
let elUrls = if config.noEl:
14691471
return newSeq[EngineApiUrl]()
14701472
elif config.elUrls.len == 0 and config.web3Urls.len == 0:
1471-
@[defaultEngineApiUrl]
1473+
@[getDefaultEngineApiUrl(config.jwtSecret)]
14721474
else:
14731475
config.elUrls
14741476

beacon_chain/conf_light_client.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ proc engineApiUrls*(config: LightClientConf): seq[EngineApiUrl] =
170170
let elUrls = if config.noEl:
171171
return newSeq[EngineApiUrl]()
172172
elif config.elUrls.len == 0 and config.web3Urls.len == 0:
173-
@[defaultEngineApiUrl]
173+
@[getDefaultEngineApiUrl(config.jwtSecret)]
174174
else:
175175
config.elUrls
176176

beacon_chain/el/el_conf.nim

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

88
import
9-
std/[options, strutils, uri],
9+
std/[options, uri],
1010
stew/results, chronicles, confutils,
1111
confutils/toml/defs as confTomlDefs,
1212
confutils/toml/std/net as confTomlNet,
@@ -15,6 +15,8 @@ import
1515
toml_serialization, toml_serialization/lexer,
1616
../spec/engine_authentication
1717

18+
from std/strutils import toLowerAscii, split, startsWith
19+
1820
export
1921
toml_serialization, confTomlDefs, confTomlNet, confTomlUri
2022

@@ -41,11 +43,7 @@ const
4143
defaultEngineApiRoles* = { DepositSyncing, BlockValidation, BlockProduction }
4244

4345
# https://github.com/ethereum/execution-apis/pull/302
44-
defaultJwtSecret* = "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
45-
46-
defaultEngineApiUrl* = EngineApiUrlConfigValue(
47-
url: "http://127.0.0.1:8551",
48-
jwtSecret: some defaultJwtSecret)
46+
defaultJwtSecret = "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
4947

5048
chronicles.formatIt EngineApiUrl:
5149
it.url
@@ -156,6 +154,19 @@ proc fixupWeb3Urls*(web3Url: var string) =
156154
warn "The Web3 URL does not specify a protocol. Assuming a WebSocket server", web3Url
157155
web3Url = "ws://" & web3Url
158156

157+
func getDefaultEngineApiUrl*(x: Option[InputFile]): EngineApiUrlConfigValue =
158+
EngineApiUrlConfigValue(
159+
url: "http://127.0.0.1:8551",
160+
jwtSecret:
161+
if x.isSome:
162+
# Provided by toFinalUrl() and toFinalEngineApiUrls(); otherwise, if
163+
# defaultJwtSecret is specified here, no-EL-URL-specified cases when
164+
# JWT secret is specified get stuck with defaultJwtSecret regardless
165+
# of being otherwise overridden.
166+
none string
167+
else:
168+
some defaultJwtSecret)
169+
159170
proc toFinalUrl*(confValue: EngineApiUrlConfigValue,
160171
confJwtSecret: Opt[seq[byte]]): Result[EngineApiUrl, cstring] =
161172
if confValue.jwtSecret.isSome and confValue.jwtSecretFile.isSome:

ncli/ncli_testnet.nim

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
import
1111
std/[json, options],
1212
chronos, bearssl/rand, chronicles, confutils, stint, json_serialization,
13-
web3, web3/confutils_defs, eth/keys, eth/p2p/discoveryv5/random2,
13+
web3, eth/keys, eth/p2p/discoveryv5/random2,
1414
stew/[io2, byteutils], json_rpc/jsonmarshal,
15-
../beacon_chain/[conf, filepath],
15+
../beacon_chain/conf,
1616
../beacon_chain/el/el_manager,
1717
../beacon_chain/networking/eth2_network,
18-
../beacon_chain/spec/[beaconstate, eth2_merkleization],
18+
../beacon_chain/spec/eth2_merkleization,
1919
../beacon_chain/spec/datatypes/base,
2020
../beacon_chain/spec/eth2_apis/eth2_rest_serialization,
2121
../beacon_chain/validators/keystore_management,
22-
../tests/mocking/mock_genesis,
2322
./logtrace
2423

2524
from std/os import changeFileExt, fileExists
2625
from std/sequtils import mapIt, toSeq
27-
from std/terminal import readPasswordFromStdin
2826
from std/times import toUnix
27+
from ../beacon_chain/spec/beaconstate import initialize_beacon_state_from_eth1
28+
from ../tests/mocking/mock_genesis import mockEth1BlockHash
2929

3030
# Compiled version of /scripts/depositContract.v.py in this repo
3131
# The contract was compiled in Remix (https://remix.ethereum.org/) with vyper (remote) compiler.
@@ -583,6 +583,12 @@ proc sendDeposits(deposits: seq[LaunchPadDeposit],
583583
{.pop.} # TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
584584

585585
when isMainModule:
586+
import
587+
web3/confutils_defs,
588+
../beacon_chain/filepath
589+
590+
from std/terminal import readPasswordFromStdin
591+
586592
proc main() {.async.} =
587593
var conf = try: CliConfig.load()
588594
except CatchableError as exc:

0 commit comments

Comments
 (0)