Last active
June 5, 2018 20:42
-
-
Save Znuff/316b4b35f62e6bb5ea12cb3d496730c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
explorer_height=$(curl -s https://explorer.gravium.io/api/getblockcount) | |
latest_hash=$(curl -s https://explorer.gravium.io/api/getblockhash?index=$explorer_height) | |
block_to_check=$((explorer_height - 3)) | |
explorer_hash=$(curl -s https://explorer.gravium.io/api/getblockhash?index=$block_to_check) | |
# environment setup, make it pretty | |
tred=$(tput setaf 1); tgreen=$(tput setaf 2); tyellow=$(tput setaf 3); tblue=$(tput setaf 4); tmagenta=$(tput setaf 5); tcyan=$(tput setaf 6); treset=$(tput sgr0); tclear=$(tput clear); twbg=$(tput setab 7) | |
# quick check for jq | |
DEBIAN_FRONTEND=noninteractive apt install -yqq -o=Dpkg::Use-Pty=0 jq | |
echo $tclear | |
function do_reindex() { | |
gravium-cli stop | |
sleep 2 | |
killall -9 graviumd | |
rm -rf /root/.graviumcore/{banlist,fee_estimates,governance,mncache,mnpayments,netfulfilled,peers}.dat | |
rm -rf /root/.graviumcore/{blocks,chainstate,database,debug.log} | |
graviumd | |
[[ $addnodes =~ "addnode" ]] && echo "$tred""Warning!$treset Your config has hardcoded$tcyan addnode=$treset. This is not recommended." | |
} | |
echo "" | |
echo "Explorer is at block height: $tcyan$explorer_height$treset => $tmagenta$latest_hash$treset" | |
echo "Checking the previous block: $tyellow$block_to_check$treset => $tgreen$explorer_hash$treset" | |
echo "" | |
echo "Checking for masternode debug: $tcyan$(gravium-cli masternode debug 2> /dev/null)$treset" | |
echo "Checking for masternode status: $tcyan$(gravium-cli masternode status 2>/dev/null | jq .status)$treset" | |
echo "" | |
mnsync_status=$(gravium-cli mnsync status) | |
echo -n "Checking for sync status: " | |
if [[ $mnsync_status =~ "MASTERNODE_SYNC_FINISHED" ]]; then | |
echo "$tgreen OK$treset." | |
else | |
while [[ ! $mnsync_status =~ "MASTERNODE_SYNC_FINISHED" ]]; do | |
sleep 3 | |
mnsync_status=$(gravium-cli mnsync status) | |
echo -n "$tred"".""$treset" | |
done | |
echo "$tgreen OK$treset." | |
fi | |
addnodes=$(cat /root/.graviumcore/gravium.conf 2>/dev/null) | |
local_block_height=$(gravium-cli getblockcount) | |
block_difference=$((explorer_height - local_block_height)) | |
if (( block_difference == 0 )); then | |
echo "Your node is on the same block ($tyellow$explorer_height$treset) as the Explorer. This is$tgreen good$treset." | |
elif (( block_difference > 100)); then | |
echo "Your node is more than$tred 100$treset blocks behind. This is$tred bad$treset. Triggering cleanup & reindex. You can run this script again in a few minutes." | |
do_reindex | |
exit 1 | |
elif (( block_difference < 4 )); then | |
echo "Your node is $tmagenta$block_difference$treset blocks behind. We can work with this." | |
fi | |
echo -n "Checking block hashes..." | |
local_blockhash_result=$(gravium-cli getblockhash $block_to_check) | |
if [[ $explorer_hash != $local_blockhash_result ]]; then | |
echo "" | |
echo "Your node's block height seems to be the same as the Explorer, but you seem to be on a different chain. Possibly that the block chain has split." | |
echo "Your block $tyellow$block_to_check$treset => $tred$local_blockhash_result$treset" | |
echo "Explorer's $tyellow$block_to_check$treset => $tgreen$explorer_hash$treset". | |
echo "We are triggering a clean up & reindex. Please run this script again in a few minutes." | |
do_reindex | |
echo "" | |
exit 1 | |
else | |
echo "You're$tgreen good$treset." | |
echo "" | |
echo "If your node is still not$tgreen ENABLED$treset, please try starting it again from your wallet." | |
echo "" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment