Skip to content

Instantly share code, notes, and snippets.

@Znuff
Last active March 9, 2018 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Znuff/6cbf13c9e08805bf826a6107b6932394 to your computer and use it in GitHub Desktop.
Save Znuff/6cbf13c9e08805bf826a6107b6932394 to your computer and use it in GitHub Desktop.
#!/bin/bash
explorer_height=$(curl -s http://explorer.coin2fly.com/api/getblockcount)
latest_hash=$(curl -s http://explorer.coin2fly.com/api/getblockhash?index=$explorer_height)
block_to_check=$((explorer_height - 3))
explorer_hash=$(curl -s http://explorer.coin2fly.com/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() {
systemctl stop coin2flyd-reindex
systemctl stop coin2flyd
rm -rf /home/coin2fly/.coin2flycore/{banlist,fee_estimates,governance,mncache,mnpayments,netfulfilled,peers}.dat
rm -rf /home/coin2fly/.coin2flycore/{blocks,chainstate,database,debug.log}
systemctl start coin2flyd
[[ $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$(coin2fly-cli masternode debug 2> /dev/null)$treset"
echo "Checking for masternode status: $tcyan$(coin2fly-cli masternode status 2>/dev/null | jq .status)$treset"
echo ""
mnsync_status=$(coin2fly-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=$(coin2fly-cli mnsync status)
echo -n "$tred"".""$treset"
done
echo "$tgreen OK$treset."
fi
addnodes=$(cat /home/coin2fly/.coin2flycore/coin2fly.conf 2>/dev/null)
local_block_height=$(coin2fly-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=$(coin2fly-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