diff --git a/docker-compose.yml b/docker-compose.yml index e4347b4..ab4bfbb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: RPC_MAX_BLOCKS_PER_FILTER: "0" EXTRA_OPTS: null ARCHIVE_NODE: "false" + DOWNLOAD_SNAPSHOT: "true" + STORAGE_MODE: full restart: unless-stopped volumes: reth: {} diff --git a/reth/entrypoint.sh b/reth/entrypoint.sh index 46a5b6f..16a2220 100755 --- a/reth/entrypoint.sh +++ b/reth/entrypoint.sh @@ -8,12 +8,87 @@ echo "${JWT_SECRET}" >"${JWT_PATH}" post_jwt_to_dappmanager "${JWT_PATH}" +DOWNLOAD_SNAPSHOT="${DOWNLOAD_SNAPSHOT:-true}" +ARCHIVE_NODE="${ARCHIVE_NODE:-false}" +STORAGE_MODE="${STORAGE_MODE:-full}" + +case "${DOWNLOAD_SNAPSHOT}" in +true | false) ;; +*) + echo "[ERROR - entrypoint] DOWNLOAD_SNAPSHOT must be 'true' or 'false'" + exit 1 + ;; +esac + +if [ "${ARCHIVE_NODE}" = true ]; then + echo "[INFO - entrypoint] ARCHIVE_NODE=true detected; using STORAGE_MODE=archive" + STORAGE_MODE="archive" +fi + +case "${STORAGE_MODE}" in +full) + STORAGE_MODE_FLAG="--full" + SNAPSHOT_MODE_FLAG="--full" + ;; +minimal) + STORAGE_MODE_FLAG="--minimal" + SNAPSHOT_MODE_FLAG="--minimal" + ;; +archive) + STORAGE_MODE_FLAG="" + SNAPSHOT_MODE_FLAG="--archive" + ;; +custom) + STORAGE_MODE_FLAG="--block-interval 5 --prune.senderrecovery.full --prune.receipts.before 0 --prune.accounthistory.distance 10064 --prune.storagehistory.distance 10064" + SNAPSHOT_MODE_FLAG="" + ;; +*) + echo "[ERROR - entrypoint] STORAGE_MODE must be 'full', 'minimal', 'archive', or 'custom'" + exit 1 + ;; +esac + +is_data_dir_initialized() { + for path in \ + "${DATA_DIR}/${NETWORK}/db" \ + "${DATA_DIR}/${NETWORK}/reth.toml" \ + "${DATA_DIR}/${NETWORK}/static_files" \ + "${DATA_DIR}/${NETWORK}/rocksdb" \ + "${DATA_DIR}/db" \ + "${DATA_DIR}/reth.toml" \ + "${DATA_DIR}/static_files" \ + "${DATA_DIR}/rocksdb"; do + if [ -e "${path}" ]; then + return 0 + fi + done + + return 1 +} + echo "[INFO - entrypoint] Running Reth client for network: ${NETWORK}" +if [ "${STORAGE_MODE}" = custom ]; then + echo "[INFO - entrypoint] STORAGE_MODE=custom selected; skipping snapshot download" +elif [ "${DOWNLOAD_SNAPSHOT}" = true ]; then + if is_data_dir_initialized; then + echo "[INFO - entrypoint] Reth data directory already initialized; skipping snapshot download" + else + echo "[INFO - entrypoint] Downloading ${NETWORK} ${SNAPSHOT_MODE_FLAG#--} snapshot before starting Reth" + # shellcheck disable=SC2086 + reth \ + download \ + -y \ + ${SNAPSHOT_MODE_FLAG} \ + --chain "${NETWORK}" \ + --datadir "${DATA_DIR}" + fi +fi + # shellcheck disable=SC2086 exec reth \ node \ - $( [ "${ARCHIVE_NODE}" = false ] && printf -- "--block-interval 5 --prune.senderrecovery.full --prune.receipts.before 0 --prune.accounthistory.distance 10064 --prune.storagehistory.distance 10064" ) \ + ${STORAGE_MODE_FLAG} \ --chain "${NETWORK}" \ --metrics 0.0.0.0:6060 \ --datadir "${DATA_DIR}" \