Skip to content

Commit 23be0ec

Browse files
committed
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).
1 parent 8b09cc3 commit 23be0ec

33 files changed

+141
-145
lines changed

test/functional/example_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def on_block(self, message):
5757
"""Override the standard on_block callback
5858
5959
Store the hash of a received block in the dictionary."""
60-
self.block_receive_map[message.block.sha256] += 1
60+
self.block_receive_map[message.block.hash_int] += 1
6161

6262
def on_inv(self, message):
6363
"""Override the standard on_inv callback"""
@@ -181,7 +181,7 @@ def run_test(self):
181181
block_message = msg_block(block)
182182
# Send message is used to send a P2P message to the node over our P2PInterface
183183
peer_messaging.send_without_ping(block_message)
184-
self.tip = block.sha256
184+
self.tip = block.hash_int
185185
blocks.append(self.tip)
186186
self.block_time += 1
187187
height += 1

test/functional/feature_assumeutxo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def test_snapshot_not_on_most_work_chain(self, dump_output_path):
272272
block_time = node0.getblock(node0.getbestblockhash())['time'] + 1
273273
fork_block1 = create_block(int(parent_block_hash, 16), create_coinbase(SNAPSHOT_BASE_HEIGHT), block_time)
274274
fork_block1.solve()
275-
fork_block2 = create_block(fork_block1.sha256, create_coinbase(SNAPSHOT_BASE_HEIGHT + 1), block_time + 1)
275+
fork_block2 = create_block(fork_block1.hash_int, create_coinbase(SNAPSHOT_BASE_HEIGHT + 1), block_time + 1)
276276
fork_block2.solve()
277277
node1.submitheader(fork_block1.serialize().hex())
278278
node1.submitheader(fork_block2.serialize().hex())

test/functional/feature_assumevalid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ def run_test(self):
103103
block.solve()
104104
# Save the coinbase for later
105105
self.block1 = block
106-
self.tip = block.sha256
106+
self.tip = block.hash_int
107107
height += 1
108108

109109
# Bury the block 100 deep so the coinbase output is spendable
110110
for _ in range(100):
111111
block = create_block(self.tip, create_coinbase(height), self.block_time)
112112
block.solve()
113113
self.blocks.append(block)
114-
self.tip = block.sha256
114+
self.tip = block.hash_int
115115
self.block_time += 1
116116
height += 1
117117

@@ -124,7 +124,7 @@ def run_test(self):
124124
self.block_time += 1
125125
block102.solve()
126126
self.blocks.append(block102)
127-
self.tip = block102.sha256
127+
self.tip = block102.hash_int
128128
self.block_time += 1
129129
height += 1
130130

@@ -133,7 +133,7 @@ def run_test(self):
133133
block = create_block(self.tip, create_coinbase(height), self.block_time)
134134
block.solve()
135135
self.blocks.append(block)
136-
self.tip = block.sha256
136+
self.tip = block.hash_int
137137
self.block_time += 1
138138
height += 1
139139

test/functional/feature_bip68_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
327327
for i in range(2):
328328
block = create_block(tmpl=tmpl, ntime=cur_time)
329329
block.solve()
330-
tip = block.sha256
330+
tip = block.hash_int
331331
assert_equal(None if i == 1 else 'inconclusive', self.nodes[0].submitblock(block.serialize().hex()))
332332
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
333333
tmpl['previousblockhash'] = '%x' % tip

