@@ -925,7 +925,7 @@ def run_test(self):
925
925
# \-> b67 (20)
926
926
#
927
927
#
928
- self .log .info ("Reject a block with a transaction double spending a transaction creted in the same block" )
928
+ self .log .info ("Reject a block with a transaction double spending a transaction created in the same block" )
929
929
self .move_tip (65 )
930
930
b67 = self .next_block (67 )
931
931
tx1 = self .create_and_sign_transaction (out [20 ], out [20 ].vout [0 ].nValue )
@@ -1220,7 +1220,7 @@ def run_test(self):
1220
1220
blocks = []
1221
1221
spend = out [32 ]
1222
1222
for i in range (89 , LARGE_REORG_SIZE + 89 ):
1223
- b = self .next_block (i , spend )
1223
+ b = self .next_block (i , spend , version = 4 )
1224
1224
tx = CTransaction ()
1225
1225
script_length = MAX_BLOCK_BASE_SIZE - len (b .serialize ()) - 69
1226
1226
script_output = CScript ([b'\x00 ' * script_length ])
@@ -1239,20 +1239,32 @@ def run_test(self):
1239
1239
self .move_tip (88 )
1240
1240
blocks2 = []
1241
1241
for i in range (89 , LARGE_REORG_SIZE + 89 ):
1242
- blocks2 .append (self .next_block ("alt" + str (i )))
1242
+ blocks2 .append (self .next_block ("alt" + str (i ), version = 4 ))
1243
1243
self .sync_blocks (blocks2 , False , force_send = True )
1244
1244
1245
1245
# extend alt chain to trigger re-org
1246
- block = self .next_block ("alt" + str (chain1_tip + 1 ))
1246
+ block = self .next_block ("alt" + str (chain1_tip + 1 ), version = 4 )
1247
1247
self .sync_blocks ([block ], True , timeout = 480 )
1248
1248
1249
1249
# ... and re-org back to the first chain
1250
1250
self .move_tip (chain1_tip )
1251
- block = self .next_block (chain1_tip + 1 )
1251
+ block = self .next_block (chain1_tip + 1 , version = 4 )
1252
1252
self .sync_blocks ([block ], False , force_send = True )
1253
- block = self .next_block (chain1_tip + 2 )
1253
+ block = self .next_block (chain1_tip + 2 , version = 4 )
1254
1254
self .sync_blocks ([block ], True , timeout = 480 )
1255
1255
1256
+ self .log .info ("Reject a block with an invalid block header version" )
1257
+ b_v1 = self .next_block ('b_v1' , version = 1 )
1258
+ self .sync_blocks ([b_v1 ], success = False , force_send = True , reject_reason = 'bad-version(0x00000001)' )
1259
+
1260
+ self .move_tip (chain1_tip + 2 )
1261
+ b_cb34 = self .next_block ('b_cb34' , version = 4 )
1262
+ b_cb34 .vtx [0 ].vin [0 ].scriptSig = b_cb34 .vtx [0 ].vin [0 ].scriptSig [:- 1 ]
1263
+ b_cb34 .vtx [0 ].rehash ()
1264
+ b_cb34 .hashMerkleRoot = b_cb34 .calc_merkle_root ()
1265
+ b_cb34 .solve ()
1266
+ self .sync_blocks ([b_cb34 ], success = False , reject_reason = 'bad-cb-height' , reconnect = True )
1267
+
1256
1268
# Helper methods
1257
1269
################
1258
1270
@@ -1280,7 +1292,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
1280
1292
tx .rehash ()
1281
1293
return tx
1282
1294
1283
- def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), solve = True ):
1295
+ def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), solve = True , * , version = 1 ):
1284
1296
if self .tip is None :
1285
1297
base_block_hash = self .genesis_hash
1286
1298
block_time = int (time .time ()) + 1
@@ -1293,11 +1305,11 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
1293
1305
coinbase .vout [0 ].nValue += additional_coinbase_value
1294
1306
coinbase .rehash ()
1295
1307
if spend is None :
1296
- block = create_block (base_block_hash , coinbase , block_time )
1308
+ block = create_block (base_block_hash , coinbase , block_time , version = version )
1297
1309
else :
1298
1310
coinbase .vout [0 ].nValue += spend .vout [0 ].nValue - 1 # all but one satoshi to fees
1299
1311
coinbase .rehash ()
1300
- block = create_block (base_block_hash , coinbase , block_time )
1312
+ block = create_block (base_block_hash , coinbase , block_time , version = version )
1301
1313
tx = self .create_tx (spend , 0 , 1 , script ) # spend 1 satoshi
1302
1314
self .sign_tx (tx , spend )
1303
1315
self .add_transactions_to_block (block , [tx ])
0 commit comments