Major updates to the ledger tracking system.

This commit is contained in:
JoelKatz
2012-10-25 01:50:07 -07:00
parent 390da86192
commit ef40099649
9 changed files with 98 additions and 203 deletions

View File

@@ -45,7 +45,8 @@ Ledger::pointer LedgerHistory::getLedgerBySeq(uint32 index)
{
boost::recursive_mutex::scoped_lock sl(mLedgersByHash.peekMutex());
std::map<uint32, Ledger::pointer>::iterator it(mLedgersByIndex.find(index));
if (it != mLedgersByIndex.end()) return it->second;
if (it != mLedgersByIndex.end())
return it->second;
sl.unlock();
Ledger::pointer ret(Ledger::loadByIndex(index));
@@ -61,25 +62,14 @@ Ledger::pointer LedgerHistory::getLedgerBySeq(uint32 index)
Ledger::pointer LedgerHistory::getLedgerByHash(const uint256& hash)
{
Ledger::pointer ret = mLedgersByHash.fetch(hash);
if (ret) return ret;
#if 0
// FIXME: A ledger without SHA maps isn't very useful
// This code will need to build them
// The fix is to audit all callers to this function and replace them with
// higher-level functions that ask more-specific questions that we can
// test against our database
if (ret)
return ret;
ret = Ledger::loadByHash(hash);
if (!ret) return ret;
if (!ret)
return ret;
assert(ret->getHash() == hash);
boost::recursive_mutex::scoped_lock sl(mLedgersByHash.peekMutex());
mLedgersByHash.canonicalize(hash, ret);
if (ret->isAccepted()) mLedgersByIndex[ret->getLedgerSeq()] = ret;
#endif
return ret;
}