diff --git a/.github/workflows/node-status-test.yml b/.github/workflows/node-status-test.yml new file mode 100644 index 0000000..86cf74a --- /dev/null +++ b/.github/workflows/node-status-test.yml @@ -0,0 +1,25 @@ +name: Node status test + +on: + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + env: + NODE_STATUS_TOOLS: staker-package-scripts/scripts/node_status_tools.sh + steps: + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: dappnode/staker-package-scripts + path: staker-package-scripts + - name: Test under dash + run: sh test/node_status_test.sh + - name: Test under Debian bookworm dash and jq 1.6 (the Erigon image base) + run: > + docker run --rm -e NODE_STATUS_TOOLS -v "$PWD:/work" -w /work debian:bookworm-slim sh -c + "apt-get update -qq && apt-get install -qq -y jq >/dev/null && sh test/node_status_test.sh" diff --git a/README.md b/README.md index b51864b..c8020db 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,7 @@ Erigon Dappnode Package https://github.com/erigontech/erigon + +## Node status report + +The package reports its sync phase (snapshot download, indexing, block execution) through its Docker healthcheck, which prints one JSON status report line for the DAppNode dashboard. The script is `erigon/node-status.sh` (installed as `/usr/local/bin/node-status`), built on the shared helpers `node_status_tools.sh` of `dappnode/staker-package-scripts`. Its test is `test/node_status_test.sh`: run `sh test/node_status_test.sh` with `staker-package-scripts` checked out next to this repository, or point `NODE_STATUS_TOOLS` at `node_status_tools.sh`. diff --git a/dappnode_package.json b/dappnode_package.json index 4efa778..fd8d633 100644 --- a/dappnode_package.json +++ b/dappnode_package.json @@ -13,6 +13,13 @@ "chain": "ethereum", "description": "Erigon is an implementation of Ethereum (execution layer with embeddable consensus layer), on the efficiency frontier.", "license": "GPL-3.0", + "nodes": { + "erigon": { + "role": "execution", + "probe": { "kind": "ethereum-execution", "rpcPort": 8545, "enginePort": 8551 }, + "report": "healthcheck" + } + }, "repository": { "type": "git", "url": "git+https://github.com/dappnode/DAppNodePackage-erigon-generic.git" @@ -31,7 +38,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 ce6c2c2..3e0cdc7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,11 +5,17 @@ services: context: erigon args: UPSTREAM_VERSION: v3.8.2 - STAKER_SCRIPTS_VERSION: v0.1.2 + STAKER_SCRIPTS_VERSION: v0.1.3 DATA_DIR: /home/erigon/.local/share environment: EXTRA_OPTS: "--http.api=engine,eth,erigon,web3,net,debug,trace,txpool" restart: unless-stopped + healthcheck: + test: ["CMD", "/usr/local/bin/node-status"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s ulimits: nofile: soft: 1000000 diff --git a/erigon/Dockerfile b/erigon/Dockerfile index 7327d00..713f912 100644 --- a/erigon/Dockerfile +++ b/erigon/Dockerfile @@ -14,12 +14,15 @@ ENV DATA_DIR=${DATA_DIR} \ 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/ USER root COPY entrypoint.sh /usr/local/bin/entrypoint.sh +COPY node-status.sh /usr/local/bin/node-status -RUN apt-get update && apt-get install -y curl && \ - chmod +rx /usr/local/bin/entrypoint.sh /etc/profile.d/execution_tools.sh +RUN apt-get update && apt-get install -y curl jq && \ + chmod +rx /usr/local/bin/entrypoint.sh /usr/local/bin/node-status \ + /etc/profile.d/execution_tools.sh /etc/profile.d/node_status_tools.sh ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ] diff --git a/erigon/node-status.sh b/erigon/node-status.sh new file mode 100755 index 0000000..303457d --- /dev/null +++ b/erigon/node-status.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +# Node status report of Erigon, printed by the Docker healthcheck +# +# Prints one JSON line (see ns_emit in node_status_tools.sh) telling which sync +# phase Erigon is in and how far along. Whether the node is synced is decided by +# the dappmanager, not here: "synced" only means eth_syncing returned false. +# +# Erigon 3 serves eth_syncing as {currentBlock, highestBlock, stages: [{stage_name, +# block_number}]} (rpc/jsonrpc/eth_system.go, node/shards/sync_state.go): +# - stages is empty while the snapshots are downloaded (OtterSync stage). Once +# the downloader reports, currentBlock / highestBlock is the share of bytes +# downloaded; before that both are 0. +# - stages lists every stage once the highest block is known; currentBlock is +# the progress of the Execution stage and highestBlock the head the +# consensus client sent. +# - startingBlock resets on every restart and is not used. +# The sync{stage=...} gauges of the metrics endpoint follow the stages as they +# run, ahead of eth_syncing, which only sees committed progress. +# +# Environment: +# NODE_STATUS_TOOLS: Path of node_status_tools.sh (default /etc/profile.d/node_status_tools.sh) +# NS_TIMEOUT: Timeout in seconds of each request (default 2, at most 4 requests run) +# EXTRA_OPTS: Erigon flags of the package, read for --http.port, --http.api and --metrics.port + +# shellcheck source=/dev/null +. "${NODE_STATUS_TOOLS:-/etc/profile.d/node_status_tools.sh}" + +# EXTRA_OPTS is split into words below and must not be globbed +set -f + +NS_TIMEOUT=${NS_TIMEOUT:-2} +BACKGROUND="Finishing background sync tasks" + +# Print the last value given to an Erigon flag in EXTRA_OPTS (--flag=value, +# --flag value, or with a single dash), nothing when it is not set +# +# Arguments: +# $1: Flag name without dashes +extra_opt() { + _value="" + _next="" + for _word in ${EXTRA_OPTS:-}; do + if [ -n "$_next" ]; then + _value=$_word + _next="" + continue + fi + case $_word in + --"$1"=* | -"$1"=*) _value=${_word#*=} ;; + --"$1" | -"$1") _next=1 ;; + esac + done + printf '%s' "$_value" +} + +# Print the port given to an Erigon flag in EXTRA_OPTS, or the default +# +# Arguments: +# $1: Flag name without dashes +# $2: Default port +extra_port() { + _port=$(extra_opt "$1") + case $_port in + '' | *[!0-9]*) printf '%s' "$2" ;; + *) printf '%s' "$_port" ;; + esac +} + +# Print an issue when the JSON-RPC namespaces the dashboard calls are not all +# enabled: Erigon serves only eth,erigon,engine without --http.api +api_issue() { + _apis=$(extra_opt http.api) + _missing="" + for _api in eth net web3; do + case ",${_apis:-eth,erigon,engine}," in + *",$_api,"*) ;; + *) _missing="${_missing:+$_missing, }$_api" ;; + esac + done + [ -z "$_missing" ] || printf '%s' "--http.api in EXTRA_OPTS lacks JSON-RPC namespaces the dashboard needs: $_missing" +} + +NS_RPC_PORT=${NS_RPC_PORT:-$(extra_port http.port 8545)} +METRICS_URL="http://127.0.0.1:$(extra_port metrics.port 6060)/debug/metrics/prometheus" +ISSUE=$(api_issue) + +# The JSON-RPC does not answer yet: Erigon is opening its database +if ! syncing=$(ns_rpc eth_syncing); then + ns_emit starting issue="$ISSUE" + exit $? +fi + +# Stop calling the node once a call fails: each failure can take NS_TIMEOUT +if head=$(ns_block_head); then + peers=$(ns_json_get "$(ns_rpc net_peerCount)" .) +else + head="" + peers="" +fi + +if [ "$syncing" = false ]; then + # shellcheck disable=SC2086 # $head is "height= headTime=" + ns_emit synced $head peers="$peers" issue="$ISSUE" + exit $? +fi + +# currentBlock, highestBlock, number of stages and the OtterSync stage block +fields=$(ns_json_get "$syncing" \ + '"\(.currentBlock) \(.highestBlock) \(.stages // [] | length) \(first(.stages[]? | select(.stage_name == "OtterSync") | .block_number) // 0)"') +# shellcheck disable=SC2086 # four words +set -- $fields +current=$(ns_hex_to_dec "${1:-}") || current=0 +highest=$(ns_hex_to_dec "${2:-}") || highest=0 +stage_count=${3:-0} +otter_sync=$(ns_hex_to_dec "${4:-}") || otter_sync=0 + +phase="" +progress="" +position="" +target="" + +if [ "$stage_count" -gt 0 ]; then + if [ "$otter_sync" -eq 0 ] && [ "$current" -eq 0 ]; then + # The highest block is known (sent by a consensus client, or from the header-chain + # snapshots) but the snapshot download has not reported progress yet + phase="Preparing the snapshot download" + elif [ "$highest" -gt "$current" ]; then + phase="Executing blocks" + position=$current + target=$highest + fi +elif [ "$highest" -eq 0 ]; then + # Waiting for the snapshot list, or downloading the header-chain snapshots, which report no progress + phase="Preparing the snapshot download" +elif [ -n "$head" ] && metrics=$(ns_http_get "$METRICS_URL") && + otter_metric=$(printf '%s\n' "$metrics" | ns_metric sync stage=otter_sync) && + [ "$otter_metric" != 0 ]; then + # The OtterSync stage is past the download (or ran before a restart), and + # eth_syncing still shows its last numbers until the first commit + exec_metric=$(printf '%s\n' "$metrics" | ns_metric sync stage=execution) || exec_metric=0 + exec_block=$(ns_hex_to_dec "$exec_metric") || exec_block=0 + if [ "$exec_block" -eq 0 ]; then + # Filling the database from the snapshots before execution starts + phase="Indexing snapshots" + else + [ "$exec_block" -gt "$current" ] && current=$exec_block + if [ "$highest" -gt "$current" ]; then + phase="Executing blocks" + position=$current + target=$highest + fi + fi +else + # The snapshot download: currentBlock / highestBlock is the share of bytes downloaded + permille=$((current * 1000 / highest)) + if [ "$permille" -ge 990 ]; then + # Indexing after the download leaves the numbers near the end for a long time, with nothing to measure + phase="Indexing snapshots" + else + phase="Downloading snapshots" + progress="$((permille / 10)).$((permille % 10))" + fi +fi + +# shellcheck disable=SC2086 # $head is "height= headTime=" +ns_emit syncing $head phase="$phase" progress="$progress" position="$position" target="$target" \ + peers="$peers" background="$BACKGROUND" issue="$ISSUE" +exit $? diff --git a/package_variants/gnosis/dappnode_package.json b/package_variants/gnosis/dappnode_package.json index 0434d8d..85f20f1 100644 --- a/package_variants/gnosis/dappnode_package.json +++ b/package_variants/gnosis/dappnode_package.json @@ -19,6 +19,7 @@ "homepage": "https://github.com/ledgerwatch/erigon" }, "name": "gnosis-erigon.dnp.dappnode.eth", + "nodes": { "erigon": { "network": "gnosis" } }, "optionalDependencies": { "lighthouse-gnosis.dnp.dappnode.eth": ">=0.1.15", "lodestar-gnosis.dnp.dappnode.eth": ">=0.1.32", diff --git a/package_variants/hoodi/dappnode_package.json b/package_variants/hoodi/dappnode_package.json index ced1943..4b170cc 100644 --- a/package_variants/hoodi/dappnode_package.json +++ b/package_variants/hoodi/dappnode_package.json @@ -19,5 +19,6 @@ "homepage": "https://github.com/ledgerwatch/erigon" }, "name": "hoodi-erigon.dnp.dappnode.eth", + "nodes": { "erigon": { "network": "hoodi" } }, "version": "0.1.6" } diff --git a/package_variants/mainnet/dappnode_package.json b/package_variants/mainnet/dappnode_package.json index 6080603..85d382f 100644 --- a/package_variants/mainnet/dappnode_package.json +++ b/package_variants/mainnet/dappnode_package.json @@ -19,6 +19,7 @@ "homepage": "https://github.com/ledgerwatch/erigon" }, "name": "erigon.dnp.dappnode.eth", + "nodes": { "erigon": { "network": "mainnet" } }, "version": "1.0.6", "warnings": { "onMajorUpdate": "⚠️ IMPORTANT: AFTER UPDATING, YOU MUST DELETE THE VOLUMES OF YOUR ERIGON PACKAGE ⚠️. Erigon v3 requires a full resynchronization, so removing the old volumes is mandatory. Note that Erigon now runs in non-archival mode by default. For instructions on deleting volumes, visit: https://docs.dappnode.io/docs/user/packages/understanding-dappnode-packages/info" diff --git a/test/node_status_test.sh b/test/node_status_test.sh new file mode 100644 index 0000000..95830f7 --- /dev/null +++ b/test/node_status_test.sh @@ -0,0 +1,353 @@ +#!/bin/sh + +# Tests for erigon/node-status.sh, the healthcheck that prints the node status report +# Run from anywhere with any POSIX sh: sh test/node_status_test.sh +# Needs jq and the shared helpers of dappnode/staker-package-scripts, by default +# checked out next to this repository (override with NODE_STATUS_TOOLS). +# The node is stubbed by a curl function that answers per JSON-RPC method. + +# The variables set here (EXTRA_OPTS, NS_TIMEOUT, R_*) are read by the sourced script and stubs +# shellcheck disable=SC2034 + +cd "$(dirname "$0")/.." || exit 1 +NODE_STATUS_TOOLS=${NODE_STATUS_TOOLS:-../staker-package-scripts/scripts/node_status_tools.sh} +[ -f "$NODE_STATUS_TOOLS" ] || { + echo "node_status_tools.sh not found at $NODE_STATUS_TOOLS (set NODE_STATUS_TOOLS)" >&2 + exit 1 +} +NODE_STATUS_TOOLS=$(cd "$(dirname "$NODE_STATUS_TOOLS")" && pwd)/$(basename "$NODE_STATUS_TOOLS") +SCRIPT=$(pwd)/erigon/node-status.sh +DEFAULT_OPTS="--http.api=engine,eth,erigon,web3,net,debug,trace,txpool" + +PASS=0 +FAIL=0 +TMP=$(mktemp -d) || exit 1 +trap 'rm -rf "$TMP"' EXIT + +# Stub curl. Replies come from R_SYNCING, R_BLOCK and R_PEERS (the JSON-RPC +# result) and R_METRICS (the body); the special values REFUSED and TIMEOUT fail +# like curl, NOT_FOUND answers a JSON-RPC "method not found" error. Every call +# is logged to $TMP/calls as " ", its arguments to $TMP/args. +# shellcheck disable=SC2329 # called by the helpers under test +curl() { + _url="" + _data="" + _prev="" + printf '%s\n' "$@" >"$TMP/args" + for _arg in "$@"; do + [ "$_prev" = "--data" ] && _data=$_arg + _prev=$_arg + _url=$_arg + done + case $_data in + *'"eth_syncing"'*) _name=eth_syncing _reply=$R_SYNCING ;; + *'"eth_getBlockByNumber"'*) _name=eth_getBlockByNumber _reply=$R_BLOCK ;; + *'"net_peerCount"'*) _name=net_peerCount _reply=$R_PEERS ;; + '') _name=metrics _reply=$R_METRICS ;; + *) _name=other _reply=NOT_FOUND ;; + esac + echo "$_name $_url" >>"$TMP/calls" + case $_reply in + REFUSED) return 7 ;; + TIMEOUT) return 28 ;; + NOT_FOUND) + printf '%s' '{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method does not exist/is not available"}}' + ;; + *) + if [ "$_name" = metrics ]; then + printf '%s' "$_reply" + else + printf '{"jsonrpc":"2.0","id":1,"result":%s}' "$_reply" + fi + ;; + esac +} + +# A healthy node at the head, changed by each test +reset_node() { + R_SYNCING=false + R_BLOCK='{"number":"0x1312d00","timestamp":"0x6553f100","hash":"0xab"}' + R_PEERS='"0x19"' + R_METRICS=REFUSED + EXTRA_OPTS=$DEFAULT_OPTS + unset NS_TIMEOUT NS_RPC_PORT + : >"$TMP/calls" +} + +# Eth_syncing object of Erigon: [stages JSON] +syncing_obj() { + printf '{"startingBlock":"0x0","currentBlock":"0x%x","highestBlock":"0x%x","stages":%s}' "$1" "$2" "${3:-[]}" +} + +# Erigon 3 stage list (execution/stagedsync/stages) with every stage at , OtterSync at +stages() { + printf '[{"stage_name":"OtterSync","block_number":"0x%x"}' "$2" + for _stage in Headers BlockHashes Bodies Senders Execution CustomTrace TxLookup Finish; do + printf ',{"stage_name":"%s","block_number":"0x%x"}' "$_stage" "$1" + done + printf ']' +} + +# Prometheus text with the sync{stage=...} gauges of OtterSync and Execution +metrics() { + printf '# TYPE sync gauge\nsync{stage="otter_sync"} %s\nsync{stage="headers"} 0\nsync{stage="execution"} %s\nexec_blocks 12\n' "$1" "$2" +} + +# Run the script with the stubs; sets OUT (stdout) and RC (exit status) +run() { + # shellcheck disable=SC1090 # the script under test + OUT=$(. "$SCRIPT" 2>/dev/null) + RC=$? +} + +# 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 +} + +# Field of the report, compact JSON ("null" when absent) +field() { + printf '%s' "$OUT" | jq -c "$1" 2>/dev/null +} + +# Number of calls of a kind in the last run +calls() { + grep -c "^$1 " "$TMP/calls" +} + +# The report is one JSON line that respects the contract, and the script exits 0 +check_report() { + check "$1: exit code" "0" "$RC" + check "$1: one line" "1" "$(printf '%s\n' "$OUT" | wc -l | tr -d ' ')" + check "$1: contract" "true" "$(printf '%s' "$OUT" | jq -c ' + def int: . == null or (type == "number" and . >= 0 and . == floor); + def text($n): . == null or (type == "string" and length > 0 and length <= $n); + type == "object" and .version == 1 + and (.state | IN("starting", "syncing", "synced", "error")) + and (keys - ["version", "state", "phase", "progress", "height", "headTime", "position", "target", + "unit", "peers", "awaitingTarget", "background", "issues", "details"] | length == 0) + and (.phase | text(60)) and (.background | text(60)) and (.unit | text(20)) + and (.progress | . == null or (type == "number" and . >= 0 and . <= 99.9)) + and all(.height, .headTime, .position, .target, .peers; int) + and (.awaitingTarget | . == null or . == true) + and (.issues | . == null or (type == "array" and length <= 5 and all(.[]; text(120)))) + and ((.progress != null and .position != null) | not) + and (tojson | utf8bytelength <= 2048)' 2>/dev/null)" +} + +echo "Node not answering" +reset_node +R_SYNCING=REFUSED +run +check_report "refused" +check "refused: starting" '"starting"' "$(field .state)" +check "refused: no phase" "null" "$(field .phase)" +check "refused: one call only" "eth_syncing 1 0" "$(head -n 1 "$TMP/calls" | cut -d' ' -f1) $(wc -l <"$TMP/calls" | tr -d ' ') $(calls metrics)" +check "default timeout" "2" "$(sed -n '/^--max-time$/{n;p;q;}' "$TMP/args")" +check "default url" "http://127.0.0.1:8545" "$(tail -n 1 "$TMP/args")" + +reset_node +R_SYNCING=TIMEOUT +run +check_report "timeout" +check "timeout: starting" '"starting"' "$(field .state)" +check "timeout: one call only" "1" "$(wc -l <"$TMP/calls" | tr -d ' ')" + +reset_node +R_SYNCING='"not json' +run +check_report "garbled" +check "garbled reply: starting" '"starting"' "$(field .state)" + +echo "Synced" +reset_node +run +check_report "synced" +check "synced: state" '"synced"' "$(field .state)" +check "synced: height and time" "20000000 1700000000" "$(field .height) $(field .headTime)" +check "synced: peers" "25" "$(field .peers)" +check "synced: no phase, no background" "null null" "$(field .phase) $(field .background)" +check "synced: no issues" "null" "$(field .issues)" +check "synced: metrics not fetched" "0" "$(calls metrics)" + +echo "Snapshot download (OtterSync)" +reset_node +R_SYNCING=$(syncing_obj 0 0) +run +check_report "preparing" +check "nothing known yet: preparing" '"syncing" "Preparing the snapshot download"' "$(field .state) $(field .phase)" +check "preparing: no progress" "null" "$(field .progress)" +check "preparing: metrics not fetched" "0" "$(calls metrics)" +check "preparing: background note" '"Finishing background sync tasks"' "$(field .background)" + +reset_node +R_SYNCING=$(syncing_obj 0 1200000 "$(stages 0 0)") +run +check_report "preparing with head" +check "head known, stages at 0: preparing" '"Preparing the snapshot download"' "$(field .phase)" +check "head known, stages at 0: no blocks" "null null" "$(field .position) $(field .target)" + +reset_node +R_SYNCING=$(syncing_obj 5000000 20000000) +run +check_report "download" +check "download: phase" '"Downloading snapshots"' "$(field .phase)" +check "download: progress from current / highest" "25" "$(field .progress)" +check "download: no blocks" "null null" "$(field .position) $(field .target)" +check "download: height and peers" "20000000 25" "$(field .height) $(field .peers)" + +reset_node +R_SYNCING=$(syncing_obj 5000000 20000000) +R_METRICS=$(metrics 0 0) +run +check_report "download with metrics" +check "download, OtterSync gauge at 0: progress" '"Downloading snapshots" 25' "$(field .phase) $(field .progress)" +check "download: metrics fetched once" "1" "$(calls metrics)" + +reset_node +R_SYNCING=$(syncing_obj 19790000 20000000) +run +check_report "download end" +check "download at 98.95%: still downloading" '"Downloading snapshots" 98.9' "$(field .phase) $(field .progress)" + +reset_node +R_SYNCING=$(syncing_obj 19800000 20000000) +run +check_report "indexing" +check "download at 99%: indexing" '"Indexing snapshots"' "$(field .phase)" +check "indexing: no progress" "null" "$(field .progress)" + +reset_node +R_SYNCING=$(syncing_obj 19999999 20000000) +R_METRICS=$(metrics 0 0) +run +check_report "indexing near end" +check "download numbers at the end: indexing" '"Indexing snapshots"' "$(field .phase)" + +echo "After the download (OtterSync done, eth_syncing still on the download numbers)" +reset_node +R_SYNCING=$(syncing_obj 1990000 2000000) +R_METRICS=$(metrics 1995000 0) +run +check_report "filling db" +check "OtterSync gauge set, Execution at 0: indexing" '"Indexing snapshots"' "$(field .phase)" + +reset_node +R_SYNCING=$(syncing_obj 1900000 2100000) +R_METRICS=$(metrics 1995000 1950500) +run +check_report "handoff" +check "handoff: executing" '"Executing blocks"' "$(field .phase)" +check "handoff: position from the Execution gauge" "1950500 2100000" "$(field .position) $(field .target)" +check "handoff: no progress" "null" "$(field .progress)" + +reset_node +R_SYNCING=$(syncing_obj 1960000 2100000) +R_METRICS=$(printf 'sync{stage="otter_sync"} 1.995e+06\nsync{stage="execution"} 1.9505E6\n') +run +check_report "handoff exponent" +check "gauges in exponent notation, eth_syncing ahead" "1960000 2100000" "$(field .position) $(field .target)" + +reset_node +R_SYNCING=$(syncing_obj 2000000 2000003) +R_METRICS=$(metrics 1995000 2000003) +run +check_report "restart" +check "restart at the head: nothing to tell" '"syncing" null null' "$(field .state) $(field .phase) $(field .position)" + +echo "Staged sync" +reset_node +R_SYNCING='{"startingBlock":"0x12fa660","currentBlock":"0x13069b0","highestBlock":"0x1312d00","stages":[{"stage_name":"Execution","block_number":"0x13069b0"}]}' +run +check_report "executing (old fixture)" +check "executing: phase" '"Executing blocks"' "$(field .phase)" +check "executing: blocks, ignoring startingBlock" "19950000 20000000" "$(field .position) $(field .target)" +check "executing: 50,000 blocks left" "50000" "$(field '.target - .position')" +check "executing: no progress" "null" "$(field .progress)" +check "executing: metrics not fetched" "0" "$(calls metrics)" + +reset_node +R_SYNCING=$(syncing_obj 1500000 2000000 "$(stages 1500000 1400000)") +run +check_report "executing (Erigon 3 stages)" +check "Erigon 3 stage list: executing" '"Executing blocks" 1500000 2000000' "$(field .phase) $(field .position) $(field .target)" + +reset_node +R_SYNCING=$(syncing_obj 2000000 2000000 "$(stages 2000000 1990000)") +run +check_report "no target" +check "stages at the head: nothing to tell" '"syncing" null null' "$(field .state) $(field .phase) $(field .target)" + +echo "Partial answers" +reset_node +R_SYNCING=$(syncing_obj 5000000 20000000) +R_BLOCK=TIMEOUT +R_METRICS=$(metrics 1995000 0) +run +check_report "block timeout" +check "block timeout: phase from eth_syncing" '"Downloading snapshots" 25' "$(field .phase) $(field .progress)" +check "block timeout: no height, no peers" "null null" "$(field .height) $(field .peers)" +check "block timeout: no more calls" "0 0" "$(calls net_peerCount) $(calls metrics)" + +reset_node +R_BLOCK=null +run +check_report "no block" +check "no latest block: synced without height" '"synced" null' "$(field .state) $(field .height)" + +reset_node +R_PEERS=NOT_FOUND +run +check_report "net disabled" +check "net disabled: no peers" "null" "$(field .peers)" +check "net disabled: height kept" "20000000" "$(field .height)" + +echo "EXTRA_OPTS" +reset_node +EXTRA_OPTS="--prune.mode=archive" +R_PEERS=NOT_FOUND +run +check_report "no http.api" +check "Erigon default APIs: issue" '["--http.api in EXTRA_OPTS lacks JSON-RPC namespaces the dashboard needs: net, web3"]' "$(field .issues)" + +reset_node +EXTRA_OPTS="--http.api engine,eth --http.api=eth,net,web3" +run +check_report "last http.api wins" +check "last --http.api wins" "null" "$(field .issues)" + +reset_node +EXTRA_OPTS="-http.api=engine" +R_SYNCING=NOT_FOUND +run +check_report "eth disabled" +check "eth disabled: starting with issue" '"starting" ["--http.api in EXTRA_OPTS lacks JSON-RPC namespaces the dashboard needs: eth, net, web3"]' "$(field .state) $(field .issues)" + +reset_node +EXTRA_OPTS="$DEFAULT_OPTS --http.port=8547 --metrics.port 6070" +R_SYNCING=$(syncing_obj 1900000 2100000) +R_METRICS=$(metrics 1995000 1950500) +run +check_report "ports" +check "rpc port from EXTRA_OPTS" "1" "$(grep -c '^eth_syncing http://127.0.0.1:8547$' "$TMP/calls")" +check "metrics port from EXTRA_OPTS" "1" "$(grep -c '^metrics http://127.0.0.1:6070/debug/metrics/prometheus$' "$TMP/calls")" + +reset_node +EXTRA_OPTS='--http.api=* --http.port=abc' +run +check_report "odd opts" +check "glob and invalid port in EXTRA_OPTS" "1" "$(grep -c '^eth_syncing http://127.0.0.1:8545$' "$TMP/calls")" + +reset_node +NS_TIMEOUT=1 +run +check "NS_TIMEOUT is honoured" "1" "$(sed -n '/^--max-time$/{n;p;q;}' "$TMP/args")" + +echo +echo "$PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ]