Skip to content

Commit 8b09cc3

Browse files
committed
test: remove bare CBlockHeader .rehash()/.calc_sha256() calls
Since the previous commit, CBlockHeader/CBlock object calls to the methods `.rehash()` and `.calc_sha256()` are effectively no-ops if the returned value is not used, so we can just remove them.
1 parent 0716382 commit 8b09cc3

16 files changed

+0
-32
lines changed

contrib/signet/miner

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def finish_block(block, signet_solution, grind_cmd):
9595
newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
9696
newhead = from_hex(CBlockHeader(), newheadhex.decode('utf8'))
9797
block.nNonce = newhead.nNonce
98-
block.rehash()
9998
return block
10099

101100
def new_block(tmpl, reward_spk, *, blocktime=None, poolid=None):

test/functional/example_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ 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-
message.block.calc_sha256()
6160
self.block_receive_map[message.block.sha256] += 1
6261

6362
def on_inv(self, message):

test/functional/feature_block.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ def run_test(self):
661661
while b47.sha256 <= target:
662662
# Rehash nonces until an invalid too-high-hash block is found.
663663
b47.nNonce += 1
664-
b47.rehash()
665664
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True)
666665

667666
self.log.info("Reject a block with a timestamp >2 hours in the future")

test/functional/feature_maxuploadtarget.py

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

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

4746
class MaxUploadTest(BitcoinTestFramework):

test/functional/feature_taproot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,6 @@ def gen_test_vectors(self):
15741574
assert coinbase.txid_hex == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20"
15751575
# Mine it
15761576
block = create_block(hashprev=int(self.nodes[0].getbestblockhash(), 16), coinbase=coinbase)
1577-
block.rehash()
15781577
block.solve()
15791578
self.nodes[0].submitblock(block.serialize().hex())
15801579
assert_equal(self.nodes[0].getblockcount(), 1)

test/functional/mining_mainnet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def mine(self, height, prev_hash, blocks, node, fees=0):
6666
block.vtx[0].nLockTime = 0
6767
block.vtx[0].vin[0].nSequence = SEQUENCE_FINAL
6868
block.hashMerkleRoot = block.calc_merkle_root()
69-
block.rehash()
7069
block_hex = block.serialize(with_witness=False).hex()
7170
self.log.debug(block_hex)
7271
assert_equal(node.submitblock(block_hex), None)

test/functional/mining_template_verification.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def pow_test(self, node, block):
158158
# Ensure that it doesn't meet the target by coincidence
159159
while block.sha256 <= target:
160160
block.nNonce += 1
161-
block.rehash()
162161
self.log.debug("Found a nonce")
163162

164163
self.log.info("A block template doesn't need PoW")

test/functional/p2p_compactblocks.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ def on_sendcmpct(self, message):
8080

8181
def on_cmpctblock(self, message):
8282
self.block_announced = True
83-
self.last_message["cmpctblock"].header_and_shortids.header.calc_sha256()
8483
self.announced_blockhashes.add(self.last_message["cmpctblock"].header_and_shortids.header.sha256)
8584

8685
def on_headers(self, message):
8786
self.block_announced = True
8887
for x in self.last_message["headers"].headers:
89-
x.calc_sha256()
9088
self.announced_blockhashes.add(x.sha256)
9189

9290
def on_inv(self, message):
@@ -308,7 +306,6 @@ def test_compactblock_construction(self, test_node):
308306

309307
# Store the raw block in our internal format.
310308
block = from_hex(CBlock(), node.getblock("%064x" % block_hash, False))
311-
block.rehash()
312309

313310
# Wait until the block was announced (via compact blocks)
314311
test_node.wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30)
@@ -336,7 +333,6 @@ def test_compactblock_construction(self, test_node):
336333

337334
def check_compactblock_construction_from_block(self, header_and_shortids, block_hash, block):
338335
# Check that we got the right block!
339-
header_and_shortids.header.calc_sha256()
340336
assert_equal(header_and_shortids.header.sha256, block_hash)
341337

342338
# Make sure the prefilled_txn appears to have included the coinbase
@@ -599,7 +595,6 @@ def test_getblocktxn_handler(self, test_node):
599595
test_node.last_message.pop("blocktxn", None)
600596
test_node.send_and_ping(msg)
601597
with p2p_lock:
602-
test_node.last_message["block"].block.calc_sha256()
603598
assert_equal(test_node.last_message["block"].block.sha256, int(block_hash, 16))
604599
assert "blocktxn" not in test_node.last_message
605600

@@ -656,7 +651,6 @@ def test_compactblocks_not_at_tip(self, test_node):
656651
test_node.send_without_ping(msg_getdata([CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))]))
657652
test_node.wait_until(lambda: "block" in test_node.last_message, timeout=30)
658653
with p2p_lock:
659-
test_node.last_message["block"].block.calc_sha256()
660654
assert_equal(test_node.last_message["block"].block.sha256, int(new_blocks[0], 16))
661655

662656
# Generate an old compactblock, and verify that it's not accepted.
@@ -705,7 +699,6 @@ def test_end_to_end_block_relay(self, listeners):
705699
l.wait_until(lambda: "cmpctblock" in l.last_message, timeout=30)
706700
with p2p_lock:
707701
for l in listeners:
708-
l.last_message["cmpctblock"].header_and_shortids.header.calc_sha256()
709702
assert_equal(l.last_message["cmpctblock"].header_and_shortids.header.sha256, block.sha256)
710703

711704
# Test that we don't get disconnected if we relay a compact block with valid header,

test/functional/p2p_compactblocks_blocksonly.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def build_block_on_tip(self):
3636
blockhash = self.generate(self.nodes[2], 1, sync_fun=self.no_op)[0]
3737
block_hex = self.nodes[2].getblock(blockhash=blockhash, verbosity=0)
3838
block = from_hex(CBlock(), block_hex)
39-
block.rehash()
4039
return block
4140

4241
def run_test(self):

test/functional/p2p_getdata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def __init__(self):
1919
self.blocks = defaultdict(int)
2020

2121
def on_block(self, message):
22-
message.block.calc_sha256()
2322
self.blocks[message.block.sha256] += 1
2423

2524

0 commit comments

Comments
 (0)