def test_compactblock_construction(self, test_node, use_witness_address=True):
    version = test_node.cmpct_version
    node = self.nodes[0]
    node.generate(101)
    num_transactions = 25
    address = node.getnewaddress()
    segwit_tx_generated = False
    for i in range(num_transactions):
        txid = node.sendtoaddress(address, 0.1)
        hex_tx = node.gettransaction(txid)['hex']
        tx = FromHex(CTransaction(), hex_tx)
        if (not tx.wit.is_null()):
            segwit_tx_generated = True
    if use_witness_address:
        assert segwit_tx_generated
    tip = int(node.getbestblockhash(), 16)
    test_node.wait_for_block_announcement(tip)
    self.request_cb_announcements(test_node)
    test_node.clear_block_announcement()
    block_hash = int(node.generate(1)[0], 16)
    block = FromHex(CBlock(), node.getblock(('%064x' % block_hash), False))
    for tx in block.vtx:
        tx.calc_sha256()
    block.rehash()
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    header_and_shortids = None
    with mininode_lock:
        assert ('cmpctblock' in test_node.last_message)
        header_and_shortids = HeaderAndShortIDs(test_node.last_message['cmpctblock'].header_and_shortids)
    self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)
    with mininode_lock:
        test_node.clear_block_announcement()
        inv = CInv(4, block_hash)
        test_node.send_message(msg_getdata([inv]))
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    header_and_shortids = None
    with mininode_lock:
        assert ('cmpctblock' in test_node.last_message)
        header_and_shortids = HeaderAndShortIDs(test_node.last_message['cmpctblock'].header_and_shortids)
    self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)
def test_compactblock_construction(self, test_node, use_witness_address=True):
    version = test_node.cmpct_version
    node = self.nodes[0]
    node.generate(101)
    num_transactions = 25
    address = node.getnewaddress()
    segwit_tx_generated = False
    for i in range(num_transactions):
        txid = node.sendtoaddress(address, 0.1)
        hex_tx = node.gettransaction(txid)['hex']
        tx = FromHex(CTransaction(), hex_tx)
        if (not tx.wit.is_null()):
            segwit_tx_generated = True
    if use_witness_address:
        assert segwit_tx_generated
    tip = int(node.getbestblockhash(), 16)
    test_node.wait_for_block_announcement(tip)
    self.request_cb_announcements(test_node)
    test_node.clear_block_announcement()
    block_hash = int(node.generate(1)[0], 16)
    block = FromHex(CBlock(), node.getblock(('%064x' % block_hash), False))
    for tx in block.vtx:
        tx.calc_sha256()
    block.rehash()
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    header_and_shortids = None
    with mininode_lock:
        assert ('cmpctblock' in test_node.last_message)
        header_and_shortids = HeaderAndShortIDs(test_node.last_message['cmpctblock'].header_and_shortids)
    self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)
    with mininode_lock:
        test_node.clear_block_announcement()
        inv = CInv(4, block_hash)
        test_node.send_message(msg_getdata([inv]))
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    header_and_shortids = None
    with mininode_lock:
        assert ('cmpctblock' in test_node.last_message)
        header_and_shortids = HeaderAndShortIDs(test_node.last_message['cmpctblock'].header_and_shortids)
    self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)