From 3147df0dcdc027d7ea0cad9d84310198778222dd Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 9 Apr 2021 09:26:06 +0200 Subject: [PATCH] switch to chronos metrics, remove insecure (#580) * switch to chronos metrics, remove insecure See https://github.com/status-im/nimbus-eth2/pull/2468 also fixes pcre linking for real, and adds some random build flags that help nimbus-eth2 stay afloat * fix help * don't omit frame pointers on windows --- Makefile | 8 ++++---- README.md | 4 ++-- config.nims | 27 ++++++++++++++++++++++++--- nimbus/config.nim | 19 ++++++------------- nimbus/nimbus.nim | 14 +++++++------- vendor/nim-metrics | 2 +- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index eee8ff693..540f47511 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,17 @@ -# Copyright (c) 2018-2020 Status Research & Development GmbH. Licensed under +# Copyright (c) 2018-2021 Status Research & Development GmbH. Licensed under # either of: # - Apache License, version 2.0 # - MIT license # at your option. This file may not be copied, modified, or distributed except # according to those terms. -SHELL := bash # the shell used internally by Make +SHELL := bash # the shell used internally by "make" # used inside the included makefiles BUILD_SYSTEM_DIR := vendor/nimbus-build-system +LINK_PCRE := 0 + # we don't want an error here, so we can handle things later, in the ".DEFAULT" target -include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk @@ -57,8 +59,6 @@ all: | $(TOOLS) nimbus # must be included after the default target -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk -LINK_PCRE := 0 - # default: use blst USE_MIRACL := 0 diff --git a/README.md b/README.md index 72f381e8f..6f167981f 100644 --- a/README.md +++ b/README.md @@ -308,8 +308,8 @@ cd vendor/nim-rocksdb Install Prometheus and Grafana. On Gentoo, it's `emerge prometheus grafana-bin`. ```bash -# build Nimbus with support for the HTTP endpoint -make NIMFLAGS="-d:insecure" nimbus +# build Nimbus +make nimbus # the Prometheus daemon will create its data dir in the current dir, so give it its own directory mkdir ../my_metrics # copy the basic config file over there diff --git a/config.nims b/config.nims index fa16d8772..966db422d 100644 --- a/config.nims +++ b/config.nims @@ -14,21 +14,42 @@ if defined(windows): # set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag so we can use PAE, if enabled, and access more than 2 GiB of RAM switch("passL", "-Wl,--large-address-aware") -# remember to disable -march=native for reproducible builds +# This helps especially for 32-bit x86, which sans SSE2 and newer instructions +# requires quite roundabout code generation for cryptography, and other 64-bit +# and larger arithmetic use cases, along with register starvation issues. When +# engineering a more portable binary release, this should be tweaked but still +# use at least -msse2 or -msse3. if defined(disableMarchNative): - switch("passC", "-msse3") + if defined(i386) or defined(amd64): + switch("passC", "-msse3") + switch("passL", "-msse3") else: switch("passC", "-march=native") + switch("passL", "-march=native") if defined(windows): # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782 # ("-fno-asynchronous-unwind-tables" breaks Nim's exception raising, sometimes) - switch("passC", "-mno-avx512vl") + switch("passC", "-mno-avx512f") + switch("passL", "-mno-avx512f") + +# omitting frame pointers in nim breaks the GC +# https://github.com/nim-lang/Nim/issues/10625 +if not defined(windows): + # ...except on windows where the option crashes GCC: + # https://sourceforge.net/p/mingw-w64/bugs/880/ + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86593 + switch("passC", "-fno-omit-frame-pointer") + switch("passL", "-fno-omit-frame-pointer") --threads:on --opt:speed --excessiveStackTrace:on # enable metric collection --define:metrics +# for heap-usage-by-instance-type metrics and object base-type strings +--define:nimTypeNames + +switch("define", "withoutPCRE") # the default open files limit is too low on macOS (512), breaking the # "--debugger:native" build. It can be increased with `ulimit -n 1024`. diff --git a/nimbus/config.nim b/nimbus/config.nim index 528d27fb8..c0fc0c275 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -698,9 +698,9 @@ proc processNetArguments(key, value: string): ConfigStatus = result = processInteger(value, res) if result == Success: config.net.discPort = uint16(res and 0xFFFF) - elif skey == "metricsserver" and defined(insecure): + elif skey == "metricsserver": config.net.metricsServer = true - elif skey == "metricsserverport" and defined(insecure): + elif skey == "metricsserverport": var res = 0 result = processInteger(value, res) if result == Success: @@ -893,14 +893,6 @@ proc getHelpString*(): string = continue logLevels.add($level) - when defined(insecure): - let metricsServerHelp = """ - - --metricsServer Enable the metrics HTTP server - --metricsServerPort: Metrics HTTP server port on localhost (default: 9093)""" - else: - let metricsServerHelp = "" - result = """ USAGE: @@ -918,14 +910,16 @@ NETWORKING OPTIONS: --bootnodesv5: Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) --staticnodes: Comma separated enode URLs to connect with --port: Network listening TCP port (default: 30303) - --discport: Network listening UDP port (defaults to --port argument)$7 + --discport: Network listening UDP port (defaults to --port argument) + --metricsServer Enable the metrics HTTP server + --metricsServerPort: Metrics HTTP server port on localhost (default: 9093) --maxpeers: Maximum number of network peers (default: 25) --maxpendpeers: Maximum number of pending connection attempts (default: 0) --nat: NAT port mapping mechanism (any|none|upnp|pmp|) (default: "any") --nodiscover Disables the peer discovery mechanism (manual peer addition) --v5discover Enables the experimental RLPx V5 (Topic Discovery) mechanism --nodekey: P2P node private key (as hexadecimal string) - --networkid: Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: $8) + --networkid: Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: $7) --testnet Use Ethereum Default Test Network (Ropsten) --ropsten Use Ethereum Ropsten Test Network --rinkeby Use Ethereum Rinkeby Test Network @@ -957,7 +951,6 @@ LOGGING AND DEBUGGING OPTIONS: strip($defaultProtocols, chars = {'{','}'}), $defaultMaxMsgSize, $defaultMinPow, - metricsServerHelp, $ord(defaultNetwork) ] diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index 18dbac016..0e96dbca5 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -15,7 +15,8 @@ import eth/p2p/rlpx_protocols/[eth_protocol, les_protocol, whisper_protocol], eth/p2p/blockchain_sync, eth/net/nat, eth/p2p/peer_pool, config, genesis, rpc/[common, p2p, debug, whisper, key_storage], p2p/chain, - eth/trie/db, metrics, metrics/chronicles_support, utils, ./conf_utils + eth/trie/db, metrics, metrics/[chronos_httpserver, chronicles_support], + utils, ./conf_utils ## TODO: ## * No IPv6 support @@ -53,7 +54,7 @@ proc start(nimbus: NimbusNode) = if canonicalHeadHashKey().toOpenArray notin trieDB: initializeEmptyDb(chainDb) doAssert(canonicalHeadHashKey().toOpenArray in trieDB) - + if conf.importFile.len > 0: importRlpBlock(conf.importFile, chainDB) quit(QuitSuccess) @@ -137,11 +138,10 @@ proc start(nimbus: NimbusNode) = nimbus.rpcServer.start() # metrics server - when defined(insecure): - if conf.net.metricsServer: - let metricsAddress = "127.0.0.1" - info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsServerPort - metrics.startHttpServer(metricsAddress, Port(conf.net.metricsServerPort)) + if conf.net.metricsServer: + let metricsAddress = "127.0.0.1" + info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsServerPort + startMetricsHttpServer(metricsAddress, Port(conf.net.metricsServerPort)) # Connect directly to the static nodes for enode in conf.net.staticNodes: diff --git a/vendor/nim-metrics b/vendor/nim-metrics index 16ec7aecc..1edce7ebd 160000 --- a/vendor/nim-metrics +++ b/vendor/nim-metrics @@ -1 +1 @@ -Subproject commit 16ec7aeccc2020666d6b7c63288153f3917222fb +Subproject commit 1edce7ebde5b629f3f128ca09e25c3068dac3f0d