From 417cfc2fb049dada484d196225cbfe49e54ad411 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Wed, 12 Jan 2022 14:33:06 -0800 Subject: [PATCH] Adjust pathfinding configuration defaults: 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. --- src/ripple/core/Config.h | 6 ++-- src/test/app/Path_test.cpp | 70 +++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 034f81e38d3..c4a5076e76f 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -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 diff --git a/src/test/app/Path_test.cpp b/src/test/app/Path_test.cpp index 32eb1990588..b83b0d00deb 100644 --- a/src/test/app/Path_test.cpp +++ b/src/test/app/Path_test.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include namespace ripple { @@ -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 cfg) { + cfg->PATH_SEARCH_OLD = 7; + cfg->PATH_SEARCH = 7; + cfg->PATH_SEARCH_MAX = 10; + return cfg; + })); + } + public: class gate { @@ -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"); @@ -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 = @@ -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"); @@ -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); @@ -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); @@ -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)); @@ -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"); @@ -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); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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); @@ -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"); @@ -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}"), @@ -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"); @@ -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))); @@ -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"}; @@ -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"}; @@ -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"}; @@ -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"}; @@ -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"}; @@ -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); @@ -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);