diff --git a/test/functional/example_test.py b/test/functional/example_test.py index 8e88fe00018..1e11586b50e 100755 --- a/test/functional/example_test.py +++ b/test/functional/example_test.py @@ -57,7 +57,7 @@ class BaseNode(P2PInterface): """Override the standard on_block callback Store the hash of a received block in the dictionary.""" - self.block_receive_map[message.block.sha256] += 1 + self.block_receive_map[message.block.hash_int] += 1 def on_inv(self, message): """Override the standard on_inv callback""" @@ -181,7 +181,7 @@ class ExampleTest(BitcoinTestFramework): block_message = msg_block(block) # Send message is used to send a P2P message to the node over our P2PInterface peer_messaging.send_without_ping(block_message) - self.tip = block.sha256 + self.tip = block.hash_int blocks.append(self.tip) self.block_time += 1 height += 1 diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index f044b6951eb..fc3c359cccc 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -272,7 +272,7 @@ class AssumeutxoTest(BitcoinTestFramework): block_time = node0.getblock(node0.getbestblockhash())['time'] + 1 fork_block1 = create_block(int(parent_block_hash, 16), create_coinbase(SNAPSHOT_BASE_HEIGHT), block_time) fork_block1.solve() - fork_block2 = create_block(fork_block1.sha256, create_coinbase(SNAPSHOT_BASE_HEIGHT + 1), block_time + 1) + fork_block2 = create_block(fork_block1.hash_int, create_coinbase(SNAPSHOT_BASE_HEIGHT + 1), block_time + 1) fork_block2.solve() node1.submitheader(fork_block1.serialize().hex()) node1.submitheader(fork_block2.serialize().hex()) diff --git a/test/functional/feature_assumevalid.py b/test/functional/feature_assumevalid.py index 7fd9c11c7dc..0b6998c15b0 100755 --- a/test/functional/feature_assumevalid.py +++ b/test/functional/feature_assumevalid.py @@ -103,7 +103,7 @@ class AssumeValidTest(BitcoinTestFramework): block.solve() # Save the coinbase for later self.block1 = block - self.tip = block.sha256 + self.tip = block.hash_int height += 1 # Bury the block 100 deep so the coinbase output is spendable @@ -111,7 +111,7 @@ class AssumeValidTest(BitcoinTestFramework): block = create_block(self.tip, create_coinbase(height), self.block_time) block.solve() self.blocks.append(block) - self.tip = block.sha256 + self.tip = block.hash_int self.block_time += 1 height += 1 @@ -124,7 +124,7 @@ class AssumeValidTest(BitcoinTestFramework): self.block_time += 1 block102.solve() self.blocks.append(block102) - self.tip = block102.sha256 + self.tip = block102.hash_int self.block_time += 1 height += 1 @@ -133,7 +133,7 @@ class AssumeValidTest(BitcoinTestFramework): block = create_block(self.tip, create_coinbase(height), self.block_time) block.solve() self.blocks.append(block) - self.tip = block.sha256 + self.tip = block.hash_int self.block_time += 1 height += 1 diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py index 2cf75a90f8c..eeb98a72604 100755 --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -327,7 +327,7 @@ class BIP68Test(BitcoinTestFramework): for i in range(2): block = create_block(tmpl=tmpl, ntime=cur_time) block.solve() - tip = block.sha256 + tip = block.hash_int assert_equal(None if i == 1 else 'inconclusive', self.nodes[0].submitblock(block.serialize().hex())) tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS) tmpl['previousblockhash'] = '%x' % tip diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index db4e53e4ee1..3a477f969b2 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -609,11 +609,11 @@ class FullBlockTest(BitcoinTestFramework): # The next few blocks are going to be created "by hand" since they'll do funky things, such as having # the first transaction be non-coinbase, etc. The purpose of b44 is to make sure this works. self.log.info("Build block 44 manually") - height = self.block_heights[self.tip.sha256] + 1 + height = self.block_heights[self.tip.hash_int] + 1 coinbase = create_coinbase(height, self.coinbase_pubkey) b44 = CBlock() b44.nTime = self.tip.nTime + 1 - b44.hashPrevBlock = self.tip.sha256 + b44.hashPrevBlock = self.tip.hash_int b44.nBits = REGTEST_N_BITS b44.vtx.append(coinbase) tx = self.create_and_sign_transaction(out[14], 1) @@ -621,7 +621,7 @@ class FullBlockTest(BitcoinTestFramework): b44.hashMerkleRoot = b44.calc_merkle_root() b44.solve() self.tip = b44 - self.block_heights[b44.sha256] = height + self.block_heights[b44.hash_int] = height self.blocks[44] = b44 self.send_blocks([b44], True) @@ -629,12 +629,12 @@ class FullBlockTest(BitcoinTestFramework): non_coinbase = self.create_tx(out[15], 0, 1) b45 = CBlock() b45.nTime = self.tip.nTime + 1 - b45.hashPrevBlock = self.tip.sha256 + b45.hashPrevBlock = self.tip.hash_int b45.nBits = REGTEST_N_BITS b45.vtx.append(non_coinbase) b45.hashMerkleRoot = b45.calc_merkle_root() b45.solve() - self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1 + self.block_heights[b45.hash_int] = self.block_heights[self.tip.hash_int] + 1 self.tip = b45 self.blocks[45] = b45 self.send_blocks([b45], success=False, reject_reason='bad-cb-missing', reconnect=True) @@ -643,12 +643,12 @@ class FullBlockTest(BitcoinTestFramework): self.move_tip(44) b46 = CBlock() b46.nTime = b44.nTime + 1 - b46.hashPrevBlock = b44.sha256 + b46.hashPrevBlock = b44.hash_int b46.nBits = REGTEST_N_BITS b46.vtx = [] b46.hashMerkleRoot = 0 b46.solve() - self.block_heights[b46.sha256] = self.block_heights[b44.sha256] + 1 + self.block_heights[b46.hash_int] = self.block_heights[b44.hash_int] + 1 self.tip = b46 assert 46 not in self.blocks self.blocks[46] = b46 @@ -658,7 +658,7 @@ class FullBlockTest(BitcoinTestFramework): self.move_tip(44) b47 = self.next_block(47) target = uint256_from_compact(b47.nBits) - while b47.sha256 <= target: + while b47.hash_int <= target: # Rehash nonces until an invalid too-high-hash block is found. b47.nNonce += 1 self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True) @@ -731,7 +731,7 @@ class FullBlockTest(BitcoinTestFramework): self.log.info("Accept a previously rejected future block at a later time") node.setmocktime(int(time.time()) + 2*60*60) self.move_tip(48) - self.block_heights[b48.sha256] = self.block_heights[b44.sha256] + 1 # b48 is a parent of b44 + self.block_heights[b48.hash_int] = self.block_heights[b44.hash_int] + 1 # b48 is a parent of b44 b48p = self.next_block("48p") self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain node.invalidateblock(b48p.hash) # mark b48p as invalid @@ -1058,12 +1058,12 @@ class FullBlockTest(BitcoinTestFramework): b72 = self.update_block(72, [tx1, tx2]) # now tip is 72 b71 = copy.deepcopy(b72) b71.vtx.append(tx2) # add duplicate tx2 - self.block_heights[b71.sha256] = self.block_heights[b69.sha256] + 1 # b71 builds off b69 + self.block_heights[b71.hash_int] = self.block_heights[b69.hash_int] + 1 # b71 builds off b69 self.blocks[71] = b71 assert_equal(len(b71.vtx), 4) assert_equal(len(b72.vtx), 3) - assert_equal(b72.sha256, b71.sha256) + assert_equal(b72.hash_int, b71.hash_int) self.move_tip(71) self.send_blocks([b71], success=False, reject_reason='bad-txns-duplicate', reconnect=True) @@ -1368,7 +1368,7 @@ class FullBlockTest(BitcoinTestFramework): base_block_hash = self.genesis_hash block_time = int(time.time()) + 1 else: - base_block_hash = self.tip.sha256 + base_block_hash = self.tip.hash_int block_time = self.tip.nTime + 1 # First create the coinbase height = self.block_heights[base_block_hash] + 1 @@ -1386,7 +1386,7 @@ class FullBlockTest(BitcoinTestFramework): # Block is created. Find a valid nonce. block.solve() self.tip = block - self.block_heights[block.sha256] = height + self.block_heights[block.hash_int] = height assert number not in self.blocks self.blocks[number] = block return block @@ -1409,16 +1409,16 @@ class FullBlockTest(BitcoinTestFramework): def update_block(self, block_number, new_transactions, *, nTime=None): block = self.blocks[block_number] self.add_transactions_to_block(block, new_transactions) - old_sha256 = block.sha256 + old_hash_int = block.hash_int if nTime is not None: block.nTime = nTime block.hashMerkleRoot = block.calc_merkle_root() block.solve() # Update the internal state just like in next_block self.tip = block - if block.sha256 != old_sha256: - self.block_heights[block.sha256] = self.block_heights[old_sha256] - del self.block_heights[old_sha256] + if block.hash_int != old_hash_int: + self.block_heights[block.hash_int] = self.block_heights[old_hash_int] + del self.block_heights[old_hash_int] self.blocks[block_number] = block return block diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index 06b5bf9698d..9d2060405da 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -130,7 +130,7 @@ class BIP65Test(BitcoinTestFramework): assert_equal(self.nodes[0].getbestblockhash(), block.hash) self.log.info("Test that blocks must now be at least version 4") - tip = block.sha256 + tip = block.hash_int block_time += 1 block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3) block.solve() @@ -196,7 +196,7 @@ class BIP65Test(BitcoinTestFramework): self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules peer.send_and_ping(msg_block(block)) self.test_cltv_info(is_active=True) # Active as of current tip - assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256) + assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int) if __name__ == '__main__': diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py index ec7688e0b49..2abfa84300f 100755 --- a/test/functional/feature_csv_activation.py +++ b/test/functional/feature_csv_activation.py @@ -165,7 +165,7 @@ class BIP68_112_113Test(BitcoinTestFramework): block = self.create_test_block([]) test_blocks.append(block) self.last_block_time += 600 - self.tip = block.sha256 + self.tip = block.hash_int self.tipheight += 1 return test_blocks diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py index 9687b80de9d..f20b045cea4 100755 --- a/test/functional/feature_dersig.py +++ b/test/functional/feature_dersig.py @@ -95,7 +95,7 @@ class BIP66Test(BitcoinTestFramework): assert_equal(self.nodes[0].getbestblockhash(), block.hash) self.log.info("Test that blocks must now be at least version 3") - tip = block.sha256 + tip = block.hash_int block_time += 1 block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2) block.solve() @@ -146,7 +146,7 @@ class BIP66Test(BitcoinTestFramework): self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules peer.send_and_ping(msg_block(block)) self.test_dersig_info(is_active=True) # Active as of current tip - assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256) + assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int) if __name__ == '__main__': diff --git a/test/functional/feature_maxuploadtarget.py b/test/functional/feature_maxuploadtarget.py index 7d408f7fc1f..6c4366c0208 100755 --- a/test/functional/feature_maxuploadtarget.py +++ b/test/functional/feature_maxuploadtarget.py @@ -41,7 +41,7 @@ class TestP2PConn(P2PInterface): pass def on_block(self, message): - self.block_receive_map[message.block.sha256] += 1 + self.block_receive_map[message.block.hash_int] += 1 class MaxUploadTest(BitcoinTestFramework): diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index bedfceee576..f8323454d78 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -58,7 +58,7 @@ def mine_large_blocks(node, n): # Submit to the node node.submitblock(block.serialize().hex()) - previousblockhash = block.sha256 + previousblockhash = block.hash_int height += 1 mine_large_blocks.nTime += 1 diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index 8df423422d5..2e427ec0d7b 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -1342,7 +1342,7 @@ class TaprootTest(BitcoinTestFramework): assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg) if accept: assert node.getbestblockhash() == block.hash, "Failed to accept: %s (response: %s)" % (msg, block_response) - self.tip = block.sha256 + self.tip = block.hash_int self.lastblockhash = block.hash self.lastblocktime += 1 self.lastblockheight += 1 diff --git a/test/functional/feature_versionbits_warning.py b/test/functional/feature_versionbits_warning.py index af59666222e..96ec7c570fa 100755 --- a/test/functional/feature_versionbits_warning.py +++ b/test/functional/feature_versionbits_warning.py @@ -50,7 +50,7 @@ class VersionBitsWarningTest(BitcoinTestFramework): peer.send_without_ping(msg_block(block)) block_time += 1 height += 1 - tip = block.sha256 + tip = block.hash_int peer.sync_with_ping() def versionbits_in_alert_file(self): diff --git a/test/functional/interface_zmq.py b/test/functional/interface_zmq.py index 01b3f763259..11cd8e63485 100755 --- a/test/functional/interface_zmq.py +++ b/test/functional/interface_zmq.py @@ -424,7 +424,7 @@ class ZMQTest (BitcoinTestFramework): block.solve() assert_equal(self.nodes[0].submitblock(block.serialize().hex()), None) tip = self.nodes[0].getbestblockhash() - assert_equal(int(tip, 16), block.sha256) + assert_equal(int(tip, 16), block.hash_int) orig_txid_2 = self.wallet.send_self_transfer(from_node=self.nodes[0])['txid'] # Flush old notifications until evicted tx original entry diff --git a/test/functional/mempool_updatefromblock.py b/test/functional/mempool_updatefromblock.py index 4ceeb3f149a..fdc6b9a34e1 100755 --- a/test/functional/mempool_updatefromblock.py +++ b/test/functional/mempool_updatefromblock.py @@ -44,7 +44,7 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework): block = create_block(tip, create_coinbase(height + 1), block_time) block.solve() blocks.append(block) - tip = block.sha256 + tip = block.hash_int block_time += 1 height += 1 diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 53cb42f837a..b60d07b52fa 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -473,7 +473,7 @@ class MiningTest(BitcoinTestFramework): assert_equal(node.submitblock(hexdata=bad_block_lock.serialize().hex()), 'duplicate-invalid') # Build a "good" block on top of the submitted bad block bad_block2 = copy.deepcopy(block) - bad_block2.hashPrevBlock = bad_block_lock.sha256 + bad_block2.hashPrevBlock = bad_block_lock.hash_int bad_block2.solve() assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=CBlockHeader(bad_block2).serialize().hex())) diff --git a/test/functional/mining_template_verification.py b/test/functional/mining_template_verification.py index 526a9139b95..de0833c596d 100755 --- a/test/functional/mining_template_verification.py +++ b/test/functional/mining_template_verification.py @@ -156,7 +156,7 @@ class MiningTemplateVerificationTest(BitcoinTestFramework): self.log.info("Generate a block") target = uint256_from_compact(block.nBits) # Ensure that it doesn't meet the target by coincidence - while block.sha256 <= target: + while block.hash_int <= target: block.nNonce += 1 self.log.debug("Found a nonce") diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index 8f5c5ad8bbe..c006910d443 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -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) diff --git a/test/functional/p2p_compactblocks_blocksonly.py b/test/functional/p2p_compactblocks_blocksonly.py index c4c19e19278..a4a4154cc9e 100755 --- a/test/functional/p2p_compactblocks_blocksonly.py +++ b/test/functional/p2p_compactblocks_blocksonly.py @@ -72,14 +72,14 @@ class P2PCompactBlocksBlocksOnly(BitcoinTestFramework): # A -blocksonly node should not request BIP152 high bandwidth mode upon # receiving a new valid block at the tip. p2p_conn_blocksonly.send_and_ping(msg_block(block0)) - assert_equal(int(self.nodes[0].getbestblockhash(), 16), block0.sha256) + assert_equal(int(self.nodes[0].getbestblockhash(), 16), block0.hash_int) assert_equal(p2p_conn_blocksonly.message_count['sendcmpct'], 1) assert_equal(p2p_conn_blocksonly.last_message['sendcmpct'].announce, False) # A normal node participating in transaction relay should request BIP152 # high bandwidth mode upon receiving a new valid block at the tip. p2p_conn_high_bw.send_and_ping(msg_block(block0)) - assert_equal(int(self.nodes[1].getbestblockhash(), 16), block0.sha256) + assert_equal(int(self.nodes[1].getbestblockhash(), 16), block0.hash_int) p2p_conn_high_bw.wait_until(lambda: p2p_conn_high_bw.message_count['sendcmpct'] == 2) assert_equal(p2p_conn_high_bw.last_message['sendcmpct'].announce, True) @@ -93,25 +93,25 @@ class P2PCompactBlocksBlocksOnly(BitcoinTestFramework): block1 = self.build_block_on_tip() p2p_conn_blocksonly.send_and_ping(msg_headers(headers=[CBlockHeader(block1)])) - assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.sha256)]) + assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.hash_int)]) p2p_conn_high_bw.send_and_ping(msg_headers(headers=[CBlockHeader(block1)])) - assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)]) + assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.hash_int)]) self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections" " when no -blocksonly nodes are involved") p2p_conn_low_bw.send_and_ping(msg_headers(headers=[CBlockHeader(block1)])) - assert_equal(p2p_conn_low_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)]) + assert_equal(p2p_conn_low_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.hash_int)]) self.log.info("Test that -blocksonly nodes still serve compact blocks") def test_for_cmpctblock(block): if 'cmpctblock' not in p2p_conn_blocksonly.last_message: return False - return p2p_conn_blocksonly.last_message['cmpctblock'].header_and_shortids.header.rehash() == block.sha256 + return p2p_conn_blocksonly.last_message['cmpctblock'].header_and_shortids.header.hash_int == block.hash_int - p2p_conn_blocksonly.send_without_ping(msg_getdata([CInv(MSG_CMPCT_BLOCK, block0.sha256)])) + p2p_conn_blocksonly.send_without_ping(msg_getdata([CInv(MSG_CMPCT_BLOCK, block0.hash_int)])) p2p_conn_blocksonly.wait_until(lambda: test_for_cmpctblock(block0)) # Request BIP152 high bandwidth mode from the -blocksonly node. diff --git a/test/functional/p2p_fingerprint.py b/test/functional/p2p_fingerprint.py index 412de0149f8..99030141505 100755 --- a/test/functional/p2p_fingerprint.py +++ b/test/functional/p2p_fingerprint.py @@ -79,7 +79,7 @@ class P2PFingerprintTest(BitcoinTestFramework): # Force reorg to a longer chain node0.send_without_ping(msg_headers(new_blocks)) - node0.wait_for_getdata([x.sha256 for x in new_blocks]) + node0.wait_for_getdata([x.hash_int for x in new_blocks]) for block in new_blocks: node0.send_and_ping(msg_block(block)) diff --git a/test/functional/p2p_getdata.py b/test/functional/p2p_getdata.py index 8d3c5bf4a0b..96e43560dcd 100755 --- a/test/functional/p2p_getdata.py +++ b/test/functional/p2p_getdata.py @@ -19,7 +19,7 @@ class P2PStoreBlock(P2PInterface): self.blocks = defaultdict(int) def on_block(self, message): - self.blocks[message.block.sha256] += 1 + self.blocks[message.block.hash_int] += 1 class GetdataTest(BitcoinTestFramework): diff --git a/test/functional/p2p_headers_sync_with_minchainwork.py b/test/functional/p2p_headers_sync_with_minchainwork.py index 6e7b4b399e5..3cb9ff2139a 100755 --- a/test/functional/p2p_headers_sync_with_minchainwork.py +++ b/test/functional/p2p_headers_sync_with_minchainwork.py @@ -129,7 +129,7 @@ class RejectLowDifficultyHeadersTest(BitcoinTestFramework): block = create_block(hashprev = hashPrevBlock, tmpl=node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)) block.solve() new_blocks.append(block) - hashPrevBlock = block.sha256 + hashPrevBlock = block.hash_int headers_message = msg_headers(headers=new_blocks) p2p.send_and_ping(headers_message) diff --git a/test/functional/p2p_ibd_stalling.py b/test/functional/p2p_ibd_stalling.py index 75f55edb603..542d767ccee 100755 --- a/test/functional/p2p_ibd_stalling.py +++ b/test/functional/p2p_ibd_stalling.py @@ -62,11 +62,11 @@ class P2PIBDStallingTest(BitcoinTestFramework): for _ in range(NUM_BLOCKS): 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 - block_dict[blocks[-1].sha256] = blocks[-1] - stall_block = blocks[0].sha256 + block_dict[blocks[-1].hash_int] = blocks[-1] + stall_block = blocks[0].hash_int headers_message = msg_headers() headers_message.headers = [CBlockHeader(b) for b in blocks[:NUM_BLOCKS-1]] diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py index 8b177542dcc..6252d0e6239 100755 --- a/test/functional/p2p_invalid_block.py +++ b/test/functional/p2p_invalid_block.py @@ -77,13 +77,13 @@ class InvalidBlockRequestTest(BitcoinTestFramework): block2 = create_block(tip, create_coinbase(height), block_time, txlist=[tx1, tx2]) block_time += 1 block2.solve() - orig_hash = block2.sha256 + orig_hash = block2.hash_int block2_orig = copy.deepcopy(block2) # Mutate block 2 block2.vtx.append(tx2) assert_equal(block2.hashMerkleRoot, block2.calc_merkle_root()) - assert_equal(orig_hash, block2.rehash()) + assert_equal(orig_hash, block2.hash_int) assert_not_equal(block2_orig.vtx, block2.vtx) peer.send_blocks_and_test([block2], node, success=False, reject_reason='bad-txns-duplicate') diff --git a/test/functional/p2p_mutated_blocks.py b/test/functional/p2p_mutated_blocks.py index 6d909ded05a..874c264d646 100755 --- a/test/functional/p2p_mutated_blocks.py +++ b/test/functional/p2p_mutated_blocks.py @@ -68,7 +68,7 @@ class MutatedBlocksTest(BitcoinTestFramework): return False get_block_txn = honest_relayer.last_message['getblocktxn'] - return get_block_txn.block_txn_request.blockhash == block.sha256 and \ + return get_block_txn.block_txn_request.blockhash == block.hash_int and \ get_block_txn.block_txn_request.indexes == [1] honest_relayer.wait_until(self_transfer_requested, timeout=5) @@ -93,7 +93,7 @@ class MutatedBlocksTest(BitcoinTestFramework): # The honest relayer should be able to complete relaying the block by # sending the blocktxn that was requested. block_txn = msg_blocktxn() - block_txn.block_transactions = BlockTransactions(blockhash=block.sha256, transactions=[tx]) + block_txn.block_transactions = BlockTransactions(blockhash=block.hash_int, transactions=[tx]) honest_relayer.send_and_ping(block_txn) assert_equal(self.nodes[0].getbestblockhash(), block.hash) diff --git a/test/functional/p2p_outbound_eviction.py b/test/functional/p2p_outbound_eviction.py index 43458decbc9..42168a7547d 100755 --- a/test/functional/p2p_outbound_eviction.py +++ b/test/functional/p2p_outbound_eviction.py @@ -190,7 +190,7 @@ class P2POutEvict(BitcoinTestFramework): self.log.info("Mine a new block and keep the unprotected honest peer on sync, all the rest off-sync") # Mine a block so all peers become outdated - target_hash = prev_header.rehash() + target_hash = prev_header.hash_int tip_hash = self.generateblock(node, output="raw(42)", transactions=[])["hash"] tip_header = from_hex(CBlockHeader(), node.getblockheader(tip_hash, False)) tip_headers_message = msg_headers([tip_header]) @@ -235,7 +235,7 @@ class P2POutEvict(BitcoinTestFramework): cur_mock_time += (CHAIN_SYNC_TIMEOUT + 1) node.setmocktime(cur_mock_time) peer.sync_with_ping() - peer.wait_for_getheaders(block_hash=tip_header.rehash()) + peer.wait_for_getheaders(block_hash=tip_header.hash_int) cur_mock_time += (HEADERS_RESPONSE_TIME + 1) node.setmocktime(cur_mock_time) self.log.info("Test that the peer gets evicted") diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index fd296c2c86a..101cccc70e2 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -195,10 +195,10 @@ class TestP2PConn(P2PInterface): if use_header: self.send_without_ping(msg) else: - self.send_without_ping(msg_inv(inv=[CInv(MSG_BLOCK, block.sha256)])) + self.send_without_ping(msg_inv(inv=[CInv(MSG_BLOCK, block.hash_int)])) self.wait_for_getheaders(block_hash=block.hashPrevBlock, timeout=timeout) self.send_without_ping(msg) - self.wait_for_getdata([block.sha256], timeout=timeout) + self.wait_for_getdata([block.hash_int], timeout=timeout) def request_block(self, blockhash, inv_type, timeout=60): with p2p_lock: @@ -414,8 +414,8 @@ class SegWitTest(BitcoinTestFramework): test_witness_block(self.nodes[0], self.test_node, block, accepted=True) # Now try to retrieve it... rpc_block = self.nodes[0].getblock(block.hash, False) - non_wit_block = self.test_node.request_block(block.sha256, 2) - wit_block = self.test_node.request_block(block.sha256, 2 | MSG_WITNESS_FLAG) + non_wit_block = self.test_node.request_block(block.hash_int, 2) + wit_block = self.test_node.request_block(block.hash_int, 2 | MSG_WITNESS_FLAG) assert_equal(wit_block.serialize(), bytes.fromhex(rpc_block)) assert_equal(wit_block.serialize(False), non_wit_block.serialize()) assert_equal(wit_block.serialize(), block.serialize()) @@ -443,7 +443,7 @@ class SegWitTest(BitcoinTestFramework): msg.headers = [CBlockHeader(block4)] self.old_node.send_without_ping(msg) self.old_node.announce_tx_and_wait_for_getdata(block4.vtx[0]) - assert block4.sha256 not in self.old_node.getdataset + assert block4.hash_int not in self.old_node.getdataset @subtest def test_v0_outputs_arent_spendable(self): diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py index aaf2e953f6a..49680e5d626 100755 --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -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 diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py index 34c2654b9b4..c8b99a10266 100755 --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -122,7 +122,7 @@ class AcceptBlockTest(BitcoinTestFramework): assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_h1f.hash) # 4. Send another two block that build on the fork. - block_h2f = create_block(block_h1f.sha256, create_coinbase(2), block_time) + block_h2f = create_block(block_h1f.hash_int, create_coinbase(2), block_time) block_time += 1 block_h2f.solve() test_node.send_and_ping(msg_block(block_h2f)) @@ -141,7 +141,7 @@ class AcceptBlockTest(BitcoinTestFramework): self.log.info("Second height 2 block accepted, but not reorg'ed to") # 4b. Now send another block that builds on the forking chain. - block_h3 = create_block(block_h2f.sha256, create_coinbase(3), block_h2f.nTime+1) + block_h3 = create_block(block_h2f.hash_int, create_coinbase(3), block_h2f.nTime+1) block_h3.solve() test_node.send_and_ping(msg_block(block_h3)) @@ -164,7 +164,7 @@ class AcceptBlockTest(BitcoinTestFramework): tip = block_h3 all_blocks = [] for i in range(288): - next_block = create_block(tip.sha256, create_coinbase(i + 4), tip.nTime+1) + next_block = create_block(tip.hash_int, create_coinbase(i + 4), tip.nTime+1) next_block.solve() all_blocks.append(next_block) tip = next_block @@ -215,14 +215,14 @@ class AcceptBlockTest(BitcoinTestFramework): with p2p_lock: # Clear state so we can check the getdata request test_node.last_message.pop("getdata", None) - test_node.send_without_ping(msg_inv([CInv(MSG_BLOCK, block_h3.sha256)])) + test_node.send_without_ping(msg_inv([CInv(MSG_BLOCK, block_h3.hash_int)])) test_node.sync_with_ping() with p2p_lock: getdata = test_node.last_message["getdata"] # Check that the getdata includes the right block - assert_equal(getdata.inv[0].hash, block_h1f.sha256) + assert_equal(getdata.inv[0].hash, block_h1f.hash_int) self.log.info("Inv at tip triggered getdata for unprocessed block") # 7. Send the missing block for the third time (now it is requested) @@ -235,15 +235,15 @@ class AcceptBlockTest(BitcoinTestFramework): # 8. Create a chain which is invalid at a height longer than the # current chain, but which has more blocks on top of that - block_289f = create_block(all_blocks[284].sha256, create_coinbase(289), all_blocks[284].nTime+1) + block_289f = create_block(all_blocks[284].hash_int, create_coinbase(289), all_blocks[284].nTime+1) block_289f.solve() - block_290f = create_block(block_289f.sha256, create_coinbase(290), block_289f.nTime+1) + block_290f = create_block(block_289f.hash_int, create_coinbase(290), block_289f.nTime+1) block_290f.solve() # block_291 spends a coinbase below maturity! tx_to_add = create_tx_with_script(block_290f.vtx[0], 0, script_sig=b"42", amount=1) - block_291 = create_block(block_290f.sha256, create_coinbase(291), block_290f.nTime+1, txlist=[tx_to_add]) + block_291 = create_block(block_290f.hash_int, create_coinbase(291), block_290f.nTime+1, txlist=[tx_to_add]) block_291.solve() - block_292 = create_block(block_291.sha256, create_coinbase(292), block_291.nTime+1) + block_292 = create_block(block_291.hash_int, create_coinbase(292), block_291.nTime+1) block_292.solve() # Now send all the headers on the chain and enough blocks to trigger reorg @@ -283,7 +283,7 @@ class AcceptBlockTest(BitcoinTestFramework): assert_equal(self.nodes[0].getblock(block_291.hash)["confirmations"], -1) # Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected - block_293 = create_block(block_292.sha256, create_coinbase(293), block_292.nTime+1) + block_293 = create_block(block_292.hash_int, create_coinbase(293), block_292.nTime+1) block_293.solve() headers_message = msg_headers() headers_message.headers.append(CBlockHeader(block_293)) diff --git a/test/functional/p2p_v2_encrypted.py b/test/functional/p2p_v2_encrypted.py index 3e8ce09d24d..36e2f31673c 100755 --- a/test/functional/p2p_v2_encrypted.py +++ b/test/functional/p2p_v2_encrypted.py @@ -41,7 +41,7 @@ class P2PEncrypted(BitcoinTestFramework): block = create_block(tip, create_coinbase(tipheight + 1), last_block_time + 1) block.solve() test_blocks.append(block) - tip = block.sha256 + tip = block.hash_int tipheight += 1 last_block_time += 1 return test_blocks diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 936126b8c5b..7f6ad587bf2 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -621,7 +621,7 @@ class BlockchainTest(BitcoinTestFramework): return b b1 = solve_and_send_block(int(fork_hash, 16), fork_height+1, fork_block['time'] + 1) - b2 = solve_and_send_block(b1.sha256, fork_height+2, b1.nTime + 1) + b2 = solve_and_send_block(b1.hash_int, fork_height+2, b1.nTime + 1) node.invalidateblock(b2.hash) @@ -734,7 +734,7 @@ class BlockchainTest(BitcoinTestFramework): self.log.info("Test getblock when block data is available but undo data isn't") # Submits a block building on the header-only block, so it can't be connected and has no undo data tx = create_tx_with_script(block.vtx[0], 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN) - block_noundo = create_block(block.sha256, create_coinbase(current_height + 2, nValue=100), block_time + 1, txlist=[tx]) + block_noundo = create_block(block.hash_int, create_coinbase(current_height + 2, nValue=100), block_time + 1, txlist=[tx]) block_noundo.solve() node.submitblock(block_noundo.serialize().hex()) diff --git a/test/functional/rpc_getchaintips.py b/test/functional/rpc_getchaintips.py index 226e995307c..7bf8e4d82b2 100755 --- a/test/functional/rpc_getchaintips.py +++ b/test/functional/rpc_getchaintips.py @@ -73,7 +73,7 @@ class GetChainTipsTest (BitcoinTestFramework): invalid_block.solve() block_time += 1 - block2 = create_block(invalid_block.sha256, create_coinbase(2), block_time, version=4) + block2 = create_block(invalid_block.hash_int, create_coinbase(2), block_time, version=4) block2.solve() self.log.info("Submit headers-only chain") diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 94068924094..104fda94174 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -753,14 +753,10 @@ class CBlockHeader: return hash256(self._serialize_header())[::-1].hex() @property - def sha256(self): + def hash_int(self): """Return block header hash as integer.""" return uint256_from_str(hash256(self._serialize_header())) - # TODO: get rid of this method, replace call-sites by .sha256 access (if return value is used) - def rehash(self): - return self.sha256 - def __repr__(self): return "CBlockHeader(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x)" \ % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, @@ -819,7 +815,7 @@ class CBlock(CBlockHeader): def is_valid(self): target = uint256_from_compact(self.nBits) - if self.sha256 > target: + if self.hash_int > target: return False for tx in self.vtx: if not tx.is_valid(): @@ -830,7 +826,7 @@ class CBlock(CBlockHeader): def solve(self): target = uint256_from_compact(self.nBits) - while self.sha256 > target: + while self.hash_int > target: self.nNonce += 1 # Calculate the block weight using witness and non-witness diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index e7064e386f2..fbbf4189cc1 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -625,7 +625,7 @@ class P2PInterface(P2PConnection): def wait_for_block(self, blockhash, *, timeout=60): def test_function(): - return self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash + return self.last_message.get("block") and self.last_message["block"].block.hash_int == blockhash self.wait_until(test_function, timeout=timeout) @@ -634,7 +634,7 @@ class P2PInterface(P2PConnection): last_headers = self.last_message.get('headers') if not last_headers: return False - return last_headers.headers[0].rehash() == int(blockhash, 16) + return last_headers.headers[0].hash_int == int(blockhash, 16) self.wait_until(test_function, timeout=timeout) @@ -643,7 +643,7 @@ class P2PInterface(P2PConnection): last_filtered_block = self.last_message.get('merkleblock') if not last_filtered_block: return False - return last_filtered_block.merkleblock.header.rehash() == int(blockhash, 16) + return last_filtered_block.merkleblock.header.hash_int == int(blockhash, 16) self.wait_until(test_function, timeout=timeout) @@ -837,14 +837,14 @@ class P2PDataStore(P2PInterface): return headers_list = [self.block_store[self.last_block_hash]] - while headers_list[-1].sha256 not in locator.vHave: + while headers_list[-1].hash_int not in locator.vHave: # Walk back through the block store, adding headers to headers_list # as we go. prev_block_hash = headers_list[-1].hashPrevBlock if prev_block_hash in self.block_store: prev_block_header = CBlockHeader(self.block_store[prev_block_hash]) headers_list.append(prev_block_header) - if prev_block_header.sha256 == hash_stop: + if prev_block_header.hash_int == hash_stop: # if this is the hashstop header, stop here break else: @@ -872,8 +872,8 @@ class P2PDataStore(P2PInterface): with p2p_lock: for block in blocks: - self.block_store[block.sha256] = block - self.last_block_hash = block.sha256 + self.block_store[block.hash_int] = block + self.last_block_hash = block.hash_int reject_reason = [reject_reason] if reject_reason else [] with node.assert_debug_log(expected_msgs=reject_reason): @@ -885,7 +885,7 @@ class P2PDataStore(P2PInterface): else: self.send_without_ping(msg_headers([CBlockHeader(block) for block in blocks])) self.wait_until( - lambda: blocks[-1].sha256 in self.getdata_requests, + lambda: blocks[-1].hash_int in self.getdata_requests, timeout=timeout, check_connected=success, )