def test_compactblocks_not_at_tip(self, node, test_node):
    MAX_CMPCTBLOCK_DEPTH = 5
    new_blocks = []
    for i in range((MAX_CMPCTBLOCK_DEPTH + 1)):
        test_node.clear_block_announcement()
        new_blocks.append(node.generate(1)[0])
        wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
    wait_until((lambda : ('cmpctblock' in test_node.last_message)), timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    node.generate(1)
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    with mininode_lock:
        test_node.last_message.pop('block', None)
    test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
    wait_until((lambda : ('block' in test_node.last_message)), timeout=30, lock=mininode_lock)
    with mininode_lock:
        test_node.last_message['block'].block.calc_sha256()
        assert_equal(test_node.last_message['block'].block.sha256, int(new_blocks[0], 16))
    cur_height = node.getblockcount()
    hashPrevBlock = int(node.getblockhash((cur_height - 5)), 16)
    block = self.build_block_on_tip(node)
    block.hashPrevBlock = hashPrevBlock
    block.solve()
    comp_block = HeaderAndShortIDs()
    comp_block.initialize_from_block(block)
    test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
    tips = node.getchaintips()
    found = False
    for x in tips:
        if (x['hash'] == block.hash):
            assert_equal(x['status'], 'headers-only')
            found = True
            break
    assert found
    msg = msg_getblocktxn()
    msg.block_txn_request = BlockTransactionsRequest(block.sha256, [0])
    with mininode_lock:
        test_node.last_message.pop('blocktxn', None)
    test_node.send_and_ping(msg)
    with mininode_lock:
        assert ('blocktxn' not in test_node.last_message)
def test_compactblocks_not_at_tip(self, node, test_node):
    MAX_CMPCTBLOCK_DEPTH = 5
    new_blocks = []
    for i in range((MAX_CMPCTBLOCK_DEPTH + 1)):
        test_node.clear_block_announcement()
        new_blocks.append(node.generate(1)[0])
        wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
    wait_until((lambda : ('cmpctblock' in test_node.last_message)), timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    node.generate(1)
    wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
    test_node.clear_block_announcement()
    with mininode_lock:
        test_node.last_message.pop('block', None)
    test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
    wait_until((lambda : ('block' in test_node.last_message)), timeout=30, lock=mininode_lock)
    with mininode_lock:
        test_node.last_message['block'].block.calc_sha256()
        assert_equal(test_node.last_message['block'].block.sha256, int(new_blocks[0], 16))
    cur_height = node.getblockcount()
    hashPrevBlock = int(node.getblockhash((cur_height - 5)), 16)
    block = self.build_block_on_tip(node)
    block.hashPrevBlock = hashPrevBlock
    block.solve()
    comp_block = HeaderAndShortIDs()
    comp_block.initialize_from_block(block)
    test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
    tips = node.getchaintips()
    found = False
    for x in tips:
        if (x['hash'] == block.hash):
            assert_equal(x['status'], 'headers-only')
            found = True
            break
    assert found
    msg = msg_getblocktxn()
    msg.block_txn_request = BlockTransactionsRequest(block.sha256, [0])
    with mininode_lock:
        test_node.last_message.pop('blocktxn', None)
    test_node.send_and_ping(msg)
    with mininode_lock:
        assert ('blocktxn' not in test_node.last_message)