Exemplo n.º 1
0
 // VFALCO TODO This should return boost::optional<uint256>
 LedgerHash getLedgerHash(Ledger::pointer ledger, LedgerIndex index)
 {
     boost::optional<LedgerHash> hash;
     try
     {
         hash = hashOfSeq(*ledger, index,
             getApp().getSLECache(), m_journal);
     }
     catch (SHAMapMissingNode &)
     {
         m_journal.warning <<
             "Node missing from ledger " << ledger->getLedgerSeq();
         getApp().getInboundLedgers().acquire (
             ledger->getHash(), ledger->getLedgerSeq(), InboundLedger::fcGENERIC);
     }
     return hash ? *hash : zero; // kludge
 }
Exemplo n.º 2
0
 // VFALCO TODO This should return boost::optional<uint256>
 LedgerHash getLedgerHash(
     std::shared_ptr<ReadView const>& ledger,
     LedgerIndex index)
 {
     boost::optional<LedgerHash> hash;
     try
     {
         hash = hashOfSeq(*ledger, index, j_);
     }
     catch (SHAMapMissingNode &)
     {
         JLOG (j_.warn()) <<
             "Node missing from ledger " << ledger->info().seq;
         app_.getInboundLedgers().acquire (
             ledger->info().hash, ledger->info().seq,
             InboundLedger::fcGENERIC);
     }
     return hash ? *hash : zero; // kludge
 }
Exemplo n.º 3
0
    void
    testSkipList()
    {
        beast::Journal const j;
        std::vector<std::shared_ptr<Ledger>> history;
        {
            jtx::Env env(*this);
            Config config;
            auto prev =
                std::make_shared<Ledger>(create_genesis, config, env.app().family());
            history.push_back(prev);
            for (auto i = 0; i < 1023; ++i)
            {
                auto next = std::make_shared<Ledger>(
                    *prev,
                    env.app().timeKeeper().closeTime());
                next->updateSkipList();
                history.push_back(next);
                prev = next;
            }
        }

        {
            auto l = *(std::next(std::begin(history)));
            expect((*std::begin(history))->info().seq <
                l->info().seq);
            expect(hashOfSeq(*l, l->info().seq + 1,
                j) == boost::none);
            expect(hashOfSeq(*l, l->info().seq,
                j) == l->info().hash);
            expect(hashOfSeq(*l, l->info().seq - 1,
                j) == l->info().parentHash);
            expect(hashOfSeq(*history.back(),
                l->info().seq, j) == boost::none);
        }

        // ledger skip lists store up to the previous 256 hashes
        for (auto i = history.crbegin();
            i != history.crend(); i += 256)
        {
            for (auto n = i;
                n != std::next(i,
                    (*i)->info().seq - 256 > 1 ? 257 : 256);
                ++n)
            {
                expect(hashOfSeq(**i,
                    (*n)->info().seq, j) ==
                        (*n)->info().hash);
            }

            // edge case accessing beyond 256
            expect(hashOfSeq(**i,
                (*i)->info().seq - 258, j) ==
                    boost::none);
        }

        // every 256th hash beyond the first 256 is stored
        for (auto i = history.crbegin();
            i != std::next(history.crend(), -512);
            i += 256)
        {
            for (auto n = std::next(i, 512);
                n != history.crend();
                n += 256)
            {
                expect(hashOfSeq(**i,
                    (*n)->info().seq, j) ==
                        (*n)->info().hash);
            }
        }
    }