test/functional/feature_block.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -609,32 +609,32 @@ def run_test(self):
609609
# The next few blocks are going to be created "by hand" since they'll do funky things, such as having
610610
# the first transaction be non-coinbase, etc. The purpose of b44 is to make sure this works.
611611
self.log.info("Build block 44 manually")
612-
height = self.block_heights[self.tip.sha256] + 1
612+
height = self.block_heights[self.tip.hash_int] + 1
613613
coinbase = create_coinbase(height, self.coinbase_pubkey)
614614
b44 = CBlock()
615615
b44.nTime = self.tip.nTime + 1
616-
b44.hashPrevBlock = self.tip.sha256
616+
b44.hashPrevBlock = self.tip.hash_int
617617
b44.nBits = REGTEST_N_BITS
618618
b44.vtx.append(coinbase)
619619
tx = self.create_and_sign_transaction(out[14], 1)
620620
b44.vtx.append(tx)
621621
b44.hashMerkleRoot = b44.calc_merkle_root()
622622
b44.solve()
623623
self.tip = b44
624-
self.block_heights[b44.sha256] = height
624+
self.block_heights[b44.hash_int] = height
625625
self.blocks[44] = b44
626626
self.send_blocks([b44], True)
627627

628628
self.log.info("Reject a block with a non-coinbase as the first tx")
629629
non_coinbase = self.create_tx(out[15], 0, 1)
630630
b45 = CBlock()
631631
b45.nTime = self.tip.nTime + 1
632-
b45.hashPrevBlock = self.tip.sha256
632+
b45.hashPrevBlock = self.tip.hash_int
633633
b45.nBits = REGTEST_N_BITS
634634
b45.vtx.append(non_coinbase)
635635
b45.hashMerkleRoot = b45.calc_merkle_root()
636636
b45.solve()
637-
self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1
637+
self.block_heights[b45.hash_int] = self.block_heights[self.tip.hash_int] + 1
638638
self.tip = b45
639639
self.blocks[45] = b45
640640
self.send_blocks([b45], success=False, reject_reason='bad-cb-missing', reconnect=True)
@@ -643,12 +643,12 @@ def run_test(self):
643643
self.move_tip(44)
644644
b46 = CBlock()
645645
b46.nTime = b44.nTime + 1
646-
b46.hashPrevBlock = b44.sha256
646+
b46.hashPrevBlock = b44.hash_int
647647
b46.nBits = REGTEST_N_BITS
648648
b46.vtx = []
649649
b46.hashMerkleRoot = 0
650650
b46.solve()
651-
self.block_heights[b46.sha256] = self.block_heights[b44.sha256] + 1
651+
self.block_heights[b46.hash_int] = self.block_heights[b44.hash_int] + 1
652652
self.tip = b46
653653
assert 46 not in self.blocks
654654
self.blocks[46] = b46
@@ -658,7 +658,7 @@ def run_test(self):
658658
self.move_tip(44)
659659
b47 = self.next_block(47)
660660
target = uint256_from_compact(b47.nBits)
661-
while b47.sha256 <= target:
661+
while b47.hash_int <= target:
662662
# Rehash nonces until an invalid too-high-hash block is found.
663663
b47.nNonce += 1
664664
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True)
@@ -731,7 +731,7 @@ def run_test(self):
731731
self.log.info("Accept a previously rejected future block at a later time")
732732
node.setmocktime(int(time.time()) + 2*60*60)
733733
self.move_tip(48)
734-
self.block_heights[b48.sha256] = self.block_heights[b44.sha256] + 1 # b48 is a parent of b44
734+
self.block_heights[b48.hash_int] = self.block_heights[b44.hash_int] + 1 # b48 is a parent of b44
735735
b48p = self.next_block("48p")
736736
self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain
737737
node.invalidateblock(b48p.hash) # mark b48p as invalid
@@ -1058,12 +1058,12 @@ def run_test(self):
10581058
b72 = self.update_block(72, [tx1, tx2]) # now tip is 72
10591059
b71 = copy.deepcopy(b72)
10601060
b71.vtx.append(tx2) # add duplicate tx2
1061-
self.block_heights[b71.sha256] = self.block_heights[b69.sha256] + 1 # b71 builds off b69
1061+
self.block_heights[b71.hash_int] = self.block_heights[b69.hash_int] + 1 # b71 builds off b69
10621062
self.blocks[71] = b71
10631063

10641064
assert_equal(len(b71.vtx), 4)
10651065
assert_equal(len(b72.vtx), 3)
1066-
assert_equal(b72.sha256, b71.sha256)
1066+
assert_equal(b72.hash_int, b71.hash_int)
10671067

