diff --git a/src/ripple/rpc/handlers/LedgerHandler.h b/src/ripple/rpc/handlers/LedgerHandler.h index 5c33c1392a4..b0bca8e6635 100644 --- a/src/ripple/rpc/handlers/LedgerHandler.h +++ b/src/ripple/rpc/handlers/LedgerHandler.h @@ -61,7 +61,7 @@ class LedgerHandler static constexpr char name[] = "ledger"; - static constexpr unsigned minApiVer = 1; + static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion; static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion; diff --git a/src/ripple/rpc/handlers/Version.h b/src/ripple/rpc/handlers/Version.h index 69578727fab..8f33b62f1cf 100644 --- a/src/ripple/rpc/handlers/Version.h +++ b/src/ripple/rpc/handlers/Version.h @@ -48,7 +48,7 @@ class VersionHandler static constexpr char const* name = "version"; - static constexpr unsigned minApiVer = 1; + static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion; static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion; diff --git a/src/ripple/rpc/impl/Handler.cpp b/src/ripple/rpc/impl/Handler.cpp index 98f4a533d4d..c31619efbf8 100644 --- a/src/ripple/rpc/impl/Handler.cpp +++ b/src/ripple/rpc/impl/Handler.cpp @@ -206,13 +206,13 @@ class HandlerTable assert(minVer <= maxVer); assert(maxVer <= RPC::apiMaximumValidVersion); - for (; range.first != range.second; range.first++) - { - if (range.first->second.minApiVer_ <= maxVer && - range.first->second.maxApiVer_ >= minVer) - return true; - } - return false; + return std::any_of( + range.first, + range.second, // + [minVer, maxVer](auto const& item) { + return item.second.minApiVer_ <= maxVer && + item.second.maxApiVer_ >= minVer; + }); } template @@ -256,7 +256,7 @@ class HandlerTable auto const range = table_.equal_range(name); auto const i = std::find_if( range.first, range.second, [version](auto const& entry) { - return version >= entry.second.minApiVer_ && + return entry.second.minApiVer_ <= version && version <= entry.second.maxApiVer_; }); @@ -282,6 +282,8 @@ class HandlerTable { static_assert(HandlerImpl::minApiVer <= HandlerImpl::maxApiVer); static_assert(HandlerImpl::maxApiVer <= RPC::apiMaximumValidVersion); + static_assert( + RPC::apiMinimumSupportedVersion <= HandlerImpl::minApiVer); if (overlappingApiVersion( table_.equal_range(HandlerImpl::name), diff --git a/src/test/rpc/Handler_test.cpp b/src/test/rpc/Handler_test.cpp index 16a87d949a5..ba26a27c806 100644 --- a/src/test/rpc/Handler_test.cpp +++ b/src/test/rpc/Handler_test.cpp @@ -27,7 +27,7 @@ #include #include -namespace ripple::RPC { +namespace ripple::test { // NOTE: there should be no need for this function; // `std::cout << some_duration` should just work if built with a compliant @@ -39,7 +39,7 @@ operator<<(std::ostream& os, std::chrono::nanoseconds ns) return (os << ns.count() << "ns"); } -// NOTE This is a rather naiive effort at a microbenchmark. Ideally we want +// NOTE This is a rather naive effort at a microbenchmark. Ideally we want // Google Benchmark, or something similar. Also, this actually does not belong // to unit tests, as it makes little sense to run it in conditions very // dissimilar to how rippled will normally work. @@ -99,7 +99,7 @@ class Handler_test : public beast::unit_test::suite std::random_device dev; std::ranlux48 prng(dev()); - std::set handlerNames = getHandlerNames(); + std::set handlerNames = RPC::getHandlerNames(); std::vector names( handlerNames.begin(), handlerNames.end()); @@ -109,7 +109,7 @@ class Handler_test : public beast::unit_test::suite auto const [mean, stdev, n] = time( 1'000'000, [&](std::size_t i) { - auto const d = getHandler(1, false, names[i]); + auto const d = RPC::getHandler(1, false, names[i]); dummy = dummy + i + (int)d->role_; }, [&]() -> std::size_t { return distr(prng); }); @@ -128,6 +128,6 @@ class Handler_test : public beast::unit_test::suite } }; -BEAST_DEFINE_TESTSUITE(Handler, rpc, ripple); +BEAST_DEFINE_TESTSUITE_MANUAL(Handler, test, ripple); -} // namespace ripple::RPC +} // namespace ripple::test