From 55c22b681800b6f3cf2ca7ae3ea2f2c05913e4f5 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 11:34:09 +0530 Subject: [PATCH 01/16] Add a stack with a compose file --- README.md | 6 ++++- .../compose/docker-compose-bsc-node.yml | 23 +++++++++++++++++++ .../config/docker-entrypoint.sh | 19 +++++++++++++++ stack-orchestrator/stacks/bsc-node/README.md | 9 ++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 stack-orchestrator/compose/docker-compose-bsc-node.yml create mode 100755 stack-orchestrator/config/docker-entrypoint.sh create mode 100644 stack-orchestrator/stacks/bsc-node/README.md diff --git a/README.md b/README.md index 6561249..3280f8f 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# bsc-stack \ No newline at end of file +# bsc-stack + +Stack definitions for BSC full node deployment. + +[stack documentation](stack-orchestrator/stacks/bsc-node/README.md) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml new file mode 100644 index 0000000..be99ccf --- /dev/null +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -0,0 +1,23 @@ +services: + bsc: + image: ghcr.io/bnb-chain/bsc:1.4.8 + restart: unless-stopped + environment: + volumes: + - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh + - data:/data + - config:/bsc/config + ports: + - 30311:30311 + - 8545:8545 + - 8546:8546 + healthcheck: + test: ["CMD", "nc", "-vz", "localhost", "8545"] + interval: 5s + retries: 5 + start_period: 10s + timeout: 3s + +volumes: + data: + config: diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh new file mode 100755 index 0000000..d27950f --- /dev/null +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +# TODO: Check for testnet flag +# TODO: Download and unzip the config files + +BSC_CONFIG=${BSC_HOME}/config/config.toml +BSC_GENESIS=${BSC_HOME}/config/genesis.json + +# Init genesis state if geth not exist +DATA_DIR=$(cat ${BSC_CONFIG} | grep -A1 '\[Node\]' | grep -oP '\"\K.*?(?=\")') + +GETH_DIR=${DATA_DIR}/geth +if [ ! -d "$GETH_DIR" ]; then + geth --datadir ${DATA_DIR} init ${BSC_GENESIS} +fi + +# TODO: Check for archive mode flag +exec "geth" "--config" ${BSC_CONFIG} "$@" diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md new file mode 100644 index 0000000..2c6e37e --- /dev/null +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -0,0 +1,9 @@ +# bsc-node + +Instructions for running a BSC node + +## Prerequisite + +Downloaded chain snapshot + + -- 2.45.2 From 1bdff2b22e904b1f667abd1e8ba76b49302dcf47 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 12:16:43 +0530 Subject: [PATCH 02/16] Setup config on startup and fix node initialization --- .../compose/docker-compose-bsc-node.yml | 7 ++++--- .../config/docker-entrypoint.sh | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index be99ccf..a2a2938 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -2,12 +2,13 @@ services: bsc: image: ghcr.io/bnb-chain/bsc:1.4.8 restart: unless-stopped - environment: + # environment: volumes: - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh - data:/data - - config:/bsc/config + - bsc:/bsc ports: + - 30303:30303 - 30311:30311 - 8545:8545 - 8546:8546 @@ -20,4 +21,4 @@ services: volumes: data: - config: + bsc: diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index d27950f..2e7afb4 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -1,19 +1,28 @@ #!/bin/bash set -e -# TODO: Check for testnet flag -# TODO: Download and unzip the config files - BSC_CONFIG=${BSC_HOME}/config/config.toml BSC_GENESIS=${BSC_HOME}/config/genesis.json -# Init genesis state if geth not exist -DATA_DIR=$(cat ${BSC_CONFIG} | grep -A1 '\[Node\]' | grep -oP '\"\K.*?(?=\")') +# TODO: Check for testnet flag +if [ -f "$BSC_CONFIG" ]; then + echo "Config file found at $BSC_CONFIG" +else + echo "Config file not found at $BSC_CONFIG, downloading..." + + # 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 mainnet |cut -d\" -f4) + unzip config.zip -d config +fi + +# Init genesis state if geth sub dir does not exist GETH_DIR=${DATA_DIR}/geth if [ ! -d "$GETH_DIR" ]; then + echo Initializing geth... geth --datadir ${DATA_DIR} init ${BSC_GENESIS} + echo Initialization done fi # TODO: Check for archive mode flag -exec "geth" "--config" ${BSC_CONFIG} "$@" +exec "geth" "--config" ${BSC_CONFIG} "--datadir" ${DATA_DIR} "$@" -- 2.45.2 From 372cace05f44e09bf8b631599e655d2f4f9c98d3 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 12:40:03 +0530 Subject: [PATCH 03/16] Add a config option for testnet --- .../compose/docker-compose-bsc-node.yml | 3 ++- .../config/docker-entrypoint.sh | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index a2a2938..da6133b 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -2,7 +2,8 @@ services: bsc: image: ghcr.io/bnb-chain/bsc:1.4.8 restart: unless-stopped - # environment: + environment: + CERC_BSC_NETWORK: ${CERC_BSC_NETWORK:-mainnet} volumes: - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh - data:/data diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index 2e7afb4..4e1a243 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -1,18 +1,18 @@ #!/bin/bash set -e +echo "Setting up BSC $CERC_BSC_NETWORK" + BSC_CONFIG=${BSC_HOME}/config/config.toml BSC_GENESIS=${BSC_HOME}/config/genesis.json -# TODO: Check for testnet flag - if [ -f "$BSC_CONFIG" ]; then echo "Config file found at $BSC_CONFIG" else - echo "Config file not found at $BSC_CONFIG, downloading..." + 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 mainnet |cut -d\" -f4) + 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 @@ -25,4 +25,16 @@ if [ ! -d "$GETH_DIR" ]; then fi # TODO: Check for archive mode flag -exec "geth" "--config" ${BSC_CONFIG} "--datadir" ${DATA_DIR} "$@" +exec "geth" \ + --config="${BSC_CONFIG}" \ + --datadir="${DATA_DIR}" \ + --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="*" \ + "$@" -- 2.45.2 From a2abcff2a7c0921b0bc82ecdb0759add8a262ac8 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 14:37:34 +0530 Subject: [PATCH 04/16] Add support for archive node --- .../compose/docker-compose-bsc-node.yml | 2 ++ stack-orchestrator/config/docker-entrypoint.sh | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index da6133b..3a971d6 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_GETH_GCMODE: ${CERC_GETH_GCMODE:-full} + CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} volumes: - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh - data:/data diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index 4e1a243..c9a000a 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -19,8 +19,14 @@ fi # Init genesis state if geth sub dir does not exist GETH_DIR=${DATA_DIR}/geth 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} init ${BSC_GENESIS} + geth --datadir ${DATA_DIR} ${STATE_SCHEME_OPTS} init ${BSC_GENESIS} echo Initialization done fi @@ -37,4 +43,8 @@ exec "geth" \ --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" \ "$@" -- 2.45.2 From aa04f65468f61a8b04a20dd3b52ce962e1ee842a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 17:31:25 +0530 Subject: [PATCH 05/16] 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 \ -- 2.45.2 From d9210326d0ced3ee0ce3e936e90931457136528f Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 18:10:33 +0530 Subject: [PATCH 06/16] 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} \ "$@" -- 2.45.2 From 082566f7c9d6098c528613236578c8babf0abb51 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 19:05:49 +0530 Subject: [PATCH 07/16] Extend bsc Dockerfile for additional dependencies --- stack-orchestrator/compose/docker-compose-bsc-node.yml | 2 +- stack-orchestrator/config/docker-entrypoint.sh | 4 ++-- .../container-build/cerc-bsc-geth/Dockerfile | 5 +++++ stack-orchestrator/container-build/cerc-bsc-geth/build.sh | 7 +++++++ stack-orchestrator/stacks/bsc-node/stack.yml | 8 ++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile create mode 100755 stack-orchestrator/container-build/cerc-bsc-geth/build.sh create mode 100644 stack-orchestrator/stacks/bsc-node/stack.yml diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index 58c1dea..257cbe9 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -1,6 +1,6 @@ services: bsc: - image: ghcr.io/bnb-chain/bsc:1.4.8 + image: cerc/bsc-geth:local restart: unless-stopped environment: CERC_BSC_NETWORK: ${CERC_BSC_NETWORK:-mainnet} diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index fd3c184..6d40fbc 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -28,9 +28,9 @@ if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapsho if [ "$CERC_BSC_NETWORK" = "testnet" ]; then # 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 + lz4 -d ${snapshot_file} | tar -C ${DATA_DIR}/ -xvf - --strip-components=3 server/testnet/dataseed/geth else - tar -C /${DATA_DIR}/ -I lz4 -xvf ${snapshot_file} --strip-components=2 server/data-seed/geth + lz4 -d ${snapshot_file} | tar -C ${DATA_DIR}/ -xvf - --strip-components=2 server/data-seed/geth fi if [ "${CERC_FAST_NODE}" = "true" ]; then diff --git a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile new file mode 100644 index 0000000..a1771c6 --- /dev/null +++ b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/bnb-chain/bsc:1.4.8 + +USER root +RUN apk add lz4 +USER bsc diff --git a/stack-orchestrator/container-build/cerc-bsc-geth/build.sh b/stack-orchestrator/container-build/cerc-bsc-geth/build.sh new file mode 100755 index 0000000..3c398ac --- /dev/null +++ b/stack-orchestrator/container-build/cerc-bsc-geth/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Build cerc/bsc-geth +docker build -t cerc/bsc-geth:local ${build_command_args} ${SCRIPT_DIR} diff --git a/stack-orchestrator/stacks/bsc-node/stack.yml b/stack-orchestrator/stacks/bsc-node/stack.yml new file mode 100644 index 0000000..a017c2e --- /dev/null +++ b/stack-orchestrator/stacks/bsc-node/stack.yml @@ -0,0 +1,8 @@ +version: "1.0" +name: bsc-node +description: "BSC node stack" +repos: +containers: + - cerc/bsc-geth +pods: + - bsc-node -- 2.45.2 From 175208d0558550cc7f7dc9d580d73ac288b4451f Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 19:18:58 +0530 Subject: [PATCH 08/16] Maintain transactions index for all blocks --- stack-orchestrator/config/docker-entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index 6d40fbc..606b840 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -61,6 +61,7 @@ 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 \ -- 2.45.2 From cb4b2501ebb5df27a6732ec437d2856064ce67ad Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 10:39:34 +0530 Subject: [PATCH 09/16] Add instructions --- .../compose/docker-compose-bsc-node.yml | 12 +- .../{ => bsc-node}/docker-entrypoint.sh | 8 +- stack-orchestrator/stacks/bsc-node/README.md | 128 +++++++++++++++++- 3 files changed, 136 insertions(+), 12 deletions(-) rename stack-orchestrator/config/{ => bsc-node}/docker-entrypoint.sh (91%) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index 257cbe9..9789a63 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -9,16 +9,16 @@ services: CERC_GETH_GCMODE: ${CERC_GETH_GCMODE:-full} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} volumes: - - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh + - ../config/bsc-node/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 + - "30303" + - "30311" + - "6060" + - "8545" + - "8546" healthcheck: test: ["CMD", "nc", "-vz", "localhost", "8545"] interval: 5s diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh similarity index 91% rename from stack-orchestrator/config/docker-entrypoint.sh rename to stack-orchestrator/config/bsc-node/docker-entrypoint.sh index 606b840..a003169 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/bash + set -e echo "Setting up BSC $CERC_BSC_NETWORK" @@ -15,13 +16,14 @@ 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) + 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 -geth_dir=${DATA_DIR}/geth +# 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" @@ -37,7 +39,7 @@ if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapsho 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} + geth snapshot insecure-prune-all --datadir ${DATA_DIR} ${BSC_GENESIS} # Turn off snapshot verification ADDITIONAL_FLAGS="--tries-verify-mode none" diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index 2c6e37e..e9d3afa 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -2,8 +2,130 @@ Instructions for running a BSC node -## Prerequisite +## Setup -Downloaded chain snapshot +* (Optional) Download the snapshot for BSC network (mainetn | testnet) by following instructions from - +* Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/bsc-stack + ``` + +* Build the container images: + + ```bash + laconic-so --stack ~/cerc/bsc-stack/stack-orchestrator/stacks/bsc-node build-containers + ``` + +## Create a deployment + +* Create a spec file for the deployment: + + ```bash + laconic-so --stack ~/cerc/bsc-stack/stack-orchestrator/stacks/bsc-node deploy init --map-ports-to-host any-same --output bsc-node-spec.yml + ``` + +* Edit `network` in the spec file to map container ports to host ports as required + +* Create a deployment directory from the spec file: + + ```bash + laconic-so --stack ~/cerc/bsc-stack/stack-orchestrator/stacks/bsc-node deploy create --spec-file bsc-node-spec.yml --deployment-dir bsc-node-deployment + ``` + +* (Optional) Copy over the snapshot file (`*.tar.lz4`) in snapshot data directory in the deployment (`bsc-node-deployment/data/snapshot`): + + ```bash + # Example + cp geth-pbss-pebble-20240514.tar.lz4 bsc-node-deployment/data/snapshot/ + ``` + +## Configuration + +* Environment variables for Lotus node can be configured by setting them in `config.env` inside deployment directory: + + ```bash + # All optional + # Runs a full node syncing from genesis if none are set + + # BSC network to run (mainnet | testnet) (default: mainnet) + CERC_BSC_NETWORK= + + # Whether to sync from a snapshot (true | false) (default: false) + # Requires snapshot file with extension .tar.lz4 to be placed in the snapshot directory + CERC_USE_SNAPSHOT= + + # Whether to run as a fast node (true | false) (default: false) + # Fast node does not generate trie data when syncing + CERC_FAST_NODE= + + # Garbage collection mode (full | archive) (default: archive) + # Set to archive for archive node + CERC_GETH_GCMODE= + + # Logging verbosity (default: 3) + # 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail + CERC_GETH_VERBOSITY= + ``` + +## Start the deployment + +```bash +laconic-so deployment --dir bsc-node-deployment up +``` + +## Check status + +* To list down and monitor the running containers: + + ```bash + # With status + docker ps -a + + # Check logs for a container + docker logs -f + ``` + +* Log in with bash into the bsc container: + + ```bash + docker exec -it bash + ``` + +* Check Synchronization: + + ```bash + # Inside the bsc container + + # Start geth console + geth attach ipc:node/geth.ipc + + >eth.syncing + ``` + +* Check geth logs: + + ```bash + # Inside the bsc container + tail -f /data/bsc.log + ``` + +## Clean up + +* Stop all services running in the background: + + ```bash + # Stop the docker containers + laconic-so deployment --dir bsc-node-deployment down + ``` + +* To stop all services and also delete data: + + ```bash + # Stop the docker containers + laconic-so deployment --dir bsc-node-deployment down --delete-volumes + + # Remove deployment directory (deployment will have to be recreated for a re-run) + rm -r bsc-node-deployment + ``` -- 2.45.2 From 6794cb3a938687033ef7b28628cb52cf03c22522 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 10:50:01 +0530 Subject: [PATCH 10/16] Add an example for downloading snapshot and fix typos --- README.md | 2 +- .../config/bsc-node/docker-entrypoint.sh | 4 ++-- stack-orchestrator/stacks/bsc-node/README.md | 14 +++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3280f8f..64b63f5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # bsc-stack -Stack definitions for BSC full node deployment. +Stack definitions for BSC node deployment. [stack documentation](stack-orchestrator/stacks/bsc-node/README.md) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index a003169..1787875 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -15,8 +15,8 @@ if [ -f "$BSC_CONFIG" ]; then 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) + # 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 diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index e9d3afa..8b43f83 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -4,7 +4,15 @@ Instructions for running a BSC node ## Setup -* (Optional) Download the snapshot for BSC network (mainetn | testnet) by following instructions from +* (Optional) Download the snapshot for BSC network (mainnet | testnet) by following instructions from + + ```bash + # Example (mainnet) + wget -O geth.tar.lz4 https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/geth-pbss-pebble-20240514.tar.lz4 + + # Example (testnet) + wget -O geth.tar.lz4 https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/testnet-geth-pbss-20240307.tar.lz4 + ``` * Clone the stack repo: @@ -43,7 +51,7 @@ Instructions for running a BSC node ## Configuration -* Environment variables for Lotus node can be configured by setting them in `config.env` inside deployment directory: +* Environment variables for BSC node can be configured by setting them in `config.env` inside the deployment directory: ```bash # All optional @@ -99,7 +107,7 @@ laconic-so deployment --dir bsc-node-deployment up # Inside the bsc container # Start geth console - geth attach ipc:node/geth.ipc + geth attach ipc:/data/geth.ipc >eth.syncing ``` -- 2.45.2 From b98018b9f6cc1cb5368177e7d10896c41623068c Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 11:36:03 +0530 Subject: [PATCH 11/16] Update instructions --- .../container-build/cerc-bsc-geth/Dockerfile | 3 +++ stack-orchestrator/stacks/bsc-node/README.md | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile index a1771c6..4a521c6 100644 --- a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile +++ b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile @@ -1,5 +1,8 @@ FROM ghcr.io/bnb-chain/bsc:1.4.8 USER root + +# Add lz4 for extracting files from a lz4 snapshot RUN apk add lz4 + USER bsc diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index 8b43f83..940bbbe 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -95,19 +95,11 @@ laconic-so deployment --dir bsc-node-deployment up docker logs -f ``` -* Log in with bash into the bsc container: - - ```bash - docker exec -it bash - ``` - * Check Synchronization: ```bash - # Inside the bsc container - # Start geth console - geth attach ipc:/data/geth.ipc + laconic-so deployment --dir bsc-node-deployment exec bsc "geth attach ipc:/data/geth.ipc" >eth.syncing ``` @@ -115,8 +107,7 @@ laconic-so deployment --dir bsc-node-deployment up * Check geth logs: ```bash - # Inside the bsc container - tail -f /data/bsc.log + laconic-so deployment --dir bsc-node-deployment exec bsc "tail -f /data/bsc.log" ``` ## Clean up -- 2.45.2 From f989b58f2a2727d5d9f6687f4e98595daf6b2ad2 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 12:31:36 +0530 Subject: [PATCH 12/16] Add upgrade instructions --- .../config/bsc-node/docker-entrypoint.sh | 2 +- stack-orchestrator/stacks/bsc-node/README.md | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index 1787875..bfd1183 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -22,7 +22,7 @@ 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) +snapshot_file=$((ls /var/tmp/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 diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index 940bbbe..4c0d810 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -11,7 +11,7 @@ Instructions for running a BSC node wget -O geth.tar.lz4 https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/geth-pbss-pebble-20240514.tar.lz4 # Example (testnet) - wget -O geth.tar.lz4 https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/testnet-geth-pbss-20240307.tar.lz4 + wget -O geth.testnet.tar.lz4 https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/testnet-geth-pbss-20240307.tar.lz4 ``` * Clone the stack repo: @@ -46,7 +46,7 @@ Instructions for running a BSC node ```bash # Example - cp geth-pbss-pebble-20240514.tar.lz4 bsc-node-deployment/data/snapshot/ + cp geth.tar.lz4 bsc-node-deployment/data/snapshot/ ``` ## Configuration @@ -68,7 +68,7 @@ Instructions for running a BSC node # Fast node does not generate trie data when syncing CERC_FAST_NODE= - # Garbage collection mode (full | archive) (default: archive) + # Garbage collection mode (full | archive) (default: full) # Set to archive for archive node CERC_GETH_GCMODE= @@ -128,3 +128,10 @@ laconic-so deployment --dir bsc-node-deployment up # Remove deployment directory (deployment will have to be recreated for a re-run) rm -r bsc-node-deployment ``` + +## Upgrading + +To upgrade the BSC release being used: + +* Upgrade the base Docker image used in [Dockerfile](`stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile`) +* Update the release assets URL used for fetching config files in [docker-entrypoint.sh](stack-orchestrator/config/bsc-node/docker-entrypoint.sh) -- 2.45.2 From 2b1fcebab275d0a4cd67e3cc8b5a1f488cc08032 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 15:49:39 +0530 Subject: [PATCH 13/16] Support zst archive for snapshots --- .../config/bsc-node/docker-entrypoint.sh | 28 +++++++++++++------ .../container-build/cerc-bsc-geth/Dockerfile | 4 +-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index bfd1183..b97073c 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -21,19 +21,31 @@ else fi # Use snapshot if provided -# Take first file with extension .tar.lz4 from the snapshot dir -snapshot_file=$((ls /var/tmp/snapshot/*.tar.lz4) 2>/dev/null | head -1) +# 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 [ "$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 + temp_dir=$(mktemp -d) + case $snapshot_file in + *.lz4) + lz4 -d $snapshot_file | tar -C $temp_dir -xvf - + ;; + *.zst) + zstd -c -d $snapshot_file | tar -C $temp_dir -xvf - + ;; + *) + echo "Unsupported archive format for the snapshot file: $snapshot_file" + exit 1 + ;; + esac + + # Move geth data to data dir + extracted_geth_dir=$(find $temp_dir -type d -name "geth" -print -quit) + mv $extracted_geth_dir ${DATA_DIR}/ + rm -rf $temp_dir if [ "${CERC_FAST_NODE}" = "true" ]; then echo "Pruning trie data and turning snapshot verification off" diff --git a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile index 4a521c6..f159a76 100644 --- a/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile +++ b/stack-orchestrator/container-build/cerc-bsc-geth/Dockerfile @@ -2,7 +2,7 @@ FROM ghcr.io/bnb-chain/bsc:1.4.8 USER root -# Add lz4 for extracting files from a lz4 snapshot -RUN apk add lz4 +# Add lz4, zstd and tar for extracting snapshot files +RUN apk add lz4 zstd tar USER bsc -- 2.45.2 From b7ccf24c93e023a1b01decb3ee5afc0ecd123ad1 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 16:19:07 +0530 Subject: [PATCH 14/16] Read snapshot file paths --- stack-orchestrator/config/bsc-node/docker-entrypoint.sh | 2 +- stack-orchestrator/stacks/bsc-node/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index b97073c..09d5f1d 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -22,7 +22,7 @@ fi # Use snapshot if provided # Take first file from the snapshot dir -snapshot_file=$((ls /var/tmp/snapshot/) 2>/dev/null | head -1) +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 diff --git a/stack-orchestrator/stacks/bsc-node/README.md b/stack-orchestrator/stacks/bsc-node/README.md index 4c0d810..9853f6f 100644 --- a/stack-orchestrator/stacks/bsc-node/README.md +++ b/stack-orchestrator/stacks/bsc-node/README.md @@ -42,7 +42,7 @@ Instructions for running a BSC node laconic-so --stack ~/cerc/bsc-stack/stack-orchestrator/stacks/bsc-node deploy create --spec-file bsc-node-spec.yml --deployment-dir bsc-node-deployment ``` -* (Optional) Copy over the snapshot file (`*.tar.lz4`) in snapshot data directory in the deployment (`bsc-node-deployment/data/snapshot`): +* (Optional) Copy over the snapshot file (`*.tar.lz4` or `*.tar.zst`) in snapshot data directory in the deployment (`bsc-node-deployment/data/snapshot`): ```bash # Example @@ -61,7 +61,7 @@ Instructions for running a BSC node CERC_BSC_NETWORK= # Whether to sync from a snapshot (true | false) (default: false) - # Requires snapshot file with extension .tar.lz4 to be placed in the snapshot directory + # Requires snapshot file with extension .tar.lz4 or .tar.zst to be placed in the snapshot directory CERC_USE_SNAPSHOT= # Whether to run as a fast node (true | false) (default: false) -- 2.45.2 From 0bbce517e347535885ec99d96bfc15e934c5c27b Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 17:29:34 +0530 Subject: [PATCH 15/16] Extract geth data directly to destination directory --- .../config/bsc-node/docker-entrypoint.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index 09d5f1d..168a9d7 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -28,13 +28,18 @@ ADDITIONAL_FLAGS="" if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapshot_file" ]; then echo "Using snapshot $snapshot_file" - temp_dir=$(mktemp -d) case $snapshot_file in *.lz4) - lz4 -d $snapshot_file | tar -C $temp_dir -xvf - + archive_geth_path=$(lz4 -c -d $snapshot_file | tar -tf - | grep -m1 -E 'geth/?$') + to_strip=$(($(echo "$archive_geth_path" | grep -o '/' | wc -l) - 1)) + + 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 $temp_dir -xvf - + archive_geth_path=$(zstd -c -d $snapshot_file | tar -tf - | grep -m1 -E 'geth/?$') + to_strip=$(($(echo "$archive_geth_path" | grep -o '/' | wc -l) - 1)) + + 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" @@ -42,11 +47,6 @@ if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapsho ;; esac - # Move geth data to data dir - extracted_geth_dir=$(find $temp_dir -type d -name "geth" -print -quit) - mv $extracted_geth_dir ${DATA_DIR}/ - rm -rf $temp_dir - if [ "${CERC_FAST_NODE}" = "true" ]; then echo "Pruning trie data and turning snapshot verification off" -- 2.45.2 From 7e3e793575e53bfc338257e4c5630e59072d1b3f Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Jun 2024 17:48:50 +0530 Subject: [PATCH 16/16] Add explanatory comments --- stack-orchestrator/config/bsc-node/docker-entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh index 168a9d7..056a1d0 100755 --- a/stack-orchestrator/config/bsc-node/docker-entrypoint.sh +++ b/stack-orchestrator/config/bsc-node/docker-entrypoint.sh @@ -30,7 +30,10 @@ if [ ! -d "$geth_dir" ] && [ "${CERC_USE_SNAPSHOT}" = "true" ] && [ -n "$snapsho case $snapshot_file in *.lz4) + # Determine where geth dir is located archive_geth_path=$(lz4 -c -d $snapshot_file | tar -tf - | grep -m1 -E 'geth/?$') + + # Determine strip-components count from the path to_strip=$(($(echo "$archive_geth_path" | grep -o '/' | wc -l) - 1)) lz4 -c -d $snapshot_file | tar -C ${DATA_DIR}/ -xvf - --strip-components=$to_strip $archive_geth_path -- 2.45.2