100 lines
2.9 KiB
Bash
Executable File
100 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"
|
|
|
|
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)
|
|
# 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)
|
|
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} \
|
|
"$@"
|