Skip to content

Commit

Permalink
Adjust pathfinding configuration defaults:
Browse files Browse the repository at this point in the history
The pathfinding engine built into the code has several configurable
parameters to adjust the depth of the paths indexed and explored.

These parameters can dramatically impact the performance and memory
consumption of a server; higher values can result in resource usage
increasing exponentially.

These default values were decided early and somewhat arbitrarily at
a time when the network and the size of the network state were much
smaller.

This commit adjusts the default values to reduce the depth of paths
to more reasonable levels; unless explicitly overriden, the changes
mean that pathfinding operations will return fewer, shallower paths
than previous versions of the software.
  • Loading branch information
nbougalis committed Jan 13, 2022
1 parent febbe14 commit 417cfc2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/ripple/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ class Config : public BasicConfig
// Servers operating as validators disable path finding by
// default by setting the `PATH_SEARCH_MAX` option to 0
// unless it is explicitly set in the configuration file.
int PATH_SEARCH_OLD = 7;
int PATH_SEARCH = 7;
int PATH_SEARCH_OLD = 2;
int PATH_SEARCH = 2;
int PATH_SEARCH_FAST = 2;
int PATH_SEARCH_MAX = 10;
int PATH_SEARCH_MAX = 3;

// Validation
std::optional<std::size_t>
Expand Down
70 changes: 43 additions & 27 deletions src/test/app/Path_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <condition_variable>
#include <mutex>
#include <test/jtx.h>
#include <test/jtx/envconfig.h>
#include <thread>

