From 7e4206054104a0128c535c31d97d4e205dd8d252 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 6 Jun 2024 04:33:25 +0000 Subject: [PATCH] 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: https://git.vdb.to/cerc-io/bsc-stack/pulls/2 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- .../compose/docker-compose-bsc-node.yml | 1 + .../config/bsc-node/docker-entrypoint.sh | 21 +++++++++++-------- stack-orchestrator/stacks/bsc-node/README.md | 4 ++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index 9789a63..b797e7b 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -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} diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index 056a1d0..0d155c3 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -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 ;; *) diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index 9853f6f..13a5f26 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -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=