void transaction_pool::reorganize(const std::error_code& ec,
    size_t /* fork_point */, const blockchain::block_list& new_blocks,
    const blockchain::block_list& replaced_blocks)
{
    if (ec)
    {
        BITCOIN_ASSERT(ec == error::service_stopped);
        return;
    }

    log_debug(LOG_BLOCKCHAIN)
        << "Reorganize: tx pool size (" << buffer_.size()
        << ") new blocks (" << new_blocks.size()
        << ") replace blocks (" << replaced_blocks.size() << ")";

    if (replaced_blocks.empty())
        strand_.queue(
            std::bind(&transaction_pool::delete_confirmed,
                this, new_blocks));
    else
        strand_.queue(
            std::bind(&transaction_pool::invalidate_pool,
                this));

    // new blocks come in - remove txs in new
    // old blocks taken out - resubmit txs in old
    blockchain_.subscribe_reorganize(
        std::bind(&transaction_pool::reorganize,
            this, _1, _2, _3, _4));
}
void server_node::reorganize(const std::error_code& /* ec */,
    size_t fork_point,
    const blockchain::block_list& new_blocks,
    const blockchain::block_list& /* replaced_blocks */)
{
    // magic number (height) - how does this apply to testnet?
    // Don't bother publishing blocks when in the initial blockchain download.
    if (fork_point > 235866)
        for (size_t i = 0; i < new_blocks.size(); ++i)
        {
            size_t height = fork_point + i + 1;
            const block_type& blk = *new_blocks[i];
            for (const auto notify: notify_blocks_)
                notify(height, blk);
        }
    chain_.subscribe_reorganize(
        std::bind(&server_node::reorganize, this, _1, _2, _3, _4));
}
Exemple #3
0
void session::set_start_depth(const std::error_code& ec, size_t fork_point,
    const blockchain::block_list& new_blocks,
    const blockchain::block_list& replaced_blocks)
{
    size_t last_depth = fork_point + new_blocks.size();
    handshake_.set_start_depth(last_depth, handle_set_start_depth);
    chain_.subscribe_reorganize(
        std::bind(&session::set_start_depth,
            this, _1, _2, _3, _4));
    // Broadcast invs of new blocks
    inventory_type blocks_inv;
    for (auto block: new_blocks)
    {
        blocks_inv.inventories.push_back({
            inventory_type_id::block,
            hash_block_header(*block)});
    }
    protocol_.broadcast(blocks_inv);
}