Skip to content

Commit 6720a0e

Browse files
Port eth2 binary main style to eth1 (#3712)
* Port eth2 binary `main` style to eth1 Making the two projects more similar makes it easier to maintain a cohesive user experience over time: * remove metrics logging - this is not viable for the amount of metrics that we have (no other project has this either) * remove `EthContext` - looks like a refactoring leftover * reuse more `nimbus_binary_common` utilities instead of homegrown versions * bump eth2 * fixes * lint/modules * lint/test * fixes * move import * writePanicLine helper * bump * oops * bump * tests * bump submodules to matching versions * bump * use el version string --------- Co-authored-by: chirag-parmar <chiragparmar12209@gmail.com>
1 parent 49f09d0 commit 6720a0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+283
-401
lines changed

execution_chain/common.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2022 Status Research & Development GmbH
2+
# Copyright (c) 2022-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -10,9 +10,9 @@
1010
import
1111
./common/common,
1212
./common/genesis,
13-
./common/context
13+
./common/manager
1414

1515
export
1616
common,
1717
genesis,
18-
context
18+
manager

execution_chain/common/context.nim

Lines changed: 0 additions & 82 deletions
This file was deleted.

execution_chain/common/manager.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2021-2024 Status Research & Development GmbH
2+
# Copyright (c) 2021-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -27,9 +27,6 @@ type
2727
AccountsManager* = object
2828
accounts: Table[Address, NimbusAccount]
2929

30-
proc init*(_: type AccountsManager): AccountsManager =
31-
discard
32-
3330
proc loadKeystores*(am: var AccountsManager, path: string):
3431
Result[void, string] =
3532
try:

execution_chain/config.nim

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,8 @@ import
3939

4040
export net, defs, jsdefs, jsnet, nimbus_binary_common
4141

42-
const
43-
# e.g.: Copyright (c) 2018-2025 Status Research & Development GmbH
44-
NimbusCopyright* = "Copyright (c) 2018-" &
45-
CompileDate.split('-')[0] &
46-
" Status Research & Development GmbH"
47-
48-
# e.g.:
49-
# nimbus_execution_client/v0.1.0-abcdef/os-cpu/nim-a.b.c/emvc
50-
# Copyright (c) 2018-2025 Status Research & Development GmbH
51-
NimbusBuild* = "$#\p$#" % [
52-
ClientId,
53-
NimbusCopyright,
54-
]
55-
56-
NimbusHeader* = "$#\p\pNim version $#" % [
57-
NimbusBuild,
58-
nimBanner()
59-
]
42+
const NimbusCopyright* =
43+
"Copyright (c) 2018-" & compileYear & " Status Research & Development GmbH"
6044

6145
func getLogLevels(): string =
6246
var logLevels: seq[string]
@@ -196,16 +180,6 @@ type
196180
defaultValue: StdoutLogKind.Auto
197181
name: "log-format" .}: StdoutLogKind
198182

199-
logMetricsEnabled* {.
200-
desc: "Enable metrics logging"
201-
defaultValue: false
202-
name: "log-metrics" .}: bool
203-
204-
logMetricsInterval* {.
205-
desc: "Interval at which to log metrics, in seconds"
206-
defaultValue: 10
207-
name: "log-metrics-interval" .}: int
208-
209183
metricsEnabled* {.
210184
desc: "Enable the built-in metrics HTTP server"
211185
defaultValue: false
@@ -320,7 +294,7 @@ type
320294
separator: "\pPERFORMANCE OPTIONS",
321295
defaultValue: 0,
322296
desc: "Number of worker threads (\"0\" = use as many threads as there are CPU cores available)"
323-
name: "num-threads" .}: uint
297+
name: "num-threads" .}: int
324298

