mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 09:17:57 +00:00
Rework dispatch of new API PF requests.
This commit is contained in:
@@ -628,6 +628,13 @@ void LedgerMaster::tryPublish()
|
|||||||
mPubThread = true;
|
mPubThread = true;
|
||||||
theApp->getJobQueue().addJob(jtPUBLEDGER, "Ledger::pubThread",
|
theApp->getJobQueue().addJob(jtPUBLEDGER, "Ledger::pubThread",
|
||||||
BIND_TYPE(&LedgerMaster::pubThread, this));
|
BIND_TYPE(&LedgerMaster::pubThread, this));
|
||||||
|
mPathFindNewLedger = true;
|
||||||
|
if (!mPathFindThread)
|
||||||
|
{
|
||||||
|
mPathFindThread = true;
|
||||||
|
theApp->getJobQueue().addJob(jtUPDATE_PF, "updatePaths",
|
||||||
|
BIND_TYPE(&LedgerMaster::updatePaths, this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,22 +676,44 @@ void LedgerMaster::pubThread()
|
|||||||
void LedgerMaster::updatePaths()
|
void LedgerMaster::updatePaths()
|
||||||
{
|
{
|
||||||
Ledger::pointer lastLedger;
|
Ledger::pointer lastLedger;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
bool newOnly = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||||
if (lastLedger.get() == mPubLedger.get())
|
if (mPathFindNewLedger || (lastLedger && (lastLedger.get() != mPubLedger.get())))
|
||||||
|
lastLedger = mPubLedger;
|
||||||
|
else if (mPathFindNewRequest)
|
||||||
|
{
|
||||||
|
newOnly = true;
|
||||||
|
lastLedger = boost::make_shared<Ledger>(*mCurrentLedger, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
mPathFindThread = false;
|
mPathFindThread = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastLedger = mPubLedger;
|
lastLedger = mPubLedger;
|
||||||
|
mPathFindNewLedger = false;
|
||||||
|
mPathFindNewRequest = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PFRequest::updateAll(lastLedger);
|
PFRequest::updateAll(lastLedger, newOnly);
|
||||||
|
|
||||||
} while(1);
|
} while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LedgerMaster::newPFRequest()
|
||||||
|
{
|
||||||
|
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||||
|
mPathFindNewRequest = true;
|
||||||
|
if (!mPathFindThread)
|
||||||
|
{
|
||||||
|
mPathFindThread = true;
|
||||||
|
theApp->getJobQueue().addJob(jtUPDATE_PF, "updatePaths",
|
||||||
|
BIND_TYPE(&LedgerMaster::updatePaths, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ protected:
|
|||||||
|
|
||||||
std::list<Ledger::pointer> mPubLedgers; // List of ledgers to publish
|
std::list<Ledger::pointer> mPubLedgers; // List of ledgers to publish
|
||||||
bool mPubThread; // Publish thread is running
|
bool mPubThread; // Publish thread is running
|
||||||
|
|
||||||
bool mPathFindThread; // Pathfind thread is running
|
bool mPathFindThread; // Pathfind thread is running
|
||||||
|
bool mPathFindNewLedger;
|
||||||
|
bool mPathFindNewRequest;
|
||||||
|
|
||||||
void applyFutureTransactions(uint32 ledgerIndex);
|
void applyFutureTransactions(uint32 ledgerIndex);
|
||||||
bool isValidTransaction(Transaction::ref trans);
|
bool isValidTransaction(Transaction::ref trans);
|
||||||
@@ -60,7 +63,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
LedgerMaster() : mHeldTransactions(uint256()), mMissingSeq(0),
|
LedgerMaster() : mHeldTransactions(uint256()), mMissingSeq(0),
|
||||||
mMinValidations(0), mLastValidateSeq(0), mPubThread(false), mPathFindThread(false)
|
mMinValidations(0), mLastValidateSeq(0), mPubThread(false),
|
||||||
|
mPathFindThread(false), mPathFindNewLedger(false), mPathFindNewRequest(false)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
uint32 getCurrentLedgerIndex();
|
uint32 getCurrentLedgerIndex();
|
||||||
@@ -157,6 +161,7 @@ public:
|
|||||||
void checkAccept(const uint256& hash);
|
void checkAccept(const uint256& hash);
|
||||||
void checkAccept(const uint256& hash, uint32 seq);
|
void checkAccept(const uint256& hash, uint32 seq);
|
||||||
void tryPublish();
|
void tryPublish();
|
||||||
|
void newPFRequest();
|
||||||
|
|
||||||
static bool shouldAcquire(uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger);
|
static bool shouldAcquire(uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ boost::recursive_mutex PFRequest::sLock;
|
|||||||
std::set<PFRequest::wptr> PFRequest::sRequests;
|
std::set<PFRequest::wptr> PFRequest::sRequests;
|
||||||
|
|
||||||
PFRequest::PFRequest(const boost::shared_ptr<InfoSub>& subscriber) :
|
PFRequest::PFRequest(const boost::shared_ptr<InfoSub>& subscriber) :
|
||||||
wpSubscriber(subscriber), jvStatus(Json::objectValue), bValid(false)
|
wpSubscriber(subscriber), jvStatus(Json::objectValue), bValid(false), bNew(true)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,12 @@ bool PFRequest::isValid()
|
|||||||
return bValid;
|
return bValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PFRequest::isNew()
|
||||||
|
{
|
||||||
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
return bNew;
|
||||||
|
}
|
||||||
|
|
||||||
bool PFRequest::isValid(Ledger::ref lrLedger)
|
bool PFRequest::isValid(Ledger::ref lrLedger)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
@@ -198,6 +204,8 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
|
|||||||
jvStatus = Json::objectValue;
|
jvStatus = Json::objectValue;
|
||||||
if (!isValid(cache->getLedger()))
|
if (!isValid(cache->getLedger()))
|
||||||
return false;
|
return false;
|
||||||
|
if (!fast)
|
||||||
|
bNew = false;
|
||||||
|
|
||||||
std::set<currIssuer_t> sourceCurrencies(sciSourceCurrencies);
|
std::set<currIssuer_t> sourceCurrencies(sciSourceCurrencies);
|
||||||
if (sourceCurrencies.empty())
|
if (sourceCurrencies.empty())
|
||||||
@@ -248,11 +256,10 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFRequest::updateAll(const boost::shared_ptr<Ledger>& ledger)
|
void PFRequest::updateAll(Ledger::ref ledger, bool newOnly)
|
||||||
{
|
{
|
||||||
assert(ledger->isImmutable());
|
|
||||||
|
|
||||||
std::set<wptr> requests;
|
std::set<wptr> requests;
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(sLock);
|
boost::recursive_mutex::scoped_lock sl(sLock);
|
||||||
requests = sRequests;
|
requests = sRequests;
|
||||||
@@ -267,7 +274,7 @@ void PFRequest::updateAll(const boost::shared_ptr<Ledger>& ledger)
|
|||||||
{
|
{
|
||||||
bool remove = true;
|
bool remove = true;
|
||||||
PFRequest::pointer pRequest = wRequest.lock();
|
PFRequest::pointer pRequest = wRequest.lock();
|
||||||
if (pRequest)
|
if (pRequest && (!newOnly || pRequest->isNew()))
|
||||||
{
|
{
|
||||||
InfoSub::pointer ipSub = pRequest->wpSubscriber.lock();
|
InfoSub::pointer ipSub = pRequest->wpSubscriber.lock();
|
||||||
if (ipSub)
|
if (ipSub)
|
||||||
@@ -275,7 +282,7 @@ void PFRequest::updateAll(const boost::shared_ptr<Ledger>& ledger)
|
|||||||
Json::Value update;
|
Json::Value update;
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(pRequest->mLock);
|
boost::recursive_mutex::scoped_lock sl(pRequest->mLock);
|
||||||
pRequest->doUpdate(cache, true);
|
pRequest->doUpdate(cache, false);
|
||||||
update = pRequest->jvStatus;
|
update = pRequest->jvStatus;
|
||||||
}
|
}
|
||||||
update["type"] = "path_find";
|
update["type"] = "path_find";
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ protected:
|
|||||||
std::vector<Json::Value> vjvBridges;
|
std::vector<Json::Value> vjvBridges;
|
||||||
|
|
||||||
bool bValid;
|
bool bValid;
|
||||||
|
bool bNew;
|
||||||
|
|
||||||
// Track all requests
|
// Track all requests
|
||||||
static std::set<wptr> sRequests;
|
static std::set<wptr> sRequests;
|
||||||
@@ -66,6 +67,7 @@ public:
|
|||||||
|
|
||||||
bool isValid(const boost::shared_ptr<Ledger>&);
|
bool isValid(const boost::shared_ptr<Ledger>&);
|
||||||
bool isValid();
|
bool isValid();
|
||||||
|
bool isNew();
|
||||||
Json::Value getStatus();
|
Json::Value getStatus();
|
||||||
|
|
||||||
Json::Value doCreate(const boost::shared_ptr<Ledger>&, const Json::Value&);
|
Json::Value doCreate(const boost::shared_ptr<Ledger>&, const Json::Value&);
|
||||||
@@ -74,7 +76,7 @@ public:
|
|||||||
|
|
||||||
bool doUpdate(const boost::shared_ptr<RLCache>&, bool fast); // update jvStatus
|
bool doUpdate(const boost::shared_ptr<RLCache>&, bool fast); // update jvStatus
|
||||||
|
|
||||||
static void updateAll(const boost::shared_ptr<Ledger> &);
|
static void updateAll(const boost::shared_ptr<Ledger>& ledger, bool newOnly);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1185,7 +1185,10 @@ Json::Value RPCHandler::doPathFind(Json::Value jvRequest, int& cost, ScopedLock&
|
|||||||
PFRequest::pointer request = boost::make_shared<PFRequest>(mInfoSub);
|
PFRequest::pointer request = boost::make_shared<PFRequest>(mInfoSub);
|
||||||
Json::Value result = request->doCreate(mNetOps->getClosedLedger(), jvRequest);
|
Json::Value result = request->doCreate(mNetOps->getClosedLedger(), jvRequest);
|
||||||
if (request->isValid())
|
if (request->isValid())
|
||||||
|
{
|
||||||
mInfoSub->setPFRequest(request);
|
mInfoSub->setPFRequest(request);
|
||||||
|
theApp->getLedgerMaster().newPFRequest();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user