diff --git a/.github/workflows/node-status-test.yml b/.github/workflows/node-status-test.yml new file mode 100644 index 0000000..17e1ff7 --- /dev/null +++ b/.github/workflows/node-status-test.yml @@ -0,0 +1,21 @@ +name: Node status test + +on: + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: dappnode/staker-package-scripts + path: staker-package-scripts + - name: Run the node status test + run: sh test/node_status_test.sh + env: + NODE_STATUS_TOOLS: staker-package-scripts/scripts/node_status_tools.sh diff --git a/README.md b/README.md index f791e06..cf3b883 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ This package by default uses the newer BONSAI storage structure. You can switch This DAppNode package uses the Besu Execution Client. +# Node status + +The package reports Besu's sync phase (snap sync state download, healing, chain download, waiting for the consensus client) to the DAppNode dashboard through its Docker healthcheck, which prints one JSON status line. The script is `besu/node-status.sh`, installed in the image as `/usr/local/bin/node-status`. Its test is `test/node_status_test.sh`: run `sh test/node_status_test.sh` with a clone of `dappnode/staker-package-scripts` next to this repository, or point `NODE_STATUS_TOOLS` at its `scripts/node_status_tools.sh`. + # License This repository is offered under the Apache 2.0 license. See LICENSE for details. diff --git a/besu/Dockerfile b/besu/Dockerfile index 7dac5ec..7fe403c 100644 --- a/besu/Dockerfile +++ b/besu/Dockerfile @@ -23,16 +23,19 @@ ENV BESU_RPC_WS_HOST=0.0.0.0 \ STAKER_SCRIPTS_URL=https://github.com/dappnode/staker-package-scripts/releases/download/${STAKER_SCRIPTS_VERSION} ADD ${STAKER_SCRIPTS_URL}/execution_tools.sh /etc/profile.d/ +ADD ${STAKER_SCRIPTS_URL}/node_status_tools.sh /etc/profile.d/ COPY entrypoint.sh /usr/local/bin/entrypoint.sh +COPY node-status.sh /usr/local/bin/node-status USER root # curl install throws error in ARM64 arch. It should not prevent build -RUN apt-get update && apt-get --no-install-recommends --yes install curl && apt-get clean || true +RUN apt-get update && apt-get --no-install-recommends --yes install curl jq && apt-get clean || true RUN mkdir ${DATA_DIR} && chown -R besu:besu ${DATA_DIR} && \ - chmod +rx /usr/local/bin/entrypoint.sh /etc/profile.d/execution_tools.sh + chmod +rx /usr/local/bin/entrypoint.sh /usr/local/bin/node-status /etc/profile.d/execution_tools.sh && \ + chmod +r /etc/profile.d/node_status_tools.sh # This env changes the variant # Placed at the end to regenerate the least amount of layers diff --git a/besu/node-status.sh b/besu/node-status.sh new file mode 100755 index 0000000..fd132e2 --- /dev/null +++ b/besu/node-status.sh @@ -0,0 +1,125 @@ +#!/bin/sh + +# Node status report of the Besu execution client, run as the Docker healthcheck. +# Prints one JSON line (see node_status_tools.sh in dappnode/staker-package-scripts) +# telling the sync phase only Besu knows; the dappmanager decides by itself whether +# the node is synced, waiting for the consensus client or stalled. +# +# Signals (Besu 26.11): +# - eth_syncing is false once the initial sync is done, and an object +# {startingBlock, currentBlock, highestBlock} for the whole snap sync, where +# currentBlock is the last block whose body and receipts the chain download stored. +# - besu_synchronizer_sync_duration_count{name=} exists from the moment a +# snap sync phase starts in this process, 0 while it runs and 1 once it ended. +# - besu_synchronizer_fast_sync_pivot_block_current is the snap sync pivot block, +# 0 until the consensus client gave one. +# +# Environment: +# NODE_STATUS_TOOLS: Path of node_status_tools.sh (default /etc/profile.d/node_status_tools.sh) +# BESU_METRICS_PORT: Metrics port, read by Besu itself as well (default 9545) +# NS_TIMEOUT: Timeout in seconds of each request (default 2) + +# shellcheck source=/dev/null +. "${NODE_STATUS_TOOLS:-/etc/profile.d/node_status_tools.sh}" || exit 1 + +# A handful of calls stay well inside the 10 s healthcheck timeout +NS_TIMEOUT=${NS_TIMEOUT:-2} +METRICS_URL="http://127.0.0.1:${BESU_METRICS_PORT:-9545}/metrics" +BACKGROUND="Finishing background sync tasks" + +# The JSON-RPC does not answer yet: Besu is still opening its database +if ! syncing=$(ns_rpc eth_syncing); then + ns_emit starting + exit $? +fi + +state=syncing +[ "$syncing" = false ] && state=synced + +# Value of a sync duration timer: 0 while the phase runs, 1 once it ended, nothing when +# the phase never started in this process +timer() { + printf '%s\n' "$metrics" | ns_metric besu_synchronizer_sync_duration_count "name=$1" +} + +# Every call below can take NS_TIMEOUT seconds: stop at the first one that fails +set -- +answered=false +if head=$(ns_block_head); then + # shellcheck disable=SC2086 # head is "height= headTime=" + set -- $head + if peers=$(ns_rpc net_peerCount); then + set -- "$@" peers="$(ns_json_get "$peers")" + answered=true + fi +fi + +# Synced, or nothing more to learn +if [ "$state" = synced ] || [ "$answered" = false ]; then + ns_emit "$state" "$@" + exit $? +fi + +# eth_syncing is an object while the snap sync runs: work that may go on near the head +set -- "$@" background="$BACKGROUND" + +# Only the lines read below, so that each lookup scans a few lines +metrics=$(ns_http_get "$METRICS_URL" | + grep -E '^besu_synchronizer_(sync_duration_count|fast_sync_pivot_block_current)[{ ]') +total=$(timer TOTAL_SYNC_DURATION) + +# The sync already ended in this process: nothing to add +if [ -n "$total" ] && [ "$total" != 0 ]; then + ns_emit syncing "$@" + exit $? +fi + +world_state=$(timer SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION) +healing=$(timer SNAP_WORLD_STATE_HEALING_DURATION) +flat_heal=$(timer FLAT_DB_HEAL) +chain=$(timer CHAIN_DOWNLOAD_DURATION) +pivot=$(ns_hex_to_dec "$(printf '%s\n' "$metrics" | ns_metric besu_synchronizer_fast_sync_pivot_block_current)") || + pivot=0 +[ "$pivot" -gt 0 ] && set -- "$@" detail="Pivot block:$pivot" + +# The world state and the chain download in parallel; the state takes longer, so it names the phase +if [ "$world_state" = 0 ]; then + ns_emit syncing phase="Downloading state" "$@" + exit $? +fi +if [ "$healing" = 0 ]; then + ns_emit syncing phase="Healing state" "$@" + exit $? +fi +if [ "$flat_heal" = 0 ]; then + ns_emit syncing phase="Healing the flat database" "$@" + exit $? +fi + +if [ "$chain" = 0 ]; then + starting=$(ns_hex_to_dec "$(ns_json_get "$syncing" .startingBlock)") || starting=0 + current=$(ns_hex_to_dec "$(ns_json_get "$syncing" .currentBlock)") || current=0 + highest=$(ns_hex_to_dec "$(ns_json_get "$syncing" .highestBlock)") || highest=0 + # Headers are downloaded backwards from the pivot first; only the bodies and receipts + # that follow move currentBlock + if [ "$current" -le "$starting" ]; then + ns_emit syncing phase="Downloading block headers" "$@" + exit $? + fi + # The chain download runs up to the pivot + target=$pivot + [ "$target" -gt "$current" ] || target=$highest + [ "$target" -gt "$current" ] || target="" + ns_emit syncing phase="Downloading blocks" position="$current" target="$target" "$@" + exit $? +fi + +# The sync runs (its timer exists, so the metrics answered) but neither download started: +# no pivot block yet, which comes from the consensus client +if [ "$total" = 0 ] && [ -z "$world_state" ] && [ -z "$chain" ] && [ "$pivot" -eq 0 ]; then + ns_emit syncing awaitingTarget=true "$@" + exit $? +fi + +ns_emit syncing "$@" +exit $? diff --git a/dappnode_package.json b/dappnode_package.json index 8db1ad7..407cc56 100644 --- a/dappnode_package.json +++ b/dappnode_package.json @@ -19,6 +19,17 @@ "execution" ], "license": "Apache-2.0", + "nodes": { + "besu": { + "role": "execution", + "probe": { + "kind": "ethereum-execution", + "rpcPort": 8545, + "enginePort": 8551 + }, + "report": "healthcheck" + } + }, "repository": { "type": "git", "url": "https://github.com/dappnode/DAppNodePackage-besu-generic.git" @@ -37,7 +48,7 @@ { "arg": "STAKER_SCRIPTS_VERSION", "repo": "dappnode/staker-package-scripts", - "version": "v0.1.2" + "version": "v0.1.3" } ] } diff --git a/docker-compose.yml b/docker-compose.yml index ea8be2a..c6ee7e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: context: besu args: UPSTREAM_VERSION: 26.11.0 - STAKER_SCRIPTS_VERSION: v0.1.2 + STAKER_SCRIPTS_VERSION: v0.1.3 DATA_DIR: /var/lib/besu volumes: - data:/var/lib/besu @@ -20,6 +20,12 @@ services: BESU_OPTS: "-Xmx8g" EXTRA_OPTS: "" restart: unless-stopped + healthcheck: + test: ["CMD", "/usr/local/bin/node-status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s security_opt: - seccomp:unconfined volumes: diff --git a/package_variants/hoodi/dappnode_package.json b/package_variants/hoodi/dappnode_package.json index ccbaae4..cdd6c08 100644 --- a/package_variants/hoodi/dappnode_package.json +++ b/package_variants/hoodi/dappnode_package.json @@ -20,5 +20,10 @@ "homepage": "https://github.com/hyperledger/besu" }, "name": "hoodi-besu.dnp.dappnode.eth", + "nodes": { + "besu": { + "network": "hoodi" + } + }, "version": "0.1.8" } diff --git a/package_variants/mainnet/dappnode_package.json b/package_variants/mainnet/dappnode_package.json index e19e3a3..36ef025 100644 --- a/package_variants/mainnet/dappnode_package.json +++ b/package_variants/mainnet/dappnode_package.json @@ -20,5 +20,10 @@ "homepage": "https://github.com/hyperledger/besu" }, "name": "besu.public.dappnode.eth", + "nodes": { + "besu": { + "network": "mainnet" + } + }, "version": "1.2.18" } diff --git a/test/node_status_test.sh b/test/node_status_test.sh new file mode 100644 index 0000000..6fb4044 --- /dev/null +++ b/test/node_status_test.sh @@ -0,0 +1,311 @@ +#!/bin/sh + +# Tests for besu/node-status.sh +# Run from anywhere with any POSIX sh: sh test/node_status_test.sh +# Needs jq. NODE_STATUS_TOOLS is the path of node_status_tools.sh from +# dappnode/staker-package-scripts (default: a clone next to this repo). The +# network is stubbed by a curl function returning canned replies. + +cd "$(dirname "$0")/.." || exit 1 +NODE_STATUS_TOOLS=${NODE_STATUS_TOOLS:-../staker-package-scripts/scripts/node_status_tools.sh} +SCRIPT=./besu/node-status.sh +if [ ! -r "$NODE_STATUS_TOOLS" ]; then + echo "node_status_tools.sh not found at $NODE_STATUS_TOOLS (set NODE_STATUS_TOOLS)" >&2 + exit 1 +fi + +PASS=0 +FAIL=0 +TMP=$(mktemp -d) || exit 1 +trap 'rm -rf "$TMP"' EXIT + +# check +check() { + if [ "$2" = "$3" ]; then + PASS=$((PASS + 1)) + else + FAIL=$((FAIL + 1)) + printf 'FAIL: %s\n expected: %s\n actual: %s\n' "$1" "$2" "$3" + fi +} + +# Canned replies. An RPC reply is the JSON "result"; FAIL makes curl fail like a +# refused connection, ERROR returns a JSON-RPC error. +SYNCING=false +BLOCK='{"number":"0x1312d00","timestamp":"0x6b49d200","hash":"0xab"}' +PEERS='"0x19"' +METRICS="" + +# Stub curl: records the URL and the JSON-RPC method of each call, then answers +# shellcheck disable=SC2329 # called by the script under test +curl() { + _url="" + _body="" + while [ $# -gt 0 ]; do + case $1 in + --data) shift && _body=$1 ;; + http://*) _url=$1 ;; + esac + shift + done + _method=$(printf '%s' "$_body" | jq -r '.method // empty' 2>/dev/null) + printf '%s %s\n' "$_url" "$_method" >>"$TMP/calls" + case $_url in + */metrics) _reply=$METRICS ;; + *) + case $_method in + eth_syncing) _reply=$SYNCING ;; + eth_getBlockByNumber) _reply=$BLOCK ;; + net_peerCount) _reply=$PEERS ;; + *) _reply=ERROR ;; + esac + ;; + esac + case $_reply in + FAIL) return 7 ;; + ERROR) printf '{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"Method not found"}}' ;; + *) + case $_url in + */metrics) printf '%s\n' "$_reply" ;; + *) printf '{"jsonrpc":"2.0","id":1,"result":%s}' "$_reply" ;; + esac + ;; + esac +} + +# status: runs the script with the stub, sets OUT (stdout), RC (exit status) and CALLS +# (number of requests); stderr is discarded +status() { + : >"$TMP/calls" + OUT=$( + exec 2>/dev/null + # shellcheck source=/dev/null + . "$SCRIPT" + ) + RC=$? + CALLS=$(wc -l <"$TMP/calls" | tr -d ' ') +} + +# Field of the last report, compact +field() { + printf '%s\n' "$OUT" | jq -c "$1" +} + +# Checks that the output is one JSON line that respects the contract +check_valid() { + _lines=$(printf '%s\n' "$OUT" | wc -l | tr -d ' ') + _valid=$(printf '%s\n' "$OUT" | jq -r ' + def int: type == "number" and . >= 0 and . == floor; + def text($n): type == "string" and length > 0 and length <= $n; + (keys - ["version", "state", "phase", "progress", "height", "headTime", "position", "target", + "unit", "peers", "awaitingTarget", "background", "issues", "details"]) == [] + and .version == 1 + and (.state | IN("starting", "syncing", "synced", "error")) + and (.phase == null or (.phase | text(60) and (endswith(".") | not))) + and (.progress == null or (.progress | type == "number" and . >= 0 and . <= 100)) + and (.progress == null or .position == null) + and all(.height, .headTime, .position, .target, .peers; . == null or int) + and (.unit == null or (.unit | text(20))) + and (.awaitingTarget == null or .awaitingTarget == true) + and (.background == null or (.background | text(60))) + and (.issues == null or (.issues | length <= 5 and all(text(120)))) + and (.details == null or (.details | length <= 8 and all(.label and .value))) + and (tojson | utf8bytelength <= 2048) + ' 2>/dev/null) + check "$1: one valid report" "1 true" "$_lines $_valid" +} + +# Metric lines in the Prometheus text format Besu prints, with the trailing comma +timers() { + for _pair in "$@"; do + printf 'besu_synchronizer_sync_duration_count{name="%s",} %s\n' "${_pair%%=*}" "${_pair#*=}" + done +} +HEADER='# HELP besu_synchronizer_sync_duration Time taken to sync +# TYPE besu_synchronizer_sync_duration histogram +besu_synchronizer_sync_duration_bucket{name="TOTAL_SYNC_DURATION",le="1.0",} 0.0 +besu_synchronizer_sync_duration_sum{name="TOTAL_SYNC_DURATION",} 0.0 +besu_synchronizer_fast_sync_pivot_block_selected_count 1.0 +besu_synchronizer_snap_world_state_accounts_total 123456.0' +pivot() { + printf 'besu_synchronizer_fast_sync_pivot_block_current %s\n' "$1" +} +SNAP_SYNCING='{"startingBlock":"0x0","currentBlock":"0x0","highestBlock":"0x12d687"}' + +echo "Not answering" +SYNCING=FAIL +status +check "refused: starting" '{"version":1,"state":"starting"}' "$OUT" +check "refused: exit 0" 0 "$RC" +check "refused: no call after the first failure" 1 "$CALLS" +check_valid "refused" +SYNCING=ERROR +status +check "rpc error: starting" '"starting" 0' "$(field .state) $RC" +SYNCING='not json' +status +check "not json: starting" '"starting" 0' "$(field .state) $RC" + +echo "eth_syncing false" +SYNCING=false +METRICS=FAIL +status +check "synced report" '{"version":1,"state":"synced","height":20000000,"headTime":1800000000,"peers":25}' "$OUT" +check "synced: exit 0" 0 "$RC" +check "synced: metrics not fetched" 3 "$CALLS" +check_valid "synced" +METRICS="$HEADER +$(timers TOTAL_SYNC_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=0.0)" +status +check "false with snap timers (Besu up to 26.10): synced, no phase" '"synced" null 3' \ + "$(field .state) $(field .phase) $CALLS" +PEERS='"0x0"' +status +check "no peers: peers 0, no issue" '0 null' "$(field .peers) $(field .issues)" +PEERS='"0x19"' + +echo "Calls failing after eth_syncing" +SYNCING=$SNAP_SYNCING +BLOCK=FAIL +status +check "no block: syncing without head" '{"version":1,"state":"syncing"}' "$OUT" +check "no block: stops after the failure" "0 2" "$RC $CALLS" +check_valid "no block" +BLOCK='{"number":"0x1312d00","timestamp":"0x6b49d200"}' +PEERS=FAIL +status +check "no peers answer: head only, no metrics" '{"version":1,"state":"syncing","height":20000000,"headTime":1800000000} 3' "$OUT $CALLS" +PEERS='"0x19"' +BLOCK=null +status +check "null block: syncing without head" '{"version":1,"state":"syncing"} 2' "$OUT $CALLS" +BLOCK='{"number":"0x0","timestamp":"0x0"}' + +echo "Snap sync phases" +METRICS=FAIL +status +check "metrics fail: syncing with background, no phase" \ + '{"version":1,"state":"syncing","height":0,"headTime":0,"peers":25,"background":"Finishing background sync tasks"}' "$OUT" +check "metrics fail: exit 0, 4 calls" "0 4" "$RC $CALLS" +check_valid "metrics fail" + +METRICS="$HEADER +$(timers TOTAL_SYNC_DURATION=0.0) +$(pivot 0.0)" +status +check "no pivot yet: awaiting target" 'true null' "$(field .awaitingTarget) $(field .phase)" +check "no pivot yet: background" '"Finishing background sync tasks"' "$(field .background)" +check_valid "awaiting target" +METRICS="$(timers TOTAL_SYNC_DURATION=0.0)" +status +check "no pivot gauge: awaiting target" 'true' "$(field .awaitingTarget)" +METRICS="$HEADER" +status +check "timers absent: no phase, not awaiting" 'null null "syncing"' "$(field .phase) $(field .awaitingTarget) $(field .state)" + +METRICS="$HEADER +$(timers TOTAL_SYNC_DURATION=0.0 CHAIN_DOWNLOAD_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=0.0) +$(pivot 1234567.0)" +status +check "world state download" '"Downloading state" null null' "$(field .phase) $(field .progress) $(field .position)" +check "world state: pivot detail" '[{"label":"Pivot block","value":"1234567"}]' "$(field .details)" +check "world state: not awaiting" null "$(field .awaitingTarget)" +check_valid "world state" + +# Fixture of the old dappmanager parser (no TOTAL_SYNC_DURATION line) +METRICS='besu_synchronizer_sync_duration_count{name="CHAIN_DOWNLOAD_DURATION",} 1.0 +besu_synchronizer_sync_duration_count{name="SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION",} 1.0 +besu_synchronizer_sync_duration_count{name="SNAP_WORLD_STATE_HEALING_DURATION",} 0.0' +status +check "old fixture: healing state" '"Healing state" null' "$(field .phase) $(field .progress)" +check_valid "healing" + +# Prometheus client 1.x format: no trailing comma, integer values +METRICS='besu_synchronizer_sync_duration_count{name="TOTAL_SYNC_DURATION"} 0 +besu_synchronizer_sync_duration_count{name="SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION"} 1 +besu_synchronizer_sync_duration_count{name="SNAP_WORLD_STATE_HEALING_DURATION"} 0 +besu_synchronizer_fast_sync_pivot_block_current 1.2345678E7' +status +check "format without trailing comma: healing state" '"Healing state"' "$(field .phase)" +check "scientific pivot value" '"12345678"' "$(field '.details[0].value')" + +METRICS="$(timers TOTAL_SYNC_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=1.0 \ + SNAP_WORLD_STATE_HEALING_DURATION=1.0 FLAT_DB_HEAL=0.0 CHAIN_DOWNLOAD_DURATION=1.0)" +status +check "flat database heal" '"Healing the flat database"' "$(field .phase)" +check_valid "flat heal" + +# Chain download still running after the state is complete +CHAIN_RUNNING="$(timers TOTAL_SYNC_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=1.0 \ + SNAP_WORLD_STATE_HEALING_DURATION=1.0 CHAIN_DOWNLOAD_DURATION=0.0)" +SYNCING='{"startingBlock":"0x0","currentBlock":"0xe6f3b2","highestBlock":"0x1312d10"}' +BLOCK='{"number":"0xe6f3b2","timestamp":"0x62d5f000"}' +METRICS="$CHAIN_RUNNING +$(pivot 19999900)" +status +check "chain download: blocks towards the pivot" '"Downloading blocks" 15135666 19999900 null' \ + "$(field .phase) $(field .position) $(field .target) $(field .progress)" +check_valid "chain download" +METRICS="$CHAIN_RUNNING" +status +check "chain download without pivot: towards highest" '15135666 20000016' "$(field .position) $(field .target)" +METRICS="$CHAIN_RUNNING +$(pivot 15000000)" +status +check "pivot below position: highest" '20000016' "$(field .target)" +SYNCING='{"startingBlock":"0x0","currentBlock":"0x1312d10","highestBlock":"0x1312d10"}' +status +check "position at highest: no target" '"Downloading blocks" 20000016 null' \ + "$(field .phase) $(field .position) $(field .target)" +check_valid "no target" +SYNCING='{"startingBlock":"0x1000","currentBlock":"0x1000","highestBlock":"0x1312d10"}' +status +check "nothing stored yet: headers" '"Downloading block headers" null null' \ + "$(field .phase) $(field .position) $(field .target)" +check_valid "headers" + +SYNCING=$SNAP_SYNCING +METRICS="$(timers TOTAL_SYNC_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=1.0 \ + SNAP_WORLD_STATE_HEALING_DURATION=1.0 CHAIN_DOWNLOAD_DURATION=1.0) +$(pivot 1234567)" +status +check "every phase ended: no phase" 'null null "Finishing background sync tasks"' \ + "$(field .phase) $(field .awaitingTarget) $(field .background)" +METRICS="$(timers TOTAL_SYNC_DURATION=1.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=0.0)" +status +check "sync ended in this process: no phase" 'null "syncing"' "$(field .phase) $(field .state)" + +echo "Requests" +METRICS="$(timers TOTAL_SYNC_DURATION=0.0 SNAP_INITIAL_WORLD_STATE_DOWNLOAD_DURATION=0.0)" +status +check "four calls while syncing" 4 "$CALLS" +check "only 127.0.0.1" 4 "$(grep -c '^http://127\.0\.0\.1:' "$TMP/calls")" +check "metrics URL" 'http://127.0.0.1:9545/metrics' "$(sed -n '4s/ .*//p' "$TMP/calls")" +export BESU_METRICS_PORT=9999 +status +check "metrics port follows BESU_METRICS_PORT" 'http://127.0.0.1:9999/metrics' "$(sed -n '4s/ .*//p' "$TMP/calls")" +unset BESU_METRICS_PORT +SYNCING=FAIL +status +check "rpc on 8545" 'http://127.0.0.1:8545 eth_syncing' "$(cat "$TMP/calls")" + +echo "Library missing" +SAVED=$NODE_STATUS_TOOLS +NODE_STATUS_TOOLS=$TMP/missing.sh +status +check "missing library: non-zero exit, no output" "1 " "$([ "$RC" -ne 0 ] && echo 1) $OUT" +NODE_STATUS_TOOLS=$SAVED + +echo "Exit codes" +for case in starting synced syncing; do + case $case in + starting) SYNCING=FAIL ;; + synced) SYNCING=false ;; + syncing) SYNCING=$SNAP_SYNCING ;; + esac + status + check "exit 0 for $case" "0 \"$case\"" "$RC $(field .state)" +done + +printf '\n%s passed, %s failed\n' "$PASS" "$FAIL" +[ "$FAIL" -eq 0 ]