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
2 changed files with 36 additions and 1 deletions

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