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
21 changes: 21 additions & 0 deletions .github/workflows/node-status-test.yml
Original file line number Diff line number Diff line change
@@ -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
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 @@ -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.
7 changes: 5 additions & 2 deletions besu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
125 changes: 125 additions & 0 deletions besu/node-status.sh
Original file line number Diff line number Diff line change
@@ -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=<phase>} 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=<n> headTime=<n>"
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 $?
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 All @@ -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"
Expand All @@ -37,7 +48,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,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
Expand All @@ -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:
Expand Down
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 @@ -20,5 +20,10 @@
"homepage": "https://github.com/hyperledger/besu"
},
"name": "hoodi-besu.dnp.dappnode.eth",
"nodes": {
"besu": {
"network": "hoodi"
}
},
"version": "0.1.8"
}
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 @@ -20,5 +20,10 @@
"homepage": "https://github.com/hyperledger/besu"
},
"name": "besu.public.dappnode.eth",
"nodes": {
"besu": {
"network": "mainnet"
}
},
"version": "1.2.18"
}
Loading
Loading