325299
persistBatchSize* {.
326300
hidden
@@ -802,31 +776,10 @@ func dbOptions*(conf: NimbusConf, noKeyCache = false): DbOptions =
802776
# Constructor
803777
#-------------------------------------------------------------------
804778

805-
proc makeConfig*(cmdLine = commandLineParams()): NimbusConf =
779+
proc makeConfig*(cmdLine = commandLineParams(), ignoreUnknown = false): NimbusConf =
806780
## Note: this function is not gc-safe
807-
try:
808-
result = NimbusConf.load(
809-
cmdLine,
810-
version = NimbusBuild,
811-
copyrightBanner = NimbusHeader,
812-
secondarySources = proc (
813-
conf: NimbusConf, sources: ref SecondarySources
814-
) {.raises: [ConfigurationError].} =
815-
if conf.configFile.isSome:
816-
sources.addConfigFile(Toml, conf.configFile.get)
817-
)
818-
except CatchableError as err:
819-
if err[] of ConfigurationError and err.parent != nil:
820-
if err.parent[] of TomlFieldReadingError:
821-
let fieldName = ((ref TomlFieldReadingError)(err.parent)).field
822-
echo "Error when parsing ", fieldName, ": ", err.msg
823-
elif err.parent[] of TomlReaderError:
824-
type TT = ref TomlReaderError
825-
echo TT(err).formatMsg("")
826-
else:
827-
echo "Error when parsing config file: ", err.msg
828-
else:
829-
echo "Error when parsing command line params: ", err.msg
781+
result = NimbusConf.loadWithBanners(ClientId, NimbusCopyright, [], ignoreUnknown, cmdLine).valueOr:
782+
writePanicLine error # Logging not yet set up
830783
quit QuitFailure
831784

832785
processNetworkParamsAndNetworkId(result)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Nimbus
2+
# Copyright (c) 2021-2025 Status Research & Development GmbH
3+
# Licensed under either of
4+
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
5+
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
6+
# at your option.
7+
# This file may not be copied, modified, or distributed except according to
8+
# those terms.
9+
10+
{.push raises: [].}
11+
12+
import std/[strutils, os], stew/[io2, byteutils], results, eth/common/keys
13+
14+
proc containsOnlyHexDigits(hex: string): bool =
15+
const HexDigitsX = HexDigits + {'x'}
16+
for c in hex:
17+
if c notin HexDigitsX:
18+
return false
19+
true
20+
21+
proc getNetKeys*(rng: var HmacDrbgContext, netKey: string): Result[KeyPair, string] =
22+
let privateKey =
23+
if netKey.len == 0 or netKey == "random":
24+
PrivateKey.random(rng)
25+
elif netKey.len in {64, 66} and netKey.containsOnlyHexDigits:
26+
PrivateKey.fromHex(netKey).valueOr:
27+
return err($error)
28+
else:
29+
# TODO: should we secure the private key with
30+
# keystore encryption?
31+
if fileAccessible(netKey, {AccessFlags.Find}):
32+
try:
33+
let lines = netKey.readLines(1)
34+
if lines.len == 0:
35+
return err("empty network key file")
36+
PrivateKey.fromHex(lines[0]).valueOr:
37+
return err($error)
38+
except IOError as e:
39+
return err("cannot open network key file: " & e.msg)
40+
else:
41+
let privateKey = PrivateKey.random(rng)
42+
43+
try:
44+
createDir(netKey.splitFile.dir)
45+
netKey.writeFile(privateKey.toRaw.to0xHex)
46+
except OSError as e:
47+
return err("could not create network key file: " & e.msg)
48+
except IOError as e:
49+
return err("could not write network key file: " & e.msg)
50+
51+
privateKey
52+
ok privateKey.toKeyPair()

execution_chain/nimbus_desc.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ type
4545
httpServer*: NimbusHttpServerRef
4646
engineApiServer*: NimbusHttpServerRef
4747
ethNode*: EthereumNode
48-
ctx*: EthContext
4948
fc*: ForkedChainRef
5049
txPool*: TxPoolRef
5150
peerManager*: PeerManagerRef
5251
beaconSyncRef*: BeaconSyncRef
5352
beaconEngine*: BeaconEngineRef
54-
metricsServer*: MetricsHttpServerRef
5553
wire*: EthWireRef
54+
accountsManager*: ref AccountsManager
55+
rng*: ref HmacDrbgContext
5656

5757
proc closeWait*(nimbus: NimbusNode) {.async.} =
5858
trace "Graceful shutdown"
@@ -67,8 +67,6 @@ proc closeWait*(nimbus: NimbusNode) {.async.} =
6767
waitedFutures.add nimbus.peerManager.stop()
6868
if nimbus.beaconSyncRef.isNil.not:
6969
waitedFutures.add nimbus.beaconSyncRef.stop()
70-
if nimbus.metricsServer.isNil.not:
71-
waitedFutures.add nimbus.metricsServer.stop()
7270
if nimbus.wire.isNil.not:
7371
waitedFutures.add nimbus.wire.stop()
7472

0 commit comments

Comments
 (0)