Skip to content
Open
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
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
env:
NODE_STATUS_TOOLS: ${{ github.workspace }}/staker-package-scripts/scripts/node_status_tools.sh
- name: Test under busybox ash (Alpine, like the Geth image)
run: >
docker run --rm -v "$PWD:/work" -w /work alpine:3 sh -c
"apk add -q jq && NODE_STATUS_TOOLS=/work/staker-package-scripts/scripts/node_status_tools.sh 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
@@ -1 +1,5 @@
# DAppNode package Geth

## Node status report

The package reports Geth's sync phase (header, block and state download, healing, transaction indexing) through its Docker healthcheck, which the dappmanager reads to show the node's status. The healthcheck script is [`geth/node-status.sh`](geth/node-status.sh), installed in the image as `/usr/local/bin/node-status`; it uses the shared helpers from `dappnode/staker-package-scripts`. Its test is [`test/node_status_test.sh`](test/node_status_test.sh): run `sh test/node_status_test.sh` with a clone of `staker-package-scripts` next to this repository, or point `NODE_STATUS_TOOLS` at its `scripts/node_status_tools.sh`.
13 changes: 12 additions & 1 deletion dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"architectures": [
"linux/amd64",
Expand Down Expand Up @@ -26,6 +26,17 @@
"execution"
],
"license": "GPL-3.0",
"nodes": {
"geth": {
"role": "execution",
"probe": {
"kind": "ethereum-execution",
"rpcPort": 8545,
"enginePort": 8551
},
"report": "healthcheck"
}
},
"repository": {
"type": "git",
"url": "https://github.com/dappnode/DAppNodePackage-geth-generic.git"
Expand All @@ -44,7 +55,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,8 +5,14 @@ services:
context: geth
args:
UPSTREAM_VERSION: v1.17.10
STAKER_SCRIPTS_VERSION: v0.1.2
STAKER_SCRIPTS_VERSION: v0.1.3
environment:
EXTRA_OPTS: ""
SYNCMODE: snap
restart: unless-stopped
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
7 changes: 5 additions & 2 deletions geth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ ENV GETH_HTTP=true \
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

RUN apk update && apk add curl && apk cache clean && \
chmod +rx /usr/local/bin/entrypoint.sh /etc/profile.d/execution_tools.sh
RUN apk update && apk add curl jq && apk cache clean && \
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

# If NETWORK == lukso mkdir /config
RUN if [ "${NETWORK}" = "lukso" ]; then \
Expand Down
146 changes: 146 additions & 0 deletions geth/node-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/sh

# Node status report of the Geth package, run as the Docker healthcheck.
# Prints one JSON line (see the node status contract) telling which sync phase
# Geth is in and how far along. Whether the node is synced is decided by the
# dappmanager, not here.
#
# Geth snap sync, as of v1.17:
# - Before a consensus client drives it, eth_syncing is an object with
# currentBlock and highestBlock at 0: nothing to sync towards yet.
# - The latest block stays at genesis until the state is complete. Meanwhile
# the chain (headers, bodies, receipts) and the state download run together.
# eth_syncing gives no total for the state; the snap progress metric does
# (v1.17.6+). Healing has no total at all.
# - Snap/2 (only after the Amsterdam fork) replaces healing with a BAL
# catch-up and a trie generation, both measurable from eth_syncing.
# - eth_syncing stays an object after reaching the head until transactions
# (and state history, if enabled) are indexed: background work.
#
# Environment:
# NODE_STATUS_TOOLS: Path of the shared helpers (default /etc/profile.d/node_status_tools.sh)
# GETH_METRICS_PORT: Port of the metrics server, also read by Geth itself (default 6060)
# NS_RPC_PORT, NS_TIMEOUT: See node_status_tools.sh

# At most four calls, each with its own timeout, and none after the JSON-RPC
# fails, so the script ends well inside the healthcheck timeout even when Geth hangs
NS_TIMEOUT=${NS_TIMEOUT:-2}

# shellcheck source=/dev/null
. "${NODE_STATUS_TOOLS:-/etc/profile.d/node_status_tools.sh}" || exit 1

METRICS_URL="http://127.0.0.1:${GETH_METRICS_PORT:-6060}/debug/metrics/prometheus"

# Decimal value of a quantity field of the eth_syncing object, 0 when absent
sync_field() {
ns_hex_to_dec "$(ns_json_get "$syncing" ".$1")" 2>/dev/null || echo 0
}

# Percentage of $1 over $2 with one decimal, nothing when $2 is not positive
percent() {
awk -v done="$1" -v total="$2" 'BEGIN { if (total > 0) printf "%.1f\n", done * 100 / total }'
}

# The JSON-RPC does not answer yet: Geth is starting (opening its database)
if ! syncing=$(ns_rpc eth_syncing); then
ns_emit starting
exit $?
fi

# Latest block and peers, skipped after the first call that fails
head=""
height=""
peers=""
if head=$(ns_block_head); then
height=${head#height=}
height=${height%% *}
peers=$(ns_json_get "$(ns_rpc net_peerCount)" .) || peers=""
else
head=""
fi

if [ "$syncing" = "false" ]; then
# shellcheck disable=SC2086 # $head holds height=<n> headTime=<n>
ns_emit synced $head peers="$peers"
exit $?
fi

# Anything but an object tells nothing more
case $syncing in
"{"*) ;;
*)
# shellcheck disable=SC2086 # $head holds height=<n> headTime=<n>
ns_emit syncing $head peers="$peers"
exit $?
;;
esac

