Created
February 28, 2021 15:30
-
-
Save gotjoshua/27f345ee07546f931670aaa0d9493b9e to your computer and use it in GitHub Desktop.
sync
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 | |
#source profile with GO path etc | |
. /etc/profile.d/regen.sh | |
x=1 | |
limit=${1:-100} | |
while [ $x -le $limit ] | |
do | |
UPSTREAM_BLOCKS=$(curl -s http://161.35.51.84:26657/consensus_state | jq -r '.result.round_state."height/round/step"' | cut -d'/' -f1) | |
LOCAL_BLOCKS=$(regen status |& jq -r '.SyncInfo.latest_block_height') | |
PREV=${BEHIND:-$(($UPSTREAM_BLOCKS-$LOCAL_BLOCKS))} | |
BEHIND=$(($UPSTREAM_BLOCKS-$LOCAL_BLOCKS)) | |
echo "$UPSTREAM_BLOCKS vs $LOCAL_BLOCKS behind by: $BEHIND" | |
x=$(( $x+1 )) | |
if [[ $BEHIND -le 2 ]] | |
then | |
echo "All caught up, if you're jailed, run:" | |
echo "regen tx slashing unjail --from $REGEN_KEY --gas auto -y --fees=4000utree --chain-id aplikigo-1" | |
echo "If needed, edit --from, --chain-id, and --node" | |
exit | |
else | |
PREV_SL=${SLEEPSEC:-300} | |
SLEEPSEC=$(( $BEHIND*10 )) | |
SLEEPSEC=$(( $SLEEPSEC<300 ? $SLEEPSEC : 300 )) | |
RATE=$(((3600/PREV_SL)*(PREV-BEHIND))) | |
echo "$(date +%T) - sleeping for $SLEEPSEC @ $RATE blocks/hr" | |
sleep $SLEEPSEC` | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nifty! Just have to make sure I set
REGEN_KEY
before running. I would also make the chain-id a variable, since this could be useful on other chains. And, thinking of that, I would change fromREGEN_KEY
toVALIDATOR_KEY
-- this way it's more generic for use by other Cosmos SDK apps.