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
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 tests
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 @@ -3,3 +3,7 @@
Light wrapper around the Nethermind Ethereum client

> Nethermind - The world’s fastest Ethereum .NET Client and P2P Data Marketplace for the decentralised future\nOur flagship .NET Core-based Ethereum client is all about performance and flexibility. We have built a lean, stable and feature-rich gateway to allow anyone, anywhere, to take part in the decentralised future.

## Node status report

The package reports its sync phase to the DAppNode dashboard through its Docker healthcheck: `/usr/local/bin/node-status` prints one JSON line with what Nethermind is doing (sync phase, progress, latest block, peers, background work and health issues). The script is [`nethermind/node-status.sh`](nethermind/node-status.sh), built on the shared helpers of [staker-package-scripts](https://github.com/dappnode/staker-package-scripts). Its tests are in [`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 All @@ -13,6 +13,17 @@
"chain": "ethereum",
"description": "Nethermind - The world's fastest Ethereum .NET Client and P2P Data Marketplace for the decentralised future\nOur flagship .NET Core-based Ethereum client is all about performance and flexibility. We have built a lean, stable and feature-rich gateway to allow anyone, anywhere, to take part in the decentralised future.",
"license": "GPL-3.0",
"nodes": {
"nethermind": {
"role": "execution",
"probe": {
"kind": "ethereum-execution",
"rpcPort": 8545,
"enginePort": 8551
},
"report": "healthcheck"
}
},
"repository": {
"type": "git",
"url": "https://github.com/dappnode/DAppNodePackage-nethermind-generic.git"
Expand All @@ -31,7 +42,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: nethermind
args:
UPSTREAM_VERSION: 2.2.2
STAKER_SCRIPTS_VERSION: v0.1.2
STAKER_SCRIPTS_VERSION: v0.1.3
DATA_DIR: /data
restart: unless-stopped
security_opt:
Expand All @@ -25,5 +25,11 @@ services:
nofile:
soft: 1000000
hard: 1000000
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
data: {}
7 changes: 5 additions & 2 deletions nethermind/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ ENV NETHERMIND_JSONRPCCONFIG_ENABLED=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 apt-get update && apt-get --yes install curl && \
RUN apt-get update && apt-get --yes install curl jq && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
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 /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
109 changes: 109 additions & 0 deletions nethermind/node-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/sh

# Node status report of the Nethermind execution client, run as the Docker
# healthcheck. Prints one JSON line (node status contract, version 1) telling
# which sync phase Nethermind is in and how far along it is. Whether the node is
# synced, waiting on the consensus client or stalled is decided by the
# dappmanager, not here.
#
# What it relies on, as of NethermindEth/nethermind 2.2.2:
# - eth_syncing (src/Nethermind/Nethermind.Facade/Eth/EthSyncingInfo.cs): an
# object while the head is more than 8 blocks behind the highest known block
# (the best suggested header or the beacon sync target), or while old bodies
# and receipts are still downloading. The head (currentBlock) stays at
# genesis until the snap state sync ends. From 2.3 the object also carries
# warpChunksProcessed / warpChunksAmount during the state download.
# - health_nodeStatus (src/Nethermind/Nethermind.HealthChecks/NodeHealthService.cs):
# "errors" lists ClUnavailable (no forkchoice or payload from the consensus
# client for 5 minutes) and LowDiskSpace, among others.
#
# Environment:
# NODE_STATUS_TOOLS: Path of the shared helpers (default /etc/profile.d/node_status_tools.sh)
# NS_RPC_PORT, NS_TIMEOUT: See node_status_tools.sh (NS_TIMEOUT defaults to 2 here)

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

# At most four sequential calls: keep the worst case well inside the 10 s healthcheck timeout
NS_TIMEOUT=${NS_TIMEOUT:-2}

# Nethermind counts the head as synced within this many blocks of the highest known block
# (EthSyncingInfo.MaxDistanceForSynced)
MAX_DISTANCE_FOR_SYNCED=8

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

# Latest block, peers and health issues, in that order; a failed call means the
# node stopped answering, so the remaining ones are skipped
set --
if head=$(ns_block_head); then
# shellcheck disable=SC2086 # height=<n> headTime=<n>, two arguments
set -- $head
if peers=$(ns_rpc net_peerCount); then
set -- "$@" peers="$(ns_json_get "$peers")"
if health=$(ns_rpc health_nodeStatus); then
# NoPeers is left out: the dappmanager derives it from peers. SyncDegraded is
# left out too: Nethermind raises it while it only waits for the consensus client
for error in $(ns_json_get "$health" '(.errors // .Errors // [])[] | strings'); do
case $error in
ClUnavailable) set -- "$@" issue="Consensus client not connected" ;;
LowDiskSpace) set -- "$@" issue="Low disk space" ;;
esac
done
fi
fi
fi

if [ "$syncing" = "false" ]; then
ns_emit synced "$@"
exit $?
fi

if [ "$(ns_json_get "$syncing" type)" != "object" ]; then
ns_emit syncing "$@"
exit $?
fi

# Missing or unreadable numbers count as 0, like the dappmanager's old parser
number() {
ns_hex_to_dec "$(ns_json_get "$syncing" "$1")" || echo 0
}
current=$(number .currentBlock)
highest=$(number .highestBlock)

# The head is past genesis: the state is complete
if [ "$current" -gt 0 ]; then
if [ "$highest" -gt $((current + MAX_DISTANCE_FOR_SYNCED)) ]; then
ns_emit syncing "$@" phase="Catching up" position="$current" target="$highest"
exit $?
fi
# At the head and still reported as syncing: old bodies and receipts are downloading
ns_emit syncing "$@" background="Downloading old blocks and receipts"
exit $?
fi

# No consensus client has given a target since the start
if [ "$highest" -eq 0 ]; then
ns_emit syncing "$@" phase="Downloading block headers" awaitingTarget=true
exit $?
fi

# Snap state download, measured from 2.3 on
processed=$(number .warpChunksProcessed)
amount=$(number .warpChunksAmount)
if [ "$amount" -gt 0 ]; then
if [ "$processed" -ge "$amount" ]; then
ns_emit syncing "$@" phase="Healing state"
exit $?
fi
ns_emit syncing "$@" phase="Downloading state" progress="$(jq -n "$processed * 100 / $amount")"
exit $?
fi

# Up to 2.2 nothing tells the header download, the state download and healing apart
ns_emit syncing "$@" phase="Downloading headers and state"
exit $?
5 changes: 5 additions & 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,11 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-nethermind-generic#readme"
},
"name": "nethermind-xdai.dnp.dappnode.eth",
"nodes": {
"nethermind": {
"network": "gnosis"
}
},
"requirements": {
"minimumDappnodeVersion": "0.3.12",
"notInstalledPackages": [
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 @@ -19,5 +19,10 @@
"homepage": "https://github.com/dappnode/DAppNodePackage-nethermind-generic#readme"
},
"name": "hoodi-nethermind.dnp.dappnode.eth",
"nodes": {
"nethermind": {
"network": "hoodi"
}
},
"version": "0.1.24"
}
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-nethermind-generic#readme"
},
"name": "nethermind.public.dappnode.eth",
"nodes": {
"nethermind": {
"network": "mainnet"
}
},
"version": "1.0.88"
}
Loading
Loading