From a3024352bae73bbcdbf95db652dfd0425ad8b14c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 12 Nov 2013 13:18:55 -0800 Subject: [PATCH] Pathfinding improvements. --- src/ripple_app/ledger/LedgerMaster.cpp | 24 +++++++++++++++++++++++- src/ripple_app/ledger/LedgerMaster.h | 1 + src/ripple_app/ledger/OrderBookDB.cpp | 1 + src/ripple_app/paths/PathRequest.cpp | 12 +++++++++++- src/ripple_app/paths/PathRequest.h | 3 ++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/ripple_app/ledger/LedgerMaster.cpp b/src/ripple_app/ledger/LedgerMaster.cpp index 15ce7c2a0..146f907bd 100644 --- a/src/ripple_app/ledger/LedgerMaster.cpp +++ b/src/ripple_app/ledger/LedgerMaster.cpp @@ -924,9 +924,17 @@ void LedgerMaster::updatePaths (Job& job) { Ledger::pointer lastLedger; + if (getApp().getOPs().isNeedNetworkLedger ()) + { + ScopedLockType ml (mLock, __FILE__, __LINE__); + mPathFindThread = false; + return; + } + while (! job.shouldCancel()) { bool newOnly = true; + bool hasNew = mPathFindNewRequest; { ScopedLockType ml (mLock, __FILE__, __LINE__); @@ -952,7 +960,7 @@ void LedgerMaster::updatePaths (Job& job) } // VFALCO TODO Fix this global variable - PathRequest::updateAll (lastLedger, newOnly, job.getCancelCallback ()); + PathRequest::updateAll (lastLedger, newOnly, hasNew, job.getCancelCallback ()); } } @@ -968,3 +976,17 @@ void LedgerMaster::newPathRequest () BIND_TYPE (&LedgerMaster::updatePaths, this, P_1)); } } + +// If the order book is radically updated, we need to reprocess all pathfinding requests +void LedgerMaster::newOrderBookDB () +{ + ScopedLockType ml (mLock, __FILE__, __LINE__); + mPathLedger.reset(); + + if (!mPathFindThread) + { + mPathFindThread = true; + getApp().getJobQueue ().addJob (jtUPDATE_PF, "updatePaths", + BIND_TYPE (&LedgerMaster::updatePaths, this, P_1)); + } +} diff --git a/src/ripple_app/ledger/LedgerMaster.h b/src/ripple_app/ledger/LedgerMaster.h index f95d89b35..89104e484 100644 --- a/src/ripple_app/ledger/LedgerMaster.h +++ b/src/ripple_app/ledger/LedgerMaster.h @@ -213,6 +213,7 @@ public: void tryAdvance (); void newPathRequest (); + void newOrderBookDB (); static bool shouldAcquire (uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger); diff --git a/src/ripple_app/ledger/OrderBookDB.cpp b/src/ripple_app/ledger/OrderBookDB.cpp index 6e3ea26b0..11705efd7 100644 --- a/src/ripple_app/ledger/OrderBookDB.cpp +++ b/src/ripple_app/ledger/OrderBookDB.cpp @@ -116,6 +116,7 @@ void OrderBookDB::update (Ledger::pointer ledger) mSourceMap.swap(sourceMap); mDestMap.swap(destMap); } + getApp().getLedgerMaster().newOrderBookDB(); } void OrderBookDB::addOrderBook(const uint160& ci, const uint160& co, diff --git a/src/ripple_app/paths/PathRequest.cpp b/src/ripple_app/paths/PathRequest.cpp index f75a28101..f7c0a8d6a 100644 --- a/src/ripple_app/paths/PathRequest.cpp +++ b/src/ripple_app/paths/PathRequest.cpp @@ -256,6 +256,12 @@ Json::Value PathRequest::doStatus (const Json::Value&) return jvStatus; } +void PathRequest::resetLevel (int l) +{ + if (iLastLevel > l) + iLastLevel = l; +} + bool PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) { WriteLog (lsDEBUG, PathRequest) << iIdentifier << " update " << (fast ? "fast" : "normal"); @@ -403,7 +409,7 @@ bool PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) return true; } -void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, CancelCallback shouldCancel) +void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, bool hasNew, CancelCallback shouldCancel) { std::set requests; @@ -433,6 +439,10 @@ void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, CancelCallback sh if (pRequest) { + // Drop old requests level to get new ones done faster + if (hasNew) + pRequest->resetLevel(getConfig().PATH_SEARCH); + if (newOnly && !pRequest->isNew ()) remove = false; else diff --git a/src/ripple_app/paths/PathRequest.h b/src/ripple_app/paths/PathRequest.h index 4d4ae87fd..2fc87658d 100644 --- a/src/ripple_app/paths/PathRequest.h +++ b/src/ripple_app/paths/PathRequest.h @@ -58,10 +58,11 @@ public: bool doUpdate (const boost::shared_ptr&, bool fast); // update jvStatus - static void updateAll (const boost::shared_ptr& ledger, bool newOnly, CancelCallback shouldCancel); + static void updateAll (const boost::shared_ptr& ledger, bool newOnly, bool hasNew, CancelCallback shouldCancel); private: void setValid (); + void resetLevel (int level); int parseJson (const Json::Value&, bool complete); typedef RippleRecursiveMutex LockType;