Skip to content

Instantly share code, notes, and snippets.

@nothingmuch
Last active January 19, 2019 11:56
Show Gist options
  • Save nothingmuch/6583893dc038b7c158fe85890ecb55c6 to your computer and use it in GitHub Desktop.
Save nothingmuch/6583893dc038b7c158fe85890ecb55c6 to your computer and use it in GitHub Desktop.
#!/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"
@nothingmuch
Copy link
Author

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