From d5535dbdfdfcba305aeb160fca0a829cf38cb08a Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 22 Apr 2013 12:45:37 -0700 Subject: [PATCH] More fetch pack work. --- src/cpp/ripple/LedgerAcquire.cpp | 8 ++++- src/cpp/ripple/LedgerMaster.cpp | 58 ++++++++++++++++++-------------- src/cpp/ripple/NetworkOPs.cpp | 1 - 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/cpp/ripple/LedgerAcquire.cpp b/src/cpp/ripple/LedgerAcquire.cpp index 99bbf7ed5..51da537be 100644 --- a/src/cpp/ripple/LedgerAcquire.cpp +++ b/src/cpp/ripple/LedgerAcquire.cpp @@ -118,7 +118,7 @@ bool LedgerAcquire::tryLocal() std::vector data; if (!theApp->getOPs().getFetchPack(mHash, data)) return false; - cLog(lsINFO) << "Ledger base found in fetch pack"; + cLog(lsTRACE) << "Ledger base found in fetch pack"; mLedger = boost::make_shared(data, true); theApp->getHashedObjectStore().store(hotLEDGER, mLedger->getLedgerSeq(), data, mHash); } @@ -792,7 +792,13 @@ LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash) ptr->setTimer(); // Cannot call in constructor } else + { + Ledger::pointer ledger = ptr->getLedger(); + ledger->setClosed(); + ledger->setImmutable(); + theApp->getLedgerMaster().storeLedger(ledger); cLog(lsDEBUG) << "Acquiring ledger we already have: " << hash; + } return ptr; } diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 0e9f08da3..6368a580e 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -251,6 +251,38 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l theApp->getIOService().post(boost::bind(&LedgerMaster::missingAcquireComplete, this, mMissingLedger)); } + int fetchMax = theConfig.getSize(siLedgerFetch); + int timeoutCount; + int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount); + + if ((fetchCount < fetchMax) && theApp->getOPs().isFull()) + { + if (timeoutCount > 2) + { + cLog(lsDEBUG) << "Not acquiring due to timeouts"; + } + else + { + typedef std::pair u_pair; + std::vector vec = origLedger->getLedgerHashes(); + BOOST_FOREACH(const u_pair& it, vec) + { + if ((fetchCount < fetchMax) && (it.first < ledgerSeq) && + !mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second)) + { + LedgerAcquire::pointer acq = theApp->getMasterLedgerAcquire().findCreate(it.second); + if (acq && acq->isComplete()) + { + acq->getLedger()->setAccepted(); + setFullLedger(acq->getLedger()); + mLedgerHistory.addAcceptedLedger(acq->getLedger(), false); + } + else ++fetchCount; + } + } + } + } + if (theApp->getOPs().shouldFetchPack()) { // refill our fetch pack Ledger::pointer nextLedger = mLedgerHistory.getLedgerBySeq(ledgerSeq + 1); @@ -286,32 +318,6 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l } } - int fetchMax = theConfig.getSize(siLedgerFetch); - int timeoutCount; - int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount); - - if ((fetchCount < fetchMax) && theApp->getOPs().isFull()) - { - if (timeoutCount > 2) - { - cLog(lsDEBUG) << "Not acquiring due to timeouts"; - } - else - { - typedef std::pair u_pair; - std::vector vec = origLedger->getLedgerHashes(); - BOOST_FOREACH(const u_pair& it, vec) - { - if ((fetchCount < fetchMax) && (it.first < ledgerSeq) && - !mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second)) - { - ++fetchCount; - theApp->getMasterLedgerAcquire().findCreate(it.second); - } - } - } - } - return true; } diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 1491d47fe..45ef05104 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -2088,7 +2088,6 @@ bool NetworkOPs::getFetchPack(const uint256& hash, std::vector& d cLog(lsWARNING) << "Bad entry in fetch pack"; return false; } - cLog(lsINFO) << hash << " found in fetch pack"; return true; }