diff --git a/modules/ripple_app/ledger/LedgerMaster.cpp b/modules/ripple_app/ledger/LedgerMaster.cpp index c5e291e897..ffc3ea79de 100644 --- a/modules/ripple_app/ledger/LedgerMaster.cpp +++ b/modules/ripple_app/ledger/LedgerMaster.cpp @@ -561,11 +561,15 @@ void LedgerMaster::advanceThread() getFetchPack(nextLedger); if (!getApp().getInboundLedgers().isFailure(nextLedger->getParentHash())) { + sl.unlock(); InboundLedger::pointer acq = getApp().getInboundLedgers().findCreate(nextLedger->getParentHash(), nextLedger->getLedgerSeq() - 1); if (acq && acq->isComplete() && !acq->isFailed()) ledger = acq->getLedger(); + sl.lock(); + if (mValidLedger->getLedgerSeq() != mPubLedger->getLedgerSeq()) + progress = true; } } if (ledger) @@ -632,23 +636,20 @@ std::list LedgerMaster::findNewLedgersToPublish() } else if (mValidLedger->getLedgerSeq () > mPubLedger->getLedgerSeq ()) { - int acq = 0; + int acqCount = 0; for (uint32 seq = mPubLedger->getLedgerSeq () + 1; seq <= mValidLedger->getLedgerSeq (); ++seq) { WriteLog (lsTRACE, LedgerMaster) << "Trying to publish ledger " << seq; Ledger::pointer ledger; - uint256 hash; + uint256 hash = mValidLedger->getLedgerHash (seq); if (seq == mValidLedger->getLedgerSeq ()) { // We need to publish the ledger we just fully validated ledger = mValidLedger; - hash = ledger->getHash (); } else { - hash = mValidLedger->getLedgerHash (seq); - if (hash.isZero ()) { WriteLog (lsFATAL, LedgerMaster) << "Ledger: " << mValidLedger->getLedgerSeq () << " does not have hash for " << @@ -659,7 +660,7 @@ std::list LedgerMaster::findNewLedgersToPublish() ledger = mLedgerHistory.getLedgerByHash (hash); } - if (!ledger && (++acq < 4)) + if (!ledger && (++acqCount < 4)) { // We can try to acquire the ledger we need InboundLedger::pointer acq = getApp().getInboundLedgers ().findCreate (hash, seq); diff --git a/modules/ripple_app/ledger/ripple_InboundLedger.cpp b/modules/ripple_app/ledger/ripple_InboundLedger.cpp index 3439b3726d..2b88800a5a 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedger.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedger.cpp @@ -29,15 +29,22 @@ InboundLedger::InboundLedger (uint256 const& hash, uint32 seq) tryLocal (); } -void InboundLedger::checkLocal () +// Returns true if progress is made +bool InboundLedger::checkLocal () { - boost::recursive_mutex::scoped_lock sl (mLock); + bool ret = false; - if (isDone ()) - return; + { + boost::recursive_mutex::scoped_lock sl (mLock); - if (tryLocal ()) - done (); + if (!isDone () && tryLocal()) + { + done(); + ret = true; + } + } + + return ret; } bool InboundLedger::tryLocal () diff --git a/modules/ripple_app/ledger/ripple_InboundLedger.h b/modules/ripple_app/ledger/ripple_InboundLedger.h index 9085fc1641..7bcdb67d82 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedger.h +++ b/modules/ripple_app/ledger/ripple_InboundLedger.h @@ -71,7 +71,7 @@ public: void addPeers (); void awaitData (); void noAwaitData (); - void checkLocal (); + bool checkLocal (); typedef std::pair neededHash_t; diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp index fd4b94cd98..2fbb411857 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp @@ -257,12 +257,15 @@ void InboundLedgers::gotFetchPack (Job&) acquires.push_back (it.second); } + bool progress = false; BOOST_FOREACH (const InboundLedger::pointer & acquire, acquires) { - acquire->checkLocal (); + if (acquire->checkLocal ()) + progress = true; } - getApp().getLedgerMaster().tryAdvance(); + if (progress) + getApp().getLedgerMaster().tryAdvance(); } void InboundLedgers::clearFailures ()