Compare commits

..

20 Commits

Author SHA1 Message Date
JCW
b7a066caa1 Updated the approach after we introduced the use of canonlalize in DatabaseNodeImp.cpp 2026-06-06 18:13:47 +01:00
JCW
79d19f392c Merge remote-tracking branch 'origin/develop' into a1q123456/remove-const-cast-from-tagged-cache 2026-06-06 12:11:43 +01:00
JCW
b3e1937244 Address PR comments 2026-04-01 21:07:28 +01:00
Jingchen
e7f3241af3 Update src/test/basics/TaggedCache_test.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-01 21:05:57 +01:00
JCW
9c23371c46 Address PR comments 2026-04-01 21:04:20 +01:00
Jingchen
f2edebd919 Merge branch 'develop' into a1q123456/remove-const-cast-from-tagged-cache 2026-04-01 16:20:45 +01:00
JCW
a7ee324153 Split the function into 2 2026-04-01 16:19:53 +01:00
JCW
39c66b4da0 Simplify the code and address PR comments
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-03-18 22:23:53 +00:00
JCW
0bcf43a26e Simplify the code and address PR comments
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-03-18 22:06:17 +00:00
JCW
9b42bd288a Merge remote-tracking branch 'origin/develop' into a1q123456/remove-const-cast-from-tagged-cache
Signed-off-by: JCW <a1q123456@users.noreply.github.com>

# Conflicts:
#	include/xrpl/basics/TaggedCache.h
#	include/xrpl/basics/TaggedCache.ipp
#	src/test/basics/TaggedCache_test.cpp
2026-03-18 21:47:22 +00:00
JCW
95969cb95e Remove unrelated optimisation to make the PR easier to review
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-03-18 21:45:22 +00:00
JCW
bf4dc342c6 Fix formatting
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-10-29 14:36:18 +00:00
JCW
a71cd5d271 Address PR comments
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-10-28 11:31:45 +00:00
JCW
45baf7339c Merge remote-tracking branch 'origin/develop' into a1q123456/remove-const-cast-from-tagged-cache 2025-10-28 11:26:58 +00:00
JCW
2bc2930a28 Fix errors
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-09-18 20:16:36 +01:00
JCW
e837171f7c Fix formatting
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-09-18 20:16:36 +01:00
JCW
6f05bd035c Add test case and improve test coverage
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-09-18 20:16:36 +01:00
JCW
b98b42bbec Fix comment and fix formatting
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-09-18 20:16:36 +01:00
JCW
6e6ea4311b Add unittest
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2025-09-18 20:16:36 +01:00
JCW
f2271305e5 Fix attempt 2025-09-18 20:16:34 +01:00
52 changed files with 321 additions and 142 deletions

View File

@@ -95,7 +95,13 @@ strUnHex(std::size_t strSize, Iterator begin, Iterator end)
}
inline std::optional<Blob>
strUnHex(std::string_view strSrc)
strUnHex(std::string const& strSrc)
{
return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend());
}
inline std::optional<Blob>
strViewUnHex(std::string_view strSrc)
{
return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend());
}

View File

