Skip to content

Commit

Permalink
Added healthcheck script
Browse files Browse the repository at this point in the history
  • Loading branch information
rzmahmood committed Dec 22, 2024
1 parent c267450 commit a7cd198
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Testnet Deployment CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
testnet:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up Go 1.23.0
uses: actions/setup-go@v4
with:
go-version: '1.23.0'

- name: Install JQ
run: sudo apt-get install jq

- name: Build dependencies
run: ./build-dependencies.sh

- name: Start Testnet
run: |
./node.sh &
sleep 60
- name: Run Health check
run: ./healthcheck.sh
39 changes: 39 additions & 0 deletions healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

BEACON_CONFIG_DIR=./config/beacond
BEACOND_BINARY=./dependencies/beacon-kit/build/bin/beacond
INTERVAL=5 # Interval in seconds between checks
TRIES=5 # Number of times to check

# Initialize the previous block height
previous_block_height=0

for ((i = 1; i <= TRIES; i++)); do
# Get the latest block height
latest_block_height=$($BEACOND_BINARY --home=$BEACON_CONFIG_DIR status | jq -r .sync_info.latest_block_height)

# Validate the block height is a number
if ! [[ "$latest_block_height" =~ ^[0-9]+$ ]]; then
echo "Error: Failed to fetch latest_block_height. Received: $latest_block_height"
exit 1
fi

echo "Check $i: Latest Block Height = $latest_block_height"

# Compare with the previous block height
if (( i > 1 )) && (( latest_block_height <= previous_block_height )); then
echo "Block height is not increasing (previous: $previous_block_height, current: $latest_block_height)."
exit 1
fi

# Update the previous block height
previous_block_height=$latest_block_height

# Sleep before the next iteration (skip sleep after the last iteration)
if (( i < TRIES )); then
sleep $INTERVAL
fi
done

echo "Block height is increasing consistently over $TRIES checks."
exit 0
2 changes: 1 addition & 1 deletion node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ MONIKER_NAME=BIG_BERA_DEFAULT_QUICKSTART_NODE_$(date +"%s")

# If USE_SNAPSHOT is true, then a snapshot will be downloaded to bootstrap the state, allowing for faster sync time.
# Introduces a trust assumption that the snapshot provider is trustworthy
USE_SNAPSHOT=true
USE_SNAPSHOT=false
SNAPSHOTS_DIRECTORY=./snapshots

# Update to use a source closer to your geography.
Expand Down

0 comments on commit a7cd198

Please sign in to comment.