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:
parent
f9de5cfa30
commit
eb4926b203
@ -30,14 +30,22 @@ RUN apk update && \
|
|||||||
build-base \
|
build-base \
|
||||||
bind-tools \
|
bind-tools \
|
||||||
libev-dev \
|
libev-dev \
|
||||||
curl-dev
|
curl-dev \
|
||||||
|
curl \
|
||||||
|
jq
|
||||||
|
|
||||||
COPY --from=builder /usr/local/bin/txood /usr/bin/txood
|
COPY --from=builder /usr/local/bin/txood /usr/bin/txood
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
COPY healthcheck.sh /healthcheck.sh
|
||||||
|
RUN chmod +x /healthcheck.sh
|
||||||
|
|
||||||
VOLUME ["${TXOO_DATA}"]
|
VOLUME ["${TXOO_DATA}"]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=5s --timeout=10s --start-period=5s \
|
||||||
|
CMD ["/bin/sh", "-c", "/healthcheck.sh"]
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
CMD ["txood"]
|
CMD ["txood"]
|
||||||
|
27
txood/healthcheck.sh
Normal file
27
txood/healthcheck.sh
Normal 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
|
Loading…
x
Reference in New Issue
Block a user