Last active
January 19, 2019 11:56
-
-
Save nothingmuch/6583893dc038b7c158fe85890ecb55c6 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 | |
set -e | |
echo "Pinging peers..." | |
bitcoin-cli ping | |
sleep 2 | |
# loop until all but 2 slowest peers have responded | |
while [ "$( bitcoin-cli getpeerinfo | grep -c pingwait )" -gt 2 ]; do | |
# spit out peers from fastest to slowest | |
echo; echo | |
bitcoin-cli getpeerinfo | jq -r 'sort_by(.pingtime, .pingwait) | .[] | [.addr, .pingtime, .pingwait] | @tsv' | |
sleep 2 | |
done; | |
# ditch slowest peer by ping time | |
slowest="$( bitcoin-cli getpeerinfo | jq -r 'sort_by(.pingtime) | .[-1].addr' )" | |
echo "Disconnecting from $slowest" | |
bitcoin-cli disconnectnode "$slowest" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note: https://twitter.com/ercwl/status/1086592029130440704