bsc-stack/stack-orchestrator/config/bsc-node/docker-entrypoint.sh

82 lines
2.4 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
wget -O config.zip $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest | grep browser_ | grep $CERC_BSC_NETWORK | cut -d\" -f4)
unzip config.zip -d config
fi
# Use snapshot if provided
# Take first file with extension .tar.lz4 from the snapshot dir
snapshot_file=$((ls /var/dev/snapshot/*.tar.lz4) 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
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} \
"$@"