From 8c104a0b94840692034badcc49bfb1c1aa3e124f Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 16 Dec 2019 11:22:01 +0100 Subject: [PATCH] inspector: add readme entry, decoding option --- README.md | 20 ++++++++++++++++++++ beacon_chain/inspector.nim | 23 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d93c522da..0c0c40bd5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ You can check where the beacon chain fits in the Ethereum ecosystem our Two-Poin - [State transition simulation](#state-transition-simulation) - [Local network simulation](#local-network-simulation) - [Visualising simulation metrics](#visualising-simulation-metrics) + - [Network inspection](#network-inspection) - [For developers](#for-developers) - [Windows dev environment](#windows-dev-environment) - [Linux, MacOS](#linux-macos) @@ -182,6 +183,25 @@ The dashboard you need to import in Grafana is "tests/simulation/beacon-chain-si ![monitoring dashboard](./media/monitoring.png) +### Network inspection + +The [inspector tool](./beacon_chain/inspector.nim) can help monitor the libp2p network and the various channels where blocks and attestations are being transmitted, showing message and connectivity metadata. By default, it will monitor all ethereum 2 gossip traffic. + +```bash +. ./env.sh +# Build inspector for minimal config: +./env.sh nim c -d:const_preset=minimal -o:build/inspector_minimal beacon_chain/inspector.nim + +# Build inspector for mainnet config: +./env.sh nim c -d:const_preset=mainnet -o:build/inspector_mainnet beacon_chain/inspector.nim + +# See available options +./env.sh build/inspector_minimal --help + +# Connect to a network from eth2 testnet repo bootstrap file - --decode option attempts to decode the messages as well +./env.sh build/inspector_minimal --decode -b:$(curl -s https://raw.githubusercontent.com/eth2-clients/eth2-testnets/master/nimbus/testnet0/bootstrap_nodes.txt | head -n1) +``` + ## For developers Latest updates happen in the `devel` branch which is merged into `master` every week on Tuesday before deploying a new testnets diff --git a/beacon_chain/inspector.nim b/beacon_chain/inspector.nim index 76b86cc7c..cf0572812 100644 --- a/beacon_chain/inspector.nim +++ b/beacon_chain/inspector.nim @@ -8,7 +8,7 @@ import strutils, os, tables import confutils, chronicles, chronos, libp2p/daemon/daemonapi, libp2p/multiaddress import stew/byteutils as bu -import spec/network +import spec/[crypto, datatypes, network, digest], ssz const InspectorName* = "Beacon-Chain Network Inspector" @@ -88,6 +88,11 @@ type abbr: "b" name: "bootnodes" }: seq[string] + decode* {. + desc: "Try to decode message using SSZ" + abbr: "d" + defaultValue: false }: bool + proc getTopic(filter: TopicFilter): string {.inline.} = case filter of TopicFilter.Blocks: @@ -176,6 +181,22 @@ proc run(conf: InspectorConf) {.async.} = mtopics = $message.topics, message = bu.toHex(message.data), zpeers = len(pubsubPeers) + + if conf.decode: + try: + if ticket.topic.startsWith(topicBeaconBlocks): + info "BeaconBlock", msg = SSZ.decode(message.data, BeaconBlock) + elif ticket.topic.startsWith(topicAttestations): + info "Attestation", msg = SSZ.decode(message.data, Attestation) + elif ticket.topic.startsWith(topicVoluntaryExits): + info "VoluntaryExit", msg = SSZ.decode(message.data, VoluntaryExit) + elif ticket.topic.startsWith(topicProposerSlashings): + info "ProposerSlashing", msg = SSZ.decode(message.data, ProposerSlashing) + elif ticket.topic.startsWith(topicAttesterSlashings): + info "AttesterSlashing", msg = SSZ.decode(message.data, AttesterSlashing) + except CatchableError as exc: + info "Unable to decode message", msg = exc.msg + result = true if len(conf.topics) > 0: