mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Limit legacy pathfinding requests
This commit is contained in:
@@ -36,6 +36,58 @@ RPCHandler::RPCHandler (NetworkOPs* netOps, InfoSub::pointer infoSub)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LegacyPathFind
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
LegacyPathFind (bool isAdmin) : m_isOkay (false)
|
||||||
|
{
|
||||||
|
if (isAdmin)
|
||||||
|
++inProgress;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((getApp().getJobQueue ().getJobCountGE (jtCLIENT) > 50) ||
|
||||||
|
getApp().getFeeTrack().isLoadedLocal ())
|
||||||
|
return;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int prevVal = inProgress.load();
|
||||||
|
if (prevVal >= maxInProgress)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (inProgress.compare_exchange_strong (prevVal, prevVal + 1,
|
||||||
|
std::memory_order_release, std::memory_order_relaxed))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_isOkay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
~LegacyPathFind ()
|
||||||
|
{
|
||||||
|
if (m_isOkay)
|
||||||
|
--inProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isOkay ()
|
||||||
|
{
|
||||||
|
return m_isOkay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::atomic <int> inProgress;
|
||||||
|
static int maxInProgress;
|
||||||
|
|
||||||
|
bool m_isOkay;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::atomic <int> LegacyPathFind::inProgress (0);
|
||||||
|
int LegacyPathFind::maxInProgress (2);
|
||||||
|
|
||||||
|
|
||||||
Json::Value RPCHandler::transactionSign (Json::Value params, bool bSubmit, bool bFailHard, Application::ScopedLockType& mlh)
|
Json::Value RPCHandler::transactionSign (Json::Value params, bool bSubmit, bool bFailHard, Application::ScopedLockType& mlh)
|
||||||
{
|
{
|
||||||
if (getApp().getFeeTrack().isLoadedCluster() && (mRole != Config::ADMIN))
|
if (getApp().getFeeTrack().isLoadedCluster() && (mRole != Config::ADMIN))
|
||||||
@@ -167,6 +219,10 @@ Json::Value RPCHandler::transactionSign (Json::Value params, bool bSubmit, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
LegacyPathFind lpf (mRole == Config::ADMIN);
|
||||||
|
if (!lpf.isOkay ())
|
||||||
|
return rpcError (rpcTOO_BUSY);
|
||||||
|
|
||||||
bool bValid;
|
bool bValid;
|
||||||
RippleLineCache::pointer cache = boost::make_shared<RippleLineCache> (lSnapshot);
|
RippleLineCache::pointer cache = boost::make_shared<RippleLineCache> (lSnapshot);
|
||||||
Pathfinder pf (cache, raSrcAddressID, dstAccountID,
|
Pathfinder pf (cache, raSrcAddressID, dstAccountID,
|
||||||
@@ -1473,13 +1529,10 @@ Json::Value RPCHandler::doPathFind (Json::Value params, Resource::Charge& loadTy
|
|||||||
// This interface is deprecated.
|
// This interface is deprecated.
|
||||||
Json::Value RPCHandler::doRipplePathFind (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& masterLockHolder)
|
Json::Value RPCHandler::doRipplePathFind (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& masterLockHolder)
|
||||||
{
|
{
|
||||||
int jc = getApp().getJobQueue ().getJobCountGE (jtCLIENT);
|
LegacyPathFind lpf (mRole == Config::ADMIN);
|
||||||
|
if (!lpf.isOkay ())
|
||||||
if (jc > 200)
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, RPCHandler) << "Too busy for RPF: " << jc;
|
|
||||||
return rpcError (rpcTOO_BUSY);
|
return rpcError (rpcTOO_BUSY);
|
||||||
}
|
|
||||||
loadType = Resource::feeHighBurdenRPC;
|
loadType = Resource::feeHighBurdenRPC;
|
||||||
|
|
||||||
RippleAddress raSrc;
|
RippleAddress raSrc;
|
||||||
|
|||||||
Reference in New Issue
Block a user