A collection of small bugfixes.

This commit is contained in:
JoelKatz
2013-02-08 16:22:27 -08:00
parent 0896825b92
commit e674bcea36
5 changed files with 74 additions and 58 deletions

View File

@@ -115,15 +115,12 @@ Ledger::Ledger(const std::string& rawLedger, bool hasPrefix) :
void Ledger::setImmutable() void Ledger::setImmutable()
{ {
if (!mImmutable)
{
updateHash(); updateHash();
mImmutable = true; mImmutable = true;
if (mTransactionMap) if (mTransactionMap)
mTransactionMap->setImmutable(); mTransactionMap->setImmutable();
if (mAccountStateMap) if (mAccountStateMap)
mAccountStateMap->setImmutable(); mAccountStateMap->setImmutable();
}
} }
void Ledger::updateHash() void Ledger::updateHash()
@@ -1425,6 +1422,7 @@ void Ledger::pendSave(bool fromConsensus)
{ {
if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED)) if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED))
return; return;
assert(isImmutable());
{ {
boost::recursive_mutex::scoped_lock sl(sPendingSaveLock); boost::recursive_mutex::scoped_lock sl(sPendingSaveLock);

View File

@@ -158,6 +158,7 @@ public:
SHAMap::ref peekAccountStateMap() { return mAccountStateMap; } SHAMap::ref peekAccountStateMap() { return mAccountStateMap; }
void dropCache() void dropCache()
{ {
assert(isImmutable());
if (mTransactionMap) if (mTransactionMap)
mTransactionMap->dropCache(); mTransactionMap->dropCache();
if (mAccountStateMap) if (mAccountStateMap)

View File

@@ -94,6 +94,9 @@ LedgerAcquire::LedgerAcquire(const uint256& hash) : PeerSet(hash, LEDGER_ACQUIRE
bool LedgerAcquire::tryLocal() bool LedgerAcquire::tryLocal()
{ // return value: true = no more work to do { // return value: true = no more work to do
if (!mHaveBase)
{
HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(mHash); HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(mHash);
if (!node) if (!node)
{ {
@@ -112,7 +115,10 @@ bool LedgerAcquire::tryLocal()
} }
mHaveBase = true; mHaveBase = true;
}
if (!mHaveTransactions)
{
if (mLedger->getTransHash().isZero()) if (mLedger->getTransHash().isZero())
{ {
cLog(lsDEBUG) << "No TXNs to fetch"; cLog(lsDEBUG) << "No TXNs to fetch";
@@ -135,7 +141,10 @@ bool LedgerAcquire::tryLocal()
{ {
} }
} }
}
if (!mHaveState)
{
if (mLedger->getAccountHash().isZero()) if (mLedger->getAccountHash().isZero())
mHaveState = true; mHaveState = true;
else else
@@ -155,12 +164,14 @@ bool LedgerAcquire::tryLocal()
{ {
} }
} }
}
if (mHaveTransactions && mHaveState) if (mHaveTransactions && mHaveState)
{ {
cLog(lsDEBUG) << "Had everything locally"; cLog(lsDEBUG) << "Had everything locally";
mComplete = true; mComplete = true;
mLedger->setClosed(); mLedger->setClosed();
mLedger->setImmutable();
} }
return mComplete; return mComplete;
@@ -246,6 +257,7 @@ void LedgerAcquire::done()
if (isComplete() && !isFailed() && mLedger) if (isComplete() && !isFailed() && mLedger)
{ {
mLedger->setClosed(); mLedger->setClosed();
mLedger->setImmutable();
if (mAccept) if (mAccept)
mLedger->setAccepted(); mLedger->setAccepted();
theApp->getLedgerMaster().storeLedger(mLedger); theApp->getLedgerMaster().storeLedger(mLedger);

View File

@@ -852,8 +852,9 @@ bool SHAMap::getPath(const uint256& index, std::vector< std::vector<unsigned cha
} }
void SHAMap::dropCache() void SHAMap::dropCache()
{ // CAUTION: Changes can be lost {
boost::recursive_mutex::scoped_lock sl(mLock); boost::recursive_mutex::scoped_lock sl(mLock);
assert(mState == smsImmutable);
mTNByID.clear(); mTNByID.clear();
if (root) if (root)

View File

@@ -83,6 +83,8 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
if (have_all) if (have_all)
node->setFullBelow(); node->setFullBelow();
} }
if (nodeIDs.empty())
clearSynching();
} }
std::vector<uint256> SHAMap::getNeededHashes(int max) std::vector<uint256> SHAMap::getNeededHashes(int max)
@@ -134,6 +136,8 @@ std::vector<uint256> SHAMap::getNeededHashes(int max)
if (have_all) if (have_all)
node->setFullBelow(); node->setFullBelow();
} }
if (ret.empty())
clearSynching();
return ret; return ret;
} }