diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 7666a9864..a02e429f9 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -3234,6 +3234,8 @@ + + @@ -3244,8 +3246,6 @@ - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 53206b12f..77e69c012 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -4437,6 +4437,9 @@ ripple\rpc\impl + + ripple\rpc\impl + ripple\rpc @@ -4452,9 +4455,6 @@ ripple\rpc - - ripple\rpc - ripple\sitefiles\api diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 60a76a969..fdc9d49f7 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -800,7 +800,7 @@ public: // - To modify the method, provide a new method in the request. { "account_currencies", &RPCParser::parseAccountCurrencies, 1, 2 }, { "account_info", &RPCParser::parseAccountItems, 1, 2 }, - { "account_lines", &RPCParser::parseAccountLines, 1, 3 }, + { "account_lines", &RPCParser::parseAccountLines, 1, 5 }, { "account_offers", &RPCParser::parseAccountItems, 1, 2 }, { "account_tx", &RPCParser::parseAccountTransactions, 1, 8 }, { "book_offers", &RPCParser::parseBookOffers, 2, 7 }, diff --git a/src/ripple/rpc/Tuning.h b/src/ripple/rpc/Tuning.h deleted file mode 100644 index dfa6736b8..000000000 --- a/src/ripple/rpc/Tuning.h +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_RPC_TUNING_H -#define RIPPLE_RPC_TUNING_H - -namespace ripple { -namespace RPC { - -const int DEFAULT_AUTO_FILL_FEE_MULTIPLIER = 10; -const int MAX_PATHFINDS_IN_PROGRESS = 2; -const int MAX_PATHFIND_JOB_COUNT = 50; -const int MAX_JOB_QUEUE_CLIENTS = 500; -const int MAX_VALIDATED_LEDGER_AGE = 120; -const int MAX_REQUEST_SIZE = 1000000; - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/handlers/AccountLines.cpp b/src/ripple/rpc/handlers/AccountLines.cpp index c85a902bf..8c3b39824 100644 --- a/src/ripple/rpc/handlers/AccountLines.cpp +++ b/src/ripple/rpc/handlers/AccountLines.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +#include namespace ripple { @@ -25,6 +26,8 @@ namespace ripple { // account_index: // optional, defaults to 0. // ledger_hash : // ledger_index : +// limit: integer // optional +// marker: opaque // optional, resume previous query // } Json::Value doAccountLines (RPC::Context& context) { @@ -73,53 +76,93 @@ Json::Value doAccountLines (RPC::Context& context) return result; } + unsigned int limit; + if (params.isMember (jss::limit)) + { + limit = std::max (RPC::Tuning::minLinesPerRequest, + std::min (params[jss::limit].asUInt (), + RPC::Tuning::maxLinesPerRequest)); + } + else + { + limit = RPC::Tuning::defaultLinesPerRequest; + } + + RippleAddress resumeAddress; + if (params.isMember (jss::marker)) + { + if (!resumeAddress.setAccountID (params[jss::marker].asString ())) + return rpcError (rpcACT_MALFORMED); + } + if (ledger->hasAccount (raAccount)) { result[jss::account] = raAccount.humanAccountID (); Json::Value& jsonLines = (result[jss::lines] = Json::arrayValue); + bool resume (! resumeAddress.isValid ()); + unsigned int i (0); + for (auto const& item : getRippleStateItems (raAccount.getAccountID (), ledger)) { - RippleState* line = (RippleState*)item.get (); + RippleState const& line (*item.get ()); + Account const& lineAccount (line.getAccountIDPeer ()); + + if (! resume && resumeAddress.getAccountID () == lineAccount) + resume = true; - if (!raPeer.isValid () || - raPeer.getAccountID () == line->getAccountIDPeer ()) + if (resume && + (!raPeer.isValid () || raPeer.getAccountID () == lineAccount)) { - STAmount const& saBalance = line->getBalance (); - STAmount const& saLimit = line->getLimit (); - STAmount const& saLimitPeer = line->getLimitPeer (); + if (i < limit) + { + STAmount const& saBalance = line.getBalance (); + STAmount const& saLimit = line.getLimit (); + STAmount const& saLimitPeer = line.getLimitPeer (); - Json::Value& jPeer = jsonLines.append (Json::objectValue); + Json::Value& jPeer = jsonLines.append (Json::objectValue); - jPeer[jss::account] = to_string (line->getAccountIDPeer ()); - // Amount reported is positive if current account holds other - // account's IOUs. - // - // Amount reported is negative if other account holds current - // account's IOUs. - jPeer[jss::balance] = saBalance.getText (); - jPeer[jss::currency] = saBalance.getHumanCurrency (); - jPeer[jss::limit] = saLimit.getText (); - jPeer[jss::limit_peer] = saLimitPeer.getText (); - jPeer[jss::quality_in] - = static_cast (line->getQualityIn ()); - jPeer[jss::quality_out] - = static_cast (line->getQualityOut ()); - if (line->getAuth()) - jPeer[jss::authorized] = true; - if (line->getAuthPeer()) - jPeer[jss::peer_authorized] = true; - if (line->getNoRipple()) - jPeer[jss::no_ripple] = true; - if (line->getNoRipplePeer()) - jPeer[jss::no_ripple_peer] = true; - if (line->getFreeze()) - jPeer[jss::freeze] = true; - if (line->getFreezePeer()) - jPeer[jss::freeze_peer] = true; + jPeer[jss::account] = to_string (lineAccount); + // Amount reported is positive if current account holds other + // account's IOUs. + // + // Amount reported is negative if other account holds current + // account's IOUs. + jPeer[jss::balance] = saBalance.getText (); + jPeer[jss::currency] = saBalance.getHumanCurrency (); + jPeer[jss::limit] = saLimit.getText (); + jPeer[jss::limit_peer] = saLimitPeer.getText (); + jPeer[jss::quality_in] + = static_cast (line.getQualityIn ()); + jPeer[jss::quality_out] + = static_cast (line.getQualityOut ()); + if (line.getAuth ()) + jPeer[jss::authorized] = true; + if (line.getAuthPeer ()) + jPeer[jss::peer_authorized] = true; + if (line.getNoRipple ()) + jPeer[jss::no_ripple] = true; + if (line.getNoRipplePeer ()) + jPeer[jss::no_ripple_peer] = true; + if (line.getFreeze ()) + jPeer[jss::freeze] = true; + if (line.getFreezePeer ()) + jPeer[jss::freeze_peer] = true; + + ++i; + } + else + { + result[jss::limit] = limit; + result[jss::marker] = to_string (lineAccount); + break; + } } } + if (! resume) + return rpcError (rpcACT_MALFORMED); + context.loadType_ = Resource::feeMediumBurdenRPC; } else diff --git a/src/ripple/rpc/impl/LegacyPathFind.cpp b/src/ripple/rpc/impl/LegacyPathFind.cpp index 7077cba1c..81aed226d 100644 --- a/src/ripple/rpc/impl/LegacyPathFind.cpp +++ b/src/ripple/rpc/impl/LegacyPathFind.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include #include namespace ripple { @@ -34,13 +34,13 @@ LegacyPathFind::LegacyPathFind (bool isAdmin) : m_isOk (false) auto& app = getApp(); auto const& jobCount = app.getJobQueue ().getJobCountGE (jtCLIENT); - if (jobCount > MAX_PATHFIND_JOB_COUNT || app.getFeeTrack().isLoadedLocal ()) + if (jobCount > Tuning::maxPathfindJobCount || app.getFeeTrack().isLoadedLocal ()) return; while (true) { int prevVal = inProgress.load(); - if (prevVal >= MAX_PATHFINDS_IN_PROGRESS) + if (prevVal >= Tuning::maxPathfindsInProgress) return; if (inProgress.compare_exchange_strong ( diff --git a/src/ripple/rpc/impl/RPCHandler.cpp b/src/ripple/rpc/impl/RPCHandler.cpp index d0b8bd91b..36f227ca7 100644 --- a/src/ripple/rpc/impl/RPCHandler.cpp +++ b/src/ripple/rpc/impl/RPCHandler.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -85,7 +85,7 @@ Json::Value RPCHandler::doCommand ( // VFALCO NOTE Should we also add up the jtRPC jobs? // int jc = getApp().getJobQueue ().getJobCountGE (jtCLIENT); - if (jc > RPC::MAX_JOB_QUEUE_CLIENTS) + if (jc > RPC::Tuning::maxJobQueueClients) { WriteLog (lsDEBUG, RPCHandler) << "Too busy for command: " << jc; return rpcError (rpcTOO_BUSY); @@ -123,7 +123,7 @@ Json::Value RPCHandler::doCommand ( if (!getConfig ().RUN_STANDALONE && (handler->condition_ & RPC::NEEDS_CURRENT_LEDGER) && (getApp().getLedgerMaster().getValidatedLedgerAge() > - RPC::MAX_VALIDATED_LEDGER_AGE)) + RPC::Tuning::maxValidatedLedgerAge)) { return rpcError (rpcNO_CURRENT); } diff --git a/src/ripple/rpc/impl/RPCServerHandler.cpp b/src/ripple/rpc/impl/RPCServerHandler.cpp index 8620c999d..a3a875a58 100644 --- a/src/ripple/rpc/impl/RPCServerHandler.cpp +++ b/src/ripple/rpc/impl/RPCServerHandler.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace ripple { @@ -55,7 +55,7 @@ std::string RPCServerHandler::processRequest ( { Json::Reader reader; - if ((request.size() > RPC::MAX_REQUEST_SIZE) || + if ((request.size() > ripple::RPC::Tuning::maxRequestSize) || ! reader.parse (request, jsonRequest) || jsonRequest.isNull () || ! jsonRequest.isObject ()) diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index 125026242..3deeb84c9 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -58,7 +58,7 @@ static void autofill_fee ( if (tx.isMember ("Fee")) return; - int mult = DEFAULT_AUTO_FILL_FEE_MULTIPLIER; + int mult = Tuning::defaultAutoFillFeeMultiplier; if (request.isMember ("fee_mult_max")) { if (request["fee_mult_max"].isNumeric ()) diff --git a/src/ripple/rpc/impl/Tuning.h b/src/ripple/rpc/impl/Tuning.h new file mode 100644 index 000000000..40c0c5380 --- /dev/null +++ b/src/ripple/rpc/impl/Tuning.h @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_RPC_TUNING_H_INCLUDED +#define RIPPLE_RPC_TUNING_H_INCLUDED + +namespace ripple { +namespace RPC { + +/** Tuned constants. */ +/** @{ */ +namespace Tuning { + +/** Default account lines return per request to the +account_lines command when no limit param is specified +*/ +unsigned int const defaultLinesPerRequest (200); + +/** Minimum account lines return per request to the +account_lines command. Specified in the limit param. +*/ +unsigned int const minLinesPerRequest (10); + +/** Maximum account lines return per request to the +account_lines command. Specified in the limit param. +*/ +unsigned int const maxLinesPerRequest (400); + +/** Default offers return per request to the account_offers command +when no limit param is specified +*/ +unsigned int const defaultOffersPerRequest (200); + +/** Minimum offers return per request to the account_offers command. +Specified in the limit param. +*/ +unsigned int const minOffersPerRequest (10); + +/** Maximum offers return per request to the account_lines command. +Specified in the limit param. +*/ +unsigned int const maxOffersPerRequest (400); + +int const defaultAutoFillFeeMultiplier (10); +int const maxPathfindsInProgress (2); +int const maxPathfindJobCount (50); +int const maxJobQueueClients (500); +int const maxValidatedLedgerAge (120); +int const maxRequestSize (1000000); + +} // Tuning +/** @} */ + +} // RPC +} // ripple + +#endif