diff --git a/src/Application.cpp b/src/Application.cpp index e500b39eeb..6b7ff795a2 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -37,7 +37,7 @@ DatabaseCon::~DatabaseCon() Application::Application() : mUNL(mIOService), - mNetOps(mIOService, &mMasterLedger), mNodeCache(16384, 600), mHashedObjectStore(16384, 300), + mNetOps(mIOService, &mMasterLedger), mTempNodeCache(16384, 90), mHashedObjectStore(16384, 300), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) { diff --git a/src/Application.h b/src/Application.h index b63ff58d41..ff0024adc7 100644 --- a/src/Application.h +++ b/src/Application.h @@ -46,7 +46,7 @@ class Application LedgerAcquireMaster mMasterLedgerAcquire; TransactionMaster mMasterTransaction; NetworkOPs mNetOps; - NodeCache mNodeCache; + NodeCache mTempNodeCache; ValidationCollection mValidations; SuppressionTable mSuppressions; HashedObjectStore mHashedObjectStore; @@ -80,7 +80,7 @@ public: LedgerMaster& getMasterLedger() { return mMasterLedger; } LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; } TransactionMaster& getMasterTransaction() { return mMasterTransaction; } - NodeCache& getNodeCache() { return mNodeCache; } + NodeCache& getTempNodeCache() { return mTempNodeCache; } HashedObjectStore& getHashedObjectStore() { return mHashedObjectStore; } ValidationCollection& getValidations() { return mValidations; } bool isNew(const uint256& s) { return mSuppressions.addSuppression(s); } diff --git a/src/Ledger.cpp b/src/Ledger.cpp index e583647a6a..1ab8fb3d5c 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -5,6 +5,8 @@ #include #include +#include "../json/writer.h" + #include "Application.h" #include "Ledger.h" #include "utils.h" @@ -350,6 +352,11 @@ Ledger::pointer Ledger::getSQL(const std::string& sql) boost::make_shared(prevHash, transHash, accountHash, totCoins, closingTime, ledgerSeq); if (ret->getHash() != ledgerHash) { + Json::StyledStreamWriter ssw; + Log(lsERROR) << "Failed on ledger"; + Json::Value p; + ret->addJson(p, LEDGER_JSON_FULL); + ssw.write(Log(lsERROR).ref(), p); assert(false); return Ledger::pointer(); } @@ -379,7 +386,8 @@ void Ledger::addJson(Json::Value& ret, int options) boost::recursive_mutex::scoped_lock sl(mLock); ledger["parentHash"] = mParentHash.GetHex(); - if(mClosed) + bool full = (options & LEDGER_JSON_FULL) != 0; + if(mClosed || full) { ledger["hash"] = mHash.GetHex(); ledger["transactionHash"] = mTransHash.GetHex(); @@ -391,8 +399,7 @@ void Ledger::addJson(Json::Value& ret, int options) else ledger["closed"] = false; if (mCloseTime != 0) ledger["closeTime"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime)); - bool full = (options & LEDGER_JSON_FULL) != 0; - if (full || ((options & LEDGER_JSON_DUMP_TXNS) != 0)) + if (mTransactionMap && (full || ((options & LEDGER_JSON_DUMP_TXNS) != 0))) { Json::Value txns(Json::arrayValue); for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem(); !!item; @@ -408,7 +415,7 @@ void Ledger::addJson(Json::Value& ret, int options) } ledger["transactions"] = txns; } - if (full || ((options & LEDGER_JSON_DUMP_STATE) != 0)) + if (mAccountStateMap && (full || ((options & LEDGER_JSON_DUMP_STATE) != 0))) { Json::Value state(Json::arrayValue); for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item; diff --git a/src/LedgerHistory.cpp b/src/LedgerHistory.cpp index f20a7ae53a..e42e13020e 100644 --- a/src/LedgerHistory.cpp +++ b/src/LedgerHistory.cpp @@ -60,9 +60,11 @@ Ledger::pointer LedgerHistory::getLedgerByHash(const uint256& hash) Ledger::pointer ret = mLedgersByHash.fetch(hash); if (ret) return ret; - ret = Ledger::loadByHash(hash); - if (!ret) return ret; - assert(ret->getHash() == hash); +// FIXME: A ledger without SHA maps isn't very useful +// This code will need to build them +// ret = Ledger::loadByHash(hash); +// if (!ret) return ret; +// assert(ret->getHash() == hash); boost::recursive_mutex::scoped_lock sl(mLedgersByHash.peekMutex()); mLedgersByHash.canonicalize(hash, ret); diff --git a/src/SHAMapSync.h b/src/SHAMapSync.h index 26b6185520..5eaf25acc5 100644 --- a/src/SHAMapSync.h +++ b/src/SHAMapSync.h @@ -15,12 +15,12 @@ public: const std::vector& nodeData, bool isLeaf) { // WRITEME: If 'isLeaf' is true, this is a transaction - theApp->getNodeCache().store(nodeHash, nodeData); + theApp->getTempNodeCache().store(nodeHash, nodeData); } virtual bool haveNode(const SHAMapNode& id, const uint256& nodeHash, std::vector& nodeData) { // WRITEME: We could check our own map, we could check transaction tables - return theApp->getNodeCache().retrieve(nodeHash, nodeData); + return theApp->getTempNodeCache().retrieve(nodeHash, nodeData); } }; @@ -40,11 +40,8 @@ public: theApp->getHashedObjectStore().store(ACCOUNT_NODE, mLedgerSeq, nodeData, nodeHash); } virtual bool haveNode(const SHAMapNode& id, const uint256& nodeHash, std::vector& nodeData) - { - HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(nodeHash); - if (!node) return false; - nodeData = node->getData(); - return true; + { // fetchNode already tried + return false; } }; @@ -64,11 +61,8 @@ public: theApp->getHashedObjectStore().store(isLeaf ? TRANSACTION : TRANSACTION_NODE, mLedgerSeq, nodeData, nodeHash); } virtual bool haveNode(const SHAMapNode& id, const uint256& nodeHash, std::vector& nodeData) - { - HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(nodeHash); - if (!node) return false; - nodeData = node->getData(); - return true; + { // fetchNode already tried + return false; } };