@@ -17,6 +17,23 @@
namespace xrpl {
namespace detail {
// Replace-policy tags used by TaggedCache::canonicalizeReplaceCache /
// canonicalizeReplaceClient when calling canonicalize. With ReplaceCached the
// cached value is always replaced with `data`, so `data` is never written back
// and may be const. With ReplaceClient the cached value is kept and written
// back into `data` (the client's pointer), which must therefore be writable.
struct ReplaceCached
{
};
struct ReplaceClient
{
};
} // namespace detail
/** Map/cache combination.
This class implements a cache and a map. The cache keeps objects alive
in the map. The map allows multiple code paths that reference objects
@@ -96,6 +113,16 @@ public:
bool
del(key_type const& key, bool valid);
private:
// Selects the `data` parameter type of canonicalize from the replace
// policy: const for detail::ReplaceCached (never written back), otherwise
// writable.
template <typename R>
using CanonicalizeClientPointerType = std::conditional_t<
std::is_same_v<detail::ReplaceCached, R>,
SharedPointerType const&,
SharedPointerType&>;
public:
/** Replace aliased objects with originals.
@@ -104,15 +131,23 @@ public:
This routine eliminates the duplicate and performs a replacement
on the callers shared pointer if needed.
`replacePolicy` is a callable taking the existing strong pointer and
returning whether to replace the cached value with `data` (true) or to
keep the cached value and write it back into `data` (false). Because the
write-back case mutates `data`, `data` must be writable.
(canonicalizeReplaceCache / canonicalizeReplaceClient call this with
internal replace-policy tags in place of a callable.)
@param key The key corresponding to the object
@param data A shared pointer to the data corresponding to the object.
@param replace Function that decides if cache should be replaced
@param replacePolicy A callable (existing strong pointer -> bool).
@return `true` If the key already existed.
*/
template <class R>
bool
canonicalize(key_type const& key, SharedPointerType& data, R&& replaceCallback);
canonicalize(key_type const& key, CanonicalizeClientPointerType<R> data, R&& replacePolicy);
bool
canonicalizeReplaceCache(key_type const& key, SharedPointerType const& data);

View File

@@ -303,10 +303,26 @@ template <
template <class R>
inline bool
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
canonicalize(key_type const& key, SharedPointerType& data, R&& replaceCallback)
canonicalize(
key_type const& key,
CanonicalizeClientPointerType<R> data,
[[maybe_unused]] R&& replacePolicy)
{
// Return canonical value, store if needed, refresh in cache
// Return values: true=we had the data already
// `replacePolicy` is one of:
// - detail::ReplaceCached: always replace the cached value with `data`;
// `data` is never written back and may be const.
// - detail::ReplaceClient: keep the cached value and write it back into
// `data` (the client's pointer), which must therefore be writable.
// - a callable(strong pointer) -> bool: decide at run time; `data` must
// be writable.
// For the latter two the write-back below requires a mutable `data`, so
// passing a const argument is a compile error.
using C = std::remove_cvref_t<R>;
constexpr bool replaceCached = std::is_same_v<C, detail::ReplaceCached>;
std::scoped_lock const lock(mutex_);
auto cit = cache_.find(key);
@@ -324,27 +340,28 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
Entry& entry = cit->second;
entry.touch(clock_.now());
auto shouldReplace = [&] {
if constexpr (std::is_invocable_r_v<bool, R>)
auto shouldReplaceCached = [&] {
if constexpr (replaceCached)
{
// The reason for this extra complexity is for intrusive
// strong/weak combo getting a strong is relatively expensive
// and not needed for many cases.
return replaceCallback();
return true;
}
else if constexpr (std::is_same_v<C, detail::ReplaceClient>)
{
return false;
}
else
{
return replaceCallback(entry.ptr.getStrong());
return replacePolicy(entry.ptr.getStrong());
}
};
if (entry.isCached())
{
if (shouldReplace())
if (shouldReplaceCached())
{
entry.ptr = data;
}
else
else if constexpr (!replaceCached)
{
data = entry.ptr.getStrong();
}
@@ -356,11 +373,11 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
if (cachedData)
{
if (shouldReplace())
if (shouldReplaceCached())
{
entry.ptr = data;
}
else
else if constexpr (!replaceCached)
{
entry.ptr.convertToStrong();
data = cachedData;
@@ -389,7 +406,7 @@ inline bool
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
canonicalizeReplaceCache(key_type const& key, SharedPointerType const& data)
{
return canonicalize(key, const_cast<SharedPointerType&>(data), []() { return true; });
return canonicalize(key, data, detail::ReplaceCached{});
}
template <
@@ -405,7 +422,7 @@ inline bool
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
canonicalizeReplaceClient(key_type const& key, SharedPointerType& data)
{
return canonicalize(key, data, []() { return false; });
return canonicalize(key, data, detail::ReplaceClient{});
}
template <

View File

@@ -43,7 +43,7 @@ std::string
base64Encode(std::uint8_t const* data, std::size_t len);
inline std::string
base64Encode(std::string_view s)
base64Encode(std::string const& s)
{
return base64Encode(reinterpret_cast<std::uint8_t const*>(s.data()), s.size());
}

View File

@@ -1,13 +1,12 @@
#pragma once
#include <string>
#include <string_view>
namespace xrpl {
template <class Stream, class Iter>
Stream&
join(Stream& s, Iter iter, Iter end, std::string_view delimiter)
join(Stream& s, Iter iter, Iter end, std::string const& delimiter)
{
if (iter == end)
return s;

View File

@@ -29,7 +29,7 @@ public:
factory function in the Collector interface.
@see Collector.
*/
explicit Counter(std::shared_ptr<CounterImpl> impl) : impl_(std::move(impl))
explicit Counter(std::shared_ptr<CounterImpl> const& impl) : impl_(impl)
{
}

View File

@@ -31,7 +31,7 @@ public:
factory function in the Collector interface.
@see Collector.
*/
explicit Event(std::shared_ptr<EventImpl> impl) : impl_(std::move(impl))
explicit Event(std::shared_ptr<EventImpl> const& impl) : impl_(impl)
{
}

View File

@@ -31,7 +31,7 @@ public:
factory function in the Collector interface.
@see Collector.
*/
explicit Gauge(std::shared_ptr<GaugeImpl> impl) : impl_(std::move(impl))
explicit Gauge(std::shared_ptr<GaugeImpl> const& impl) : impl_(impl)
{
}

View File

@@ -20,7 +20,7 @@ public:
factory function in the Collector interface.
@see Collector.
*/
explicit Hook(std::shared_ptr<HookImpl> impl) : impl_(std::move(impl))
explicit Hook(std::shared_ptr<HookImpl> const& impl) : impl_(impl)
{
}

View File

@@ -28,7 +28,7 @@ public:
factory function in the Collector interface.
@see Collector.
*/
explicit Meter(std::shared_ptr<MeterImpl> impl) : impl_(std::move(impl))
explicit Meter(std::shared_ptr<MeterImpl> const& impl) : impl_(impl)
{
}

View File

@@ -41,7 +41,7 @@ private:
public:
template <class = void>
explicit Selector(ModeT mode, std::string pattern = "");
explicit Selector(ModeT mode, std::string const& pattern = "");
template <class = void>
bool
@@ -51,7 +51,7 @@ public:
//------------------------------------------------------------------------------
template <class>
Selector::Selector(ModeT mode, std::string pattern) : mode_(mode), pat_(std::move(pattern))
Selector::Selector(ModeT mode, std::string const& pattern) : mode_(mode), pat_(pattern)
{
if (mode_ == ModeT::Automatch && pattern.empty())
mode_ = ModeT::All;

View File

@@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
namespace xrpl {
@@ -35,7 +34,7 @@ private:
static void
standard(std::string& strWord);
static int
wsrch(std::string_view strWord, int iMin, int iMax);
wsrch(std::string const& strWord, int iMin, int iMax);
static int
etob(std::string& strData, std::vector<std::string> vsHuman);

View File

@@ -93,7 +93,7 @@ public:
}
void
insert(std::shared_ptr<STTx const> txn);
insert(std::shared_ptr<STTx const> const& txn);
// Pops the next transaction on account that follows seqProx in the
// sort order. Normally called when a transaction is successfully

View File

@@ -53,7 +53,7 @@ public:
boost::system::error_code const& ecResult,
int iStatus,
std::string const& strData)> complete,
beast::Journal const& j);
beast::Journal& j);
static void
get(bool bSSL,
@@ -67,7 +67,7 @@ public:
boost::system::error_code const& ecResult,
int iStatus,
std::string const& strData)> complete,
beast::Journal const& j);
beast::Journal& j);
static void
request(
@@ -82,7 +82,7 @@ public:
boost::system::error_code const& ecResult,
int iStatus,
std::string const& strData)> complete,
beast::Journal const& j);
beast::Journal& j);
};
} // namespace xrpl

