Address review concerns and make some steps towards json logging
This commit is contained in:
parent
06301458bf
commit
0a027e410a
|
@ -77,9 +77,14 @@ proc saveValidatorKey(key: ValidatorPrivKey, conf: BeaconNodeConf) =
|
||||||
createDir validatorsDir
|
createDir validatorsDir
|
||||||
writeFile(validatorsDir / $key.pubKey, $key)
|
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.} =
|
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
|
||||||
new result
|
new result
|
||||||
result.config = conf
|
result.config = conf
|
||||||
|
result.nickname = if conf.nodename == "auto": persistentNodeId(conf)
|
||||||
|
else: conf.nodename
|
||||||
|
|
||||||
template fail(args: varargs[untyped]) =
|
template fail(args: varargs[untyped]) =
|
||||||
stderr.write args, "\n"
|
stderr.write args, "\n"
|
||||||
|
@ -781,8 +786,8 @@ when isMainModule:
|
||||||
|
|
||||||
var node = waitFor BeaconNode.init(config)
|
var node = waitFor BeaconNode.init(config)
|
||||||
|
|
||||||
if config.tcpPort != config.defaultPort:
|
if node.nickname != "":
|
||||||
dynamicLogScope(node = config.tcpPort): node.start()
|
dynamicLogScope(node = node.nickname): node.start()
|
||||||
else:
|
else:
|
||||||
node.start()
|
node.start()
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ type
|
||||||
#
|
#
|
||||||
# #############################################
|
# #############################################
|
||||||
BeaconNode* = ref object
|
BeaconNode* = ref object
|
||||||
|
nickname*: string
|
||||||
network*: EthereumNode
|
network*: EthereumNode
|
||||||
networkMetadata*: NetworkMetadata
|
networkMetadata*: NetworkMetadata
|
||||||
isBootstrapNode*: bool
|
isBootstrapNode*: bool
|
||||||
|
|
|
@ -69,6 +69,11 @@ type
|
||||||
desc: "Json file specifying a recent state snapshot"
|
desc: "Json file specifying a recent state snapshot"
|
||||||
shortform: "s".}: Option[TypedInputFile[BeaconState, Json, "json"]]
|
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:
|
of createTestnet:
|
||||||
networkId* {.
|
networkId* {.
|
||||||
desc: "An unique numeric identifier for the network".}: uint64
|
desc: "An unique numeric identifier for the network".}: uint64
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
# types / composition
|
# types / composition
|
||||||
|
|
||||||
import
|
import
|
||||||
hashes, math,
|
hashes, math, json,
|
||||||
eth/[common, rlp],
|
eth/[common, rlp],
|
||||||
./bitfield, ./crypto, ./digest
|
./bitfield, ./crypto, ./digest
|
||||||
|
|
||||||
|
@ -574,6 +574,7 @@ template ethTimeUnit(typ: type) {.dirty.} =
|
||||||
# Nim integration
|
# Nim integration
|
||||||
proc `$`*(x: typ): string {.borrow.}
|
proc `$`*(x: typ): string {.borrow.}
|
||||||
proc hash*(x: typ): Hash {.borrow.}
|
proc hash*(x: typ): Hash {.borrow.}
|
||||||
|
proc `%`*(x: typ): JsonNode {.borrow.}
|
||||||
|
|
||||||
# Serialization
|
# Serialization
|
||||||
proc read*(rlp: var Rlp, T: type typ): typ {.inline.} =
|
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) =
|
proc readValue*(reader: var JsonReader, value: var typ) =
|
||||||
value = typ reader.readValue(uint64)
|
value = typ reader.readValue(uint64)
|
||||||
|
|
||||||
|
proc `%`*(i: uint64): JsonNode =
|
||||||
|
% int(i)
|
||||||
|
|
||||||
ethTimeUnit Slot
|
ethTimeUnit Slot
|
||||||
ethTimeUnit Epoch
|
ethTimeUnit Epoch
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,12 @@ source "$NETWORK_NAME.env"
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
NIM_FLAGS="-d:debug -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
|
NIM_FLAGS="-d:release --stacktraces:on -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
|
||||||
nim c $NIM_FLAGS -r beacon_chain/beacon_node
|
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
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ fi
|
||||||
$BEACON_NODE_BIN \
|
$BEACON_NODE_BIN \
|
||||||
--network:$NETWORK_METADATA_FILE \
|
--network:$NETWORK_METADATA_FILE \
|
||||||
--dataDir:$DATA_DIR \
|
--dataDir:$DATA_DIR \
|
||||||
|
--nodename:${1} \
|
||||||
--validator:${V_PREFIX}0.privkey \
|
--validator:${V_PREFIX}0.privkey \
|
||||||
--validator:${V_PREFIX}1.privkey \
|
--validator:${V_PREFIX}1.privkey \
|
||||||
--validator:${V_PREFIX}2.privkey \
|
--validator:${V_PREFIX}2.privkey \
|
||||||
|
|
Loading…
Reference in New Issue