std::error_code organizer_impl::verify(size_t fork_index,
    const block_detail_list& orphan_chain, size_t orphan_index)
{
    BITCOIN_ASSERT(orphan_index < orphan_chain.size());
    const auto& current_block = orphan_chain[orphan_index]->actual();
    const size_t height = fork_index + orphan_index + 1;
    BITCOIN_ASSERT(height != 0);

    validate_block_impl validate(interface_, fork_index, orphan_chain,
        orphan_index, height, current_block, checkpoints_);

    auto code = validate.check_block();
    if (code)
        return code;

    code = validate.accept_block();
    if (code)
        return code;

    // Skip strict validation if above last checkpoint.
    if (fork_index > checkpoints_.last())
        code = validate.connect_block();

    return code;
}
Ejemplo n.º 2
0
std::error_code leveldb_organizer::verify(int fork_index,
    const block_detail_list& orphan_chain, int orphan_index)
{
    BITCOIN_ASSERT(orphan_index < orphan_chain.size());
    const block_type& current_block = orphan_chain[orphan_index]->actual();
    size_t depth = fork_index + orphan_index + 1;
    BITCOIN_ASSERT(depth != 0);
    leveldb_validate_block validate(common_, fork_index, orphan_chain,
        orphan_index, depth, current_block);
    return validate.start();
}
std::error_code organizer_impl::verify(size_t fork_point,
    const block_detail_list& orphan_chain, size_t orphan_index)
{
    BITCOIN_ASSERT(orphan_index < orphan_chain.size());
    const auto& current_block = orphan_chain[orphan_index]->actual();
    const size_t height = fork_point + orphan_index + 1;
    BITCOIN_ASSERT(height != 0);

    validate_block_impl validate(interface_, fork_point, orphan_chain,
        orphan_index, height, current_block, checkpoints_);

    // Checks that are independent of the chain.
    auto ec = validate.check_block();
    if (ec)
        return ec;

    // Checks that are dependent on height and preceding blocks.
    ec = validate.accept_block();
    if (ec)
        return ec;

    // Start strict validation if past last checkpoint.
    if (strict(fork_point))
    {
        const auto total_inputs = count_inputs(current_block);
        const auto total_transactions = current_block.transactions.size();

        log_info(LOG_BLOCKCHAIN)
            << "Block [" << height << "] verify ("
            << total_transactions << ") txs and ("
            << total_inputs << ") inputs";

        // Time this for logging.
        const auto timed = [&ec, &validate]()
        {
            // Checks that include input->output traversal.
            ec = validate.connect_block();
        };

        // Execute the timed validation.
        const auto elapsed = timer<std::chrono::milliseconds>::duration(timed);
        const auto ms_per_block = static_cast<float>(elapsed.count());
        const auto ms_per_input = ms_per_block / total_inputs;
        const auto secs_per_block = ms_per_block / 1000;
        const auto verified = ec ? "unverified" : "verified";

        log_info(LOG_BLOCKCHAIN)
            << "Block [" << height << "] " << verified << " in ("
            << secs_per_block << ") secs or ("
            << ms_per_input << ") ms/input";
    }

    return ec;
}
Ejemplo n.º 4
0
std::error_code leveldb_organizer::verify(size_t fork_index,
    const block_detail_list& orphan_chain, size_t orphan_index)
{
    BITCOIN_ASSERT(orphan_index < orphan_chain.size());
    const block_type& current_block = orphan_chain[orphan_index]->actual();
    size_t height = fork_index + orphan_index + 1;
    BITCOIN_ASSERT(height != 0);
    leveldb_validate_block validate(common_, fork_index, orphan_chain,
        orphan_index, height, current_block);
    // Perform checks.
    std::error_code ec;
    ec = validate.check_block();
    if (ec)
        return ec;
    ec = validate.accept_block();
    if (ec)
        return ec;
    // Skip non-essential checks if before last checkpoint.
    if (fork_index < 278702)
        return std::error_code();
    // Perform strict but slow tests - connect_block()
    return validate.connect_block();
}