I found an anomaly in the block size data: block 295182. This one seems to have a way higher payload. What happened there?
Or is this there something wrong with my parsing? This file block does appear to be at the end of a .dat file.
Here's the code I used:
import struct
import matplotlib.pyplot as plt
blockchain_path = 'mypath/blocks'
def get_block_path(index):
file = 'blk' + str(index).zfill(5) + '.dat'
return blockchain_path + '/' + file
def plot(x, y, title, xlabel, ylabel):
plt.scatter(x, y)
plt.suptitle(title, fontsize=20)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.show()
def uint4(stream):
return struct.unpack('I', stream.read(4))[0]
def blocks_remaining(f, i):
cur = f.tell()
try:
uint4(f)
f.seek(cur)
return True
except:
print("End of file: blk" + str(i).zfill(5) + '.dat')
return False
BlockHeight, BlockSize = ([] for i in range(2))
cur_block_height = -1
for i in range(0, 100):
block_path = get_block_path(i)
#stay with single file
f = open(block_path, 'rb', buffering=16 * 1024 * 1024)
#loop blocks in file
while blocks_remaining(f, i):
cur_block_height += 1
magic_num = uint4(f)
block_size = uint4(f)
print(cur_block_height, f.tell(), magic_num, block_size)
#append data
BlockHeight.append(cur_block_height)
BlockSize.append(block_size)
#skip to next block
f.read(block_size)
plot(BlockHeight, BlockSize, 'Block Size', 'block height', 'bytes')