@@ -630,17 +630,19 @@ def run_test(self):
630
630
631
631
self .log .info ("Reject a block with invalid work" )
632
632
self .move_tip (44 )
633
- b47 = self .next_block (47 , solve = False )
633
+ b47 = self .next_block (47 )
634
634
target = uint256_from_compact (b47 .nBits )
635
635
while b47 .sha256 <= target :
636
+ # Rehash nonces until an invalid too-high-hash block is found.
636
637
b47 .nNonce += 1
637
638
b47 .rehash ()
638
639
self .send_blocks ([b47 ], False , force_send = True , reject_reason = 'high-hash' , reconnect = True )
639
640
640
641
self .log .info ("Reject a block with a timestamp >2 hours in the future" )
641
642
self .move_tip (44 )
642
- b48 = self .next_block (48 , solve = False )
643
+ b48 = self .next_block (48 )
643
644
b48 .nTime = int (time .time ()) + 60 * 60 * 3
645
+ # Header timestamp has changed. Re-solve the block.
644
646
b48 .solve ()
645
647
self .send_blocks ([b48 ], False , force_send = True , reject_reason = 'time-too-new' )
646
648
@@ -1321,7 +1323,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
1321
1323
tx .rehash ()
1322
1324
return tx
1323
1325
1324
- def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), solve = True , * , version = 1 ):
1326
+ def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), * , version = 1 ):
1325
1327
if self .tip is None :
1326
1328
base_block_hash = self .genesis_hash
1327
1329
block_time = int (time .time ()) + 1
@@ -1343,10 +1345,8 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
1343
1345
self .sign_tx (tx , spend )
1344
1346
self .add_transactions_to_block (block , [tx ])
1345
1347
block .hashMerkleRoot = block .calc_merkle_root ()
1346
- if solve :
1347
- block .solve ()
1348
- else :
1349
- block .rehash ()
1348
+ # Block is created. Find a valid nonce.
1349
+ block .solve ()
1350
1350
self .tip = block
1351
1351
self .block_heights [block .sha256 ] = height
1352
1352
assert number not in self .blocks
0 commit comments