Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions execution_chain/common.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2022 Status Research & Development GmbH
# Copyright (c) 2022-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand All @@ -10,9 +10,9 @@
import
./common/common,
./common/genesis,
./common/context
./common/manager

export
common,
genesis,
context
manager
82 changes: 0 additions & 82 deletions execution_chain/common/context.nim

This file was deleted.

5 changes: 1 addition & 4 deletions execution_chain/common/manager.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Copyright (c) 2021-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -27,9 +27,6 @@ type
AccountsManager* = object
accounts: Table[Address, NimbusAccount]

proc init*(_: type AccountsManager): AccountsManager =
discard

proc loadKeystores*(am: var AccountsManager, path: string):
Result[void, string] =
try:
Expand Down
59 changes: 6 additions & 53 deletions execution_chain/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,8 @@ import

export net, defs, jsdefs, jsnet, nimbus_binary_common

const
# e.g.: Copyright (c) 2018-2025 Status Research & Development GmbH
NimbusCopyright* = "Copyright (c) 2018-" &
CompileDate.split('-')[0] &
" Status Research & Development GmbH"

# e.g.:
# nimbus_execution_client/v0.1.0-abcdef/os-cpu/nim-a.b.c/emvc
# Copyright (c) 2018-2025 Status Research & Development GmbH
NimbusBuild* = "$#\p$#" % [
ClientId,
NimbusCopyright,
]

NimbusHeader* = "$#\p\pNim version $#" % [
NimbusBuild,
nimBanner()
]
const NimbusCopyright* =
"Copyright (c) 2018-" & compileYear & " Status Research & Development GmbH"

func getLogLevels(): string =
var logLevels: seq[string]
Expand Down Expand Up @@ -196,16 +180,6 @@ type
defaultValue: StdoutLogKind.Auto
name: "log-format" .}: StdoutLogKind

logMetricsEnabled* {.
desc: "Enable metrics logging"
defaultValue: false
name: "log-metrics" .}: bool

logMetricsInterval* {.
desc: "Interval at which to log metrics, in seconds"
defaultValue: 10
name: "log-metrics-interval" .}: int

metricsEnabled* {.
desc: "Enable the built-in metrics HTTP server"
defaultValue: false
Expand Down Expand Up @@ -320,7 +294,7 @@ type
separator: "\pPERFORMANCE OPTIONS",
defaultValue: 0,
desc: "Number of worker threads (\"0\" = use as many threads as there are CPU cores available)"
name: "num-threads" .}: uint
name: "num-threads" .}: int

