Created
January 19, 2018 22:42
-
-
Save jnewbery/df0a98f3d2fea52e487001bf2b9ef1fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
"""Search for blocks where the BIP34 indicated coinbase height is > block height. | |
Uses Bitcoin Core's test framework.""" | |
import time | |
from authproxy import AuthServiceProxy | |
from script import CScript | |
a = AuthServiceProxy("http://<user>:<password>@<ip>:<port>") | |
START_BLOCK = 1 | |
NUM_BLOCKS = 227940 #BIP34 activated at height 227931 | |
with open('coin_base_heights.csv', 'w') as csvfile: | |
csvfile.write(','.join(['block_height', 'coinbase_height']) + '\n') | |
heights = [] | |
for block_height in range(START_BLOCK, START_BLOCK + NUM_BLOCKS): | |
if not block_height % 100: | |
print("Processing block at height {}".format(block_height)) | |
print("Time: {}".format(time.strftime("%X"))) | |
block = a.getblock(a.getblockhash(block_height)) | |
tx = block['tx'][0] | |
script = CScript(bytearray.fromhex(a.getrawtransaction(tx, True)['vin'][0]['coinbase'])) | |
if script[0] == 1: | |
BIP34_height = int.from_bytes(script[1:2], 'little') | |
elif script[0] == 2: | |
BIP34_height = int.from_bytes(script[1:3], 'little') | |
elif script[0] == 3: | |
BIP34_height = int.from_bytes(script[1:4], 'little') | |
else: | |
# first byte will be 3 until height 16,777,215 | |
BIP34_height = 0 | |
if BIP34_height > block_height: | |
heights.append([block_height, BIP34_height]) | |
heights.sort(key=lambda x:x[1]) | |
csvfile.write("\n".join(["{},{}".format(h[0], h[1]) for h in heights])) |
This file contains hidden or 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
block_height,coinbase_height,equal | |
164384,1983702,TRUE | |
169895,3708179,TRUE | |
170307,3709183,TRUE | |
171896,3712990,TRUE | |
172069,3713413,TRUE | |
172357,3714082,TRUE | |
172428,3714265,TRUE | |
174151,5208854,TRUE | |
176684,490897,TRUE | |
183669,3761471,TRUE | |
196988,4275806,TRUE | |
201577,5327833,TRUE | |
206039,7299941,TRUE | |
206354,7299941,TRUE | |
209920,209921,TRUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can reduce the number of RPC calls down to one by using
getblock
with verbosity level 2 (removes thegetrawtransaction
call) and getting the block hash for the next block with thenextblockhash
field ofgetblock
's output (removes thegetblockhash
call).