mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-26 21:45:50 +00:00
Charge pathfinding consumers per source currency (RIPD-1019):
The IP address used to perform pathfinding operations is now charged an additional resource increment for each source currency in the path set. * NOTE: This charge is a local resource charge, not a transaction fee charge.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <ripple/rpc/impl/Tuning.h>
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <boost/algorithm/clamp.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <tuple>
|
||||
|
||||
@@ -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 <void(void)> 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<RippleLineCache> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
PathRequest (
|
||||
Application& app,
|
||||
std::function <void (void)> const& completion,
|
||||
Resource::Consumer& consumer,
|
||||
int id,
|
||||
PathRequests&,
|
||||
beast::Journal journal);
|
||||
@@ -78,7 +79,6 @@ public:
|
||||
bool isNew ();
|
||||
bool needsUpdate (bool newOnly, LedgerIndex index);
|
||||
void updateComplete ();
|
||||
Json::Value getStatus ();
|
||||
|
||||
std::pair<bool, Json::Value> doCreate (
|
||||
std::shared_ptr<RippleLineCache> const&,
|
||||
@@ -121,6 +121,7 @@ private:
|
||||
|
||||
std::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
|
||||
std::function <void (void)> fCompletion;
|
||||
Resource::Consumer& consumer_; // Charge according to source currencies
|
||||
|
||||
Json::Value jvId;
|
||||
Json::Value jvStatus; // Last result
|
||||
|
||||
@@ -96,8 +96,6 @@ void PathRequests::updateAll (std::shared_ptr <ReadView const> 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 <void (void)> completion,
|
||||
Resource::Consumer& consumer,
|
||||
std::shared_ptr<ReadView const> const& inLedger,
|
||||
Json::Value const& request)
|
||||
{
|
||||
// This assignment must take place before the
|
||||
// completion function is called
|
||||
req = std::make_shared<PathRequest> (
|
||||
app_, completion, ++mLastIdentifier, *this, mJournal);
|
||||
app_, completion, consumer, ++mLastIdentifier,
|
||||
*this, mJournal);
|
||||
|
||||
auto result = req->doCreate (
|
||||
getLineCache (inLedger, false), request);
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
Json::Value makeLegacyPathRequest (
|
||||
PathRequest::pointer& req,
|
||||
std::function <void (void)> completion,
|
||||
Resource::Consumer& consumer,
|
||||
std::shared_ptr<ReadView const> const& inLedger,
|
||||
Json::Value const& request);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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" );
|
||||
|
||||
@@ -53,6 +53,7 @@ struct Context
|
||||
Resource::Charge& loadType;
|
||||
NetworkOPs& netOps;
|
||||
LedgerMaster& ledgerMaster;
|
||||
Resource::Consumer& consumer;
|
||||
Role role;
|
||||
std::shared_ptr<JobCoro> jobCoro;
|
||||
InfoSub::pointer infoSub;
|
||||
|
||||
@@ -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<RippleLineCache> 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<PaymentSandbox> sandbox;
|
||||
sandbox.emplace(&*cache->getLedger(), tapNONE);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -286,8 +286,9 @@ Json::Value ConnectionImpl <WebSocket>::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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user