Add support for fast node

This commit is contained in:
Prathamesh Musale 2024-06-04 18:10:33 +05:30
parent aa04f65468
commit d9210326d0
2 changed files with 22 additions and 6 deletions

View File

@ -4,6 +4,8 @@ services:
restart: unless-stopped restart: unless-stopped
environment: environment:
CERC_BSC_NETWORK: ${CERC_BSC_NETWORK:-mainnet} CERC_BSC_NETWORK: ${CERC_BSC_NETWORK:-mainnet}
CERC_USE_SNAPSHOT: ${CERC_USE_SNAPSHOT:-false}
CERC_FAST_NODE: ${CERC_FAST_NODE:-false}
CERC_GETH_GCMODE: ${CERC_GETH_GCMODE:-full} CERC_GETH_GCMODE: ${CERC_GETH_GCMODE:-full}
CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3}
volumes: volumes:

View File

@ -2,10 +2,13 @@
set -e set -e
echo "Setting up BSC $CERC_BSC_NETWORK" 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_CONFIG=${BSC_HOME}/config/config.toml
BSC_GENESIS=${BSC_HOME}/config/genesis.json BSC_GENESIS=${BSC_HOME}/config/genesis.json
# Setup config
if [ -f "$BSC_CONFIG" ]; then if [ -f "$BSC_CONFIG" ]; then
echo "Config file found at $BSC_CONFIG" echo "Config file found at $BSC_CONFIG"
else else
@ -19,15 +22,26 @@ fi
# Use snapshot if provided # Use snapshot if provided
geth_dir=${DATA_DIR}/geth geth_dir=${DATA_DIR}/geth
snapshot_file=$((ls /var/dev/snapshot/*.tar.lz4) 2>/dev/null | head -1) snapshot_file=$((ls /var/dev/snapshot/*.tar.lz4) 2>/dev/null | head -1)
if [ ! -d "$geth_dir" ] && [ -n "$snapshot_file" ]; then ADDITIONAL_FLAGS=""
echo Using snapshot $snapshot_file if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapshot_file" ]; then
echo "Using snapshot $snapshot_file"
if [ "$CERC_BSC_NETWORK" = "testnet" ]; then if [ "$CERC_BSC_NETWORK" = "testnet" ]; then
# snapshot dir structure for testnet different than that for mainnet # Snapshot dir structure for testnet is different than that for mainnet
tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --strip-components=3 server/testnet/dataseed/geth tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --strip-components=3 server/testnet/dataseed/geth
else else
tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --strip-components=2 server/data-seed/geth tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --strip-components=2 server/data-seed/geth
fi 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 fi
# Init genesis state if geth sub dir does not exist # Init genesis state if geth sub dir does not exist
@ -38,12 +52,11 @@ if [ ! -d "$geth_dir" ]; then
STATE_SCHEME_OPTS="--state.scheme=hash" STATE_SCHEME_OPTS="--state.scheme=hash"
fi fi
echo Initializing geth... echo "Initializing geth..."
geth --datadir ${DATA_DIR} ${STATE_SCHEME_OPTS} init ${BSC_GENESIS} geth --datadir ${DATA_DIR} ${STATE_SCHEME_OPTS} init ${BSC_GENESIS}
echo Initialization done echo "Initialization done"
fi fi
# TODO: Check for archive mode flag
exec "geth" \ exec "geth" \
--config="${BSC_CONFIG}" \ --config="${BSC_CONFIG}" \
--datadir="${DATA_DIR}" \ --datadir="${DATA_DIR}" \
@ -61,4 +74,5 @@ exec "geth" \
--verbosity=${CERC_GETH_VERBOSITY} \ --verbosity=${CERC_GETH_VERBOSITY} \
--metrics \ --metrics \
--metrics.addr="0.0.0.0" \ --metrics.addr="0.0.0.0" \
${ADDITIONAL_FLAGS} \
"$@" "$@"