From d9210326d0ced3ee0ce3e936e90931457136528f Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 18:10:33 +0530 Subject: [PATCH] Add support for fast node --- .../compose/docker-compose-bsc-node.yml | 2 ++ .../config/docker-entrypoint.sh | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index 5b0e4f4..58c1dea 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -4,6 +4,8 @@ services: restart: unless-stopped environment: 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_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} volumes: diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index 17ff0da..fd3c184 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -2,10 +2,13 @@ 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 @@ -19,15 +22,26 @@ fi # Use snapshot if provided geth_dir=${DATA_DIR}/geth snapshot_file=$((ls /var/dev/snapshot/*.tar.lz4) 2>/dev/null | head -1) -if [ ! -d "$geth_dir" ] && [ -n "$snapshot_file" ]; then - echo Using snapshot $snapshot_file +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 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 else tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --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 @@ -38,12 +52,11 @@ if [ ! -d "$geth_dir" ]; then STATE_SCHEME_OPTS="--state.scheme=hash" fi - echo Initializing geth... + echo "Initializing geth..." geth --datadir ${DATA_DIR} ${STATE_SCHEME_OPTS} init ${BSC_GENESIS} - echo Initialization done + echo "Initialization done" fi -# TODO: Check for archive mode flag exec "geth" \ --config="${BSC_CONFIG}" \ --datadir="${DATA_DIR}" \ @@ -61,4 +74,5 @@ exec "geth" \ --verbosity=${CERC_GETH_VERBOSITY} \ --metrics \ --metrics.addr="0.0.0.0" \ + ${ADDITIONAL_FLAGS} \ "$@"