示例#1
0
 void test() {
     const pretype& const_pre_vector = pre_vector;
     local_check_equal(real_vector.size(), pre_vector.size());
     local_check_equal(real_vector.empty(), pre_vector.empty());
     for (Size s = 0; s < real_vector.size(); s++) {
          local_check(real_vector[s] == pre_vector[s]);
          local_check(&(pre_vector[s]) == &(pre_vector.begin()[s]));
          local_check(&(pre_vector[s]) == &*(pre_vector.begin() + s));
          local_check(&(pre_vector[s]) == &*((pre_vector.end() + s) - real_vector.size()));
     }
     // local_check(realtype(pre_vector) == real_vector);
     local_check(pretype(real_vector.begin(), real_vector.end()) == pre_vector);
     local_check(pretype(pre_vector.begin(), pre_vector.end()) == pre_vector);
     size_t pos = 0;
     for (const T& v : pre_vector) {
          local_check(v == real_vector[pos++]);
     }
     for (const T& v : reverse_iterate(pre_vector)) {
          local_check(v == real_vector[--pos]);
     }
     for (const T& v : const_pre_vector) {
          local_check(v == real_vector[pos++]);
     }
     for (const T& v : reverse_iterate(const_pre_vector)) {
          local_check(v == real_vector[--pos]);
     }
     CDataStream ss1(SER_DISK, 0);
     CDataStream ss2(SER_DISK, 0);
     ss1 << real_vector;
     ss2 << pre_vector;
     local_check_equal(ss1.size(), ss2.size());
     for (Size s = 0; s < ss1.size(); s++) {
         local_check_equal(ss1[s], ss2[s]);
     }
 }
示例#2
0
    CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
    {
        const MapCheckpoints& checkpoints = data.mapCheckpoints;

        for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
        {
            const uint256& hash = i.second;
            BlockMap::const_iterator t = mapBlockIndex.find(hash);
            if (t != mapBlockIndex.end())
                return t->second;
        }
        return nullptr;
    }
示例#3
0
    CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
    {
        const MapCheckpoints& checkpoints = data.mapCheckpoints;

        for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
        {
            const uint256& hash = i.second;
            CBlockIndex* pindex = LookupBlockIndex(hash);
            if (pindex) {
                return pindex;
            }
        }
        return nullptr;
    }
示例#4
0
// vHashesToUpdate is the set of transaction hashes from a disconnected block
// which has been re-added to the mempool.
// for each entry, look for descendants that are outside vHashesToUpdate, and
// add fee/size information for such descendants to the parent.
// for each such descendant, also update the ancestor state to include the parent.
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate)
{
    LOCK(cs);
    // For each entry in vHashesToUpdate, store the set of in-mempool, but not
    // in-vHashesToUpdate transactions, so that we don't have to recalculate
    // descendants when we come across a previously seen entry.
    cacheMap mapMemPoolDescendantsToUpdate;

    // Use a set for lookups into vHashesToUpdate (these entries are already
    // accounted for in the state of their ancestors)
    std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());

    // Iterate in reverse, so that whenever we are looking at a transaction
    // we are sure that all in-mempool descendants have already been processed.
    // This maximizes the benefit of the descendant cache and guarantees that
    // setMemPoolChildren will be updated, an assumption made in
    // UpdateForDescendants.
    for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
        // we cache the in-mempool children to avoid duplicate updates
        setEntries setChildren;
        // calculate children from mapNextTx
        txiter it = mapTx.find(hash);
        if (it == mapTx.end()) {
            continue;
        }
        auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
        // First calculate the children, and update setMemPoolChildren to
        // include them, and update their setMemPoolParents to include this tx.
        for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
            const uint256 &childHash = iter->second->GetHash();
            txiter childIter = mapTx.find(childHash);
            assert(childIter != mapTx.end());
            // We can skip updating entries we've encountered before or that
            // are in the block (which are already accounted for).
            if (setChildren.insert(childIter).second && !setAlreadyIncluded.count(childHash)) {
                UpdateChild(it, childIter, true);
                UpdateParent(childIter, it, true);
            }
        }
        UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
    }
}