View File

@@ -17,8 +17,8 @@ public:
STVector256() = default;
explicit STVector256(SField const& n);
explicit STVector256(std::vector<uint256> vector);
STVector256(SField const& n, std::vector<uint256> vector);
explicit STVector256(std::vector<uint256> const& vector);
STVector256(SField const& n, std::vector<uint256> const& vector);
STVector256(SerialIter& sit, SField const& name);
[[nodiscard]] SerializedTypeID
@@ -103,12 +103,12 @@ inline STVector256::STVector256(SField const& n) : STBase(n)
{
}
inline STVector256::STVector256(std::vector<uint256> vector) : value_(std::move(vector))
inline STVector256::STVector256(std::vector<uint256> const& vector) : value_(vector)
{
}
inline STVector256::STVector256(SField const& n, std::vector<uint256> vector)
: STBase(n), value_(std::move(vector))
inline STVector256::STVector256(SField const& n, std::vector<uint256> const& vector)
: STBase(n), value_(vector)
{
}

View File

@@ -10,7 +10,6 @@
#include <functional>
#include <memory>
#include <ostream>
#include <string_view>
#include <vector>
namespace xrpl {
@@ -54,10 +53,10 @@ public:
/** Send a copy of data asynchronously. */
/** @{ */
void
write(std::string_view s)
write(std::string const& s)
{
if (!s.empty())
write(s.data(), s.size());
write(&s[0], std::distance(s.begin(), s.end()));
}
template <typename BufferSequence>

View File

@@ -161,7 +161,7 @@ public:
setLedgerSeq(std::uint32_t lseq);
bool
fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter const* filter);
fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
// normal hash access functions
@@ -248,7 +248,7 @@ public:
@param return The nodes known to be missing
*/
std::vector<std::pair<SHAMapNodeID, uint256>>
getMissingNodes(int maxNodes, SHAMapSyncFilter const* filter);
getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
bool
getNodeFat(
@@ -281,9 +281,9 @@ public:
serializeRoot(Serializer& s) const;
SHAMapAddNode
addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFilter const* filter);
addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFilter* filter);
SHAMapAddNode
addKnownNode(SHAMapNodeID const& nodeID, Slice const& rawNode, SHAMapSyncFilter const* filter);
addKnownNode(SHAMapNodeID const& nodeID, Slice const& rawNode, SHAMapSyncFilter* filter);
// status functions
void
@@ -343,11 +343,11 @@ private:
SHAMapTreeNodePtr
fetchNodeNT(SHAMapHash const& hash) const;
SHAMapTreeNodePtr
fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const;
fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
SHAMapTreeNodePtr
fetchNode(SHAMapHash const& hash) const;
SHAMapTreeNodePtr
checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const;
checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
/** Update hashes up to the root */
void
@@ -411,7 +411,7 @@ private:
descendAsync(
SHAMapInnerNode* parent,
int branch,
SHAMapSyncFilter const* filter,
SHAMapSyncFilter* filter,
bool& pending,
descendCallback&&) const;
@@ -420,7 +420,7 @@ private:
SHAMapInnerNode* parent,
SHAMapNodeID const& parentID,
int branch,
SHAMapSyncFilter const* filter) const;
SHAMapSyncFilter* filter) const;
// Non-storing
// Does not hook the returned node to its parent
@@ -461,7 +461,7 @@ private:
// basic parameters
int max;
SHAMapSyncFilter const* filter;
SHAMapSyncFilter* filter;
int const maxDefer;
std::uint32_t generation;
@@ -500,11 +500,7 @@ private:
// reads
std::map<SHAMapInnerNode*, SHAMapNodeID> resumes;
MissingNodes(
int max,
SHAMapSyncFilter const* filter,
int maxDefer,
std::uint32_t generation)
MissingNodes(int max, SHAMapSyncFilter* filter, int maxDefer, std::uint32_t generation)
: max(max), filter(filter), maxDefer(maxDefer), generation(generation), deferred(0)
{
missingNodes.reserve(max);

View File

@@ -127,7 +127,7 @@ operator<<(std::ostream& out, SHAMapNodeID const& node)
deserializeSHAMapNodeID(void const* data, std::size_t size);
[[nodiscard]] inline std::optional<SHAMapNodeID>
deserializeSHAMapNodeID(std::string_view s)
deserializeSHAMapNodeID(std::string const& s)
{
return deserializeSHAMapNodeID(s.data(), s.size());
}

View File

@@ -66,7 +66,7 @@ public:
class StatsDHookImpl : public HookImpl, public StatsDMetricBase
{
public:
StatsDHookImpl(HandlerType handler, std::shared_ptr<StatsDCollectorImp> impl);
StatsDHookImpl(HandlerType handler, std::shared_ptr<StatsDCollectorImp> const& impl);
~StatsDHookImpl() override;
@@ -86,7 +86,7 @@ private:
class StatsDCounterImpl : public CounterImpl, public StatsDMetricBase
{
public:
StatsDCounterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl);
StatsDCounterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl);
~StatsDCounterImpl() override;
@@ -115,7 +115,7 @@ private:
class StatsDEventImpl : public EventImpl
{
public:
StatsDEventImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl);
StatsDEventImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl);
~StatsDEventImpl() override = default;
@@ -140,7 +140,7 @@ private:
class StatsDGaugeImpl : public GaugeImpl, public StatsDMetricBase
{
public:
StatsDGaugeImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl);
StatsDGaugeImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl);
~StatsDGaugeImpl() override;
@@ -174,7 +174,7 @@ private:
class StatsDMeterImpl : public MeterImpl, public StatsDMetricBase
{
public:
explicit StatsDMeterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl);
explicit StatsDMeterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl);
~StatsDMeterImpl() override;
@@ -478,8 +478,8 @@ public:
//------------------------------------------------------------------------------
StatsDHookImpl::StatsDHookImpl(HandlerType handler, std::shared_ptr<StatsDCollectorImp> impl)
: impl_(std::move(impl)), handler_(std::move(handler))
StatsDHookImpl::StatsDHookImpl(HandlerType handler, std::shared_ptr<StatsDCollectorImp> const& impl)
: impl_(impl), handler_(std::move(handler))
{
impl_->add(*this);
}
@@ -497,8 +497,10 @@ StatsDHookImpl::doProcess()
//------------------------------------------------------------------------------
StatsDCounterImpl::StatsDCounterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl)
: impl_(std::move(impl)), name_(std::move(name))
StatsDCounterImpl::StatsDCounterImpl(
std::string name,
std::shared_ptr<StatsDCollectorImp> const& impl)
: impl_(impl), name_(std::move(name))
{
impl_->add(*this);
}
@@ -548,8 +550,8 @@ StatsDCounterImpl::doProcess()
//------------------------------------------------------------------------------
StatsDEventImpl::StatsDEventImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl)
: impl_(std::move(impl)), name_(std::move(name))
StatsDEventImpl::StatsDEventImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl)
: impl_(impl), name_(std::move(name))
{
}
@@ -575,8 +577,8 @@ StatsDEventImpl::doNotify(EventImpl::value_type const& value)
//------------------------------------------------------------------------------
StatsDGaugeImpl::StatsDGaugeImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl)
: impl_(std::move(impl)), name_(std::move(name))
StatsDGaugeImpl::StatsDGaugeImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl)
: impl_(impl), name_(std::move(name))
{
impl_->add(*this);
}
@@ -662,8 +664,8 @@ StatsDGaugeImpl::doProcess()
//------------------------------------------------------------------------------
StatsDMeterImpl::StatsDMeterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> impl)
: impl_(std::move(impl)), name_(std::move(name))
StatsDMeterImpl::StatsDMeterImpl(std::string name, std::shared_ptr<StatsDCollectorImp> const& impl)
: impl_(impl), name_(std::move(name))
{
impl_->add(*this);
}

