A few more fixes.

This commit is contained in:
JoelKatz
2013-08-11 22:21:48 -07:00
parent 9a1e7e69c2
commit 8b06891663
4 changed files with 26 additions and 15 deletions

View File

@@ -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<Ledger::pointer> 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<Ledger::pointer> 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);

View File

@@ -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 ()

View File

@@ -71,7 +71,7 @@ public:
void addPeers ();
void awaitData ();
void noAwaitData ();
void checkLocal ();
bool checkLocal ();
typedef std::pair <protocol::TMGetObjectByHash::ObjectType, uint256> neededHash_t;

View File

@@ -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 ()