rippled
Loading...
Searching...
No Matches
BuildInfo.cpp
1#include <xrpl/basics/contract.h>
2#include <xrpl/beast/core/LexicalCast.h>
3#include <xrpl/beast/core/SemanticVersion.h>
4#include <xrpl/git/Git.h>
5#include <xrpl/protocol/BuildInfo.h>
6#include <xrpl/protocol/SystemParameters.h>
7
8#include <boost/preprocessor/stringize.hpp>
9
10#include <algorithm>
11#include <cstdint>
12#include <string>
13#include <string_view>
14
15namespace xrpl {
16
17namespace BuildInfo {
18
19namespace {
20
21//--------------------------------------------------------------------------
22// The build version number. You must edit this for each release
23// and follow the format described at http://semver.org/
24//------------------------------------------------------------------------------
25// clang-format off
26char const* const versionString = "3.2.0-b0"
27 // clang-format on
28 ;
29
30//
31// Don't touch anything below this line
32//
33
35buildVersionString()
36{
37 std::string version = versionString;
38
39#if defined(DEBUG) || defined(SANITIZERS)
40 std::string metadata;
41
42 std::string const& commitHash = xrpl::git::getCommitHash();
43 if (!commitHash.empty())
44 metadata += commitHash + ".";
45
46#ifdef DEBUG
47 metadata += "DEBUG";
48#endif
49
50#if defined(DEBUG) && defined(SANITIZERS)
51 metadata += ".";
52#endif
53
54#ifdef SANITIZERS
55 metadata += BOOST_PP_STRINGIZE(SANITIZERS); // cspell: disable-line
56#endif
57
58 if (!metadata.empty())
59 version += "+" + metadata;
60#endif
61
62 return version;
63}
64
65} // namespace
66
67std::string const&
69{
70 static std::string const value = [] {
71 std::string const s = buildVersionString();
72
74 if (!v.parse(s) || v.print() != s)
75 LogicError(s + ": Bad server version string");
76 return s;
77 }();
78 return value;
79}
80
81std::string const&
83{
84 static std::string const value = systemName() + "-" + getVersionString();
85 return value;
86}
87
88static constexpr std::uint64_t implementationVersionIdentifier = 0x183B'0000'0000'0000LLU;
89static constexpr std::uint64_t implementationVersionIdentifierMask = 0xFFFF'0000'0000'0000LLU;
90
93{
95
97
98 if (v.parse(versionStr))
99 {
100 if (v.majorVersion >= 0 && v.majorVersion <= 255)
101 c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
102
103 if (v.minorVersion >= 0 && v.minorVersion <= 255)
104 c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
105
106 if (v.patchVersion >= 0 && v.patchVersion <= 255)
107 c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
108
109 if (!v.isPreRelease())
110 c |= static_cast<std::uint64_t>(0xC00000);
111
112 if (v.isPreRelease())
113 {
114 std::uint8_t x = 0;
115
116 for (auto const& id : v.preReleaseIdentifiers)
117 {
118 auto parsePreRelease = [](std::string_view identifier,
119 std::string_view prefix,
120 std::uint8_t key,
121 std::uint8_t lok,
122 std::uint8_t hik) -> std::uint8_t {
123 std::uint8_t ret = 0;
124
125 if (prefix != identifier.substr(0, prefix.length()))
126 return 0;
127
129 ret, std::string(identifier.substr(prefix.length()))))
130 return 0;
131
132 if (std::clamp(ret, lok, hik) != ret)
133 return 0;
134
135 return ret + key;
136 };
137
138 x = parsePreRelease(id, "rc", 0x80, 0, 63);
139
140 if (x == 0)
141 x = parsePreRelease(id, "b", 0x40, 0, 63);
142
143 if ((x & 0xC0) != 0)
144 {
145 c |= static_cast<std::uint64_t>(x) << 16;
146 break;
147 }
148 }
149 }
150 }
151
152 return c;
153}
154
157{
158 static std::uint64_t const cookie = {encodeSoftwareVersion(getVersionString())};
159 return cookie;
160}
161
162bool
167
168bool
170{
171 if (isRippledVersion(version))
172 return version > getEncodedVersion();
173 return false;
174}
175
176} // namespace BuildInfo
177
178} // namespace xrpl
T clamp(T... args)
A Semantic Version number.
identifier_list preReleaseIdentifiers
bool isPreRelease() const noexcept
bool parse(std::string_view input)
Parse a semantic version string.
std::string print() const
Produce a string from semantic version components.
T empty(T... args)
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
std::string const & getFullVersionString()
Full server version string.
Definition BuildInfo.cpp:82
static constexpr std::uint64_t implementationVersionIdentifierMask
Definition BuildInfo.cpp:89
std::uint64_t getEncodedVersion()
Returns this server's version packed in a 64-bit integer.
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
static constexpr std::uint64_t implementationVersionIdentifier
Definition BuildInfo.cpp:88
std::uint64_t encodeSoftwareVersion(std::string_view versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:92
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:68
std::string const & getCommitHash()
Definition Git.cpp:18
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
static std::string const & systemName()
T substr(T... args)