Add config for geth dir path in snapshot archive (#2)

Part of [Create a stack to run a BSC node](https://www.notion.so/Create-a-stack-to-run-a-BSC-node-5740b35b02974661a0237dcf57ab8150)

Reviewed-on: #2
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-06-06 04:33:25 +00:00 committed by ashwin
parent e908b5a7b3
commit 7e42060541
3 changed files with 17 additions and 9 deletions

View File

@ -5,6 +5,7 @@ services:
environment:
CERC_BSC_NETWORK: ${CERC_BSC_NETWORK:-mainnet}
CERC_USE_SNAPSHOT: ${CERC_USE_SNAPSHOT:-false}
CERC_SNAPSHOT_GETH_PATH: ${CERC_SNAPSHOT_GETH_PATH}
CERC_FAST_NODE: ${CERC_FAST_NODE:-false}
CERC_GETH_GCMODE: ${CERC_GETH_GCMODE:-full}
CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3}

View File

@ -28,20 +28,23 @@ ADDITIONAL_FLAGS=""
if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapshot_file" ]; then
echo "Using snapshot $snapshot_file"
if [ -z "$CERC_SNAPSHOT_GETH_PATH" ]; then
echo CERC_SNAPSHOT_GETH_PATH not set
exit 1
else
# Remove any trailing / from the given path
archive_geth_path=$(echo "$CERC_SNAPSHOT_GETH_PATH" | sed 's:/*$::')
# Determine strip-components count from the geth dir path
to_strip=$(echo "$archive_geth_path" | grep -o '/' | wc -l)
fi
case $snapshot_file in
*.lz4)
# Determine where geth dir is located
archive_geth_path=$(lz4 -c -d $snapshot_file | tar -tf - | grep -m1 -E 'geth/?$')
# Determine strip-components count from the path
to_strip=$(($(echo "$archive_geth_path" | grep -o '/' | wc -l) - 1))
# Extract geth data directly to destination directory
lz4 -c -d $snapshot_file | tar -C ${DATA_DIR}/ -xvf - --strip-components=$to_strip $archive_geth_path
;;
*.zst)
archive_geth_path=$(zstd -c -d $snapshot_file | tar -tf - | grep -m1 -E 'geth/?$')
to_strip=$(($(echo "$archive_geth_path" | grep -o '/' | wc -l) - 1))
zstd -c -d $snapshot_file | tar -C ${DATA_DIR}/ -xvf - --strip-components=$to_strip $archive_geth_path
;;
*)

View File

@ -64,6 +64,10 @@ Instructions for running a BSC node
# Requires snapshot file with extension .tar.lz4 or .tar.zst to be placed in the snapshot directory
CERC_USE_SNAPSHOT=
# Path where geth dir is located in the snapshot archive
# Required when using a snapshot; example: "server/data-seed/geth"
CERC_SNAPSHOT_GETH_PATH=
# Whether to run as a fast node (true | false) (default: false)
# Fast node does not generate trie data when syncing
CERC_FAST_NODE=