From aa04f65468f61a8b04a20dd3b52ce962e1ee842a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 17:31:25 +0530 Subject: [PATCH] Load from a snapshot if provided --- .../compose/docker-compose-bsc-node.yml | 3 +++ stack-orchestrator/config/docker-entrypoint.sh | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index 3a971d6..5b0e4f4 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -10,9 +10,11 @@ services: - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh - data:/data - bsc:/bsc + - snapshot:/var/tmp/snapshot ports: - 30303:30303 - 30311:30311 + - 6060:6060 - 8545:8545 - 8546:8546 healthcheck: @@ -25,3 +27,4 @@ services: volumes: data: bsc: + snapshot: diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index c9a000a..17ff0da 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -16,9 +16,22 @@ else unzip config.zip -d config 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 + + if [ "$CERC_BSC_NETWORK" = "testnet" ]; then + # snapshot dir structure for testnet 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 +fi + # Init genesis state if geth sub dir does not exist -GETH_DIR=${DATA_DIR}/geth -if [ ! -d "$GETH_DIR" ]; then +if [ ! -d "$geth_dir" ]; then STATE_SCHEME_OPTS="" if [ "$CERC_GETH_GCMODE" = "archive" ]; then # Archive mode only works with state.scheme set to hash @@ -34,6 +47,7 @@ fi exec "geth" \ --config="${BSC_CONFIG}" \ --datadir="${DATA_DIR}" \ + --rpc.allow-unprotected-txs \ --http \ --http.addr="0.0.0.0" \ --http.port 8545 \