Add lightNode and logMetrics options

This commit is contained in:
kdeme 2020-01-14 23:35:47 +01:00 committed by zah
parent 8c3595ff94
commit 574c5ec0af
4 changed files with 39 additions and 4 deletions

View File

@ -107,3 +107,7 @@ wrappers-static: | build deps libnimbus.a go-checks
wakunode: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim wakunode $(NIM_PARAMS) nimbus.nims
wakusim: | build deps wakunode
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim quicksim $(NIM_PARAMS) nimbus.nims

View File

@ -40,6 +40,8 @@ task test, "Run tests":
task nimbus, "Build Nimbus":
buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE"
task wakunode, "Build Waku":
task wakunode, "Build Waku node":
buildBinary "wakunode", "waku/", "-d:chronicles_log_level=TRACE"
buildBinary "quicksim", "waku/", "-d:chronicles_log_level=TRACE"
task quicksim, "Build quicksim":
buildBinary "quicksim", "waku/", "-d:chronicles_log_level=INFO"

View File

@ -62,6 +62,11 @@ type
defaultValue: false
name: "whisper-bridge" }: bool
lightNode* {.
desc: "Run as light node (no message relay).",
defaultValue: false
name: "light-node" }: bool
wakuMode* {.
desc: "Select the Waku mode.",
defaultValue: WakuSan
@ -113,6 +118,11 @@ type
defaultValue: 8008
name: "metrics-server-port" }: uint16
logMetrics* {.
desc: "Enable metrics logging."
defaultValue: false
name: "log-metrics" }: bool
# TODO:
# - nat
# - discv5 + topic register

View File

@ -1,7 +1,7 @@
import
confutils, config, chronos, json_rpc/rpcserver, metrics,
chronicles/topics_registry, # TODO: What? Need this for setLoglevel, weird.
eth/[keys, p2p, async_utils],
eth/[keys, p2p, async_utils], eth/common/utils,
eth/p2p/[discovery, enode, peer_pool, bootnodes, whispernodes],
eth/p2p/rlpx_protocols/[whisper_protocol, waku_protocol, waku_bridge],
../nimbus/rpc/waku
@ -39,7 +39,7 @@ proc run(config: WakuNodeConf) =
node.addCapability Waku # Always enable Waku protocol
let wakuConfig = WakuConfig(powRequirement: config.wakuPow,
bloom: fullBloom(),
isLightNode: false,
isLightNode: config.lightNode,
maxMsgSize: waku_protocol.defaultMaxMsgSize,
wakuMode: config.wakuMode,
topics: @[])
@ -81,6 +81,25 @@ proc run(config: WakuNodeConf) =
info "Starting metrics HTTP server", address, port
metrics.startHttpServer($address, Port(port))
if config.logMetrics:
proc logMetrics(udata: pointer) {.closure, gcsafe.} =
{.gcsafe.}:
let
connectedPeers = connected_peers.value
validEnvelopes = waku_protocol.valid_envelopes.value
invalidEnvelopes = waku_protocol.dropped_expired_envelopes.value +
waku_protocol.dropped_from_future_envelopes.value +
waku_protocol.dropped_low_pow_envelopes.value +
waku_protocol.dropped_too_large_envelopes.value +
waku_protocol.dropped_bloom_filter_mismatch_envelopes.value +
waku_protocol.dropped_topic_mismatch_envelopes.value +
waku_protocol.dropped_benign_duplicate_envelopes.value +
waku_protocol.dropped_malicious_duplicate_envelopes.value
info "Node metrics", connectedPeers, validEnvelopes, invalidEnvelopes
addTimer(Moment.fromNow(2.seconds), logMetrics)
addTimer(Moment.fromNow(2.seconds), logMetrics)
runForever()
when isMainModule: