Skip to content

Commit

Permalink
Unable to download Lisk Sepolia datadir snapshots (#50)
Browse files Browse the repository at this point in the history
🔨 Automatically update SNAPSHOT_URL to use alertnate source if original URL doesn't respond
  • Loading branch information
sameersubudhi authored Dec 2, 2024
1 parent 16864e8 commit 74eee56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions geth/download-apply-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,35 @@ if [[ "${GETH_DATA_DIR-x}" == x ]]; then
exit 1
fi

if [[ "${SNAPSHOT_URL-x}" == x || -z $SNAPSHOT_URL ]]; then
readonly SNAPSHOT_URL_BASE="https://snapshots.lisk.com/$SNAPSHOT_NETWORK"
# Snapshot base URLs
readonly SNAPSHOT_BASE_URL_DEFAULT="https://snapshots.lisk.com"
readonly SNAPSHOT_BASE_URL_ALTERNATE="https://s3.eu-west-3.amazonaws.com/snapshots.lisk.com"

# Automatically resolve SNAPSHOT_URL, if not specified
SNAPSHOT_URL="$SNAPSHOT_URL"
if [[ "${SNAPSHOT_URL-x}" == x || -z $SNAPSHOT_URL ]];
then
readonly SNAPSHOT_URL_BASE="$SNAPSHOT_BASE_URL_DEFAULT/$SNAPSHOT_NETWORK"
readonly LATEST_SNAPSHOT_NAME=$(curl --silent --location $SNAPSHOT_URL_BASE/latest-$SNAPSHOT_TYPE)
readonly SNAPSHOT_URL="$SNAPSHOT_URL_BASE/$LATEST_SNAPSHOT_NAME"

SNAPSHOT_URL="$SNAPSHOT_URL_BASE/$LATEST_SNAPSHOT_NAME"
echo "SNAPSHOT_URL not specified; automatically resolved to $SNAPSHOT_URL"
fi

# Update SNAPSHOT_URL to alternate URL, if it uses the default base URL and it doesn't respond
readonly http_code=$(curl -o /dev/null --silent -Iw '%{http_code}' $SNAPSHOT_URL)
if [[ "$http_code" != "200" ]];
then
echo "Unable to access $SNAPSHOT_URL"
if [[ $SNAPSHOT_URL =~ $SNAPSHOT_BASE_URL_DEFAULT ]];
then
readonly SNAPSHOT_URL=$(echo "${SNAPSHOT_URL/$SNAPSHOT_BASE_URL_DEFAULT/$SNAPSHOT_BASE_URL_ALTERNATE}")
echo "Updating SNAPSHOT_URL to $SNAPSHOT_URL"
else
echo "Try using the official URL instead. Exiting snapshot download & application..."
exit 2
fi
fi

readonly SNAPSHOT_DIR=./snapshot
readonly SNAPSHOT_REMOTE_FILENAME=$(basename ${SNAPSHOT_URL})
readonly SNAPSHOT_SHA256_URL="${SNAPSHOT_URL}.SHA256"
Expand Down Expand Up @@ -102,4 +123,4 @@ if [[ "$SNAPSHOT_IMPORT_EXIT_CODE" == "0" ]]; then
else
echo "Snapshot import failed. Skipping snapshot application..."
exit 12
fi
fi
2 changes: 1 addition & 1 deletion geth/geth-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
mkdir -p $GETH_DATA_DIR

# Download and apply snapshot, when configured
(. download-apply-snapshot.sh)
(. download-apply-snapshot.sh) || echo "Unable to download and apply snapshot. Skipping snapshot application..."

# Set the start flags
echo "$OP_NODE_L2_ENGINE_AUTH_RAW" > "$OP_NODE_L2_ENGINE_AUTH"
Expand Down

0 comments on commit 74eee56

Please sign in to comment.