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
27 changes: 27 additions & 0 deletions .github/workflows/node-status-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
ref: v0.1.3
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 the image's shell (Debian bookworm dash, jq 1.6)
run: >
docker run --rm -v "$PWD:/work" -w /work debian:bookworm-slim sh -c
"apt-get update -qq && apt-get install -qq -y jq >/dev/null &&
NODE_STATUS_TOOLS=/work/staker-package-scripts/scripts/node_status_tools.sh sh test/node_status_test.sh"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ curl -X POST \
- `RUST_LOG`: Logging level
- `PATHFINDER_DB_DIR`: Database directory

### Node status report

The package reports Pathfinder's sync status (snapshot download and extraction, blocks left to the head, synced, and the latest block verified on Ethereum) through its Docker healthcheck, which the DAppNode dashboard reads to show the node's status. The healthcheck script is [`pathfinder/node-status.sh`](pathfinder/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`.

### Storage Requirements

- **Initial Sync**: ~50GB+ (varies by network and state size)
Expand Down
9 changes: 8 additions & 1 deletion dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"shortDescription": "Pathfinder Starknet full node",
"description": "Pathfinder - Starknet Node Client",
Expand All @@ -21,5 +21,12 @@
"type": "git",
"url": "https://github.com/dappnode/DAppNodePackage-pathfinder-generic"
},
"license": "GPL-3.0"
"license": "GPL-3.0",
"nodes": {
"pathfinder": {
"role": "node",
"probe": { "kind": "status-report", "maxHeadAgeSeconds": 300 },
"report": "healthcheck"
}
}
}
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ services:
PATHFINDER_MONITOR_ADDRESS: 0.0.0.0:9547
volumes:
- pathfinder-data:/usr/share/pathfinder/data
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
pathfinder-data: {}
8 changes: 7 additions & 1 deletion package_variants/mainnet/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "pathfinder.dnp.dappnode.eth",
"version": "0.1.2",
Expand All @@ -12,5 +12,11 @@
"description": "JSON RPC endpoint for Pathfinder",
"port": 9555
}
]
],
"nodes": {
"pathfinder": {
"network": "starknet",
"requires": [{ "network": "mainnet", "role": "execution" }]
}
}
}
8 changes: 7 additions & 1 deletion package_variants/sepolia/dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "pathfinder-sepolia.dnp.dappnode.eth",
"version": "0.1.1",
Expand All @@ -17,5 +17,11 @@
"description": "WebSocket RPC endpoint for StarkNet Sepolia",
"port": 6061
}
]
],
"nodes": {
"pathfinder": {
"network": "starknet-sepolia",
"requires": [{ "network": "sepolia", "role": "execution" }]
}
}
}
8 changes: 6 additions & 2 deletions pathfinder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ FROM eqlabs/pathfinder:${UPSTREAM_VERSION}
# Stay as root for everything
USER root

# Install rclone and zstd
RUN apt-get update && apt-get install -y curl zstd unzip && \
# Install rclone and zstd, and jq for the healthcheck
RUN apt-get update && apt-get install -y curl zstd unzip jq && \
curl https://rclone.org/install.sh | bash && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Healthcheck: prints the node status report (helpers from dappnode/staker-package-scripts)
ADD --chmod=644 https://github.com/dappnode/staker-package-scripts/releases/download/v0.1.3/node_status_tools.sh /etc/profile.d/node_status_tools.sh
COPY --chmod=755 node-status.sh /usr/local/bin/node-status

COPY --chmod=755 entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
44 changes: 36 additions & 8 deletions pathfinder/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ esac

TARGET_DB="${DATA_DIR}/${BASE}.sqlite"

# Read by the healthcheck (node-status) to report the snapshot download and extraction before
# Pathfinder serves its RPC
NODE_STATUS_DIR=/tmp/node-status
SNAPSHOT_MARKER="${NODE_STATUS_DIR}/snapshot"

# A marker left by a container that was killed mid-download must not outlive that run
rm -f "${SNAPSHOT_MARKER}" || true

# Writes the snapshot marker atomically. It never fails, so it cannot stop this script (set -e).
# Arguments: PID of the rclone or zstd process, phase, size of the compressed snapshot in bytes
write_snapshot_marker() {
{
mkdir -p "${NODE_STATUS_DIR}" &&
printf 'pid=%s\nphase=%s\nsize=%s\n' "$1" "$2" "$3" >"${SNAPSHOT_MARKER}.tmp" &&
mv -f "${SNAPSHOT_MARKER}.tmp" "${SNAPSHOT_MARKER}"
} 2>/dev/null || true
}

# Check if database already exists
if [ -f "$TARGET_DB" ] && [ -s "$TARGET_DB" ]; then
echo "✅ Database already exists at $TARGET_DB, skipping download"
Expand All @@ -48,35 +66,43 @@ EOF

if [ "$NETWORK" = "mainnet" ]; then
# For mainnet, find latest mainnet_ file
SNAPSHOT_FILE=$(rclone ls pathfinder-snapshots:pathfinder-snapshots/ | \
SNAPSHOT_LINE=$(rclone ls pathfinder-snapshots:pathfinder-snapshots/ | \
grep "mainnet_.*\.sqlite\.zst" | \
grep -v "_archive" | \
sort -k2 | \
tail -1 | \
awk '{print $2}')
tail -1)
else
# For sepolia, find latest from both naming patterns
SNAPSHOT_FILE=$(rclone ls pathfinder-snapshots:pathfinder-snapshots/ | \
SNAPSHOT_LINE=$(rclone ls pathfinder-snapshots:pathfinder-snapshots/ | \
grep -E "(sepolia-testnet_|testnet-sepolia_).*\.sqlite\.zst" | \
grep -v "_archive" | \
sort -k2 | \
tail -1 | \
awk '{print $2}')
tail -1)
fi
# rclone ls prints "<size in bytes> <name>"; the size lets the healthcheck measure progress
SNAPSHOT_FILE=$(echo "$SNAPSHOT_LINE" | awk '{print $2}')
SNAPSHOT_SIZE=$(echo "$SNAPSHOT_LINE" | awk '{print $1}')

if [ -z "$SNAPSHOT_FILE" ]; then
echo "❌ No snapshot found for network: $NETWORK"
echo "🚀 Starting Pathfinder without snapshot..."
else
echo "⏬ Downloading $SNAPSHOT_FILE..."
rclone copy -P "pathfinder-snapshots:pathfinder-snapshots/$SNAPSHOT_FILE" .
# In the background only so that its PID can vouch for the marker; set -e still stops on failure
rclone copy -P "pathfinder-snapshots:pathfinder-snapshots/$SNAPSHOT_FILE" . &
SNAPSHOT_PID=$!
write_snapshot_marker "$SNAPSHOT_PID" "Downloading snapshot" "$SNAPSHOT_SIZE"
wait "$SNAPSHOT_PID"

# Verify download
if [ ! -f "$SNAPSHOT_FILE" ] || [ ! -s "$SNAPSHOT_FILE" ]; then
echo "❌ Download failed. Starting Pathfinder without snapshot..."
else
echo "⏳ Decompressing snapshot..."
zstd -T0 -d "$SNAPSHOT_FILE" -o "${BASE}.sqlite"
zstd -T0 -d "$SNAPSHOT_FILE" -o "${BASE}.sqlite" &
SNAPSHOT_PID=$!
write_snapshot_marker "$SNAPSHOT_PID" "Extracting snapshot" "$SNAPSHOT_SIZE"
wait "$SNAPSHOT_PID"

# Move to target location
mkdir -p "$DATA_DIR"
Expand All @@ -88,5 +114,7 @@ EOF
fi
fi

rm -f "${SNAPSHOT_MARKER}" || true

echo "🚀 Starting Pathfinder..."
exec pathfinder "$@"
136 changes: 136 additions & 0 deletions pathfinder/node-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/sh

# Node status report of the Pathfinder package, run as the Docker healthcheck.
# Prints one JSON line (see node_status_tools.sh in dappnode/staker-package-scripts):
# what Pathfinder is doing, from its own JSON-RPC and the snapshot marker the entrypoint
# leaves. Pathfinder is not an Ethereum client, so the report carries the verdict: the
# manifest declares this node as a status-report probe.
#
# Environment:
# NODE_STATUS_TOOLS: Helper library to source (default /etc/profile.d/node_status_tools.sh)
# NODE_STATUS_DIR: Directory of the snapshot marker (default /tmp/node-status)
# NODE_STATUS_PROC: Process information directory (default /proc)
# PATHFINDER_HTTP_RPC_ADDRESS: Pathfinder's own setting; the JSON-RPC port is taken from it

# Every call gets 2 s, so even a node that stops answering midway stays well inside the 10 s timeout
NS_TIMEOUT=${NS_TIMEOUT:-2}

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

SNAPSHOT_MARKER="${NODE_STATUS_DIR:-/tmp/node-status}/snapshot"
PROC_DIR=${NODE_STATUS_PROC:-/proc}

# A block older than this is not the chain head, whatever starknet_syncing says. Same value as
# probe.maxHeadAgeSeconds in dappnode_package.json; Starknet blocks come every few seconds.
MAX_HEAD_AGE_SECONDS=300

NS_RPC_PORT=${PATHFINDER_HTTP_RPC_ADDRESS##*:}
case $NS_RPC_PORT in
'' | *[!0-9]*) NS_RPC_PORT=6060 ;;
esac
# Pathfinder's own methods are served under this path, not on the root
PATHFINDER_RPC_PATH=/rpc/pathfinder/v0_1

# The JSON-RPC does not answer: the entrypoint downloads or extracts a database snapshot, or
# Pathfinder is opening (and migrating) its database. The marker counts only while the
# process it names runs, so a marker left by a failed or killed run is never trusted. Progress
# is the share of the compressed snapshot that process has written (rclone) or read (zstd).
report_starting() {
pid=""
phase=""
size=""
if [ -f "$SNAPSHOT_MARKER" ]; then
while IFS='=' read -r key value; do
case $key in
pid) pid=$value ;;
phase) phase=$value ;;
size) size=$value ;;
esac
done <"$SNAPSHOT_MARKER"
fi
case $phase in
"Downloading snapshot") command=rclone counter=wchar ;;
"Extracting snapshot") command=zstd counter=rchar ;;
*) phase="" ;;
esac
case $pid in
'' | *[!0-9]*) phase="" ;;
esac
if [ -z "$phase" ] || [ "$(process_name "$pid")" != "$command" ]; then
ns_emit starting
return
fi
progress=""
bytes=$(sed -n "s/^$counter:[[:space:]]*//p" "$PROC_DIR/$pid/io" 2>/dev/null)
case $size$bytes in
*[!0-9]*) ;;
*)
if [ "${size:-0}" -gt 0 ] && [ -n "$bytes" ]; then
permille=$((bytes * 1000 / size))
progress="$((permille / 10)).$((permille % 10))"
fi
;;
esac
ns_emit starting phase="$phase" progress="$progress"
}

# Prints the program name of a running process (basename of its first argument), nothing when
# it does not run
process_name() {
name=$(tr '\0' '\n' 2>/dev/null <"$PROC_DIR/$1/cmdline" | head -n 1)
printf '%s\n' "${name##*/}"
}

if ! syncing=$(ns_rpc starknet_syncing); then
report_starting
exit $?
fi

# Stop at the first call that fails: each one can take the full timeout. An empty database has
# no latest block yet (Pathfinder answers with an error).
height=""
head_time=""
set --
if block=$(ns_rpc starknet_getBlockWithTxHashes '["latest"]'); then
height=$(ns_hex_to_dec "$(ns_json_get "$block" .block_number)")
head_time=$(ns_hex_to_dec "$(ns_json_get "$block" .timestamp)")
# Latest block whose state update Pathfinder has seen on Ethereum (L1). ns_rpc only calls the
# root path, so this one is a plain curl with the same discipline.
if l1=$(curl -sfg --noproxy '*' --proto '=http' --max-time "$NS_TIMEOUT" --connect-timeout "$NS_TIMEOUT" \
-H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","id":1,"method":"pathfinder_lastL1AcceptedBlockHashAndNumber","params":[]}' \
"http://127.0.0.1:$NS_RPC_PORT$PATHFINDER_RPC_PATH"); then
verified=$(ns_json_get "$l1" '
def commas: tostring | if length > 3 then (.[:-3] | commas) + "," + .[-3:] else . end;
.result.block_number | numbers | floor | commas')
[ -n "$verified" ] && set -- detail="Verified on Ethereum:Block $verified"
fi
fi

fresh=false
case $head_time in
'' | *[!0-9]*) ;;
*) [ $(($(date +%s) - head_time)) -le "$MAX_HEAD_AGE_SECONDS" ] && fresh=true ;;
esac

# starknet_syncing is false when Pathfinder is fewer than 6 blocks behind the head it last saw,
# but also before it first asked the gateway for the head, so only a recent block makes it synced
if [ "$syncing" = "false" ] && [ "$fresh" = true ]; then
ns_emit synced height="$height" headTime="$head_time" "$@"
exit $?
fi

# The object: Pathfinder downloads and applies blocks one by one up to the head of the gateway
current=$(ns_json_get "$syncing" 'objects | .current_block_num')
highest=$(ns_json_get "$syncing" 'objects | .highest_block_num')
if [ -n "$current" ] && [ -n "$highest" ]; then
ns_emit syncing phase="Downloading blocks" position="$current" target="$highest" \
height="$height" headTime="$head_time" "$@"
exit $?
fi

# Not reporting progress, but its latest block is old (or there is none): the head age shows how
# far behind it is
ns_emit syncing height="$height" headTime="$head_time" "$@"
exit $?
Loading
Loading