txoo: healthcheck based on latest block

- fail if latest attestation is more than a block behind
Signed-off-by: Lakshya Singh <lakshay.singh1108@gmail.com>
This commit is contained in:
Lakshya Singh 2023-11-20 23:43:49 +05:30
parent f9de5cfa30
commit eb4926b203
No known key found for this signature in database
GPG Key ID: D3239BA6109A2CE7
2 changed files with 36 additions and 1 deletions

View File

@ -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"]

27
txood/healthcheck.sh Normal file
View File

@ -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