@@ -310,6 +310,9 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
310
310
tip = int (node .getbestblockhash (), 16 )
311
311
assert (test_node .wait_for_block_announcement (tip ))
312
312
313
+ # Make sure we will receive a fast-announce compact block
314
+ self .request_cb_announcements (test_node , node , version )
315
+
313
316
# Now mine a block, and look at the resulting compact block.
314
317
test_node .clear_block_announcement ()
315
318
block_hash = int (node .generate (1 )[0 ], 16 )
@@ -319,27 +322,36 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
319
322
[tx .calc_sha256 () for tx in block .vtx ]
320
323
block .rehash ()
321
324
322
- # Don't care which type of announcement came back for this test; just
323
- # request the compact block if we didn't get one yet.
325
+ # Wait until the block was announced (via compact blocks)
324
326
wait_until (test_node .received_block_announcement , timeout = 30 )
325
327
assert (test_node .received_block_announcement ())
326
328
329
+ # Now fetch and check the compact block
330
+ header_and_shortids = None
331
+ with mininode_lock :
332
+ assert (test_node .last_cmpctblock is not None )
333
+ # Convert the on-the-wire representation to absolute indexes
334
+ header_and_shortids = HeaderAndShortIDs (test_node .last_cmpctblock .header_and_shortids )
335
+ self .check_compactblock_construction_from_block (version , header_and_shortids , block_hash , block )
336
+
337
+ # Now fetch the compact block using a normal non-announce getdata
327
338
with mininode_lock :
328
- if test_node .last_cmpctblock is None :
329
- test_node .clear_block_announcement ()
330
- inv = CInv (4 , block_hash ) # 4 == "CompactBlock"
331
- test_node .send_message (msg_getdata ([inv ]))
339
+ test_node .clear_block_announcement ()
340
+ inv = CInv (4 , block_hash ) # 4 == "CompactBlock"
341
+ test_node .send_message (msg_getdata ([inv ]))
332
342
333
343
wait_until (test_node .received_block_announcement , timeout = 30 )
334
344
assert (test_node .received_block_announcement ())
335
345
336
- # Now we should have the compactblock
346
+ # Now fetch and check the compact block
337
347
header_and_shortids = None
338
348
with mininode_lock :
339
349
assert (test_node .last_cmpctblock is not None )
340
350
# Convert the on-the-wire representation to absolute indexes
341
351
header_and_shortids = HeaderAndShortIDs (test_node .last_cmpctblock .header_and_shortids )
352
+ self .check_compactblock_construction_from_block (version , header_and_shortids , block_hash , block )
342
353
354
+ def check_compactblock_construction_from_block (self , version , header_and_shortids , block_hash , block ):
343
355
# Check that we got the right block!
344
356
header_and_shortids .header .calc_sha256 ()
345
357
assert_equal (header_and_shortids .header .sha256 , block_hash )
0 commit comments