Skip to content

Instantly share code, notes, and snippets.

@gotjoshua
Created February 28, 2021 15:30
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 gotjoshua/27f345ee07546f931670aaa0d9493b9e to your computer and use it in GitHub Desktop.
Save gotjoshua/27f345ee07546f931670aaa0d9493b9e to your computer and use it in GitHub Desktop.
sync
#!/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
@patogit
Copy link

patogit commented Mar 5, 2021

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 from REGEN_KEY to VALIDATOR_KEY -- this way it's more generic for use by other Cosmos SDK apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment