From 32edd7aea783ca934e661519b9ab5b830e485fdf Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 6 Dec 2022 17:17:24 -0600 Subject: [PATCH] 46: Make it possible to launch fixturenet with or without the statediff DB. (#59) * 46: Make it possible to launch fixturenet with or without the statediff DB. * Require the hostname as well. --- compose/docker-compose-fixturenet-eth.yml | 3 +-- config/fixturenet-eth/fixturenet-eth.env | 1 + .../cerc-fixturenet-eth-geth/Dockerfile | 2 +- .../cerc-fixturenet-eth-geth/run-el.sh | 25 +++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/compose/docker-compose-fixturenet-eth.yml b/compose/docker-compose-fixturenet-eth.yml index 96e3d2ba..df6ae30a 100644 --- a/compose/docker-compose-fixturenet-eth.yml +++ b/compose/docker-compose-fixturenet-eth.yml @@ -31,7 +31,7 @@ services: fixturenet-eth-geth-2: hostname: fixturenet-eth-geth-2 environment: - CERC_RUN_STATEDIFF: "true" + CERC_RUN_STATEDIFF: "detect" CERC_STATEDIFF_DB_NODE_ID: 2 healthcheck: test: ["CMD", "nc", "-v", "localhost", "8545"] @@ -43,7 +43,6 @@ services: - ../config/fixturenet-eth/fixturenet-eth.env image: cerc/fixturenet-eth-geth:local depends_on: - - migrations - fixturenet-eth-bootnode-geth fixturenet-eth-bootnode-lighthouse: diff --git a/config/fixturenet-eth/fixturenet-eth.env b/config/fixturenet-eth/fixturenet-eth.env index 9ec6742e..10d6c94c 100644 --- a/config/fixturenet-eth/fixturenet-eth.env +++ b/config/fixturenet-eth/fixturenet-eth.env @@ -17,3 +17,4 @@ CERC_STATEDIFF_DB_PORT=5432 CERC_STATEDIFF_DB_NAME="cerc_testing" CERC_STATEDIFF_DB_USER="vdbm" CERC_STATEDIFF_DB_PASSWORD="password" +CERC_STATEDIFF_DB_GOOSE_MIN_VER=23 diff --git a/container-build/cerc-fixturenet-eth-geth/Dockerfile b/container-build/cerc-fixturenet-eth-geth/Dockerfile index 72c03039..cefe1bef 100644 --- a/container-build/cerc-fixturenet-eth-geth/Dockerfile +++ b/container-build/cerc-fixturenet-eth-geth/Dockerfile @@ -1,7 +1,7 @@ FROM skylenet/ethereum-genesis-generator@sha256:210353ce7c898686bc5092f16c61220a76d357f51eff9c451e9ad1b9ad03d4d3 AS ethgen FROM cerc/go-ethereum:local -RUN apk add --no-cache python3 python3-dev py3-pip curl wget jq build-base gettext libintl openssl bash +RUN apk add --no-cache python3 python3-dev py3-pip curl wget jq build-base gettext libintl openssl bash bind-tools postgresql-client COPY --from=ethgen /usr/local/bin/eth2-testnet-genesis /usr/local/bin/eth2-testnet-genesis COPY --from=ethgen /usr/local/bin/eth2-val-tools /usr/local/bin/eth2-val-tools diff --git a/container-build/cerc-fixturenet-eth-geth/run-el.sh b/container-build/cerc-fixturenet-eth-geth/run-el.sh index caf14070..34e74182 100755 --- a/container-build/cerc-fixturenet-eth-geth/run-el.sh +++ b/container-build/cerc-fixturenet-eth-geth/run-el.sh @@ -22,8 +22,33 @@ else echo -n "$JWT" > /opt/testnet/build/el/jwtsecret + if [ "$CERC_RUN_STATEDIFF" == "detect" ] && [ -n "$CERC_STATEDIFF_DB_HOST" ]; then + if [ -n "$(dig $CERC_STATEDIFF_DB_HOST +short)" ]; then + echo "Statediff DB at $CERC_STATEDIFF_DB_HOST" + CERC_RUN_STATEDIFF="true" + else + echo "No statediff DB available." + CERC_RUN_STATEDIFF="false" + fi + fi + STATEDIFF_OPTS="" if [ "$CERC_RUN_STATEDIFF" == "true" ]; then + ready=0 + while [ $ready -eq 0 ]; do + echo "Waiting for statediff DB..." + sleep 1 + export PGPASSWORD="$CERC_STATEDIFF_DB_PASSWORD" + result=$(psql -h "$CERC_STATEDIFF_DB_HOST" \ + -p "$CERC_STATEDIFF_DB_PORT" \ + -U "$CERC_STATEDIFF_DB_USER" \ + -d "$CERC_STATEDIFF_DB_NAME" \ + -t -c 'select max(version_id) from goose_db_version;' 2>/dev/null | awk '{ print $1 }') + if [ -n "$result" ] && [ $result -ge $CERC_STATEDIFF_DB_GOOSE_MIN_VER ]; then + echo "DB ready..." + ready=1 + fi + done STATEDIFF_OPTS="--statediff=true \ --statediff.db.host=$CERC_STATEDIFF_DB_HOST \ --statediff.db.name=$CERC_STATEDIFF_DB_NAME \