inspector: add readme entry, decoding option

This commit is contained in:
Jacek Sieka 2019-12-16 11:22:01 +01:00 committed by zah
parent 963f23e5ea
commit 8c104a0b94
2 changed files with 42 additions and 1 deletions

View File

@ -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

View File

@ -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: