From 0e027f5213ad19811a332d464d09108fb18a4882 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 28 Sep 2026 01:12:47 +0700 Subject: [PATCH 1/2] fix: validate node type and drop dead vars in init-bedrock - Reject unknown NODE_TYPE values early. Previously a typo such as NODE_TYPE=ful silently fell through and synced from genesis as a full node instead of failing. - Require BEDROCK_DATADIR to be set with a clear error instead of failing later inside extract with an empty datadir. - Remove the unused TORRENTS_DIR and BEDROCK_TMP_PATH variables and initialize BEDROCK_TAR_DOWNLOAD so the download block never reads an unset variable. --- scripts/init-bedrock.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/init-bedrock.sh b/scripts/init-bedrock.sh index 6b47cf0..a0cb785 100755 --- a/scripts/init-bedrock.sh +++ b/scripts/init-bedrock.sh @@ -7,11 +7,11 @@ source ./scripts/utils.sh # Common variables. INITIALIZED_FLAG=/shared/initialized.txt BEDROCK_JWT_PATH=/shared/jwt.txt -GETH_DATA_DIR=$BEDROCK_DATADIR -TORRENTS_DIR=/torrents/$NETWORK_NAME +: "${BEDROCK_DATADIR:?BEDROCK_DATADIR is not set (expected from envs//op-geth.env)}" +GETH_DATA_DIR="$BEDROCK_DATADIR" BEDROCK_TAR_PATH=/downloads/bedrock.tar BEDROCK_TAR_CHECKSUM_PATH= -BEDROCK_TMP_PATH=/bedrock-tmp +BEDROCK_TAR_DOWNLOAD="" function validate_snapshot_filename() { local snapshot_filename="$1" @@ -71,6 +71,14 @@ fi echo "Bedrock node needs to be initialized..." echo "Initializing via download..." +# Fail fast on an unknown node type: without this, a typo such as +# NODE_TYPE=ful would silently fall through and sync from genesis as a +# full node. +if [ "$NODE_TYPE" != "archive" ] && [ "$NODE_TYPE" != "full" ]; then + echo "Unsupported node type: $NODE_TYPE (expected 'full' or 'archive')" >&2 + exit 1 +fi + # Resolve the latest archival geth datadir snapshot from the ChainSnap indexes. echo "Fetching download link..." From d72f27b53b81d641bfd84cb97284333a031ed892 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 5 Oct 2026 08:03:18 +0700 Subject: [PATCH 2/2] fix(init-bedrock): actionable errors and a snapshot URL override The hosted Gelato snapshot indexes no longer resolve, so NODE_TYPE=archive died with a curl resolver error and no guidance (inkonchain/node#68, #87). - split index-fetch failures from "no matching file" so the message says what actually happened, and point at NODE_TYPE=full or a custom snapshot - honour an operator-provided BEDROCK_TAR_DOWNLOAD in archive mode instead of overwriting it, and document it in .env.example - fail clearly when .sha256 is missing, and verify the checksum against the archive basename so an override URL verifies the same way --- .env.example | 6 ++++++ scripts/init-bedrock.sh | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 831345b..dd7e1b4 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,12 @@ NETWORK_NAME=ink-sepolia # back to full. NODE_TYPE=full +# Optional: URL of a geth datadir snapshot for bedrock-init to restore, +# overriding the hosted index (used in archive mode). The URL must have a +# ".sha256" checksum file next to it; the download is verified against it. +# Leave empty to use the hosted index. +BEDROCK_TAR_DOWNLOAD= + # For a quick Sepolia smoke test, these public endpoints worked during docs # validation: # - https://ethereum-sepolia-rpc.publicnode.com diff --git a/scripts/init-bedrock.sh b/scripts/init-bedrock.sh index a0cb785..f16146d 100755 --- a/scripts/init-bedrock.sh +++ b/scripts/init-bedrock.sh @@ -11,7 +11,10 @@ BEDROCK_JWT_PATH=/shared/jwt.txt GETH_DATA_DIR="$BEDROCK_DATADIR" BEDROCK_TAR_PATH=/downloads/bedrock.tar BEDROCK_TAR_CHECKSUM_PATH= -BEDROCK_TAR_DOWNLOAD="" +# Optional operator override: a geth datadir tarball URL (with a matching +# .sha256). Honoured in archive mode, so a node can bootstrap from a +# snapshot mirror even when the hosted index below is unreachable. +BEDROCK_TAR_DOWNLOAD="${BEDROCK_TAR_DOWNLOAD:-}" function validate_snapshot_filename() { local snapshot_filename="$1" @@ -27,13 +30,28 @@ function validate_snapshot_filename() { fi } +function snapshot_bootstrap_hint() { + cat >&2 <<'EOF' +Either set NODE_TYPE=full in .env to sync from genesis, or set +BEDROCK_TAR_DOWNLOAD in .env to a geth datadir tarball that has a +matching .sha256 checksum file. +EOF +} + function resolve_latest_snapshot_filename() { local index_url="$1" local filename_regex="$2" - local snapshot_filename + local index_content snapshot_filename + + if ! index_content="$(curl -fsS "$index_url")"; then + echo "Could not fetch the snapshot index: $index_url" >&2 + echo "The hosted snapshot index is unreachable or no longer published." >&2 + snapshot_bootstrap_hint + exit 1 + fi snapshot_filename="$( - curl -fsS "$index_url" | python3 -c ' + printf '%s' "$index_content" | python3 -c ' import re import sys @@ -48,13 +66,13 @@ matches = sorted( ) if not matches: - print("No matching snapshot files found in index", file=sys.stderr) sys.exit(1) print(matches[0]) ' "$filename_regex" )" || { - echo "Failed to resolve latest snapshot from $index_url" >&2 + echo "No snapshot file matching $filename_regex was listed at $index_url" >&2 + snapshot_bootstrap_hint exit 1 } @@ -83,7 +101,9 @@ fi echo "Fetching download link..." if [ "$NODE_TYPE" = "archive" ]; then - if [ "$NETWORK_NAME" = "ink-sepolia" ]; then + if [ -n "$BEDROCK_TAR_DOWNLOAD" ]; then + echo "Using snapshot from BEDROCK_TAR_DOWNLOAD: $BEDROCK_TAR_DOWNLOAD" + elif [ "$NETWORK_NAME" = "ink-sepolia" ]; then SNAPSHOT_FILENAME="$(resolve_latest_snapshot_filename \ "https://ink.t.snapshots.gelato.cloud/index.html" \ 'ink-sepolia-geth-archival-datadir-[0-9]+-[0-9]+\.tar(?:\.(?:zst|lz4))?')" @@ -110,13 +130,17 @@ if [ -n "$BEDROCK_TAR_DOWNLOAD" ]; then BEDROCK_TAR_CHECKSUM_PATH="${BEDROCK_TAR_PATH}.sha256" echo "Downloading bedrock.tar checksum..." - curl -fsS "$BEDROCK_TAR_DOWNLOAD.sha256" -o "$BEDROCK_TAR_CHECKSUM_PATH" + if ! curl -fsS "$BEDROCK_TAR_DOWNLOAD.sha256" -o "$BEDROCK_TAR_CHECKSUM_PATH"; then + echo "Could not fetch the checksum file: $BEDROCK_TAR_DOWNLOAD.sha256" >&2 + echo "Every snapshot URL must be accompanied by a .sha256 file." >&2 + exit 1 + fi echo "Downloading bedrock.tar..." download "$BEDROCK_TAR_DOWNLOAD" "$BEDROCK_TAR_PATH" echo "Verifying bedrock.tar checksum..." - verify_sha256_checksum "$BEDROCK_TAR_PATH" "$BEDROCK_TAR_CHECKSUM_PATH" "$SNAPSHOT_FILENAME" + verify_sha256_checksum "$BEDROCK_TAR_PATH" "$BEDROCK_TAR_CHECKSUM_PATH" "$(basename "$BEDROCK_TAR_DOWNLOAD")" echo "Extracting bedrock.tar..." if [[ "$BEDROCK_TAR_DOWNLOAD" == *.zst ]]; then