View File

@@ -306,7 +306,7 @@ RFC1751::standard(std::string& strWord)
// Binary search of dictionary.
int
RFC1751::wsrch(std::string_view strWord, int iMin, int iMax)
RFC1751::wsrch(std::string const& strWord, int iMin, int iMax)
{
int iResult = -1;

View File

@@ -40,11 +40,14 @@ CanonicalTXSet::accountKey(AccountID const& account)
}
void
CanonicalTXSet::insert(std::shared_ptr<STTx const> txn)
CanonicalTXSet::insert(std::shared_ptr<STTx const> const& txn)
{
Key const key(
accountKey(txn->getAccountID(sfAccount)), txn->getSeqProxy(), txn->getTransactionID());
map_.insert(std::make_pair(key, std::move(txn)));
map_.insert(
std::make_pair(
Key(accountKey(txn->getAccountID(sfAccount)),
txn->getSeqProxy(),
txn->getTransactionID()),
txn));
}
std::shared_ptr<STTx const>

View File

@@ -64,7 +64,7 @@ public:
boost::asio::io_context& ioContext,
unsigned short const port,
std::size_t maxResponseSize,
beast::Journal const& j)
beast::Journal& j)
: socket_(
ioContext,
gHttpClientSslContext->context()) // NOLINT(bugprone-unchecked-optional-access)
@@ -552,7 +552,7 @@ HTTPClient::get(
std::function<
bool(boost::system::error_code const& ecResult, int iStatus, std::string const& strData)>
complete,
beast::Journal const& j)
beast::Journal& j)
{
auto client = std::make_shared<HTTPClientImp>(ioContext, port, responseMax, j);
client->get(bSSL, deqSites, strPath, timeout, complete);
@@ -570,7 +570,7 @@ HTTPClient::get(
std::function<
bool(boost::system::error_code const& ecResult, int iStatus, std::string const& strData)>
complete,
beast::Journal const& j)
beast::Journal& j)
{
std::deque<std::string> const deqSites(1, strSite);
@@ -590,7 +590,7 @@ HTTPClient::request(
std::function<
bool(boost::system::error_code const& ecResult, int iStatus, std::string const& strData)>
complete,
beast::Journal const& j)
beast::Journal& j)
{
std::deque<std::string> const deqSites(1, strSite);

View File

@@ -206,7 +206,7 @@ SHAMap::finishFetch(SHAMapHash const& hash, std::shared_ptr<NodeObject> const& o
// See if a sync filter has a node
SHAMapTreeNodePtr
SHAMap::checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const
SHAMap::checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const
{
if (auto nodeData = filter->getNode(hash))
{
@@ -232,7 +232,7 @@ SHAMap::checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) cons
// Get a node without throwing
// Used on maps where missing nodes are expected
SHAMapTreeNodePtr
SHAMap::fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const
SHAMap::fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const
{
auto node = cacheLookup(hash);
if (node)
@@ -345,7 +345,7 @@ SHAMap::descend(
SHAMapInnerNode* parent,
SHAMapNodeID const& parentID,
int branch,
SHAMapSyncFilter const* filter) const
SHAMapSyncFilter* filter) const
{
XRPL_ASSERT(parent->isInner(), "xrpl::SHAMap::descend : valid parent input");
XRPL_ASSERT(
@@ -374,7 +374,7 @@ SHAMapTreeNode*
SHAMap::descendAsync(
SHAMapInnerNode* parent,
int branch,
SHAMapSyncFilter const* filter,
SHAMapSyncFilter* filter,
bool& pending,
descendCallback&& callback) const
{
@@ -885,7 +885,7 @@ SHAMap::updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem cons
}
bool
SHAMap::fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter const* filter)
SHAMap::fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter)
{
if (hash == root_->getHash())
return true;

View File

@@ -305,7 +305,7 @@ SHAMap::gmnProcessDeferredReads(MissingNodes& mn)
nodes that are not permanently stored locally
*/
std::vector<std::pair<SHAMapNodeID, uint256>>
SHAMap::getMissingNodes(int max, SHAMapSyncFilter const* filter)
SHAMap::getMissingNodes(int max, SHAMapSyncFilter* filter)
{
XRPL_ASSERT(root_->getHash().isNonZero(), "xrpl::SHAMap::getMissingNodes : nonzero root hash");
XRPL_ASSERT(max > 0, "xrpl::SHAMap::getMissingNodes : valid max input");
@@ -507,7 +507,7 @@ SHAMap::serializeRoot(Serializer& s) const
}
SHAMapAddNode
SHAMap::addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFilter const* filter)
SHAMap::addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFilter* filter)
{
// we already have a root_ node
if (root_->getHash().isNonZero())
@@ -542,7 +542,7 @@ SHAMap::addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFil
}
SHAMapAddNode
SHAMap::addKnownNode(SHAMapNodeID const& node, Slice const& rawNode, SHAMapSyncFilter const* filter)
SHAMap::addKnownNode(SHAMapNodeID const& node, Slice const& rawNode, SHAMapSyncFilter* filter)
{
XRPL_ASSERT(!node.isRoot(), "xrpl::SHAMap::addKnownNode : valid node input");

View File

@@ -8,6 +8,7 @@
#include <xrpl/protocol/Protocol.h>
#include <memory>
#include <utility>
namespace xrpl {
@@ -133,6 +134,129 @@ public:
BEAST_EXPECT(c.getCacheSize() == 0);
BEAST_EXPECT(c.getTrackSize() == 0);
}
{
BEAST_EXPECT(!c.insert(5, "five"));
BEAST_EXPECT(c.getCacheSize() == 1);
BEAST_EXPECT(c.size() == 1);
{
auto const p1 = c.fetch(5);
BEAST_EXPECT(p1 != nullptr);
BEAST_EXPECT(c.getCacheSize() == 1);
BEAST_EXPECT(c.size() == 1);
// Advance the clock a lot
++clock;
c.sweep();
BEAST_EXPECT(c.getCacheSize() == 0);
BEAST_EXPECT(c.size() == 1);
auto p2 = std::make_shared<std::string>("five_2");
BEAST_EXPECT(c.canonicalizeReplaceCache(5, p2));
BEAST_EXPECT(c.getCacheSize() == 1);
BEAST_EXPECT(c.size() == 1);
// Make sure the caller's original pointer is unchanged
BEAST_EXPECT(p1.get() != p2.get());
BEAST_EXPECT(*p2 == "five_2");
auto const p3 = c.fetch(5);
BEAST_EXPECT(p3 != nullptr);
BEAST_EXPECT(p3.get() == p2.get());
BEAST_EXPECT(p3.get() != p1.get());
}
++clock;
c.sweep();
BEAST_EXPECT(c.getCacheSize() == 0);
BEAST_EXPECT(c.size() == 0);
}
{
testcase("intrptr");
struct MyRefCountObject : IntrusiveRefCounts
{
std::string data;
// Needed to support weak intrusive pointers
virtual void
partialDestructor() {};
MyRefCountObject() = default;
explicit MyRefCountObject(std::string data) : data(std::move(data))
{
}
explicit MyRefCountObject(char const* data) : data(data)
{
}
MyRefCountObject&
operator=(MyRefCountObject const& other)
{
data = other.data;
return *this;
}
bool
operator==(MyRefCountObject const& other) const
{
return data == other.data;
}
bool
operator==(std::string const& other) const
{
return data == data;
}
};
using IntrPtrCache = TaggedCache<
Key,
MyRefCountObject,
/*IsKeyCache*/ false,
intr_ptr::SharedWeakUnionPtr<MyRefCountObject>,
intr_ptr::SharedPtr<MyRefCountObject>>;
IntrPtrCache intrPtrCache("IntrPtrTest", 1, 1s, clock, journal);
intrPtrCache.canonicalizeReplaceCache(1, intr_ptr::makeShared<MyRefCountObject>("one"));
BEAST_EXPECT(intrPtrCache.getCacheSize() == 1);
BEAST_EXPECT(intrPtrCache.size() == 1);
{
{
intrPtrCache.canonicalizeReplaceCache(
1, intr_ptr::makeShared<MyRefCountObject>("one_replaced"));
auto p = intrPtrCache.fetch(1);
BEAST_EXPECT(*p == "one_replaced");
// Advance the clock a lot
++clock;
intrPtrCache.sweep();
BEAST_EXPECT(intrPtrCache.getCacheSize() == 0);
BEAST_EXPECT(intrPtrCache.size() == 1);
intrPtrCache.canonicalizeReplaceCache(
1, intr_ptr::makeShared<MyRefCountObject>("one_replaced_2"));
auto p2 = intrPtrCache.fetch(1);
BEAST_EXPECT(*p2 == "one_replaced_2");
intrPtrCache.del(1, true);
}
intrPtrCache.canonicalizeReplaceCache(
1, intr_ptr::makeShared<MyRefCountObject>("one_replaced_3"));
auto p3 = intrPtrCache.fetch(1);
BEAST_EXPECT(*p3 == "one_replaced_3");
}
++clock;
intrPtrCache.sweep();
BEAST_EXPECT(intrPtrCache.getCacheSize() == 0);
BEAST_EXPECT(intrPtrCache.size() == 0);
}
}
};

View File

@@ -40,7 +40,7 @@ private:
std::vector<std::string> const credentials_;
public:
explicit Ids(std::vector<std::string> creds) : credentials_(std::move(creds))
explicit Ids(std::vector<std::string> const& creds) : credentials_(creds)
{
}

View File

@@ -133,7 +133,7 @@ public:
static void
onRequest(Session& session)
{
session.write(std::string_view("Hello, world!\n"));
session.write(std::string("Hello, world!\n"));
if (beast::rfc2616::isKeepAlive(session.request()))
{
session.complete();

View File

@@ -32,7 +32,7 @@ public:
@param l The ledger to wrap.
*/
RCLCxLedger(std::shared_ptr<Ledger const> l) : ledger{std::move(l)}
RCLCxLedger(std::shared_ptr<Ledger const> const& l) : ledger{l}
{
}

View File

@@ -32,7 +32,7 @@ public:
@param v The validation to wrap.
*/
RCLValidation(std::shared_ptr<STValidation> v) : val_{std::move(v)}
RCLValidation(std::shared_ptr<STValidation> const& v) : val_{v}
{
}

View File

@@ -8,7 +8,7 @@
namespace xrpl {
AcceptedLedger::AcceptedLedger(std::shared_ptr<ReadView const> ledger) : ledger_(std::move(ledger))
AcceptedLedger::AcceptedLedger(std::shared_ptr<ReadView const> const& ledger) : ledger_(ledger)
{
transactions_.reserve(256);
@@ -16,12 +16,12 @@ AcceptedLedger::AcceptedLedger(std::shared_ptr<ReadView const> ledger) : ledger_
for (auto const& item : txns)
{
transactions_.emplace_back(
std::make_unique<AcceptedLedgerTx>(ledger_, item.first, item.second));
std::make_unique<AcceptedLedgerTx>(ledger, item.first, item.second));
}
};
transactions_.reserve(256);
insertAll(ledger_->txs);
insertAll(ledger->txs);
std::ranges::sort(transactions_, [](auto const& a, auto const& b) {
return a->getTxnSeq() < b->getTxnSeq();

View File

@@ -25,7 +25,7 @@ namespace xrpl {
class AcceptedLedger : public CountedObject<AcceptedLedger>
{
public:
AcceptedLedger(std::shared_ptr<ReadView const> ledger);
AcceptedLedger(std::shared_ptr<ReadView const> const& ledger);
[[nodiscard]] std::shared_ptr<ReadView const> const&
getLedger() const

View File

@@ -128,13 +128,13 @@ private:
pmDowncast() override;
int
processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData const& data);
processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
bool
takeHeader(std::string const& data);
void
receiveNode(protocol::TMLedgerData const& packet, SHAMapAddNode&);
receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode&);
bool
takeTxRootNode(Slice const& data, SHAMapAddNode&);
@@ -143,10 +143,10 @@ private:
takeAsRootNode(Slice const& data, SHAMapAddNode&);
std::vector<uint256>
neededTxHashes(int max, SHAMapSyncFilter const* filter) const;
neededTxHashes(int max, SHAMapSyncFilter* filter) const;
std::vector<uint256>
neededStateHashes(int max, SHAMapSyncFilter const* filter) const;
neededStateHashes(int max, SHAMapSyncFilter* filter) const;
clock_type& clock_;
clock_type::time_point lastAction_;

View File

@@ -12,7 +12,6 @@
#include <xrpl/ledger/OpenView.h>
#include <mutex>
#include <string_view>
namespace xrpl {
@@ -150,7 +149,7 @@ public:
bool retriesFirst,
OrderedTxs& retries,
ApplyFlags flags,
std::string_view suffix = "",
std::string const& suffix = "",
modify_type const& f = {});
private:

View File

@@ -188,7 +188,7 @@ InboundLedger::~InboundLedger()
}
static std::vector<uint256>
neededHashes(uint256 const& root, SHAMap& map, int max, SHAMapSyncFilter const* filter)
neededHashes(uint256 const& root, SHAMap& map, int max, SHAMapSyncFilter* filter)
{
std::vector<uint256> ret;
@@ -211,13 +211,13 @@ neededHashes(uint256 const& root, SHAMap& map, int max, SHAMapSyncFilter const*
}
std::vector<uint256>
InboundLedger::neededTxHashes(int max, SHAMapSyncFilter const* filter) const
InboundLedger::neededTxHashes(int max, SHAMapSyncFilter* filter) const
{
return neededHashes(ledger_->header().txHash, ledger_->txMap(), max, filter);
}
std::vector<uint256>
InboundLedger::neededStateHashes(int max, SHAMapSyncFilter const* filter) const
InboundLedger::neededStateHashes(int max, SHAMapSyncFilter* filter) const
{
return neededHashes(ledger_->header().accountHash, ledger_->stateMap(), max, filter);
}
@@ -820,7 +820,7 @@ InboundLedger::takeHeader(std::string const& data)
Call with a lock
*/
void
InboundLedger::receiveNode(protocol::TMLedgerData const& packet, SHAMapAddNode& san)
InboundLedger::receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode& san)
{
if (!haveHeader_)
{
@@ -1026,7 +1026,7 @@ InboundLedger::gotData(
// TODO Change peer to Consumer
//
int
InboundLedger::processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData const& packet)
InboundLedger::processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& packet)
{
if (packet.type() == protocol::liBASE)
{

View File

@@ -82,7 +82,7 @@ OpenLedger::accept(
bool retriesFirst,
OrderedTxs& retries,
ApplyFlags flags,
std::string_view suffix,
std::string const& suffix,
modify_type const& f)
{
JLOG(j_.trace()) << "accept ledger " << ledger->seq() << " " << suffix;

View File

@@ -35,8 +35,8 @@ public:
std::uint32_t const ledgerSeq;
std::vector<xrpl::uint256> const skipList;
SkipListData(std::uint32_t const ledgerSeq, std::vector<xrpl::uint256> skipList)
: ledgerSeq(ledgerSeq), skipList(std::move(skipList))
SkipListData(std::uint32_t const ledgerSeq, std::vector<xrpl::uint256> const& skipList)
: ledgerSeq(ledgerSeq), skipList(skipList)
{
}
};

View File

@@ -492,7 +492,7 @@ public:
void
run() override;
void
signalStop(std::string const& msg) override;
signalStop(std::string msg) override;
bool
checkSigs() const override;
void
@@ -1602,7 +1602,7 @@ ApplicationImp::run()
}
void
ApplicationImp::signalStop(std::string const& msg)
ApplicationImp::signalStop(std::string msg)
{
if (!isTimeToStop.test_and_set(std::memory_order_acquire))
{

View File

@@ -111,7 +111,7 @@ public:
virtual void
run() = 0;
virtual void
signalStop(std::string const& msg) = 0;
signalStop(std::string msg) = 0;
[[nodiscard]] virtual bool
checkSigs() const = 0;
virtual void

View File

@@ -1777,7 +1777,7 @@ ValidatorList::getAvailable(
{
std::shared_lock const readLock{mutex_};
auto const keyBlob = strUnHex(pubKey);
auto const keyBlob = strViewUnHex(pubKey);
if (!keyBlob || !publicKeyType(makeSlice(*keyBlob)))
{

View File

@@ -693,7 +693,7 @@ public:
validationSET_EXPIRES ago and were not asked to keep.
*/
void
expire(beast::Journal const& j)
expire(beast::Journal& j)
{
auto const start = std::chrono::steady_clock::now();
{

View File

@@ -117,11 +117,11 @@ public:
/** Broadcast a proposal. */
virtual void
broadcast(protocol::TMProposeSet const& m) = 0;
broadcast(protocol::TMProposeSet& m) = 0;
/** Broadcast a validation. */
virtual void
broadcast(protocol::TMValidation const& m) = 0;
broadcast(protocol::TMValidation& m) = 0;
/** Relay a proposal.
* @param m the serialized proposal
@@ -130,7 +130,7 @@ public:
* @return the set of peers which have already sent us this proposal
*/
virtual std::set<Peer::id_t>
relay(protocol::TMProposeSet const& m, uint256 const& uid, PublicKey const& validator) = 0;
relay(protocol::TMProposeSet& m, uint256 const& uid, PublicKey const& validator) = 0;
/** Relay a validation.
* @param m the serialized validation
@@ -139,7 +139,7 @@ public:
* @return the set of peers which have already sent us this validation
*/
virtual std::set<Peer::id_t>
relay(protocol::TMValidation const& m, uint256 const& uid, PublicKey const& validator) = 0;
relay(protocol::TMValidation& m, uint256 const& uid, PublicKey const& validator) = 0;
/** Relay a transaction. If the tx reduce-relay feature is enabled then
* randomly select peers to relay to and queue transaction's hash

View File

@@ -67,7 +67,7 @@ Cluster::update(
iter = nodes_.erase(iter);
}
nodes_.emplace_hint(iter, identity, std::move(name), loadFee, reportTime);
nodes_.emplace_hint(iter, identity, name, loadFee, reportTime);
return true;
}

View File

@@ -407,7 +407,7 @@ OverlayImpl::makeErrorResponse(
std::shared_ptr<PeerFinder::Slot> const& slot,
http_request_type const& request,
address_type remoteAddress,
std::string const& text)
std::string text)
{
boost::beast::http::response<boost::beast::http::empty_body> msg;
msg.version(request.version());
@@ -1157,14 +1157,14 @@ OverlayImpl::findPeerByPublicKey(PublicKey const& pubKey)
}
void
OverlayImpl::broadcast(protocol::TMProposeSet const& m)
OverlayImpl::broadcast(protocol::TMProposeSet& m)
{
auto const sm = std::make_shared<Message>(m, protocol::mtPROPOSE_LEDGER);
forEach([&](std::shared_ptr<PeerImp> const& p) { p->send(sm); });
}
std::set<Peer::id_t>
OverlayImpl::relay(protocol::TMProposeSet const& m, uint256 const& uid, PublicKey const& validator)
OverlayImpl::relay(protocol::TMProposeSet& m, uint256 const& uid, PublicKey const& validator)
{
if (auto const toSkip = app_.getHashRouter().shouldRelay(uid))
{
@@ -1179,14 +1179,14 @@ OverlayImpl::relay(protocol::TMProposeSet const& m, uint256 const& uid, PublicKe
}
void
OverlayImpl::broadcast(protocol::TMValidation const& m)
OverlayImpl::broadcast(protocol::TMValidation& m)
{
auto const sm = std::make_shared<Message>(m, protocol::mtVALIDATION);
forEach([sm](std::shared_ptr<PeerImp> const& p) { p->send(sm); });
}
std::set<Peer::id_t>
OverlayImpl::relay(protocol::TMValidation const& m, uint256 const& uid, PublicKey const& validator)
OverlayImpl::relay(protocol::TMValidation& m, uint256 const& uid, PublicKey const& validator)
{
if (auto const toSkip = app_.getHashRouter().shouldRelay(uid))
{

View File

@@ -202,16 +202,16 @@ public:
findPeerByPublicKey(PublicKey const& pubKey) override;
void
broadcast(protocol::TMProposeSet const& m) override;
broadcast(protocol::TMProposeSet& m) override;
void
broadcast(protocol::TMValidation const& m) override;
broadcast(protocol::TMValidation& m) override;
std::set<Peer::id_t>
relay(protocol::TMProposeSet const& m, uint256 const& uid, PublicKey const& validator) override;
relay(protocol::TMProposeSet& m, uint256 const& uid, PublicKey const& validator) override;
std::set<Peer::id_t>
relay(protocol::TMValidation const& m, uint256 const& uid, PublicKey const& validator) override;
relay(protocol::TMValidation& m, uint256 const& uid, PublicKey const& validator) override;
void
relay(
@@ -433,7 +433,7 @@ private:
std::shared_ptr<PeerFinder::Slot> const& slot,
http_request_type const& request,
address_type remoteAddress,
std::string const& msg);
std::string msg);
/** Handles crawl requests. Crawl returns information about the
node and its peers so crawlers can map the network.

View File

@@ -201,7 +201,7 @@ public:
file, along with the set of corresponding IP addresses.
*/
virtual void
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses) = 0;
addFixedPeer(std::string const& name, std::vector<beast::IP::Endpoint> const& addresses) = 0;
/** Add a set of strings as fallback IP::Endpoint sources.
@param name A label used for diagnostics.

View File

@@ -148,13 +148,13 @@ public:
}
void
addFixedPeer(std::string_view name, beast::IP::Endpoint const& ep)
addFixedPeer(std::string const& name, beast::IP::Endpoint const& ep)
{
addFixedPeer(name, std::vector<beast::IP::Endpoint>{ep});
}
void
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses)
addFixedPeer(std::string const& name, std::vector<beast::IP::Endpoint> const& addresses)
{
std::scoped_lock const _(lock);

View File

@@ -99,7 +99,8 @@ public:
}
void
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses) override
addFixedPeer(std::string const& name, std::vector<beast::IP::Endpoint> const& addresses)
override
{
logic_.addFixedPeer(name, addresses);
}

View File

@@ -42,8 +42,7 @@ public:
{
}
Status(ErrorCodeI e, std::string s)
: type_(Type::ErrorCodeI), code_(e), messages_({std::move(s)})
Status(ErrorCodeI e, std::string const& s) : type_(Type::ErrorCodeI), code_(e), messages_({s})
{
}

View File

@@ -22,8 +22,8 @@
namespace xrpl {
AssetCache::AssetCache(std::shared_ptr<ReadView const> ledger, beast::Journal j)
: ledger_(std::move(ledger)), journal_(j)
AssetCache::AssetCache(std::shared_ptr<ReadView const> const& ledger, beast::Journal j)
: ledger_(ledger), journal_(j)
{
JLOG(journal_.debug()) << "created for ledger " << ledger_->header().seq;
}

View File

@@ -17,7 +17,7 @@ namespace xrpl {
class AssetCache final : public CountedObject<AssetCache>
{
public:
explicit AssetCache(std::shared_ptr<ReadView const> l, beast::Journal j);
explicit AssetCache(std::shared_ptr<ReadView const> const& l, beast::Journal j);
~AssetCache();
[[nodiscard]] std::shared_ptr<ReadView const> const&

View File

@@ -72,7 +72,7 @@ PathRequest::PathRequest(
PathRequest::PathRequest(
Application& app,
std::function<void(void)> completion,
std::function<void(void)> const& completion,
Resource::Consumer& consumer,
int id,
PathRequestManager& owner,
@@ -80,7 +80,7 @@ PathRequest::PathRequest(
: app_(app)
, journal_(journal)
, owner_(owner)
, fCompletion_(std::move(completion))
, fCompletion_(completion)
, consumer_(consumer)
, jvStatus_(json::ValueType::Object)
, lastIndex_(0)

View File

@@ -51,7 +51,7 @@ public:
// Completion function is called after path update is complete
PathRequest(
Application& app,
std::function<void(void)> completion,
std::function<void(void)> const& completion,
Resource::Consumer& consumer,
int id,
PathRequestManager&,