diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index dbd8c9219d..6c5264cac9 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -95,8 +95,9 @@ void startServer (Application& app) std::cerr << "Startup RPC: " << jvCommand << std::endl; Resource::Charge loadType = Resource::feeReferenceRPC; + Resource::Consumer c; RPC::Context context {app.journal ("RPCHandler"), jvCommand, app, - loadType, app.getOPs (), app.getLedgerMaster(), Role::ADMIN}; + loadType, app.getOPs (), app.getLedgerMaster(), c, Role::ADMIN}; Json::Value jvResult; RPC::doCommand (context, jvResult); diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index bf0b2703d2..58bcf8282d 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ PathRequest::PathRequest ( , m_journal (journal) , mOwner (owner) , wpSubscriber (subscriber) + , consumer_(subscriber->getConsumer()) , jvStatus (Json::objectValue) , mLastIndex (0) , mInProgress (false) @@ -62,6 +64,7 @@ PathRequest::PathRequest ( PathRequest::PathRequest ( Application& app, std::function const& completion, + Resource::Consumer& consumer, int id, PathRequests& owner, beast::Journal journal) @@ -69,6 +72,7 @@ PathRequest::PathRequest ( , m_journal (journal) , mOwner (owner) , fCompletion (completion) + , consumer_ (consumer) , jvStatus (Json::objectValue) , mLastIndex (0) , mInProgress (false) @@ -603,6 +607,13 @@ PathRequest::findPaths (std::shared_ptr const& cache, } } + /* The resource fee is based on the number of source currencies used. + The minimum cost is 50 and the maximum is 400. The cost increases + after four source currencies, 50 - (4 * 4) = 34. + */ + int const size = sourceCurrencies.size(); + consumer_.charge({boost::algorithm::clamp(size * size + 34, 50, 400), + "path update"}); return true; } diff --git a/src/ripple/app/paths/PathRequest.h b/src/ripple/app/paths/PathRequest.h index be1e585811..edd22d2960 100644 --- a/src/ripple/app/paths/PathRequest.h +++ b/src/ripple/app/paths/PathRequest.h @@ -69,16 +69,16 @@ public: PathRequest ( Application& app, std::function const& completion, + Resource::Consumer& consumer, int id, PathRequests&, beast::Journal journal); ~PathRequest (); - bool isNew (); - bool needsUpdate (bool newOnly, LedgerIndex index); - void updateComplete (); - Json::Value getStatus (); + bool isNew (); + bool needsUpdate (bool newOnly, LedgerIndex index); + void updateComplete (); std::pair doCreate ( std::shared_ptr const&, @@ -121,9 +121,10 @@ private: std::weak_ptr wpSubscriber; // Who this request came from std::function fCompletion; + Resource::Consumer& consumer_; // Charge according to source currencies Json::Value jvId; - Json::Value jvStatus; // Last result + Json::Value jvStatus; // Last result // Client request parameters boost::optional raSrcAccount; diff --git a/src/ripple/app/paths/PathRequests.cpp b/src/ripple/app/paths/PathRequests.cpp index 635ef4c2d6..d69177882e 100644 --- a/src/ripple/app/paths/PathRequests.cpp +++ b/src/ripple/app/paths/PathRequests.cpp @@ -96,8 +96,6 @@ void PathRequests::updateAll (std::shared_ptr const& inLedger, { if (auto ipSub = request->getSubscriber ()) { - ipSub->getConsumer ().charge ( - Resource::feePathFindUpdate); if (!ipSub->getConsumer ().warn ()) { Json::Value update = request->doUpdate (cache, false); @@ -228,13 +226,15 @@ Json::Value PathRequests::makeLegacyPathRequest( PathRequest::pointer& req, std::function completion, + Resource::Consumer& consumer, std::shared_ptr const& inLedger, Json::Value const& request) { // This assignment must take place before the // completion function is called req = std::make_shared ( - app_, completion, ++mLastIdentifier, *this, mJournal); + app_, completion, consumer, ++mLastIdentifier, + *this, mJournal); auto result = req->doCreate ( getLineCache (inLedger, false), request); diff --git a/src/ripple/app/paths/PathRequests.h b/src/ripple/app/paths/PathRequests.h index f84392e1ce..eb8749d2f4 100644 --- a/src/ripple/app/paths/PathRequests.h +++ b/src/ripple/app/paths/PathRequests.h @@ -57,6 +57,7 @@ public: Json::Value makeLegacyPathRequest ( PathRequest::pointer& req, std::function completion, + Resource::Consumer& consumer, std::shared_ptr const& inLedger, Json::Value const& request); diff --git a/src/ripple/app/tests/Path_test.cpp b/src/ripple/app/tests/Path_test.cpp index 5056109c46..b5e9ca3fdf 100644 --- a/src/ripple/app/tests/Path_test.cpp +++ b/src/ripple/app/tests/Path_test.cpp @@ -266,8 +266,9 @@ public: auto& app = env.app(); Resource::Charge loadType = Resource::feeReferenceRPC; - RPC::Context context {beast::Journal(), {}, app, loadType, app.getOPs(), - app.getLedgerMaster(), Role::USER, {}}; + Resource::Consumer c; + RPC::Context context {beast::Journal(), {}, app, loadType, + app.getOPs(), app.getLedgerMaster(), c, Role::USER, {}}; Json::Value result; gate g; // Test RPC::Tuning::max_src_cur source currencies. diff --git a/src/ripple/resource/impl/Fees.cpp b/src/ripple/resource/impl/Fees.cpp index 6ad632cd16..b1d03526be 100644 --- a/src/ripple/resource/impl/Fees.cpp +++ b/src/ripple/resource/impl/Fees.cpp @@ -36,7 +36,6 @@ Charge const feeLightRPC ( 5, "light RPC" ); // DAVID: C Charge const feeLowBurdenRPC ( 20, "low RPC" ); Charge const feeMediumBurdenRPC ( 40, "medium RPC" ); Charge const feeHighBurdenRPC ( 300, "heavy RPC" ); -Charge const feePathFindUpdate ( 100, "path update" ); Charge const feeLightPeer (1, "trivial peer request" ); Charge const feeLowBurdenPeer (2, "simple peer request" ); diff --git a/src/ripple/rpc/Context.h b/src/ripple/rpc/Context.h index 41ecc60f39..b50277d417 100644 --- a/src/ripple/rpc/Context.h +++ b/src/ripple/rpc/Context.h @@ -53,6 +53,7 @@ struct Context Resource::Charge& loadType; NetworkOPs& netOps; LedgerMaster& ledgerMaster; + Resource::Consumer& consumer; Role role; std::shared_ptr jobCoro; InfoSub::pointer infoSub; diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index e627108bb3..619efa3a78 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -76,7 +76,7 @@ Json::Value doRipplePathFind (RPC::Context& context) jvResult = context.app.getPathRequests().makeLegacyPathRequest ( request, std::bind(&JobCoro::post, context.jobCoro), - lpLedger, context.params); + context.consumer, lpLedger, context.params); if (request) { context.jobCoro->yield(); @@ -357,14 +357,32 @@ ripplePathFind (std::shared_ptr const& cache, STPath fullLiquidityPath; auto ps = pathfinder->getBestPaths(max_paths, fullLiquidityPath, spsComputed, issue.account); - auto& issuer = - isXRP(srcIssuerID) ? - isXRP(srcCurrencyID) ? // Default to source account. - xrpAccount() : - (raSrc) - : srcIssuerID; // Use specifed issuer. - STAmount saMaxAmount = saSendMax.value_or( - STAmount({ srcCurrencyID, issuer}, 1u, 0, true)); + + STAmount saMaxAmount; + if (saSendMax) + { + saMaxAmount = *saSendMax; + } + else + { + AccountID issuerID; + if (isXRP(srcIssuerID)) + { + // Default to source account. + if(isXRP(srcCurrencyID)) + issuerID = xrpAccount(); + else + issuerID = raSrc; + } + else + { + // Use specifed issuer. + issuerID = srcIssuerID; + } + + saMaxAmount = STAmount( + {srcCurrencyID, issuerID}, 1u, 0, true); + } boost::optional sandbox; sandbox.emplace(&*cache->getLedger(), tapNONE); diff --git a/src/ripple/server/impl/ServerHandlerImp.cpp b/src/ripple/server/impl/ServerHandlerImp.cpp index b474e2be7f..0d36c45e23 100644 --- a/src/ripple/server/impl/ServerHandlerImp.cpp +++ b/src/ripple/server/impl/ServerHandlerImp.cpp @@ -366,7 +366,7 @@ ServerHandlerImp::processRequest (Port const& port, auto const start (std::chrono::high_resolution_clock::now ()); RPC::Context context {m_journal, params, app_, loadType, m_networkOPs, - app_.getLedgerMaster(), role, jobCoro, InfoSub::pointer(), + app_.getLedgerMaster(), usage, role, jobCoro, InfoSub::pointer(), {user, forwardedFor}}; Json::Value result; RPC::doCommand (context, result); diff --git a/src/ripple/websocket/Connection.h b/src/ripple/websocket/Connection.h index 47d42b3b09..e7e0aa6c8d 100644 --- a/src/ripple/websocket/Connection.h +++ b/src/ripple/websocket/Connection.h @@ -286,8 +286,9 @@ Json::Value ConnectionImpl ::invokeCommand ( else { RPC::Context context {app_.journal ("RPCHandler"), jvRequest, - app_, loadType, m_netOPs, app_.getLedgerMaster(), role, - jobCoro, this->shared_from_this (), {m_user, m_forwardedFor}}; + app_, loadType, m_netOPs, app_.getLedgerMaster(), getConsumer(), + role, jobCoro, this->shared_from_this(), + {m_user, m_forwardedFor}}; RPC::doCommand (context, jvResult[jss::result]); }