Skip to content

Commit

Permalink
added json chronicles logging support
Browse files Browse the repository at this point in the history
 for some eth, web3 and confutils types
  • Loading branch information
Pedro Miranda committed Jan 24, 2025
1 parent 0310cbf commit 1ab736e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
4 changes: 3 additions & 1 deletion nimbus/common/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import
chronicles,
logging,
../db/[core_db, ledger, storage_types],
../utils/[utils],
".."/[constants, errors, version],
Expand All @@ -26,7 +27,8 @@ export
hardforks,
genesis,
utils,
taskpools
taskpools,
logging

type
SyncProgress = object
Expand Down
35 changes: 35 additions & 0 deletions nimbus/common/logging.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Nimbus
# Copyright (c) 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.

import
std/[typetraits, net],
json_serialization,
web3/primitives,
confutils/defs,
eth/common/eth_types_json_serialization

# nim-eth
proc writeValue*(
w: var JsonWriter, v: EthTime | NetworkId | ChainId
) {.inline, raises: [IOError].} =
w.writeValue distinctBase(v)

# nim-web3
proc writeValue*(w: var JsonWriter, v: Quantity) {.inline, raises: [IOError].} =
w.writeValue distinctBase(v)

# nim-confutils
proc writeValue*(
w: var JsonWriter, v: InputFile | OutDir | OutFile | RestOfCmdLine | OutPath
) {.inline, raises: [IOError].} =
w.writeValue distinctBase(v)

# build-system
proc writeValue*(w: var JsonWriter, v: Port) {.inline, raises: [IOError].} =
w.writeValue distinctBase(v)
4 changes: 2 additions & 2 deletions nimbus/nimbus_execution_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ proc preventLoadingDataDirForTheWrongNetwork(db: CoreDbRef; conf: NimbusConf) =
kvt.put(dataDirIdKey().toOpenArray, calculatedId.data).isOkOr:
fatal "Cannot write data dir ID", ID=calculatedId
quit(QuitFailure)

let
kvt = db.ctx.getKvt()
calculatedId = calcHash(conf.networkId, conf.networkParams)
Expand All @@ -173,7 +173,7 @@ proc preventLoadingDataDirForTheWrongNetwork(db: CoreDbRef; conf: NimbusConf) =
if conf.rewriteDatadirId:
writeDataDirId(kvt, calculatedId)
return

if calculatedId.data != dataDirIdBytes:
fatal "Data dir already initialized with other network configuration",
get=dataDirIdBytes.toHex,
Expand Down
4 changes: 2 additions & 2 deletions nimbus/nimbus_import.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2024 Status Research & Development GmbH
# Copyright (c) 2024-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 @@ -277,7 +277,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
else:
raiseAssert "Other networks are unsupported or do not have an era1"
db = Era1DbRef.init(conf.era1Dir.string, era1Name).valueOr:
fatal "Could not open era1 database", era1Dir = conf.era1Dir, era1Name, error
fatal "Could not open era1 database", era1Dir=conf.era1Dir, era1Name=era1Name, error=error
quit(QuitFailure)

notice "Importing era1 archive",
Expand Down
5 changes: 3 additions & 2 deletions nimbus/sync/protocol/eth68.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nimbus - Ethereum Wire Protocol
#
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -21,7 +21,8 @@ import
stew/byteutils,
./trace_config,
./eth/eth_types,
../../utils/utils
../../utils/utils,
../../common/logging

export
eth_types
Expand Down
4 changes: 2 additions & 2 deletions nimbus/sync/sync_sched.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
import
std/hashes,
chronos,
eth/[p2p, p2p/peer_pool, common/eth_types_json_serialization],
eth/[p2p, p2p/peer_pool],
stew/keyed_queue,
./sync_desc

Expand Down Expand Up @@ -430,7 +430,7 @@ proc onPeerConnected[S,W](dsc: RunnerSyncRef[S,W]; peer: Peer) =
# This could happen if there are idle entries in the table, i.e.
# somehow hanging runners.
if dsc.ctx.noisyLog: trace "Peer table full! Dequeuing least used entry",
oldest.peer, oldest.only, nPeers, nWorkers=dsc.buddies.len, maxWorkers
oldestPeer=oldest.peer, oldestOnly=oldest.only, nPeers=nPeers, nWorkers=dsc.buddies.len, maxWorkers
# Setting to `zombie` will trigger the worker to terminate (if any.)
oldest.ctrl.zombie = true

Expand Down

0 comments on commit 1ab736e

Please sign in to comment.