From e12b89d487367a7cc21716a6ba564835547a8756 Mon Sep 17 00:00:00 2001 From: Sameer Kumar Subudhi Date: Mon, 2 Dec 2024 14:04:33 +0100 Subject: [PATCH] :hammer: Automatically update SNAPSHOT_URL to use alertnate source if original URL doesn't respond --- geth/download-apply-snapshot.sh | 31 ++++++++++++++++++++++++++----- geth/geth-entrypoint | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/geth/download-apply-snapshot.sh b/geth/download-apply-snapshot.sh index a2e71d7..58a83e0 100755 --- a/geth/download-apply-snapshot.sh +++ b/geth/download-apply-snapshot.sh @@ -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" @@ -102,4 +123,4 @@ if [[ "$SNAPSHOT_IMPORT_EXIT_CODE" == "0" ]]; then else echo "Snapshot import failed. Skipping snapshot application..." exit 12 -fi \ No newline at end of file +fi diff --git a/geth/geth-entrypoint b/geth/geth-entrypoint index 4fa8f1d..decc020 100755 --- a/geth/geth-entrypoint +++ b/geth/geth-entrypoint @@ -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"