persistBatchSize* {.
hidden
Expand Down Expand Up @@ -802,31 +776,10 @@ func dbOptions*(conf: NimbusConf, noKeyCache = false): DbOptions =
# Constructor
#-------------------------------------------------------------------

proc makeConfig*(cmdLine = commandLineParams()): NimbusConf =
proc makeConfig*(cmdLine = commandLineParams(), ignoreUnknown = false): NimbusConf =
## Note: this function is not gc-safe
try:
result = NimbusConf.load(
cmdLine,
version = NimbusBuild,
copyrightBanner = NimbusHeader,
secondarySources = proc (
conf: NimbusConf, sources: ref SecondarySources
) {.raises: [ConfigurationError].} =
if conf.configFile.isSome:
sources.addConfigFile(Toml, conf.configFile.get)
)
except CatchableError as err:
if err[] of ConfigurationError and err.parent != nil:
if err.parent[] of TomlFieldReadingError:
let fieldName = ((ref TomlFieldReadingError)(err.parent)).field
echo "Error when parsing ", fieldName, ": ", err.msg
elif err.parent[] of TomlReaderError:
type TT = ref TomlReaderError
echo TT(err).formatMsg("")
else:
echo "Error when parsing config file: ", err.msg
else:
echo "Error when parsing command line params: ", err.msg
result = NimbusConf.loadWithBanners(ClientId, NimbusCopyright, [], ignoreUnknown, cmdLine).valueOr:
writePanicLine error # Logging not yet set up
quit QuitFailure

processNetworkParamsAndNetworkId(result)
Expand Down
12 changes: 11 additions & 1 deletion execution_chain/core/chain/forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ proc updateBase(c: ForkedChainRef, base: BlockRef): uint =
# No update, return
return

block:
# Write block contents to txFrame at the last moment - otherwise, they would
# stay both in BlockRef and TxFrame memory
# TODO probably makes sense to do it the other way around, removing blk
# from BlockRef
var blk = base
while blk.isOk:
c.writeBaggage(blk.blk, blk.hash, blk.txFrame, blk.receipts)
blk = blk.parent

# State root sanity check is performed to verify, before writing to disk,
# that optimistically checked blocks indeed end up being stored with a
# consistent state root.
Expand Down Expand Up @@ -484,7 +494,7 @@ proc validateBlock(c: ForkedChainRef,
# Update the snapshot before processing the block so that any vertexes in snapshots
# from lower levels than the baseTxFrame are removed from the snapshot before running
# the stateroot computation.
c.updateSnapshot(blk, txFrame)
c.updateSnapshot(blk.header.number, txFrame)

var receipts = c.processBlock(parent, txFrame, blk, blkHash, finalized).valueOr:
txFrame.dispose()
Expand Down
6 changes: 3 additions & 3 deletions execution_chain/core/chain/forked_chain/chain_private.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ proc writeBaggage*(c: ForkedChainRef,
header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"),
blk.withdrawals.get)

template updateSnapshot*(c: ForkedChainRef,
blk: Block,
proc updateSnapshot*(c: ForkedChainRef,
number: BlockNumber,
txFrame: CoreDbTxRef) =
let pos = c.lastSnapshotPos
c.lastSnapshotPos = (c.lastSnapshotPos + 1) mod c.lastSnapshots.len
Expand All @@ -51,7 +51,7 @@ template updateSnapshot*(c: ForkedChainRef,
# Checkpoint creates a snapshot of ancestor changes in txFrame - it is an
# expensive operation, specially when creating a new branch (ie when blk
# is being applied to a block that is currently not a head)
txFrame.checkpoint(blk.header.number)
txFrame.checkpoint(number)

c.lastSnapshots[pos] = txFrame

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ proc replayBlock(fc: ForkedChainRef;
# Update the snapshot before processing the block so that any vertexes in snapshots
# from lower levels than the baseTxFrame are removed from the snapshot before running
# the stateroot computation.
fc.updateSnapshot(blk.blk, txFrame)
fc.updateSnapshot(blk.blk.header.number, txFrame)

var receipts = fc.processBlock(parent, txFrame, blk.blk, blk.hash, false).valueOr:
txFrame.dispose()
Expand Down
52 changes: 52 additions & 0 deletions execution_chain/networking/netkeys.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Nimbus
# Copyright (c) 2021-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.

{.push raises: [].}

import std/[strutils, os], stew/[io2, byteutils], results, eth/common/keys

proc containsOnlyHexDigits(hex: string): bool =
const HexDigitsX = HexDigits + {'x'}
for c in hex:
if c notin HexDigitsX:
return false
true

proc getNetKeys*(rng: var HmacDrbgContext, netKey: string): Result[KeyPair, string] =
let privateKey =
if netKey.len == 0 or netKey == "random":
PrivateKey.random(rng)
elif netKey.len in {64, 66} and netKey.containsOnlyHexDigits:
PrivateKey.fromHex(netKey).valueOr:
return err($error)
else:
# TODO: should we secure the private key with
# keystore encryption?
if fileAccessible(netKey, {AccessFlags.Find}):
try:
let lines = netKey.readLines(1)
if lines.len == 0:
return err("empty network key file")
PrivateKey.fromHex(lines[0]).valueOr:
return err($error)
except IOError as e:
return err("cannot open network key file: " & e.msg)
else:
let privateKey = PrivateKey.random(rng)

try:
createDir(netKey.splitFile.dir)
netKey.writeFile(privateKey.toRaw.to0xHex)
except OSError as e:
return err("could not create network key file: " & e.msg)
except IOError as e:
return err("could not write network key file: " & e.msg)

privateKey
ok privateKey.toKeyPair()
6 changes: 2 additions & 4 deletions execution_chain/nimbus_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ type
httpServer*: NimbusHttpServerRef
engineApiServer*: NimbusHttpServerRef
ethNode*: EthereumNode
ctx*: EthContext
fc*: ForkedChainRef
txPool*: TxPoolRef
peerManager*: PeerManagerRef
beaconSyncRef*: BeaconSyncRef
beaconEngine*: BeaconEngineRef
metricsServer*: MetricsHttpServerRef
wire*: EthWireRef
accountsManager*: ref AccountsManager
rng*: ref HmacDrbgContext

proc closeWait*(nimbus: NimbusNode) {.async.} =
trace "Graceful shutdown"
Expand All @@ -67,8 +67,6 @@ proc closeWait*(nimbus: NimbusNode) {.async.} =
waitedFutures.add nimbus.peerManager.stop()
if nimbus.beaconSyncRef.isNil.not:
waitedFutures.add nimbus.beaconSyncRef.stop()
if nimbus.metricsServer.isNil.not:
waitedFutures.add nimbus.metricsServer.stop()
if nimbus.wire.isNil.not:
waitedFutures.add nimbus.wire.stop()

Expand Down
Loading
Loading