Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ci/sanity-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# - file is ordered by block height in descending order
# - header hashes match header (by hashing)
# - header hashes are unique
# - binary block files have a correct bitcoin block header

import csv
import hashlib
import os

EXPECTED_COLUMNS = 3

Expand Down Expand Up @@ -42,6 +44,17 @@ def dsha256(d):

hash_count[header_hash] = hash_count.get(header_hash, 0) + 1

blockfile = f"blocks/{height}-{header_hash}.bin"
if os.path.exists(blockfile):
print(f"checking block file: {blockfile}")
with open(blockfile, "rb") as block:
header_bytes = block.read(80)
calculated_header_hash = bytes(reversed(dsha256(header_bytes))).hex()
assert header_hash == calculated_header_hash

header_hex = header_bytes.hex()
assert header == header_hex

hash_appeared_multiple_times = False
for e in hash_count.items():
header_hash, count = e
Expand Down