Package: bitcoin-peer-rotate
bitcoin-peer-rotateRotate peers for local Bitcoin Core node.bitcoin-peer-rotateis a Python package designed to facilitate the rotation of
peers for your local Bitcoin Core node as and when required.The use cases ofbitcoin-peer-rotateare intended for Bitcoin Core node
that makes outgoing connections only and does not accept incoming connections,
i.e. unreachable node.WARNING: If you are operating a reachable Bitcoin Core node, use ofbitcoin-peer-rotatewill result in your node becoming unreachable externally
from its existing peers, including from the Bitnodes crawler.New peers are sampled bybitcoin-peer-rotatefrom Bitnodes API endpoint:https://bitnodes.io/api/v1/nodes/sample/Use casesPeriodically rotate peers, i.e. disconnect existing peers and connect to a
fresh list of randomly sampled peers with optional filter for one of the
following attributes:IPv4/IPv6 peers from specific ASNsIPv4/IPv6 peers from specific countriesIPv4/IPv6 peers that meet specific minimum download speed percentileOne-off rotation to sync up your fresh Bitcoin Core node installation with
nearby peers.The use cases above assume you are operating a local Bitcoin Core node that makes
outgoing connections only and does not accept incoming connections.QuickstartInstall$ pip install bitcoin-peer-rotateAdd the following in your~/.bitcoin/bitcoin.conffile to allowbitcoin-peer-rotateto communicate with your local Bitcoin Core node locally
over RPC protocol.noconnect=1is to prevent additional connections not made
bybitcoin-peer-rotate:rpcbind=127.0.0.1
rpcport=8332
rpcallowip=127.0.0.1

noconnect=1Environment variablesbitcoin-peer-rotateuses the following environment variables.
You will need to set them only if the default values differ from your Bitcoin Core installation.Environment variable nameDefault valueBITCOIN_DIR$HOME/.bitcoinBITCOIN_RPC_HOSTlocalhostBITCOIN_RPC_PORT8332BITCOIN_RPC_COOKIE_AUTH_PATH$HOME/.bitcoin/.cookieRotateIf you intend to connect to IPv4 peers only, simply run:bitcoin-peer-rotateThis will remove existing peers and add 20 randomly selected IPv4 peers to your
Bitcoin Core node to allow it to maintain active connections with 8 of these
peers at any one time.For periodic rotation, addbitcoin-peer-rotateto your cronjob entries.
Daily rotation could look like this in your crontab:0 0 * * * bitcoin-peer-rotateSeebitcoin-peer-rotate -hfor more options, e.g. for filtering by network
types, ASNs, countries, and speed percentile.Sample log$ bitcoin-peer-rotate --limit 8
2023-05-01 11:37:41,925 - INFO - effective args - types=['ipv4'] - asns=[] - country_codes=[] - speed=1 - limit=8 - keep=[]
2023-05-01 11:37:42,529 - INFO - purging existing peers
2023-05-01 11:37:42,535 - INFO - removing peers from addednode - addr=91.19.101.14:8333
2023-05-01 11:37:42,537 - INFO - removing peers from addednode - addr=70.121.103.126:8333
2023-05-01 11:37:42,538 - INFO - removing peers from addednode - addr=87.98.243.138:8333
2023-05-01 11:37:42,539 - INFO - removing peers from addednode - addr=209.89.249.203:8333
2023-05-01 11:37:42,540 - INFO - removing peers from addednode - addr=159.246.25.52:8333
2023-05-01 11:37:42,540 - INFO - removing peers from addednode - addr=66.25.136.85:8333
2023-05-01 11:37:42,541 - INFO - removing peers from addednode - addr=193.42.110.30:8333
2023-05-01 11:37:42,542 - INFO - removing peers from addednode - addr=75.40.189.179:8333
2023-05-01 11:37:42,542 - INFO - peers purged=8
2023-05-01 11:37:42,542 - INFO - new peer - addr=91.19.101.14:8333 - data={'user_agent': '/Satoshi:24.0.1/', 'services': 1033, 'height': 787721, 'cc': 'DE', 'asn': 'AS3320', 'org': 'Deutsche Telekom AG', 'type': 'ipv4', 'mbps': 18.181859}
2023-05-01 11:37:42,543 - INFO - new peer - addr=70.121.103.126:8333 - data={'user_agent': '/Satoshi:24.0.1/', 'services': 1033, 'height': 787723, 'cc': 'US', 'asn': 'AS11427', 'org': 'TWC-11427-TEXAS', 'type': 'ipv4', 'mbps': 6.721767}
2023-05-01 11:37:42,543 - INFO - new peer - addr=87.98.243.138:8333 - data={'user_agent': '/Satoshi:22.0.0/', 'services': 1032, 'height': 787723, 'cc': 'FR', 'asn': 'AS16276', 'org': 'OVH SAS', 'type': 'ipv4', 'mbps': 84.46897}
2023-05-01 11:37:42,544 - INFO - new peer - addr=209.89.249.203:8333 - data={'user_agent': '/Satoshi:22.0.0/', 'services': 1033, 'height': 787700, 'cc': 'CA', 'asn': 'AS852', 'org': 'TELUS Communications', 'type': 'ipv4', 'mbps': 5.394991}
2023-05-01 11:37:42,545 - INFO - new peer - addr=159.246.25.52:8333 - data={'user_agent': '/Satoshi:24.0.1/', 'services': 1033, 'height': 787723, 'cc': 'US', 'asn': 'AS30491', 'org': 'CROWELLP', 'type': 'ipv4', 'mbps': 8.010063}
2023-05-01 11:37:42,545 - INFO - new peer - addr=66.25.136.85:8333 - data={'user_agent': '/Satoshi:22.0.0/', 'services': 1033, 'height': 787723, 'cc': 'US', 'asn': 'AS11427', 'org': 'TWC-11427-TEXAS', 'type': 'ipv4', 'mbps': 4.662538}
2023-05-01 11:37:42,546 - INFO - new peer - addr=193.42.110.30:8333 - data={'user_agent': '/Satoshi:22.0.0/', 'services': 1032, 'height': 787723, 'cc': 'NL', 'asn': 'AS60144', 'org': '3W Infra B.V.', 'type': 'ipv4', 'mbps': 12.099487}
2023-05-01 11:37:42,546 - INFO - new peer - addr=75.40.189.179:8333 - data={'user_agent': '/Satoshi:22.0.0/', 'services': 1033, 'height': 787723, 'cc': 'US', 'asn': 'AS7018', 'org': 'ATT-INTERNET4', 'type': 'ipv4', 'mbps': 6.546299}Reverting back to normal operationTo revert your local Bitcoin Core node to operate normally withoutbitcoin-peer-rotate, simply remove the configuration described in theInstallsection above from your~/.bitcoin/bitcoin.conffile and restart
your Bitcoin Core node.Package developmentSetup~/.pyenv/versions/3.11.2/bin/python -m venv venv
source venv/bin/activate
pip install -r requirements-dev.txtTest./test.shFormat./format.shBuild./build.sh