test: rename CBlockHeader .rehash()/.sha256 -> .hash_int for consistency

Note that we unfortunately can't use a scripted diff here, as the
`sha256` symbol is also used for other instances (e.g. as function
in hashlib, or in the `UTXO` class in p2p_segwit.py).
This commit is contained in:
Sebastian Falbesoner
2025-06-12 14:13:55 +02:00
parent 8b09cc350a
commit 23be0ec2f0
33 changed files with 141 additions and 145 deletions

View File

@@ -151,8 +151,8 @@ class BaseNode(P2PInterface):
self.block_announced = True
for x in message.headers:
# append because headers may be announced over multiple messages.
self.recent_headers_announced.append(x.sha256)
self.last_blockhash_announced = message.headers[-1].sha256
self.recent_headers_announced.append(x.hash_int)
self.last_blockhash_announced = message.headers[-1].hash_int
def clear_block_announcements(self):
with p2p_lock:
@@ -286,7 +286,7 @@ class SendHeadersTest(BitcoinTestFramework):
new_block = create_block(tip, create_coinbase(height + 1), block_time)
new_block.solve()
test_node.send_header_for_blocks([new_block])
test_node.wait_for_getdata([new_block.sha256])
test_node.wait_for_getdata([new_block.hash_int])
test_node.send_and_ping(msg_block(new_block)) # make sure this block is processed
inv_node.wait_until(lambda: inv_node.block_announced)
inv_node.clear_block_announcements()
@@ -322,7 +322,7 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(i + 1):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1
if j == 0:
@@ -336,13 +336,13 @@ class SendHeadersTest(BitcoinTestFramework):
test_node.send_header_for_blocks(blocks)
# Test that duplicate inv's won't result in duplicate
# getdata requests, or duplicate headers announcements
[inv_node.send_block_inv(x.sha256) for x in blocks]
test_node.wait_for_getdata([x.sha256 for x in blocks])
[inv_node.send_block_inv(x.hash_int) for x in blocks]
test_node.wait_for_getdata([x.hash_int for x in blocks])
inv_node.sync_with_ping()
else:
# Announce via headers
test_node.send_header_for_blocks(blocks)
test_node.wait_for_getdata([x.sha256 for x in blocks])
test_node.wait_for_getdata([x.hash_int for x in blocks])
# Test that duplicate headers won't result in duplicate
# getdata requests (the check is further down)
inv_node.send_header_for_blocks(blocks)
@@ -440,7 +440,7 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(2):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1
inv_node.send_without_ping(msg_block(blocks[-1]))
@@ -458,20 +458,20 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(3):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1
test_node.send_header_for_blocks(blocks)
test_node.sync_with_ping()
test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=DIRECT_FETCH_RESPONSE_TIME)
test_node.wait_for_getdata([x.hash_int for x in blocks], timeout=DIRECT_FETCH_RESPONSE_TIME)
[test_node.send_without_ping(msg_block(x)) for x in blocks]
test_node.sync_with_ping()
# Now announce a header that forks the last two blocks
tip = blocks[0].sha256
tip = blocks[0].hash_int
height -= 2
blocks = []
@@ -479,7 +479,7 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(20):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1
@@ -495,13 +495,13 @@ class SendHeadersTest(BitcoinTestFramework):
# both blocks (same work as tip)
test_node.send_header_for_blocks(blocks[1:2])
test_node.sync_with_ping()
test_node.wait_for_getdata([x.sha256 for x in blocks[0:2]], timeout=DIRECT_FETCH_RESPONSE_TIME)
test_node.wait_for_getdata([x.hash_int for x in blocks[0:2]], timeout=DIRECT_FETCH_RESPONSE_TIME)
# Announcing 16 more headers should trigger direct fetch for 14 more
# blocks
test_node.send_header_for_blocks(blocks[2:18])
test_node.sync_with_ping()
test_node.wait_for_getdata([x.sha256 for x in blocks[2:16]], timeout=DIRECT_FETCH_RESPONSE_TIME)
test_node.wait_for_getdata([x.hash_int for x in blocks[2:16]], timeout=DIRECT_FETCH_RESPONSE_TIME)
# Announcing 1 more header should not trigger any response
test_node.last_message.pop("getdata", None)
@@ -528,18 +528,18 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(2):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1
# Send the header of the second block -> this won't connect.
test_node.send_header_for_blocks([blocks[1]])
test_node.wait_for_getheaders(block_hash=expected_hash)
test_node.send_header_for_blocks(blocks)
test_node.wait_for_getdata([x.sha256 for x in blocks])
test_node.wait_for_getdata([x.hash_int for x in blocks])
[test_node.send_without_ping(msg_block(x)) for x in blocks]
test_node.sync_with_ping()
assert_equal(int(self.nodes[0].getbestblockhash(), 16), blocks[1].sha256)
expected_hash = blocks[1].sha256
assert_equal(int(self.nodes[0].getbestblockhash(), 16), blocks[1].hash_int)
expected_hash = blocks[1].hash_int
blocks = []
# Now we test that if we repeatedly don't send connecting headers, we
@@ -547,7 +547,7 @@ class SendHeadersTest(BitcoinTestFramework):
for _ in range(NUM_HEADERS + 1):
blocks.append(create_block(tip, create_coinbase(height), block_time))
blocks[-1].solve()
tip = blocks[-1].sha256
tip = blocks[-1].hash_int
block_time += 1
height += 1