From 2b1fcebab275d0a4cd67e3cc8b5a1f488cc08032 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 15:49:39 +0530 Subject: [PATCH] Support zst archive for snapshots --- .../config/bsc-node/docker-entrypoint.sh | 28 +++++++++++++------ .../container-build/cerc-bsc-geth/Dockerfile | 4 +-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index bfd1183..b97073c 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -21,19 +21,31 @@ else fi # Use snapshot if provided -# Take first file with extension .tar.lz4 from the snapshot dir -snapshot_file=$((ls /var/tmp/snapshot/*.tar.lz4) 2>/dev/null | head -1) +# Take first file from the snapshot dir +snapshot_file=$((ls /var/tmp/snapshot/) 2>/dev/null | head -1) geth_dir=${DATA_DIR}/geth ADDITIONAL_FLAGS="" if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapshot_file" ]; then echo "Using snapshot $snapshot_file" - if [ "$CERC_BSC_NETWORK" = "testnet" ]; then - # Snapshot dir structure for testnet is different than that for mainnet - lz4 -d ${snapshot_file} | tar -C ${DATA_DIR}/ -xvf - --strip-components=3 server/testnet/dataseed/geth - else - lz4 -d ${snapshot_file} | tar -C ${DATA_DIR}/ -xvf - --strip-components=2 server/data-seed/geth - fi + temp_dir=$(mktemp -d) + case $snapshot_file in + *.lz4) + lz4 -d $snapshot_file | tar -C $temp_dir -xvf - + ;; + *.zst) + zstd -c -d $snapshot_file | tar -C $temp_dir -xvf - + ;; + *) + echo "Unsupported archive format for the snapshot file: $snapshot_file" + exit 1 + ;; + esac + + # Move geth data to data dir + extracted_geth_dir=$(find $temp_dir -type d -name "geth" -print -quit) + mv $extracted_geth_dir ${DATA_DIR}/ + rm -rf $temp_dir if [ "${CERC_FAST_NODE}" = "true" ]; then echo "Pruning trie data and turning snapshot verification off" diff --git a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile index 4a521c6..f159a76 100644 --- a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile +++ b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile @@ -2,7 +2,7 @@ FROM ghcr.io/bnb-chain/bsc:1.4.8 USER root -# Add lz4 for extracting files from a lz4 snapshot -RUN apk add lz4 +# Add lz4, zstd and tar for extracting snapshot files +RUN apk add lz4 zstd tar USER bsc