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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# "<url>.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
Expand Down
52 changes: 42 additions & 10 deletions scripts/init-bedrock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ 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/<network>/op-geth.env)}"
GETH_DATA_DIR="$BEDROCK_DATADIR"
BEDROCK_TAR_PATH=/downloads/bedrock.tar
BEDROCK_TAR_CHECKSUM_PATH=
BEDROCK_TMP_PATH=/bedrock-tmp
# Optional operator override: a geth datadir tarball URL (with a matching
# <url>.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"
Expand All @@ -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 <url>.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

Expand All @@ -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
}

Expand All @@ -71,11 +89,21 @@ 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..."

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))?')"
Expand All @@ -102,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 <url>.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
Expand Down