Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into site-timeout
Browse files Browse the repository at this point in the history
* upstream/develop:
  Rectify the import paths of boost/iterator: (XRPLF#4293)
  Allow port numbers be be specified with a colon: (XRPLF#4328)
  Use <=> operator for base_uint, Issue, and Book: (XRPLF#4411)
  Reporting Mode: Do not attempt to acquire missing data from peer network (XRPLF#4458)
  • Loading branch information
ximinez committed Mar 15, 2023
2 parents 2a9683c + 9309b57 commit 5df53c8
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 247 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Ledger::Ledger(
{
info_.hash = calculateLedgerHash(info_);
if (acquire && !config.reporting())
family.missingNode(info_.hash, info_.seq);
family.missingNodeAcquireByHash(info_.hash, info_.seq);
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/ripple/app/tx/impl/details/NFTokenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,22 @@ getPageForToken(
return nullptr;
else
{
// This would be an ideal place for the spaceship operator...
int const relation = compare(id & nft::pageMask, cmp);
auto const relation{(id & nft::pageMask) <=> cmp};
if (relation == 0)
{
// If the passed in id belongs exactly on this (full) page
// this account simply cannot store the NFT.
return nullptr;
}

else if (relation > 0)
if (relation > 0)
{
// We need to leave the entire contents of this page in
// narr so carr stays empty. The new NFT will be
// inserted in carr. This keeps the NFTs that must be
// together all on their own page.
splitIter = narr.end();
}

// If neither of those conditions apply then put all of
// narr into carr and produce an empty narr where the new NFT
Expand Down Expand Up @@ -228,7 +231,7 @@ compareTokens(uint256 const& a, uint256 const& b)
// 96-bits are identical we still need a fully deterministic sort.
// So we sort on the low 96-bits first. If those are equal we sort on
// the whole thing.
if (auto const lowBitsCmp = compare(a & nft::pageMask, b & nft::pageMask);
if (auto const lowBitsCmp{(a & nft::pageMask) <=> (b & nft::pageMask)};
lowBitsCmp != 0)
return lowBitsCmp < 0;

Expand Down
86 changes: 25 additions & 61 deletions src/ripple/basics/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <ripple/beast/utility/Zero.h>
#include <boost/endian/conversion.hpp>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <array>
#include <cstring>
#include <functional>
Expand Down Expand Up @@ -549,103 +550,66 @@ using uint160 = base_uint<160>;
using uint256 = base_uint<256>;

template <std::size_t Bits, class Tag>
inline int
compare(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
[[nodiscard]] inline constexpr std::strong_ordering
operator<=>(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs)
{
auto ret = std::mismatch(a.cbegin(), a.cend(), b.cbegin());

if (ret.first == a.cend())
return 0;
// This comparison might seem wrong on a casual inspection because it
// compares data internally stored as std::uint32_t byte-by-byte. But
// note that the underlying data is stored in big endian, even if the
// plaform is little endian. This makes the comparison correct.
//
// FIXME: use std::lexicographical_compare_three_way once support is
// added to MacOS.

// a > b
if (*ret.first > *ret.second)
return 1;
auto const ret = std::mismatch(lhs.cbegin(), lhs.cend(), rhs.cbegin());

// a < b
return -1;
}

template <std::size_t Bits, class Tag>
inline bool
operator<(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare(a, b) < 0;
}
// a == b
if (ret.first == lhs.cend())
return std::strong_ordering::equivalent;

template <std::size_t Bits, class Tag>
inline bool
operator<=(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare(a, b) <= 0;
return (*ret.first > *ret.second) ? std::strong_ordering::greater
: std::strong_ordering::less;
}

template <std::size_t Bits, class Tag>
inline bool
operator>(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
template <std::size_t Bits, typename Tag>
[[nodiscard]] inline constexpr bool
operator==(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs)
{
return compare(a, b) > 0;
}

template <std::size_t Bits, class Tag>
inline bool
operator>=(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare(a, b) >= 0;
}

template <std::size_t Bits, class Tag>
inline bool
operator==(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare(a, b) == 0;
}

template <std::size_t Bits, class Tag>
inline bool
operator!=(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare(a, b) != 0;
return (lhs <=> rhs) == 0;
}

//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
inline bool
inline constexpr bool
operator==(base_uint<Bits, Tag> const& a, std::uint64_t b)
{
return a == base_uint<Bits, Tag>(b);
}

template <std::size_t Bits, class Tag>
inline bool
operator!=(base_uint<Bits, Tag> const& a, std::uint64_t b)
{
return !(a == b);
}

//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag>
inline constexpr base_uint<Bits, Tag>
operator^(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag>(a) ^= b;
}

template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag>
inline constexpr base_uint<Bits, Tag>
operator&(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag>(a) &= b;
}

template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag>
inline constexpr base_uint<Bits, Tag>
operator|(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag>(a) |= b;
}

template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag>
inline constexpr base_uint<Bits, Tag>
operator+(base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag>(a) += b;
Expand Down
23 changes: 23 additions & 0 deletions src/ripple/core/impl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <regex>
#include <thread>

#if BOOST_OS_WINDOWS
Expand Down Expand Up @@ -468,6 +469,28 @@ Config::loadFromString(std::string const& fileContents)
if (auto s = getIniFileSection(secConfig, SECTION_SNTP))
SNTP_SERVERS = *s;

// if the user has specified ip:port then replace : with a space.
{
auto replaceColons = [](std::vector<std::string>& strVec) {
const static std::regex e(":([0-9]+)$");
for (auto& line : strVec)
{
// skip anything that might be an ipv6 address
if (std::count(line.begin(), line.end(), ':') != 1)
continue;

std::string result = std::regex_replace(line, e, " $1");
// sanity check the result of the replace, should be same length
// as input
if (result.size() == line.size())
line = result;
}
};

replaceColons(IPS_FIXED);
replaceColons(IPS);
}

{
std::string dbPath;
if (getSingleSection(secConfig, "database_path", dbPath, j_))
Expand Down
22 changes: 18 additions & 4 deletions src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,31 @@ class RPCParser
return jvRequest;
}

// connect <ip> [port]
// connect <ip[:port]> [port]
Json::Value
parseConnect(Json::Value const& jvParams)
{
Json::Value jvRequest(Json::objectValue);

jvRequest[jss::ip] = jvParams[0u].asString();

std::string ip = jvParams[0u].asString();
if (jvParams.size() == 2)
{
jvRequest[jss::ip] = ip;
jvRequest[jss::port] = jvParams[1u].asUInt();
return jvRequest;
}

// handle case where there is one argument of the form ip:port
if (std::count(ip.begin(), ip.end(), ':') == 1)
{
std::size_t colon = ip.find_last_of(":");
jvRequest[jss::ip] = std::string{ip, 0, colon};
jvRequest[jss::port] =
Json::Value{std::string{ip, colon + 1}}.asUInt();
return jvRequest;
}

// default case, no port
jvRequest[jss::ip] = ip;
return jvRequest;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/overlay/impl/ProtocolVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <ripple/beast/core/LexicalCast.h>
#include <ripple/beast/rfc2616.h>
#include <ripple/overlay/impl/ProtocolVersion.h>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <boost/regex.hpp>
#include <algorithm>
#include <functional>
Expand Down
28 changes: 12 additions & 16 deletions src/ripple/protocol/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,24 @@ hash_append(Hasher& h, Book const& b)
Book
reversed(Book const& book);

/** Ordered comparison. */
int
compare(Book const& lhs, Book const& rhs);

/** Equality comparison. */
/** @{ */
bool
operator==(Book const& lhs, Book const& rhs);
bool
operator!=(Book const& lhs, Book const& rhs);
[[nodiscard]] inline constexpr bool
operator==(Book const& lhs, Book const& rhs)
{
return (lhs.in == rhs.in) && (lhs.out == rhs.out);
}
/** @} */

/** Strict weak ordering. */
/** @{ */
bool
operator<(Book const& lhs, Book const& rhs);
bool
operator>(Book const& lhs, Book const& rhs);
bool
operator>=(Book const& lhs, Book const& rhs);
bool
operator<=(Book const& lhs, Book const& rhs);
[[nodiscard]] inline constexpr std::weak_ordering
operator<=>(Book const& lhs, Book const& rhs)
{
if (auto const c{lhs.in <=> rhs.in}; c != 0)
return c;
return lhs.out <=> rhs.out;
}
/** @} */

} // namespace ripple
Expand Down
36 changes: 17 additions & 19 deletions src/ripple/protocol/Issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,29 @@ hash_append(Hasher& h, Issue const& r)
hash_append(h, r.currency, r.account);
}

/** Ordered comparison.
The assets are ordered first by currency and then by account,
if the currency is not XRP.
*/
int
compare(Issue const& lhs, Issue const& rhs);

/** Equality comparison. */
/** @{ */
bool
operator==(Issue const& lhs, Issue const& rhs);
bool
operator!=(Issue const& lhs, Issue const& rhs);
[[nodiscard]] inline constexpr bool
operator==(Issue const& lhs, Issue const& rhs)
{
return (lhs.currency == rhs.currency) &&
(isXRP(lhs.currency) || lhs.account == rhs.account);
}
/** @} */

/** Strict weak ordering. */
/** @{ */
bool
operator<(Issue const& lhs, Issue const& rhs);
bool
operator>(Issue const& lhs, Issue const& rhs);
bool
operator>=(Issue const& lhs, Issue const& rhs);
bool
operator<=(Issue const& lhs, Issue const& rhs);
[[nodiscard]] inline constexpr std::weak_ordering
operator<=>(Issue const& lhs, Issue const& rhs)
{
if (auto const c{lhs.currency <=> rhs.currency}; c != 0)
return c;

if (isXRP(lhs.currency))
return std::weak_ordering::equivalent;

return (lhs.account <=> rhs.account);
}
/** @} */

//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 5df53c8

Please sign in to comment.