Address review concerns and make some steps towards json logging

This commit is contained in:
Zahary Karadjov 2019-03-22 16:35:20 +02:00 committed by zah
parent 06301458bf
commit 0a027e410a
6 changed files with 27 additions and 5 deletions

View File

@ -77,9 +77,14 @@ proc saveValidatorKey(key: ValidatorPrivKey, conf: BeaconNodeConf) =
createDir validatorsDir
writeFile(validatorsDir / $key.pubKey, $key)
proc persistentNodeId*(conf: BeaconNodeConf): string =
($ensureNetworkKeys(conf).pubKey)[0..5]
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
new result
result.config = conf
result.nickname = if conf.nodename == "auto": persistentNodeId(conf)
else: conf.nodename
template fail(args: varargs[untyped]) =
stderr.write args, "\n"
@ -781,8 +786,8 @@ when isMainModule:
var node = waitFor BeaconNode.init(config)
if config.tcpPort != config.defaultPort:
dynamicLogScope(node = config.tcpPort): node.start()
if node.nickname != "":
dynamicLogScope(node = node.nickname): node.start()
else:
node.start()

View File

@ -24,6 +24,7 @@ type
#
# #############################################
BeaconNode* = ref object
nickname*: string
network*: EthereumNode
networkMetadata*: NetworkMetadata
isBootstrapNode*: bool

View File

@ -69,6 +69,11 @@ type
desc: "Json file specifying a recent state snapshot"
shortform: "s".}: Option[TypedInputFile[BeaconState, Json, "json"]]
nodename* {.
desc: "A name for this node that will appear in the logs. " &
"If you set this to 'auto', a persistent automatically generated ID will be seleceted for each --dataDir folder"
defaultValue: ""}: string
of createTestnet:
networkId* {.
desc: "An unique numeric identifier for the network".}: uint64

View File

@ -18,7 +18,7 @@
# types / composition
import
hashes, math,
hashes, math, json,
eth/[common, rlp],
./bitfield, ./crypto, ./digest
@ -574,6 +574,7 @@ template ethTimeUnit(typ: type) {.dirty.} =
# Nim integration
proc `$`*(x: typ): string {.borrow.}
proc hash*(x: typ): Hash {.borrow.}
proc `%`*(x: typ): JsonNode {.borrow.}
# Serialization
proc read*(rlp: var Rlp, T: type typ): typ {.inline.} =
@ -588,6 +589,9 @@ template ethTimeUnit(typ: type) {.dirty.} =
proc readValue*(reader: var JsonReader, value: var typ) =
value = typ reader.readValue(uint64)
proc `%`*(i: uint64): JsonNode =
% int(i)
ethTimeUnit Slot
ethTimeUnit Epoch

View File

@ -8,6 +8,12 @@ source "$NETWORK_NAME.env"
cd ..
NIM_FLAGS="-d:debug -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
nim c $NIM_FLAGS -r beacon_chain/beacon_node
NIM_FLAGS="-d:release --stacktraces:on -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
nim c $NIM_FLAGS beacon_chain/beacon_node
if [ ! -d ~/.cache/nimbus/BeaconNode/$NETWORK_NAME/validators ]; then
beacon_chain/beacon_node --network=$NETWORK_NAME importValidators
fi
beacon_chain/beacon_node

View File

@ -17,6 +17,7 @@ fi
$BEACON_NODE_BIN \
--network:$NETWORK_METADATA_FILE \
--dataDir:$DATA_DIR \
--nodename:${1} \
--validator:${V_PREFIX}0.privkey \
--validator:${V_PREFIX}1.privkey \
--validator:${V_PREFIX}2.privkey \