Created
August 30, 2020 17:50
-
-
Save andr11111/0ed0bb0b7c3b20d629c35f2a373edca7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
_blockDiff() { | |
local_hex=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' 0.0.0.0:8545 | jq -r '.result') | |
local=$(echo "ibase=16; ${local_hex^^}" | bc) | |
remote_hex=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' https://mainnet.infura.io/v3/[INSERT_KEY] | jq -r '.result') | |
remote=$(echo "ibase=16; ${remote_hex^^}" | bc) | |
diff=$(($remote-$local)) | |
echo "$diff" | |
} | |
_restartNode() { | |
echo "restarting..." | |
systemctl restart openethereum | |
sleep 5m | |
} | |
errorCount=0 | |
while true | |
do | |
blockDiff=$(_blockDiff) | |
if [ -z "$blockDiff" ] | |
then | |
# error occured | |
errorCount=$((errorCount+1)) | |
echo "error" | |
if [ $errorCount -gt 5 ] | |
then | |
errorCount=0 | |
_restartNode | |
fi | |
else | |
echo "blockDiff: $blockDiff" | |
if [ "$blockDiff" -gt 40 ] | |
then | |
errorCount=0 | |
_restartNode | |
fi | |
fi | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment