mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 16:53:52 +02:00
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:
@@ -80,12 +80,12 @@ class TestP2PConn(P2PInterface):
|
||||
|
||||
def on_cmpctblock(self, message):
|
||||
self.block_announced = True
|
||||
self.announced_blockhashes.add(self.last_message["cmpctblock"].header_and_shortids.header.sha256)
|
||||
self.announced_blockhashes.add(self.last_message["cmpctblock"].header_and_shortids.header.hash_int)
|
||||
|
||||
def on_headers(self, message):
|
||||
self.block_announced = True
|
||||
for x in self.last_message["headers"].headers:
|
||||
self.announced_blockhashes.add(x.sha256)
|
||||
self.announced_blockhashes.add(x.hash_int)
|
||||
|
||||
def on_inv(self, message):
|
||||
for x in self.last_message["inv"].inv:
|
||||
@@ -158,7 +158,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
def make_utxos(self):
|
||||
block = self.build_block_on_tip(self.nodes[0])
|
||||
self.segwit_node.send_and_ping(msg_no_witness_block(block))
|
||||
assert int(self.nodes[0].getbestblockhash(), 16) == block.sha256
|
||||
assert int(self.nodes[0].getbestblockhash(), 16) == block.hash_int
|
||||
self.generate(self.wallet, COINBASE_MATURITY)
|
||||
|
||||
total_value = block.vtx[0].vout[0].nValue
|
||||
@@ -173,7 +173,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
block2.hashMerkleRoot = block2.calc_merkle_root()
|
||||
block2.solve()
|
||||
self.segwit_node.send_and_ping(msg_no_witness_block(block2))
|
||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block2.sha256)
|
||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block2.hash_int)
|
||||
self.utxos.extend([[tx.txid_int, i, out_value] for i in range(10)])
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
def check_compactblock_construction_from_block(self, header_and_shortids, block_hash, block):
|
||||
# Check that we got the right block!
|
||||
assert_equal(header_and_shortids.header.sha256, block_hash)
|
||||
assert_equal(header_and_shortids.header.hash_int, block_hash)
|
||||
|
||||
# Make sure the prefilled_txn appears to have included the coinbase
|
||||
assert len(header_and_shortids.prefilled_txn) >= 1
|
||||
@@ -378,12 +378,12 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
block = self.build_block_on_tip(node)
|
||||
|
||||
if announce == "inv":
|
||||
test_node.send_without_ping(msg_inv([CInv(MSG_BLOCK, block.sha256)]))
|
||||
test_node.send_without_ping(msg_inv([CInv(MSG_BLOCK, block.hash_int)]))
|
||||
test_node.wait_for_getheaders(timeout=30)
|
||||
test_node.send_header_for_blocks([block])
|
||||
else:
|
||||
test_node.send_header_for_blocks([block])
|
||||
test_node.wait_for_getdata([block.sha256], timeout=30)
|
||||
test_node.wait_for_getdata([block.hash_int], timeout=30)
|
||||
assert_equal(test_node.last_message["getdata"].inv[0].type, 4)
|
||||
|
||||
# Send back a compactblock message that omits the coinbase
|
||||
@@ -403,10 +403,10 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
# Send the coinbase, and verify that the tip advances.
|
||||
msg = msg_blocktxn()
|
||||
msg.block_transactions.blockhash = block.sha256
|
||||
msg.block_transactions.blockhash = block.hash_int
|
||||
msg.block_transactions.transactions = [block.vtx[0]]
|
||||
test_node.send_and_ping(msg)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
# Create a chain of transactions from given utxo, and add to a new block.
|
||||
def build_block_with_transactions(self, node, utxo, num_transactions):
|
||||
@@ -454,8 +454,8 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
msg_bt = msg_no_witness_blocktxn()
|
||||
msg_bt = msg_blocktxn() # serialize with witnesses
|
||||
msg_bt.block_transactions = BlockTransactions(block.sha256, block.vtx[1:])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.sha256)
|
||||
msg_bt.block_transactions = BlockTransactions(block.hash_int, block.vtx[1:])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.hash_int)
|
||||
|
||||
utxo = self.utxos.pop(0)
|
||||
block = self.build_block_with_transactions(node, utxo, 5)
|
||||
@@ -464,8 +464,8 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
# Now try interspersing the prefilled transactions
|
||||
comp_block.initialize_from_block(block, prefill_list=[0, 1, 5], use_witness=True)
|
||||
test_getblocktxn_response(comp_block, test_node, [2, 3, 4])
|
||||
msg_bt.block_transactions = BlockTransactions(block.sha256, block.vtx[2:5])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.sha256)
|
||||
msg_bt.block_transactions = BlockTransactions(block.hash_int, block.vtx[2:5])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.hash_int)
|
||||
|
||||
# Now try giving one transaction ahead of time.
|
||||
utxo = self.utxos.pop(0)
|
||||
@@ -479,8 +479,8 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
comp_block.initialize_from_block(block, prefill_list=[0, 2, 3, 4], use_witness=True)
|
||||
test_getblocktxn_response(comp_block, test_node, [5])
|
||||
|
||||
msg_bt.block_transactions = BlockTransactions(block.sha256, [block.vtx[5]])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.sha256)
|
||||
msg_bt.block_transactions = BlockTransactions(block.hash_int, [block.vtx[5]])
|
||||
test_tip_after_message(node, test_node, msg_bt, block.hash_int)
|
||||
|
||||
# Now provide all transactions to the node before the block is
|
||||
# announced and verify reconstruction happens immediately.
|
||||
@@ -501,7 +501,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
# Send compact block
|
||||
comp_block.initialize_from_block(block, prefill_list=[0], use_witness=True)
|
||||
test_tip_after_message(node, test_node, msg_cmpctblock(comp_block.to_p2p()), block.sha256)
|
||||
test_tip_after_message(node, test_node, msg_cmpctblock(comp_block.to_p2p()), block.hash_int)
|
||||
with p2p_lock:
|
||||
# Shouldn't have gotten a request for any transaction
|
||||
assert "getblocktxn" not in test_node.last_message
|
||||
@@ -542,20 +542,20 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
# verifying that the block isn't marked bad permanently. This is good
|
||||
# enough for now.
|
||||
msg = msg_blocktxn()
|
||||
msg.block_transactions = BlockTransactions(block.sha256, [block.vtx[5]] + block.vtx[7:])
|
||||
msg.block_transactions = BlockTransactions(block.hash_int, [block.vtx[5]] + block.vtx[7:])
|
||||
test_node.send_and_ping(msg)
|
||||
|
||||
# Tip should not have updated
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)
|
||||
|
||||
# We should receive a getdata request
|
||||
test_node.wait_for_getdata([block.sha256], timeout=10)
|
||||
test_node.wait_for_getdata([block.hash_int], timeout=10)
|
||||
assert test_node.last_message["getdata"].inv[0].type == MSG_BLOCK or \
|
||||
test_node.last_message["getdata"].inv[0].type == MSG_BLOCK | MSG_WITNESS_FLAG
|
||||
|
||||
# Deliver the block
|
||||
test_node.send_and_ping(msg_block(block))
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
def test_getblocktxn_handler(self, test_node):
|
||||
node = self.nodes[0]
|
||||
@@ -595,7 +595,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
test_node.last_message.pop("blocktxn", None)
|
||||
test_node.send_and_ping(msg)
|
||||
with p2p_lock:
|
||||
assert_equal(test_node.last_message["block"].block.sha256, int(block_hash, 16))
|
||||
assert_equal(test_node.last_message["block"].block.hash_int, int(block_hash, 16))
|
||||
assert "blocktxn" not in test_node.last_message
|
||||
|
||||
# Request with out-of-bounds tx index results in disconnect
|
||||
@@ -651,7 +651,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
test_node.send_without_ping(msg_getdata([CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))]))
|
||||
test_node.wait_until(lambda: "block" in test_node.last_message, timeout=30)
|
||||
with p2p_lock:
|
||||
assert_equal(test_node.last_message["block"].block.sha256, int(new_blocks[0], 16))
|
||||
assert_equal(test_node.last_message["block"].block.hash_int, int(new_blocks[0], 16))
|
||||
|
||||
# Generate an old compactblock, and verify that it's not accepted.
|
||||
cur_height = node.getblockcount()
|
||||
@@ -676,7 +676,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
# Requesting this block via getblocktxn should silently fail
|
||||
# (to avoid fingerprinting attacks).
|
||||
msg = msg_getblocktxn()
|
||||
msg.block_txn_request = BlockTransactionsRequest(block.sha256, [0])
|
||||
msg.block_txn_request = BlockTransactionsRequest(block.hash_int, [0])
|
||||
with p2p_lock:
|
||||
test_node.last_message.pop("blocktxn", None)
|
||||
test_node.send_and_ping(msg)
|
||||
@@ -699,7 +699,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
l.wait_until(lambda: "cmpctblock" in l.last_message, timeout=30)
|
||||
with p2p_lock:
|
||||
for l in listeners:
|
||||
assert_equal(l.last_message["cmpctblock"].header_and_shortids.header.sha256, block.sha256)
|
||||
assert_equal(l.last_message["cmpctblock"].header_and_shortids.header.hash_int, block.hash_int)
|
||||
|
||||
# Test that we don't get disconnected if we relay a compact block with valid header,
|
||||
# but invalid transactions.
|
||||
@@ -724,7 +724,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
test_node.send_and_ping(msg)
|
||||
|
||||
# Check that the tip didn't advance
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
test_node.sync_with_ping()
|
||||
|
||||
# Helper for enabling cb announcements
|
||||
@@ -761,7 +761,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
assert tx.txid_hex in mempool
|
||||
|
||||
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
|
||||
@@ -777,13 +777,13 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
cmpct_block.use_witness = True
|
||||
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
msg = msg_no_witness_blocktxn()
|
||||
msg.block_transactions.blockhash = block.sha256
|
||||
msg.block_transactions.blockhash = block.hash_int
|
||||
msg.block_transactions.transactions = block.vtx[1:]
|
||||
stalling_peer.send_and_ping(msg)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
def test_highbandwidth_mode_states_via_getpeerinfo(self):
|
||||
# create new p2p connection for a fresh state w/o any prior sendcmpct messages sent
|
||||
@@ -836,10 +836,10 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
self.log.info(f"Setting {name} as high bandwidth peer")
|
||||
block, cmpct_block = announce_cmpct_block(node, peer, 1)
|
||||
msg = msg_blocktxn()
|
||||
msg.block_transactions.blockhash = block.sha256
|
||||
msg.block_transactions.blockhash = block.hash_int
|
||||
msg.block_transactions.transactions = block.vtx[1:]
|
||||
peer.send_and_ping(msg)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
peer.clear_getblocktxn()
|
||||
|
||||
# Test the simple parallel download case...
|
||||
@@ -854,26 +854,26 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
with p2p_lock:
|
||||
# The second peer to announce should still get a getblocktxn
|
||||
assert "getblocktxn" in delivery_peer.last_message
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
inbound_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
|
||||
with p2p_lock:
|
||||
# The third inbound peer to announce should *not* get a getblocktxn
|
||||
assert "getblocktxn" not in inbound_peer.last_message
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
outbound_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
|
||||
with p2p_lock:
|
||||
# The third peer to announce should get a getblocktxn if outbound
|
||||
assert "getblocktxn" in outbound_peer.last_message
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
# Second peer completes the compact block first
|
||||
msg = msg_blocktxn()
|
||||
msg.block_transactions.blockhash = block.sha256
|
||||
msg.block_transactions.blockhash = block.hash_int
|
||||
msg.block_transactions.transactions = block.vtx[1:]
|
||||
delivery_peer.send_and_ping(msg)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
|
||||
|
||||
# Nothing bad should happen if we get a late fill from the first peer...
|
||||
stalling_peer.send_and_ping(msg)
|
||||
|
||||
Reference in New Issue
Block a user