namespace ripple {
Expand Down Expand Up @@ -171,6 +172,21 @@ IPE(Issue const& iss)

class Path_test : public beast::unit_test::suite
{
jtx::Env
pathTestEnv()
{
// These tests were originally written with search parameters that are
// different from the current defaults. This function creates an env
// with the search parameters that the tests were written for.
using namespace jtx;
return Env(*this, envconfig([](std::unique_ptr<Config> cfg) {
cfg->PATH_SEARCH_OLD = 7;
cfg->PATH_SEARCH = 7;
cfg->PATH_SEARCH_MAX = 10;
return cfg;
}));
}

public:
class gate
{
Expand Down Expand Up @@ -314,7 +330,7 @@ class Path_test : public beast::unit_test::suite
testcase("source currency limits");
using namespace std::chrono_literals;
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
env.fund(XRP(10000), "alice", "bob", gw);
env.trust(gw["USD"](100), "alice", "bob");
Expand Down Expand Up @@ -396,7 +412,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("no direct path no intermediary no alternatives");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");

auto const result =
Expand All @@ -409,7 +425,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("direct path no intermediary");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");
env.trust(Account("alice")["USD"](700), "bob");

Expand All @@ -426,7 +442,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("payment auto path find");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
env.fund(XRP(10000), "alice", "bob", gw);
Expand All @@ -445,7 +461,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("path find");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
env.fund(XRP(10000), "alice", "bob", gw);
Expand All @@ -467,7 +483,7 @@ class Path_test : public beast::unit_test::suite
{
using namespace jtx;
testcase("XRP to XRP");
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");

auto const result = find_paths(env, "alice", "bob", XRP(5));
Expand All @@ -481,7 +497,7 @@ class Path_test : public beast::unit_test::suite
using namespace jtx;

{
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob", "carol", "dan", "edward");
env.trust(Account("alice")["USD"](10), "bob");
env.trust(Account("bob")["USD"](10), "carol");
Expand All @@ -500,7 +516,7 @@ class Path_test : public beast::unit_test::suite
}

{
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
env.fund(XRP(10000), "alice", "bob", "carol", gw);
Expand Down Expand Up @@ -534,7 +550,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("alternative path consume both");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
auto const gw2 = Account("gateway2");
Expand Down Expand Up @@ -563,7 +579,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("alternative paths consume best transfer");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
auto const gw2 = Account("gateway2");
Expand Down Expand Up @@ -592,7 +608,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("alternative paths - consume best transfer first");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
auto const gw2 = Account("gateway2");
Expand Down Expand Up @@ -623,7 +639,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("alternative paths - limit returned paths to best quality");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const USD = gw["USD"];
auto const gw2 = Account("gateway2");
Expand Down Expand Up @@ -658,7 +674,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("path negative: Issue #5");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob", "carol", "dan");
env.trust(Account("bob")["USD"](100), "alice", "carol", "dan");
env.trust(Account("alice")["USD"](100), "dan");
Expand Down Expand Up @@ -696,7 +712,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("path negative: ripple-client issue #23: smaller");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob", "carol", "dan");
env.trust(Account("alice")["USD"](40), "bob");
env.trust(Account("dan")["USD"](20), "bob");
Expand All @@ -715,7 +731,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("path negative: ripple-client issue #23: larger");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob", "carol", "dan", "edward");
env.trust(Account("alice")["USD"](120), "edward");
env.trust(Account("edward")["USD"](25), "bob");
Expand All @@ -742,7 +758,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("via gateway");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
auto const gw = Account("gateway");
auto const AUD = gw["AUD"];
env.fund(XRP(10000), "alice", "bob", "carol", gw);
Expand All @@ -764,7 +780,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("path find");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob", "carol");
env.trust(Account("alice")["USD"](1000), "bob");
env.trust(Account("bob")["USD"](1000), "carol");
Expand All @@ -782,7 +798,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("quality set and test");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");
env(trust("bob", Account("alice")["USD"](1000)),
json("{\"" + sfQualityIn.fieldName + "\": 2000}"),
Expand Down Expand Up @@ -828,7 +844,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("trust normal clear");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");
env.trust(Account("bob")["USD"](1000), "alice");
env.trust(Account("alice")["USD"](1000), "bob");
Expand Down Expand Up @@ -878,7 +894,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("trust auto clear");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), "alice", "bob");
env.trust(Account("bob")["USD"](1000), "alice");
env(pay("bob", "alice", Account("bob")["USD"](50)));
Expand Down Expand Up @@ -931,7 +947,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("Path Find: XRP -> XRP and XRP -> IOU");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
Account A1{"A1"};
Account A2{"A2"};
Account A3{"A3"};
Expand Down Expand Up @@ -1018,7 +1034,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("Path Find: non-XRP -> XRP");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
Account A1{"A1"};
Account A2{"A2"};
Account G3{"G3"};
Expand Down Expand Up @@ -1055,7 +1071,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("Path Find: Bitstamp and SnapSwap, liquidity with no offers");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
Account A1{"A1"};
Account A2{"A2"};
Account G1BS{"G1BS"};
Expand Down Expand Up @@ -1135,7 +1151,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("Path Find: non-XRP -> non-XRP, same currency");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
Account A1{"A1"};
Account A2{"A2"};
Account A3{"A3"};
Expand Down Expand Up @@ -1264,7 +1280,7 @@ class Path_test : public beast::unit_test::suite
{
testcase("Path Find: non-XRP -> non-XRP, same currency)");
using namespace jtx;
Env env(*this);
Env env = pathTestEnv();
Account A1{"A1"};
Account A2{"A2"};
Account A3{"A3"};
Expand Down Expand Up @@ -1315,7 +1331,7 @@ class Path_test : public beast::unit_test::suite
auto const USD = gw["USD"];
{
// XRP -> IOU receive max
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), alice, bob, charlie, gw);
env.close();
env.trust(USD(100), alice, bob, charlie);
Expand All @@ -1338,7 +1354,7 @@ class Path_test : public beast::unit_test::suite
}
{
// IOU -> XRP receive max
Env env(*this);
Env env = pathTestEnv();
env.fund(XRP(10000), alice, bob, charlie, gw);
env.close();
env.trust(USD(100), alice, bob, charlie);
Expand Down

0 comments on commit 417cfc2

Please sign in to comment.