Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/node-status-test.yml
Original file line number Diff line number Diff line change
@@ -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"
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
9 changes: 8 additions & 1 deletion dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"architectures": [
"linux/amd64",
Expand All @@ -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"
Expand All @@ -31,7 +38,7 @@
{
"arg": "STAKER_SCRIPTS_VERSION",
"repo": "dappnode/staker-package-scripts",
"version": "v0.1.2"
"version": "v0.1.3"
}
]
}
8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions erigon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
169 changes: 169 additions & 0 deletions erigon/node-status.sh
Original file line number Diff line number Diff line change
@@ -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=<n> headTime=<n>"
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=<n> headTime=<n>"
ns_emit syncing $head phase="$phase" progress="$progress" position="$position" target="$target" \
peers="$peers" background="$BACKGROUND" issue="$ISSUE"
exit $?
1 change: 1 addition & 0 deletions package_variants/gnosis/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"exposable": [
{
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package_variants/hoodi/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"exposable": [
{
Expand All @@ -19,5 +19,6 @@
"homepage": "https://github.com/ledgerwatch/erigon"
},
"name": "hoodi-erigon.dnp.dappnode.eth",
"nodes": { "erigon": { "network": "hoodi" } },
"version": "0.1.6"
}
1 change: 1 addition & 0 deletions package_variants/mainnet/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"exposable": [
{
Expand All @@ -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"
Expand Down
Loading
Loading