diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a8808f..b845123 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,4 +54,4 @@ compose: - ./scripts/build_from_cache.sh lightningd - ./scripts/build_from_cache.sh txood - ./scripts/build_from_cache.sh vlsd - - docker compose --profile vls up -d --wait --wait-timeout 120 --build + - docker compose --profile vls -f docker-compose.yml -f docker-compose.regtest.yml up -d --wait --wait-timeout 120 --build diff --git a/README.md b/README.md index a88e20c..ae01c3e 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,6 @@ Below are the steps required to run `vlsd2` as a standalone container. ### Docker Image ```bash -# Pull the latest release image for vlsd -docker pull registry.gitlab.com/lightning-signer/vls-container/vlsd:latest -docker tag registry.gitlab.com/lightning-signer/vls-container/vlsd:latest vlsd:latest # Build the latest docker image cd vlsd docker build -t vlsd . diff --git a/bitcoind/healthcheck.sh b/bitcoind/healthcheck.sh index d8b421a..9131b63 100755 --- a/bitcoind/healthcheck.sh +++ b/bitcoind/healthcheck.sh @@ -1 +1,15 @@ -bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo \ No newline at end of file +#!/bin/sh + +if [[ "$BITCOIN_CHAIN" = "regtest" ]]; then + # Check if the wallet already exists + if ! bitcoin-cli listwallets | grep -q "default"; then + # If the wallet does not exist, create it + bitcoin-cli createwallet default + fi + block_count=$(bitcoin-cli -chain=$BITCOIN_CHAIN getblockcount) + if [[ "$block_count" = "0" ]]; then + bitcoin-cli generatetoaddress 101 $(bitcoin-cli -chain=$BITCOIN_CHAIN getnewaddress) + fi +fi + +bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo diff --git a/docker-compose.regtest.yml b/docker-compose.regtest.yml index b7fdafd..de6a310 100644 --- a/docker-compose.regtest.yml +++ b/docker-compose.regtest.yml @@ -32,10 +32,9 @@ services: volumes: - txoo_regtest:/root/.txoo/ - bitcoin_regtest:/root/.bitcoin/ - command: - - -r http://rpcuser:VLSsigner1@bitcoind:38332 environment: - BITCOIN_NETWORK=regtest + - BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:38332 vls: container_name: vlsd-regtest diff --git a/docker-compose.yml b/docker-compose.yml index 6ad17b5..9754e08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,8 +47,6 @@ services: image: txood:${IMAGE_TAG:-latest} container_name: txood-test restart: unless-stopped - command: - - -r http://rpcuser:VLSsigner1@bitcoind:18332 networks: - lightning volumes: @@ -59,6 +57,7 @@ services: condition: service_healthy environment: - BITCOIN_NETWORK=testnet + - BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:18332 vls: build: diff --git a/txood/Dockerfile b/txood/Dockerfile index bfa8b13..13f003d 100644 --- a/txood/Dockerfile +++ b/txood/Dockerfile @@ -30,14 +30,22 @@ RUN apk update && \ build-base \ bind-tools \ libev-dev \ - curl-dev + curl-dev \ + curl \ + jq COPY --from=builder /usr/local/bin/txood /usr/bin/txood COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh +COPY healthcheck.sh /healthcheck.sh +RUN chmod +x /healthcheck.sh + VOLUME ["${TXOO_DATA}"] +HEALTHCHECK --interval=5s --timeout=10s --start-period=5s \ + CMD ["/bin/sh", "-c", "/healthcheck.sh"] + ENTRYPOINT ["/entrypoint.sh"] CMD ["txood"] diff --git a/txood/entrypoint.sh b/txood/entrypoint.sh index faf4783..69ee603 100644 --- a/txood/entrypoint.sh +++ b/txood/entrypoint.sh @@ -1,11 +1,19 @@ #!/bin/sh -set -e + +set -ex if [ $(echo "$1" | cut -c1) = "-" ]; then echo "$0: assuming arguments for txood" - set -- txood --network $BITCOIN_NETWORK "$@" + set -- txood "$@" +fi + +if [ $(echo "$1" | cut -c1) = "-" ] || [ "$1" = "txood" ]; then + echo "$0: setting network to $BITCOIN_NETWORK" + echo "$0: setting RPC URL to $BITCOIND_RPC_URL" + + set -- "$@" --network $BITCOIN_NETWORK -r $BITCOIND_RPC_URL fi echo -exec "$@" \ No newline at end of file +exec "$@" diff --git a/txood/healthcheck.sh b/txood/healthcheck.sh new file mode 100644 index 0000000..4b04c8e --- /dev/null +++ b/txood/healthcheck.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -ex + +# Get the latest file with extension .sa from /root/.txoo/$BITCOIN_NETWORK/public directory and get the block number from the file name +TXOO_LOCATION=/root/.txoo/$BITCOIN_NETWORK/public +latest_block=$(ls -r1t $TXOO_LOCATION | grep '.sa' | head -n1 | cut -d'-' -f1) + +# Check if no file was found +if [ -z "$latest_block" ]; then + echo "No file found" >&2 + exit 1 +fi + +# Convert latest_block to a number +latest_block=$(expr $latest_block + 0) + +# Get the block count from bitcoind +bitcoind_block_count=$(curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' $BITCOIND_RPC_URL | jq .result) + +blocks_behind=$((bitcoind_block_count - latest_block)) + +# Check if the latest attestation is more than 1 block behind +if [[ $blocks_behind -gt 1 ]]; then + echo "The latest attestation is more than 1 block behind" >&2 + exit 1 +fi