10681068
self.move_tip(71)
10691069
self.send_blocks([b71], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
@@ -1368,7 +1368,7 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, *, script=
13681368
base_block_hash = self.genesis_hash
13691369
block_time = int(time.time()) + 1
13701370
else:
1371-
base_block_hash = self.tip.sha256
1371+
base_block_hash = self.tip.hash_int
13721372
block_time = self.tip.nTime + 1
13731373
# First create the coinbase
13741374
height = self.block_heights[base_block_hash] + 1
@@ -1386,7 +1386,7 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, *, script=
13861386
# Block is created. Find a valid nonce.
13871387
block.solve()
13881388
self.tip = block
1389-
self.block_heights[block.sha256] = height
1389+
self.block_heights[block.hash_int] = height
13901390
assert number not in self.blocks
13911391
self.blocks[number] = block
13921392
return block
@@ -1409,16 +1409,16 @@ def move_tip(self, number):
14091409
def update_block(self, block_number, new_transactions, *, nTime=None):
14101410
block = self.blocks[block_number]
14111411
self.add_transactions_to_block(block, new_transactions)
1412-
old_sha256 = block.sha256
1412+
old_hash_int = block.hash_int
14131413
if nTime is not None:
14141414
block.nTime = nTime
14151415
block.hashMerkleRoot = block.calc_merkle_root()
14161416
block.solve()
14171417
# Update the internal state just like in next_block
14181418
self.tip = block
1419-
if block.sha256 != old_sha256:
1420-
self.block_heights[block.sha256] = self.block_heights[old_sha256]
1421-
del self.block_heights[old_sha256]
1419+
if block.hash_int != old_hash_int:
1420+
self.block_heights[block.hash_int] = self.block_heights[old_hash_int]
1421+
del self.block_heights[old_hash_int]
14221422
self.blocks[block_number] = block
14231423
return block
14241424

test/functional/feature_cltv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def run_test(self):
130130
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
131131

132132
self.log.info("Test that blocks must now be at least version 4")
133-
tip = block.sha256
133+
tip = block.hash_int
134134
block_time += 1
135135
block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3)
136136
block.solve()
@@ -196,7 +196,7 @@ def run_test(self):
196196
self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules
197197
peer.send_and_ping(msg_block(block))
198198
self.test_cltv_info(is_active=True) # Active as of current tip
199-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
199+
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int)
200200

201201

202202
if __name__ == '__main__':

test/functional/feature_csv_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def generate_blocks(self, number):
165165
block = self.create_test_block([])
166166
test_blocks.append(block)
167167
self.last_block_time += 600
168-
self.tip = block.sha256
168+
self.tip = block.hash_int
169169
self.tipheight += 1
170170
return test_blocks
171171

test/functional/feature_dersig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def run_test(self):
9595
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
9696

9797
self.log.info("Test that blocks must now be at least version 3")
98-
tip = block.sha256
98+
tip = block.hash_int
9999
block_time += 1
100100
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2)
101101
block.solve()
@@ -146,7 +146,7 @@ def run_test(self):
146146
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
147147
peer.send_and_ping(msg_block(block))
148148
self.test_dersig_info(is_active=True) # Active as of current tip
149-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
149+
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int)
150150

151151

152152
if __name__ == '__main__':

test/functional/feature_maxuploadtarget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def on_inv(self, message):
4141
pass
4242

4343
def on_block(self, message):
44-
self.block_receive_map[message.block.sha256] += 1
44+
self.block_receive_map[message.block.hash_int] += 1
4545

4646
class MaxUploadTest(BitcoinTestFramework):
4747

test/functional/feature_pruning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def mine_large_blocks(node, n):
5858
# Submit to the node
5959
node.submitblock(block.serialize().hex())
6060

61-
previousblockhash = block.sha256
61+
previousblockhash = block.hash_int
6262
height += 1
6363
mine_large_blocks.nTime += 1
6464

0 commit comments

Comments
 (0)