phase=""
progress=""
awaiting=""
background=""
detail=""

current=$(sync_field currentBlock)
highest=$(sync_field highestBlock)

if [ "$current" -eq 0 ] && [ "$highest" -eq 0 ]; then
# Nothing downloaded and no target: waits for the consensus client, or
# fetches the headers it was just given
phase="Downloading block headers"
awaiting=true
elif [ "$(($(sync_field healingTrienodes) + $(sync_field healingBytecode)))" -gt 0 ]; then
phase="Healing state"
pending=$(sync_field healingTrienodes)
[ "$pending" -gt 0 ] && detail="Trie nodes pending:$pending"
elif [ "$height" = "0" ]; then
# Snap sync before the state is complete: the latest block is genesis
synced_lists=$(sync_field syncedAccessLists)
total_lists=$(sync_field totalAccessLists)
trie_gen=$(sync_field trieGenProgress)
accounts=$(sync_field syncedAccounts)
if [ "$total_lists" -gt 0 ] && [ "$synced_lists" -lt "$total_lists" ]; then
phase="Catching up state"
progress=$(percent "$synced_lists" "$total_lists")
elif [ "$trie_gen" -gt 0 ] && [ "$trie_gen" -lt 100 ]; then
phase="Generating state trie"
progress=$trie_gen
else
# Only these two gauges are needed from the (large) metrics page
metrics=$(ns_http_get "$METRICS_URL" |
grep -E '^eth_(protocols_snap_sync_progress|downloader_chain_progress)[ {]')
# Fractions 0-1; both gauges exist from start-up at 0, so 0 means not measured yet
state_fraction=$(printf '%s\n' "$metrics" | ns_metric eth_protocols_snap_sync_progress)
chain_fraction=$(printf '%s\n' "$metrics" | ns_metric eth_downloader_chain_progress)
if awk -v f="${state_fraction:-0}" 'BEGIN { exit !(f > 0) }'; then
phase="Downloading state"
progress=$(percent "$state_fraction" 1)
detail="Accounts downloaded:$accounts"
elif [ "$accounts" -gt 0 ]; then
phase="Downloading state"
detail="Accounts downloaded:$accounts"
elif awk -v f="${chain_fraction:-0}" 'BEGIN { exit !(f > 0) }'; then
phase="Downloading blocks"
progress=$(percent "$chain_fraction" 1)
else
phase="Downloading blocks"
progress=$(percent "$current" "$highest")
fi
fi
fi

# Work that goes on once the node follows the head
if [ -z "$phase" ]; then
tx_remaining=$(sync_field txIndexRemainingBlocks)
if [ "$tx_remaining" -gt 0 ]; then
background="Indexing transactions"
detail="Blocks left to index:$tx_remaining"
elif [ "$(($(sync_field stateIndexRemaining) + $(sync_field trienodeIndexRemaining)))" -gt 0 ]; then
background="Indexing state history"
fi
fi

# shellcheck disable=SC2086 # $head holds height=<n> headTime=<n>
ns_emit syncing $head peers="$peers" phase="$phase" progress="$progress" \
awaitingTarget="$awaiting" background="$background" detail="$detail"
exit $?
5 changes: 5 additions & 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,10 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-geth-generic#readme"
},
"name": "hoodi-geth.dnp.dappnode.eth",
"nodes": {
"geth": {
"network": "hoodi"
}
},
"version": "0.1.7"
}
5 changes: 5 additions & 0 deletions package_variants/lukso/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"exposable": [
{
Expand All @@ -19,6 +19,11 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-geth-generic#readme"
},
"name": "lukso-geth.dnp.dappnode.eth",
"nodes": {
"geth": {
"network": "lukso"
}
},
"upstream": [
{
"arg": "UPSTREAM_VERSION",
Expand Down
5 changes: 5 additions & 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,5 +19,10 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-geth-generic#readme"
},
"name": "geth.dnp.dappnode.eth",
"nodes": {
"geth": {
"network": "mainnet"
}
},
"version": "0.1.52"
}
5 changes: 5 additions & 0 deletions package_variants/sepolia/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"exposable": [
{
Expand All @@ -21,5 +21,10 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-geth-generic#readme"
},
"name": "sepolia-geth.dnp.dappnode.eth",
"nodes": {
"geth": {
"network": "sepolia"
}
},
"version": "0.1.7"
}
Loading
Loading