feat: Add --definitions flag and artifact (#6858)

Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
This commit is contained in:
pdp2121
2026-04-22 16:10:52 -04:00
committed by Bart
parent 2a30934bb1
commit ea05679a39
5 changed files with 92 additions and 8 deletions

View File

@@ -210,6 +210,22 @@ jobs:
retention-days: 3
if-no-files-found: error
- name: Export server definitions
if: ${{ runner.os != 'Windows' && !inputs.build_only && env.VOIDSTAR_ENABLED != 'true' }}
working-directory: ${{ env.BUILD_DIR }}
run: |
set -o pipefail
./xrpld --definitions | python3 -m json.tool > server_definitions.json
- name: Upload server definitions
if: ${{ github.event.repository.visibility == 'public' && inputs.config_name == 'debian-bookworm-gcc-13-amd64-release' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: server-definitions
path: ${{ env.BUILD_DIR }}/server_definitions.json
retention-days: 3
if-no-files-found: error
- name: Check linking (Linux)
if: ${{ runner.os == 'Linux' && env.SANITIZERS_ENABLED == 'false' }}
working-directory: ${{ env.BUILD_DIR }}

View File

@@ -1,6 +1,7 @@
#include <test/jtx/Env.h>
#include <xrpld/rpc/handlers/server_info/ServerDefinitions.h>
#include <xrpl/beast/unit_test/suite.h>
#include <xrpl/protocol/LedgerFormats.h>
#include <xrpl/protocol/SOTemplate.h>
@@ -451,10 +452,40 @@ public:
}
}
void
testGetServerDefinitionsJson()
{
testcase("getServerDefinitionsJson");
auto const& defs = getServerDefinitionsJson();
for (auto const& field :
{jss::ACCOUNT_SET_FLAGS,
jss::FIELDS,
jss::LEDGER_ENTRY_FLAGS,
jss::LEDGER_ENTRY_FORMATS,
jss::LEDGER_ENTRY_TYPES,
jss::TRANSACTION_FLAGS,
jss::TRANSACTION_FORMATS,
jss::TRANSACTION_RESULTS,
jss::TRANSACTION_TYPES,
jss::TYPES,
jss::hash})
{
BEAST_EXPECT(defs.isMember(field));
}
// verify it returns the same hash as the RPC handler
using namespace test::jtx;
Env env(*this);
auto const rpcResult = env.rpc("server_definitions");
BEAST_EXPECT(defs[jss::hash] == rpcResult[jss::result][jss::hash]);
}
void
run() override
{
testServerDefinitions();
testGetServerDefinitionsJson();
}
};

View File

@@ -3,6 +3,7 @@
#include <xrpld/core/ConfigSections.h>
#include <xrpld/core/TimeKeeper.h>
#include <xrpld/rpc/RPCCall.h>
#include <xrpld/rpc/handlers/server_info/ServerDefinitions.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/SlabAllocator.h>
@@ -13,6 +14,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/StartUpType.h>
#include <xrpl/git/Git.h>
#include <xrpl/json/json_writer.h>
#include <xrpl/protocol/BuildInfo.h>
#include <xrpl/protocol/SystemParameters.h>
#include <xrpl/server/Vacuum.h>
@@ -376,12 +378,12 @@ run(int argc, char** argv)
"nodeid", po::value<std::string>(), "Specify the node identity for this server.")(
"quorum", po::value<std::size_t>(), "Override the minimum validation quorum.")(
"silent", "No output to the console after startup.")("standalone,a", "Run with no peers.")(
"verbose,v", "Verbose logging.")
("force_ledger_present_range",
po::value<std::string>(),
"Specify the range of present ledgers for testing purposes. Min and "
"max values are comma separated.")("version", "Display the build version.");
"verbose,v", "Verbose logging.")(
"definitions", "Output server definitions as JSON and exit.")(
"force_ledger_present_range",
po::value<std::string>(),
"Specify the range of present ledgers for testing purposes. Min and "
"max values are comma separated.")("version", "Display the build version.");
po::options_description data("Ledger/Data Options");
data.add_options()("import", importText.c_str())(
@@ -503,10 +505,20 @@ run(int argc, char** argv)
if (vm.contains("version"))
{
// LCOV_EXCL_START
std::cout << "xrpld version " << BuildInfo::getVersionString() << std::endl;
std::cout << "Git commit hash: " << xrpl::git::getCommitHash() << std::endl;
std::cout << "Git build branch: " << xrpl::git::getBuildBranch() << std::endl;
return 0;
// LCOV_EXCL_STOP
}
if (vm.contains("definitions"))
{
// LCOV_EXCL_START
std::cout << Json::FastWriter().write(getServerDefinitionsJson());
return 0;
// LCOV_EXCL_STOP
}
#ifndef ENABLE_TESTS

View File

@@ -1,3 +1,5 @@
#include <xrpld/rpc/handlers/server_info/ServerDefinitions.h>
#include <xrpld/rpc/Context.h>
#include <xrpl/basics/base_uint.h>
@@ -369,8 +371,21 @@ ServerDefinitions::ServerDefinitions() : defs_{Json::objectValue}
}
}
ServerDefinitions const&
getDefinitions()
{
static ServerDefinitions const defs{};
return defs;
}
} // namespace detail
Json::Value const&
getServerDefinitionsJson()
{
return detail::getDefinitions().get();
}
Json::Value
doServerDefinitions(RPC::JsonContext& context)
{
@@ -383,7 +398,7 @@ doServerDefinitions(RPC::JsonContext& context)
return RPC::invalid_field_error(jss::hash);
}
static detail::ServerDefinitions const defs{};
auto const& defs = detail::getDefinitions();
if (defs.hashMatches(hash))
{
Json::Value jv = Json::objectValue;

View File

@@ -0,0 +1,10 @@
#pragma once
#include <xrpl/json/json_value.h>
namespace xrpl {
Json::Value const&
getServerDefinitionsJson();
} // namespace xrpl