@@ -874,7 +874,7 @@ def run_test(self):
874
874
# \-> b67 (20)
875
875
#
876
876
#
877
- self .log .info ("Reject a block with a transaction double spending a transaction creted in the same block" )
877
+ self .log .info ("Reject a block with a transaction double spending a transaction created in the same block" )
878
878
self .move_tip (65 )
879
879
b67 = self .next_block (67 )
880
880
tx1 = self .create_and_sign_transaction (out [20 ], out [20 ].vout [0 ].nValue )
@@ -1169,7 +1169,7 @@ def run_test(self):
1169
1169
blocks = []
1170
1170
spend = out [32 ]
1171
1171
for i in range (89 , LARGE_REORG_SIZE + 89 ):
1172
- b = self .next_block (i , spend )
1172
+ b = self .next_block (i , spend , version = 4 )
1173
1173
tx = CTransaction ()
1174
1174
script_length = MAX_BLOCK_BASE_SIZE - len (b .serialize ()) - 69
1175
1175
script_output = CScript ([b'\x00 ' * script_length ])
@@ -1188,20 +1188,32 @@ def run_test(self):
1188
1188
self .move_tip (88 )
1189
1189
blocks2 = []
1190
1190
for i in range (89 , LARGE_REORG_SIZE + 89 ):
1191
- blocks2 .append (self .next_block ("alt" + str (i )))
1191
+ blocks2 .append (self .next_block ("alt" + str (i ), version = 4 ))
1192
1192
self .sync_blocks (blocks2 , False , force_send = True )
1193
1193
1194
1194
# extend alt chain to trigger re-org
1195
- block = self .next_block ("alt" + str (chain1_tip + 1 ))
1195
+ block = self .next_block ("alt" + str (chain1_tip + 1 ), version = 4 )
1196
1196
self .sync_blocks ([block ], True , timeout = 480 )
1197
1197
1198
1198
# ... and re-org back to the first chain
1199
1199
self .move_tip (chain1_tip )
1200
- block = self .next_block (chain1_tip + 1 )
1200
+ block = self .next_block (chain1_tip + 1 , version = 4 )
1201
1201
self .sync_blocks ([block ], False , force_send = True )
1202
- block = self .next_block (chain1_tip + 2 )
1202
+ block = self .next_block (chain1_tip + 2 , version = 4 )
1203
1203
self .sync_blocks ([block ], True , timeout = 480 )
1204
1204
1205
+ self .log .info ("Reject a block with an invalid block header version" )
1206
+ b_v1 = self .next_block ('b_v1' , version = 1 )
1207
+ self .sync_blocks ([b_v1 ], success = False , force_send = True , reject_reason = 'bad-version(0x00000001)' )
1208
+
1209
+ self .move_tip (chain1_tip + 2 )
1210
+ b_cb34 = self .next_block ('b_cb34' , version = 4 )
1211
+ b_cb34 .vtx [0 ].vin [0 ].scriptSig = b_cb34 .vtx [0 ].vin [0 ].scriptSig [:- 1 ]
1212
+ b_cb34 .vtx [0 ].rehash ()
1213
+ b_cb34 .hashMerkleRoot = b_cb34 .calc_merkle_root ()
1214
+ b_cb34 .solve ()
1215
+ self .sync_blocks ([b_cb34 ], success = False , reject_reason = 'bad-cb-height' , reconnect = True )
1216
+
1205
1217
# Helper methods
1206
1218
################
1207
1219
@@ -1229,7 +1241,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
1229
1241
tx .rehash ()
1230
1242
return tx
1231
1243
1232
- def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), solve = True ):
1244
+ def next_block (self , number , spend = None , additional_coinbase_value = 0 , script = CScript ([OP_TRUE ]), solve = True , * , version = 1 ):
1233
1245
if self .tip is None :
1234
1246
base_block_hash = self .genesis_hash
1235
1247
block_time = int (time .time ()) + 1
@@ -1242,11 +1254,11 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
1242
1254
coinbase .vout [0 ].nValue += additional_coinbase_value
1243
1255
coinbase .rehash ()
1244
1256
if spend is None :
1245
- block = create_block (base_block_hash , coinbase , block_time )
1257
+ block = create_block (base_block_hash , coinbase , block_time , version = version )
1246
1258
else :
1247
1259
coinbase .vout [0 ].nValue += spend .vout [0 ].nValue - 1 # all but one satoshi to fees
1248
1260
coinbase .rehash ()
1249
- block = create_block (base_block_hash , coinbase , block_time )
1261
+ block = create_block (base_block_hash , coinbase , block_time , version = version )
1250
1262
tx = self .create_tx (spend , 0 , 1 , script ) # spend 1 satoshi
1251
1263
self .sign_tx (tx , spend )
1252
1264
self .add_transactions_to_block (block , [tx ])
0 commit comments