def test_compactblock_reconstruction_multiple_peers(self, stalling_peer, delivery_peer):
    node = self.nodes[0]
    assert len(self.utxos)

    def announce_cmpct_block(node, peer):
        utxo = self.utxos.pop(0)
        block = self.build_block_with_transactions(node, utxo, 5)
        cmpct_block = HeaderAndShortIDs()
        cmpct_block.initialize_from_block(block)
        msg = msg_cmpctblock(cmpct_block.to_p2p())
        peer.send_and_ping(msg)
        with mininode_lock:
            assert ('getblocktxn' in peer.last_message)
        return (block, cmpct_block)
    (block, cmpct_block) = announce_cmpct_block(node, stalling_peer)
    for tx in block.vtx[1:]:
        delivery_peer.send_message(msg_tx(tx))
    delivery_peer.sync_with_ping()
    mempool = node.getrawmempool()
    for tx in block.vtx[1:]:
        assert (tx.hash in mempool)
    delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)
    self.utxos.append([block.vtx[(- 1)].sha256, 0, block.vtx[(- 1)].vout[0].nValue])
    (block, cmpct_block) = announce_cmpct_block(node, stalling_peer)
    for tx in block.vtx[1:]:
        delivery_peer.send_message(msg_tx(tx))
    delivery_peer.sync_with_ping()
    cmpct_block.prefilled_txn[0].tx.wit.vtxinwit = [CTxInWitness()]
    cmpct_block.prefilled_txn[0].tx.wit.vtxinwit[0].scriptWitness.stack = [ser_uint256(0)]
    cmpct_block.use_witness = True
    delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
    assert (int(node.getbestblockhash(), 16) != block.sha256)
    msg = msg_no_witness_blocktxn()
    msg.block_transactions.blockhash = block.sha256
    msg.block_transactions.transactions = block.vtx[1:]
    stalling_peer.send_and_ping(msg)
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)
def test_compactblock_reconstruction_multiple_peers(self, stalling_peer, delivery_peer):
    node = self.nodes[0]
    assert len(self.utxos)

    def announce_cmpct_block(node, peer):
        utxo = self.utxos.pop(0)
        block = self.build_block_with_transactions(node, utxo, 5)
        cmpct_block = HeaderAndShortIDs()
        cmpct_block.initialize_from_block(block)
        msg = msg_cmpctblock(cmpct_block.to_p2p())
        peer.send_and_ping(msg)
        with mininode_lock:
            assert ('getblocktxn' in peer.last_message)
        return (block, cmpct_block)
    (block, cmpct_block) = announce_cmpct_block(node, stalling_peer)
    for tx in block.vtx[1:]:
        delivery_peer.send_message(msg_tx(tx))
    delivery_peer.sync_with_ping()
    mempool = node.getrawmempool()
    for tx in block.vtx[1:]:
        assert (tx.hash in mempool)
    delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)
    self.utxos.append([block.vtx[(- 1)].sha256, 0, block.vtx[(- 1)].vout[0].nValue])
    (block, cmpct_block) = announce_cmpct_block(node, stalling_peer)
    for tx in block.vtx[1:]:
        delivery_peer.send_message(msg_tx(tx))
    delivery_peer.sync_with_ping()
    cmpct_block.prefilled_txn[0].tx.wit.vtxinwit = [CTxInWitness()]
    cmpct_block.prefilled_txn[0].tx.wit.vtxinwit[0].scriptWitness.stack = [ser_uint256(0)]
    cmpct_block.use_witness = True
    delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
    assert (int(node.getbestblockhash(), 16) != block.sha256)
    msg = msg_no_witness_blocktxn()
    msg.block_transactions.blockhash = block.sha256
    msg.block_transactions.transactions = block.vtx[1:]
    stalling_peer.send_and_ping(msg)
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)