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
28 changes: 28 additions & 0 deletions .github/workflows/node-status-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Node status test

on:
pull_request:

permissions:
contents: read

jobs:
node-status:
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 with dash
run: NODE_STATUS_TOOLS=staker-package-scripts/scripts/node_status_tools.sh dash test/node_status_test.sh

- name: Test in Debian bookworm (the base of the Juno image, dash and mawk)
run: >
docker run --rm -v "$PWD:/work" -w /work debian:bookworm-slim sh -c
"apt-get update -qq && apt-get install -qq -y --no-install-recommends 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 @@ -97,6 +97,10 @@ The package uses Docker named volumes for data persistence:
- **Data location**: `/var/lib/juno` (inside container)
- **Persistence**: Data persists across container restarts and updates

## Node status report

The package reports its sync status (snapshot download and extraction, database migration, blocks left to the chain head, whether Juno is synced, the block last verified on Ethereum) through its Docker healthcheck, which the Dappnode dashboard reads. Juno counts as synced only when it is at the chain head by its own account and its latest block is at most 5 minutes old. The script is [`juno/node-status.sh`](juno/node-status.sh), installed as `/usr/local/bin/node-status`; its tests are in [`test/node_status_test.sh`](test/node_status_test.sh) (`sh test/node_status_test.sh`, with `dappnode/staker-package-scripts` checked out next to this repository).

## WebSocket Interface

This package includes WebSocket support for real-time interactions with the Starknet network. The WebSocket server runs on port 6061 by default and supports:
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": "StarkNet full node",
"description": "Nethermind Starknet Node Client Juno",
Expand Down Expand Up @@ -39,5 +39,12 @@
"description": "WebSocket RPC endpoint for StarkNet",
"port": 6061
}
]
],
"nodes": {
"juno": {
"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 @@ -16,6 +16,12 @@ services:
WS_PORT: 6061
volumes:
- juno_data:/var/lib/juno
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
restart: unless-stopped
volumes:
juno_data: {}
11 changes: 9 additions & 2 deletions juno/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
ARG UPSTREAM_VERSION
FROM nethermind/juno:${UPSTREAM_VERSION}

# Install required tools (wget + zstd) in one layer before cleaning up
ARG NODE_STATUS_TOOLS_URL=https://github.com/dappnode/staker-package-scripts/releases/download/v0.1.3/node_status_tools.sh

# Install required tools (wget + zstd for the snapshot, curl + jq for the healthcheck) in one layer before cleaning up
RUN apt-get update && \
apt-get install -y --no-install-recommends wget zstd && \
apt-get install -y --no-install-recommends wget zstd curl jq && \
rm -rf /var/lib/apt/lists/*

# Create juno data directory
Expand All @@ -13,4 +15,9 @@ RUN mkdir -p /var/lib/juno
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Healthcheck that prints the node status report
ADD ${NODE_STATUS_TOOLS_URL} /etc/profile.d/node_status_tools.sh
COPY node-status.sh /usr/local/bin/node-status
RUN chmod 0644 /etc/profile.d/node_status_tools.sh && chmod 0755 /usr/local/bin/node-status

ENTRYPOINT ["/entrypoint.sh"]
69 changes: 67 additions & 2 deletions juno/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,79 @@ echo "Extra options: $EXTRA_OPTS"
# echo all envs
printenv

# Read by the healthcheck (node-status) to report the snapshot download and extraction before Juno
# serves its RPC. Writing it never changes what the snapshot steps do or how they fail.
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}" "${SNAPSHOT_MARKER}.tmp"

# Writes the snapshot marker atomically
# Arguments: PID of wget or tar, phase, size of the snapshot in bytes (may be empty)
write_snapshot_marker() {
{
mkdir -p "${NODE_STATUS_DIR}" &&
printf 'pid=%s\nphase=%s\nfile=%s\nsize=%s\n' "$1" "$2" "${PWD%/}/${snapshot}" "$3" >"${SNAPSHOT_MARKER}.tmp" &&
mv -f "${SNAPSHOT_MARKER}.tmp" "${SNAPSHOT_MARKER}"
} 2>/dev/null
}

# Copies the output of wget (stdin) to stderr, where wget writes it, and records the snapshot size
# from its "Length: <bytes> (...)" line
# Arguments: PID of wget
follow_snapshot_download() {
while IFS= read -r line || [ -n "$line" ]; do
printf '%s\n' "$line" >&2
case $line in
"Length: "[0-9]*)
size=${line#Length: }
write_snapshot_marker "$1" "Downloading snapshot" "${size%% *}" || true
;;
esac
done
}

# Downloads the snapshot with wget in the background, so its PID can vouch for the marker.
# Returns the exit status of wget.
download_snapshot() {
fifo="${NODE_STATUS_DIR}/wget.fifo"
if ! { mkdir -p "${NODE_STATUS_DIR}" && rm -f "$fifo" && mkfifo "$fifo"; } 2>/dev/null; then
# shellcheck disable=SC2086 # unquoted as before
wget --progress=dot:giga -O $snapshot $SNAPSHOT_URL
return
fi
# shellcheck disable=SC2086 # unquoted as before
wget --progress=dot:giga -O $snapshot $SNAPSHOT_URL 2>"$fifo" &
wget_pid=$!
write_snapshot_marker "$wget_pid" "Downloading snapshot" "" || true
follow_snapshot_download "$wget_pid" <"$fifo"
wget_status=0
wait "$wget_pid" || wget_status=$?
rm -f "$fifo" "${SNAPSHOT_MARKER}"
return "$wget_status"
}

# Extracts the snapshot with tar in the background, so its PID can vouch for the marker.
# Returns the exit status of tar.
extract_snapshot() {
tar --checkpoint=65536 -xf $snapshot -C $JUNO_DIR &
tar_pid=$!
write_snapshot_marker "$tar_pid" "Extracting snapshot" "" || true
tar_status=0
wait "$tar_pid" || tar_status=$?
rm -f "${SNAPSHOT_MARKER}"
return "$tar_status"
}

# if dir is empty and URL is configured, download the snapshot
if [ "$(ls -A $JUNO_DIR)" ]; then
echo "Skipping snapshot download."
elif [ -n "$SNAPSHOT_URL" ]; then
echo "Juno data directory is empty. Downloading snapshot."
snapshot=mainnet.tar
wget --progress=dot:giga -O $snapshot $SNAPSHOT_URL
tar --checkpoint=65536 -xf $snapshot -C $JUNO_DIR
download_snapshot
extract_snapshot
rm $snapshot
fi

Expand Down
Loading
Loading