bsc-stack/stack-orchestrator/config/bsc-node/docker-entrypoint.sh
Prathamesh Musale e908b5a7b3 Add a stack to run a BSC node (#1)
Part of [Create a stack to run a BSC node](https://www.notion.so/Create-a-stack-to-run-a-BSC-node-5740b35b02974661a0237dcf57ab8150)

Add a stack to run a BSC node for mainnet or testnet in various modes (full, archive, fast); synced from genesis or a snapshot

Reviewed-on: #1
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-06-05 12:28:19 +00:00

97 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "Setting up BSC $CERC_BSC_NETWORK"
echo DATA_DIR: ${DATA_DIR}
echo BSC_HOME: ${BSC_HOME}
BSC_CONFIG=${BSC_HOME}/config/config.toml
BSC_GENESIS=${BSC_HOME}/config/genesis.json
# Setup config
if [ -f "$BSC_CONFIG" ]; then
echo "Config file found at $BSC_CONFIG"
else
echo "Config file not found at $BSC_CONFIG, downloading config for $CERC_BSC_NETWORK..."
# Download and unzip the config files (https://github.com/bnb-chain/bsc/releases/tag/v1.4.8)
wget -O config.zip $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/156666248 | grep browser_ | grep $CERC_BSC_NETWORK | cut -d\" -f4)
unzip config.zip -d config
fi
# Use snapshot if provided
# 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"
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))
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
;;
*)
echo "Unsupported archive format for the snapshot file: $snapshot_file"
exit 1
;;
esac
if [ "${CERC_FAST_NODE}" = "true" ]; then
echo "Pruning trie data and turning snapshot verification off"
# Prune all trie data from the snapshot
geth snapshot insecure-prune-all --datadir ${DATA_DIR} ${BSC_GENESIS}
# Turn off snapshot verification
ADDITIONAL_FLAGS="--tries-verify-mode none"
fi
fi
# Init genesis state if geth sub dir does not exist
if [ ! -d "$geth_dir" ]; then
STATE_SCHEME_OPTS=""
if [ "$CERC_GETH_GCMODE" = "archive" ]; then
# Archive mode only works with state.scheme set to hash
STATE_SCHEME_OPTS="--state.scheme=hash"
fi
echo "Initializing geth..."
geth --datadir ${DATA_DIR} ${STATE_SCHEME_OPTS} init ${BSC_GENESIS}
echo "Initialization done"
fi
exec "geth" \
--config="${BSC_CONFIG}" \
--datadir="${DATA_DIR}" \
--rpc.allow-unprotected-txs \
--history.transactions 0 \
--http \
--http.addr="0.0.0.0" \
--http.port 8545 \
--http.vhosts="*" \
--http.corsdomain="*" \
--ws \
--ws.addr="0.0.0.0" \
--ws.port 8546 \
--ws.origins="*" \
--gcmode=${CERC_GETH_GCMODE} \
--verbosity=${CERC_GETH_VERBOSITY} \
--metrics \
--metrics.addr="0.0.0.0" \
${ADDITIONAL_FLAGS} \
"$@"