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
4 changes: 4 additions & 0 deletions docs/dev/github-actions/staker-packages/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ llm_description: "Overview of CI/CD workflows for Dappnode staker packages inclu

Staker packages require more complex CI than standard packages because they need integration testing on real Dappnode hardware. This ensures that execution clients, consensus clients, web3signer, and MEV-boost work correctly together in a real staking environment.

:::tip
Client packages also tell the dashboard what their client is doing (sync phase, progress, pre-start work) through a status report printed by their Docker healthcheck, using the shared helpers in `staker-package-scripts`. See [Node Status Reports](../../node-status.md).
:::

## Architecture

The staker package CI runs on a **GitHub self-hosted runner** with the following characteristics:
Expand Down
277 changes: 277 additions & 0 deletions docs/dev/node-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
---
title: "🩺 Node Status Reports"
llm_description: "How a node package declares its nodes in the manifest and reports what its client is doing through its Docker healthcheck, for the Dappnode dashboard."
---

# 🩺 Node Status Reports

A node package can tell the Dappnode dashboard what its client is doing: which sync phase it is in and how far along, what it does before its API answers (for example downloading a snapshot), what keeps running after it reached the head, and which problems it sees. The package declares its nodes in the manifest field [`nodes`](./references/manifest.md#nodes), and the service's Docker healthcheck prints a small JSON **status report**.

:::info
Today the dappmanager reads status reports from **execution clients** only: the service declared with `role: "execution"` and `report: "healthcheck"` in the package selected as execution client for a network in Stakers. It also calls the JSON-RPC and beacon API on the ports the selected packages declare. The rest of the `nodes` field is defined but not used yet, see [Not used yet](#not-used-yet).
:::

## What the user sees

The dashboard shows a card for each staking network, with one row for the execution client and one for the consensus client.

| Element | Example | Comes from |
| --- | --- | --- |
| State badge | Synced, Syncing, Waiting, Stalled | Dappmanager |
| Badge when the API does not answer | Starting, Stopped, Not responding | Dappmanager |
| Sync line, while not synced | `Downloading state · 42% · about 1 h 5 min left` | Phase from the report; percentage, distance behind and time left computed by the dappmanager |
| Progress bar | Measured, or a moving bar when nothing can be measured | Dappmanager, from the report's `progress` or `position` and `target` |
| Phase while the API does not answer | `Downloading snapshot · 37%` under a Starting badge | Report (`state: "starting"`) |
| Background line, once synced | `Indexing transactions in the background` | Report `background` |
| Warnings | `Low disk space` | Report `issues`, plus `No peers` from the dappmanager |
| Tooltip on the badge | `Latest block`, `Reports syncing`, `Package status report: Yes` | Dappmanager lines, then the report's `details` |

## Who decides what

The package says what its client is doing; the dappmanager decides the status. A report never makes a node show as synced.

| Question | Decided by |
| --- | --- |
| Phase and how far along it is | Package |
| What happens before the API answers | Package |
| Work that continues after reaching the head | Package |
| Problems the client reports about itself | Package |
| Whether the execution client is synced: its latest block is at most 3 minutes old | Dappmanager |
| Waiting for the consensus client | Dappmanager |
| Stalled: a phase measured in blocks, or the catch-up to the head, has not moved for 5 minutes; or a node that is not synced has no peers | Dappmanager |
| Time left, and time and blocks behind | Dappmanager |
| Which address to call | Dappmanager |

## Declare the nodes in the manifest

`nodes` is keyed by compose service name. Shared fields go in the root `dappnode_package.json`; each variant manifest adds only `network` (the SDK merges root and variant manifests recursively).

Root manifest:

```json
"nodes": {
"reth": {
"role": "execution",
"probe": { "kind": "ethereum-execution", "rpcPort": 8545, "enginePort": 8551 },
"report": "healthcheck"
}
}
```

Variant manifest (`package_variants/hoodi/dappnode_package.json`):

```json
"nodes": { "reth": { "network": "hoodi" } }
```

- The key must be the compose service whose container runs the healthcheck. The SDK does not check it yet; a key that matches no service means the report is never read.
- `network` is the dappmanager network name: `mainnet`, `gnosis`, `hoodi`, `sepolia` or `lukso`.
- Use the ports the client really listens on. No hostnames or URLs anywhere.

The full field description is in the [manifest reference](./references/manifest.md#nodes).

## The status report

One JSON object, printed as the **last line of stdout** of the healthcheck. At most 2,048 bytes. Only `version` and `state` are required. Leave out anything you do not know rather than sending `null` or `0`.

| Field | Type and limits | Meaning |
| --- | --- | --- |
| `version` | `1` | Required. |
| `state` | `starting`, `syncing`, `synced` or `error` | Required. The client's own view. `starting`: the node's API does not answer yet (start-up, snapshot or checkpoint download, database opening). |
| `phase` | string, up to 60 characters | What the node is doing, e.g. `Downloading state`. Sentence case, no trailing period. |
| `progress` | number, 0-100 | Progress of the current phase as a percentage. Never 100 while the phase is still running: cap at 99.9. |
| `height` | integer | Latest block the node serves (number of `eth_getBlockByNumber("latest")`). |
| `headTime` | integer, Unix seconds | Timestamp of that block. |
| `position` | integer | For a phase measured in blocks: the block the phase has reached. May differ from `height`. |
| `target` | integer | The block the node syncs towards, when the client knows it. |
| `unit` | string, up to 20 characters | Unit of `height`, `position` and `target`. Default `blocks`. |
| `peers` | integer | Connected peers. |
| `awaitingTarget` | `true` | The client has nothing to sync towards yet. Omit otherwise. |
| `background` | string, up to 60 characters | Work that continues after reaching the head, e.g. `Indexing transactions`. |
| `issues` | up to 5 strings, up to 120 characters each | Problems the client reports about itself, e.g. `Low disk space`. |
| `details` | up to 8 `{ "label", "value" }` objects, label up to 40 characters, value up to 120 | Extra lines for the tooltip, already formatted. |

For an execution client the dappmanager reads `state` (only `starting`, see below), `phase`, `progress`, `position`, `target`, `awaitingTarget`, `background`, `issues` and `details`. It takes the latest block and peers from the client's JSON-RPC, so `height`, `headTime`, `peers` and `unit` are not read today; include them anyway, they are cheap and useful for other consumers.

Examples:

```json
{"version":1,"state":"starting","phase":"Downloading snapshot","progress":37.5}
{"version":1,"state":"syncing","phase":"Executing blocks","position":21000000,"target":21500000,"height":20990000,"headTime":1730000000,"peers":25}
{"version":1,"state":"synced","height":21500000,"headTime":1732960000,"peers":31,"background":"Indexing transactions"}
```

### `progress` or `position` and `target`

Measure a phase one way, not both.

| The phase is | Send | The dappmanager shows |
| --- | --- | --- |
| Measured in blocks | `phase`, `position`, `target` (with `target` greater than `position`) | Percentage counted from where it first saw the phase, blocks behind, time left; Stalled after 5 minutes without movement |
| Measured as a share of its own work | `phase`, `progress` | The percentage and time left estimated from how fast it moves |
| Not measurable | `phase` only | The phase with a moving bar |

The dappmanager tracks progress per phase name, so a new `phase` value starts a new measurement. Keep phase names stable: no counters or numbers in them. Use the same wording as other clients where it fits, e.g. `Downloading block headers`, `Downloading state`, `Healing state`, `Executing blocks`, `Catching up`.

### `awaitingTarget`

Send `awaitingTarget: true` when the client has nothing to sync towards, for example an execution client that no consensus client has driven since it started. The dappmanager then shows the node as Waiting for the consensus client while the consensus client is not at the head, and as Syncing with your `phase` (or `Starting to sync`) once it is.

### `background`

Work that goes on after the node reached the head. It is shown only while the node is synced, as `<background> in the background`, so write it as an activity: `Indexing transactions`, `Pruning old receipts`.

### `issues`

Short problems the client reports about itself, shown as warnings whether or not the node is synced. Do not report `No peers`: the dappmanager adds it from the peer count.

### `details`

Lines appended to the tooltip under the dappmanager's own lines, as `label: value`. Format values for people (`1,234,567`, `3 h 5 min`); they are shown as plain text.

### `state`

- `starting`: while the API does not answer and the container is running, the dashboard shows your `phase` and `progress` under the Starting badge. Use it for long pre-start work such as a snapshot download; let the entrypoint leave a marker the script can read (e.g. under `/tmp`).
- `syncing`, `synced`: the client's own view. The dappmanager ignores `synced` and decides by itself.
- `error`: the client cannot work. The healthcheck exits non-zero, so Docker marks the container unhealthy after `retries` failed runs. The dashboard does not treat this state specially today: send the reason as an issue.

## Healthcheck conventions

```yaml
services:
reth:
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
```

| Rule | Why |
| --- | --- |
| Exactly one JSON object as the last line of stdout, nothing else on stdout. | The dappmanager parses only the last non-empty line. |
| Diagnostics, if any, go to stderr, are short and are written **before** the report. | Docker stores stdout and stderr together, at most 4,096 bytes per run. |
| Exit 0 for `starting`, `syncing` and `synced`; non-zero only for `error` or when nothing could be determined. | A syncing node must not be unhealthy. |
| Answer before the node's API is up: report `starting`, with a `phase` for long pre-start work. | The report is the only way to show what the client does before its API answers. |
| Every network call has its own 2-3 s timeout; stop after the first call that fails. | A run that exceeds the healthcheck `timeout` records no report. |
| Call only `127.0.0.1` or `localhost`. Write nothing to the data directory. | The script runs every interval inside the client's container. |
| Never print credentials or secrets. | Docker stores the output, and the report's strings are shown in the dashboard. |
| POSIX `sh`; depend only on `curl` and `jq`. | The images are Alpine or Debian based. |

Make the script executable for the user the container runs as. Docker `ADD` from a URL creates files with mode 600:

```Dockerfile
ADD ${STAKER_SCRIPTS_URL}/node_status_tools.sh /etc/profile.d/
COPY node-status.sh /usr/local/bin/node-status
RUN chmod +r /etc/profile.d/node_status_tools.sh && chmod +rx /usr/local/bin/node-status
```

## Missing, stale or invalid reports

A report can only add detail. Whatever the report says, the dappmanager decides from the client's own API whether it is synced.

| Situation | What the dappmanager does |
| --- | --- |
| No `nodes` declaration, or no `report: "healthcheck"` | Does not read the healthcheck output. The tooltip shows `Package status report: No`. |
| No report | Judges the client from its JSON-RPC alone: Waiting if the consensus client is not at the head, otherwise `Catching up`, measured by how fast the latest block's timestamp closes on the clock. |
| Latest healthcheck run older than 3 intervals (90 s with a 30 s interval) | Treats it as no report. |
| Last line not JSON, over 2,048 bytes, `version` not `1` or unknown `state` | Treats it as no report. |
| A field with a wrong type or a negative number | Drops that field and keeps the rest. Unknown fields are ignored. |
| Strings too long or with control characters | Removes control characters and cuts them to the limits. `progress` is clamped to 0-100. |
| `state: "synced"` but the latest block is older than 3 minutes | Shows the node as syncing, waiting or stalled. |

## Shared helpers for staker packages

Staker packages use the helpers in [`node_status_tools.sh`](https://github.com/dappnode/staker-package-scripts) from `dappnode/staker-package-scripts`. Each package keeps its client-specific logic in its own script; the helpers call the local node with short timeouts, read Prometheus metrics and print a report that respects the limits above. Their full reference is in the repository README.

| Function | Use |
| --- | --- |
| `ns_rpc <method> [params]` | Calls the JSON-RPC on `127.0.0.1:${NS_RPC_PORT:-8545}` and prints the `result`. Exit 1 when the node does not answer. |
| `ns_http_get <url>` | GETs a local URL (`http://127.0.0.1` or `http://localhost` only). |
| `ns_metric <name> [label=value ...]` | Reads Prometheus text on stdin and prints the value of a metric. |
| `ns_hex_to_dec`, `ns_json_get` | Convert a hex quantity; read a field of a JSON document. |
| `ns_block_head` | Prints `height=<n> headTime=<n>` of the latest block, to pass unquoted to `ns_emit`. |
| `ns_emit <state> [key=value ...]` | Prints the report as one JSON line. Repeat `issue=<text>` and `detail=<Label>:<Value>`. Exit 0 for `starting`, `syncing` and `synced`, 1 for `error`. |

`NS_TIMEOUT` sets the timeout of every request (default 3 s). `ns_emit` drops empty and invalid values, caps `progress` at 99.9 unless the state is `synced`, and drops details, then issues, until the line fits in 2,048 bytes. It cuts detail labels to 40 characters and values to 120, the same limits the dappmanager applies.

Example for an execution client (the snapshot marker and the metric are illustrative):

```shell
#!/bin/sh
. "${NS_TOOLS:-/etc/profile.d/node_status_tools.sh}"

# The JSON-RPC does not answer yet: say what the entrypoint is doing
if ! syncing=$(ns_rpc eth_syncing); then
if [ -f /tmp/snapshot-progress ]; then
ns_emit starting phase="Downloading snapshot" progress="$(cat /tmp/snapshot-progress)"
else
ns_emit starting
fi
exit $?
fi

head=$(ns_block_head)
peers=$(ns_json_get "$(ns_rpc net_peerCount)" .)

if [ "$syncing" = "false" ]; then
# shellcheck disable=SC2086 # head holds two key=value arguments
ns_emit synced $head peers="$peers"
exit $?
fi

current=$(ns_json_get "$syncing" .currentBlock)
highest=$(ns_json_get "$syncing" .highestBlock)
awaiting=""
[ "$highest" = "0x0" ] && awaiting=true
# shellcheck disable=SC2086
ns_emit syncing $head peers="$peers" phase="Downloading blocks" \
position="$current" target="$highest" awaitingTarget="$awaiting"
exit $?
```

## Test a script locally

Make the helpers' path overridable (the example above reads `NS_TOOLS`), stub `curl` with a shell function that returns canned replies, run the script in a subshell and check the output with `jq`:

```shell
#!/bin/sh
NS_TOOLS=../staker-package-scripts/scripts/node_status_tools.sh

# Replies by JSON-RPC method; any other call fails like a refused connection
curl() {
case "$*" in
*eth_syncing*) printf '%s' '{"jsonrpc":"2.0","id":1,"result":{"currentBlock":"0x10","highestBlock":"0x20"}}' ;;
*eth_getBlockByNumber*) printf '%s' '{"jsonrpc":"2.0","id":1,"result":{"number":"0x10","timestamp":"0x6553f100"}}' ;;
*net_peerCount*) printf '%s' '{"jsonrpc":"2.0","id":1,"result":"0x5"}' ;;
*) return 7 ;;
esac
}

out=$(. ./node-status.sh)
printf '%s\n' "$out" | tail -n 1 | jq -e '.version == 1 and .state == "syncing" and .position == 16'
```

Run it under the shell of your image (busybox `ash` on Alpine, `dash` on Debian), and cover every phase, the API not answering, the background note and the exit codes.

On a Dappnode, check what the dappmanager will read:

```shell
docker exec <container> /usr/local/bin/node-status; echo "exit $?"
docker inspect --format '{{json .State.Health}}' <container> | jq -r '.Log[-1].Output' | tail -n 1 | jq .
```

## Not used yet

These parts of the `nodes` field are defined so packages can declare them now, but the dappmanager does not use them yet. Do not rely on any behaviour from them.

| Part | Status |
| --- | --- |
| `probe.kind` and `probe.enginePort` | Required, but not read yet. The dashboard reaches the selected clients through the Stakers aliases `execution.<network>.dncore.dappnode` and `beacon-chain.<network>.dncore.dappnode` (see [DNS](./dns.md#staker-packages---fullnode)), on the declared `probe.rpcPort` and `probe.apiPort`, or on 8545 and 3500 when a package declares none. |
| Reports from consensus clients | Not read: the consensus client's status comes from its beacon API alone. |
| `probe.kind: "status-report"` and `maxHeadAgeSeconds` | Reserved for nodes that are not Ethereum clients, judged from their report. |
| `role: "node"` and `role: "validator"` | Reserved. |
| `report: { "http": { "port", "path" } }` | Reserved: the report served over HTTP by the same service. |
| `requires`, `validatorService` | Reserved. |
| Choosing clients from the declaration | The Stakers UI still uses its own list of client packages. |
2 changes: 2 additions & 0 deletions docs/dev/package-development/multi-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Manifest objects merge recursively, scalars are overridden, and arrays merge by

After merging, every `upstream[].arg` must exist in the compose and every service declaring it must match the upstream version. Explicit `mainService`, `chain.serviceName`, `backup[].service` and `globalEnvs[].services` values must name services in the resolved compose.

For [`nodes`](../references/manifest.md#nodes), the root manifest declares each node's `role`, `probe` and `report`, and each variant adds only its `network`. See [Node Status Reports](../node-status.md).

You can add more variants as needed by creating additional directories and files following this structure.

### Customize the Avatar
Expand Down
Loading
Loading