Skip to content

Instantly share code, notes, and snippets.

@LarryRuane
Last active December 27, 2022 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarryRuane/35eb30cd2051e3629bbb768a19f0c320 to your computer and use it in GitHub Desktop.
Save LarryRuane/35eb30cd2051e3629bbb768a19f0c320 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# show heights and timestamps of empty blocks, most recent first (so if using a pruned node,
# this will stop when we reach the start of the prune window)
from bitcoinrpc.authproxy import AuthServiceProxy
import json
from datetime import datetime
api = AuthServiceProxy("http://lmr:lmr@127.0.0.1:8332")
latest_height = api.getblockcount()
for i in range(latest_height, 1, -1):
bhash = api.getblockhash(i)
try:
block = api.getblock("{}".format(bhash))
except: break
if block['nTx'] == 1:
print(i, datetime.utcfromtimestamp(block['time']).strftime('%Y-%m-%d %H:%M:%S'))
""" current output, as of 12/21/2022:
768274 2022-12-20 23:17:43
768024 2022-12-19 02:57:05
767948 2022-12-18 15:23:06
767807 2022-12-17 15:25:34
766983 2022-12-11 21:58:08
766751 2022-12-10 10:29:37
766411 2022-12-08 04:30:01
"""
@YazidKurdi
Copy link

Hi, how long did the script take to run?

@LarryRuane
Copy link
Author

The script's runtime depends on your node's prune limit. With the default of 550 MB, the script didn't find any empty blocks at all. So I increased the prune setting to 5000 (5 GB), and then the script generated those results in 3.5 minutes. This is on a midrange laptop.

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