Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote API version 2 to supported #4803

Merged
merged 12 commits into from
Nov 13, 2023
16 changes: 12 additions & 4 deletions Builds/CMake/RippledCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ else ()
>)
endif ()

if (use_gold AND is_gcc)
if (use_mold)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these changes required to allow version 2?

# use mold linker if available
execute_process (
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version
ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if ("${LD_VERSION}" MATCHES "mold")
target_link_libraries (common INTERFACE -fuse-ld=mold)
endif ()
unset (LD_VERSION)
elseif (use_gold AND is_gcc)
# use gold linker if available
execute_process (
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version
Expand Down Expand Up @@ -163,9 +172,7 @@ if (use_gold AND is_gcc)
$<$<NOT:$<BOOL:${static}>>:-Wl,--disable-new-dtags>)
endif ()
unset (LD_VERSION)
endif ()

if (use_lld)
elseif (use_lld)
# use lld linker if available
execute_process (
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version
Expand All @@ -176,6 +183,7 @@ if (use_lld)
unset (LD_VERSION)
endif()


if (assert)
foreach (var_ CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
STRING (REGEX REPLACE "[-/]DNDEBUG" "" ${var_} "${${var_}}")
Expand Down
2 changes: 2 additions & 0 deletions Builds/CMake/RippledSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (is_linux)
option (static "link protobuf, openssl, libc++, and boost statically" ON)
option (perf "Enables flags that assist with perf recording" OFF)
option (use_gold "enables detection of gold (binutils) linker" ON)
option (use_mold "enables detection of mold (binutils) linker" ON)
else ()
# we are not ready to allow shared-libs on windows because it would require
# export declarations. On macos it's more feasible, but static openssl
Expand All @@ -45,6 +46,7 @@ else ()
set (static ON CACHE BOOL "static link, linux only. ON for WIN/macos" FORCE)
set (perf OFF CACHE BOOL "perf flags, linux only" FORCE)
set (use_gold OFF CACHE BOOL "gold linker, linux only" FORCE)
set (use_mold OFF CACHE BOOL "mold linker, linux only" FORCE)
endif ()
if (is_clang)
option (use_lld "enables detection of lld linker" ON)
Expand Down
82 changes: 6 additions & 76 deletions src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ createHTTPPost(
class RPCParser
{
private:
unsigned const apiVersion_;
beast::Journal const j_;

// TODO New routine for parsing ledger parameters, other routines should
Expand Down Expand Up @@ -321,8 +322,7 @@ class RPCParser

if (uLedgerMax != -1 && uLedgerMax < uLedgerMin)
{
// The command line always follows apiMaximumSupportedVersion
if (RPC::apiMaximumSupportedVersion == 1)
if (apiVersion_ == 1)
return rpcError(rpcLGR_IDXS_INVALID);
return rpcError(rpcNOT_SYNCED);
}
Expand All @@ -340,76 +340,6 @@ class RPCParser
return jvRequest;
}

// tx_account accountID [ledger_min [ledger_max [limit]]]] [binary] [count]
// [forward]
Json::Value
parseTxAccount(Json::Value const& jvParams)
{
Json::Value jvRequest(Json::objectValue);
unsigned int iParams = jvParams.size();

auto const account = parseBase58<AccountID>(jvParams[0u].asString());
if (!account)
return rpcError(rpcACT_MALFORMED);

jvRequest[jss::account] = toBase58(*account);

bool bDone = false;

while (!bDone && iParams >= 2)
{
if (jvParams[iParams - 1].asString() == jss::binary)
{
jvRequest[jss::binary] = true;
--iParams;
}
else if (jvParams[iParams - 1].asString() == jss::count)
{
jvRequest[jss::count] = true;
--iParams;
}
else if (jvParams[iParams - 1].asString() == jss::forward)
{
jvRequest[jss::forward] = true;
--iParams;
}
else
{
bDone = true;
}
}

if (1 == iParams)
{
}
else if (2 == iParams)
{
if (!jvParseLedger(jvRequest, jvParams[1u].asString()))
return jvRequest;
}
else
{
std::int64_t uLedgerMin = jvParams[1u].asInt();
std::int64_t uLedgerMax = jvParams[2u].asInt();

if (uLedgerMax != -1 && uLedgerMax < uLedgerMin)
{
// The command line always follows apiMaximumSupportedVersion
if (RPC::apiMaximumSupportedVersion == 1)
return rpcError(rpcLGR_IDXS_INVALID);
return rpcError(rpcNOT_SYNCED);
}

jvRequest[jss::ledger_index_min] = jvParams[1u].asInt();
jvRequest[jss::ledger_index_max] = jvParams[2u].asInt();

if (iParams >= 4)
jvRequest[jss::limit] = jvParams[3u].asInt();
}

return jvRequest;
}

// book_offers <taker_pays> <taker_gets> [<taker> [<ledger> [<limit>
// [<proof> [<marker>]]]]] limit: 0 = no limit proof: 0 or 1
//
Expand Down Expand Up @@ -1221,7 +1151,8 @@ class RPCParser
public:
//--------------------------------------------------------------------------

explicit RPCParser(beast::Journal j) : j_(j)
explicit RPCParser(unsigned apiVersion, beast::Journal j)
: apiVersion_(apiVersion), j_(j)
{
}

Expand Down Expand Up @@ -1317,7 +1248,6 @@ class RPCParser
{"submit_multisigned", &RPCParser::parseSubmitMultiSigned, 1, 1},
{"transaction_entry", &RPCParser::parseTransactionEntry, 2, 2},
{"tx", &RPCParser::parseTx, 1, 4},
{"tx_account", &RPCParser::parseTxAccount, 1, 7},
{"tx_history", &RPCParser::parseTxHistory, 1, 1},
{"unl_list", &RPCParser::parseAsIs, 0, 0},
{"validation_create", &RPCParser::parseValidationCreate, 0, 1},
Expand Down Expand Up @@ -1481,7 +1411,7 @@ rpcCmdToJson(
{
Json::Value jvRequest(Json::objectValue);

RPCParser rpParser(j);
RPCParser rpParser(apiVersion, j);
Json::Value jvRpcParams(Json::arrayValue);

for (int i = 1; i != args.size(); i++)
Expand Down Expand Up @@ -1673,7 +1603,7 @@ fromCommandLine(
Logs& logs)
{
auto const result =
rpcClient(vCmd, config, logs, RPC::apiMaximumSupportedVersion);
rpcClient(vCmd, config, logs, RPC::apiCommandLineVersion);

std::cout << result.second.toStyledString();

Expand Down
5 changes: 3 additions & 2 deletions src/ripple/rpc/impl/RPCHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ extern beast::SemanticVersion const lastVersion;
constexpr unsigned int apiInvalidVersion = 0;
constexpr unsigned int apiVersionIfUnspecified = 1;
constexpr unsigned int apiMinimumSupportedVersion = 1;
constexpr unsigned int apiMaximumSupportedVersion = 1;
constexpr unsigned int apiBetaVersion = 2;
constexpr unsigned int apiMaximumSupportedVersion = 2;
constexpr unsigned int apiCommandLineVersion = 1; // TODO Bump to 2 later
constexpr unsigned int apiBetaVersion = 3;
constexpr unsigned int apiMaximumValidVersion = apiBetaVersion;

static_assert(apiMinimumSupportedVersion >= apiVersionIfUnspecified);
Expand Down
43 changes: 41 additions & 2 deletions src/test/jtx/Env.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ class Env
The command is examined and used to build
the correct JSON as per the arguments.
*/
template <class... Args>
Json::Value
rpc(unsigned apiVersion,
std::unordered_map<std::string, std::string> const& headers,
std::string const& cmd,
Args&&... args);

template <class... Args>
Json::Value
rpc(unsigned apiVersion, std::string const& cmd, Args&&... args);

template <class... Args>
Json::Value
rpc(std::unordered_map<std::string, std::string> const& headers,
Expand Down Expand Up @@ -655,6 +666,7 @@ class Env

Json::Value
do_rpc(
unsigned apiVersion,
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers = {});

Expand Down Expand Up @@ -695,6 +707,31 @@ class Env
std::unordered_map<AccountID, Account> map_;
};

template <class... Args>
Json::Value
Env::rpc(
unsigned apiVersion,
std::unordered_map<std::string, std::string> const& headers,
std::string const& cmd,
Args&&... args)
{
return do_rpc(
apiVersion,
std::vector<std::string>{cmd, std::forward<Args>(args)...},
headers);
}

template <class... Args>
Json::Value
Env::rpc(unsigned apiVersion, std::string const& cmd, Args&&... args)
{
return rpc(
apiVersion,
std::unordered_map<std::string, std::string>(),
cmd,
std::forward<Args>(args)...);
}

template <class... Args>
Json::Value
Env::rpc(
Expand All @@ -703,7 +740,9 @@ Env::rpc(
Args&&... args)
{
return do_rpc(
std::vector<std::string>{cmd, std::forward<Args>(args)...}, headers);
RPC::apiCommandLineVersion,
std::vector<std::string>{cmd, std::forward<Args>(args)...},
headers);
}

template <class... Args>
Expand Down Expand Up @@ -743,7 +782,7 @@ void
forAllApiVersions(VersionedTestCallable auto... testCallable)
{
for (auto testVersion = RPC::apiMinimumSupportedVersion;
testVersion <= RPC::apiBetaVersion;
testVersion <= RPC::apiMaximumValidVersion;
++testVersion)
{
(..., testCallable(testVersion));
Expand Down
8 changes: 2 additions & 6 deletions src/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,11 @@ Env::st(JTx const& jt)

Json::Value
Env::do_rpc(
unsigned apiVersion,
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers)
{
return rpcClient(
args,
app().config(),
app().logs(),
RPC::apiMaximumSupportedVersion,
headers)
return rpcClient(args, app().config(), app().logs(), apiVersion, headers)
.second;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/jtx/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Json::Value
cmdToJSONRPC(
std::vector<std::string> const& args,
beast::Journal j,
unsigned int apiVersion = RPC::apiMaximumSupportedVersion);
unsigned int apiVersion);

} // namespace jtx
} // namespace test
Expand Down
Loading