mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-19 05:10:55 +00:00
chore: Delete dead code (#7718)
This commit is contained in:
@@ -2319,7 +2319,6 @@ AgedUnorderedContainer<IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>
|
||||
return iterator(iter);
|
||||
}
|
||||
|
||||
#if 1 // Use insert() instead of insert_check() insert_commit()
|
||||
// set, map
|
||||
template <
|
||||
bool IsMulti,
|
||||
@@ -2349,43 +2348,6 @@ AgedUnorderedContainer<IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>
|
||||
deleteElement(p);
|
||||
return std::make_pair(iterator(result.first), false);
|
||||
}
|
||||
#else // As original, use insert_check() / insert_commit () pair.
|
||||
// set, map
|
||||
template <
|
||||
bool IsMulti,
|
||||
bool IsMap,
|
||||
class Key,
|
||||
class T,
|
||||
class Clock,
|
||||
class Hash,
|
||||
class KeyEqual,
|
||||
class Allocator>
|
||||
template <bool maybe_multi, class... Args>
|
||||
auto
|
||||
AgedUnorderedContainer<IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>::emplace(
|
||||
Args&&... args) -> std::pair<iterator, bool>
|
||||
requires(!maybe_multi)
|
||||
{
|
||||
maybe_rehash(1);
|
||||
// VFALCO NOTE Its unfortunate that we need to
|
||||
// construct element here
|
||||
element* const p(new_element(std::forward<Args>(args)...));
|
||||
typename cont_type::insert_commit_data d;
|
||||
auto const result(m_cont.insert_check(
|
||||
extract(p->value),
|
||||
std::cref(m_config.hashFunction()),
|
||||
std::cref(m_config.keyValueEqual()),
|
||||
d));
|
||||
if (result.second)
|
||||
{
|
||||
auto const iter(m_cont.insert_commit(*p, d));
|
||||
chronological.list.push_back(*p);
|
||||
return std::make_pair(iterator(iter), true);
|
||||
}
|
||||
delete_element(p);
|
||||
return std::make_pair(iterator(result.first), false);
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// multiset, multimap
|
||||
template <
|
||||
|
||||
@@ -328,7 +328,6 @@ private:
|
||||
fail("handshake", ec);
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
boost::asio::async_read_until(
|
||||
stream,
|
||||
buf,
|
||||
@@ -339,9 +338,6 @@ private:
|
||||
error_code const& ec, std::size_t bytesTransferred) {
|
||||
self->onRead(ec, bytesTransferred);
|
||||
}));
|
||||
#else
|
||||
close();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -533,7 +529,6 @@ private:
|
||||
}
|
||||
write(buf, "HELLO\n");
|
||||
|
||||
#if 1
|
||||
boost::asio::async_write(
|
||||
stream,
|
||||
buf.data(),
|
||||
@@ -543,11 +538,6 @@ private:
|
||||
error_code const& ec, std::size_t bytesTransferred) {
|
||||
self->onWrite(ec, bytesTransferred);
|
||||
}));
|
||||
#else
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
[self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); }));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -559,7 +549,6 @@ private:
|
||||
fail("write", ec);
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
boost::asio::async_read_until(
|
||||
stream,
|
||||
buf,
|
||||
@@ -570,11 +559,6 @@ private:
|
||||
error_code const& ec, std::size_t bytesTransferred) {
|
||||
self->onRead(ec, bytesTransferred);
|
||||
}));
|
||||
#else
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
[self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); }));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
#include <test/shamap/common.h>
|
||||
#include <test/unit_test/SuiteJournal.h>
|
||||
|
||||
#include <xrpl/basics/Blob.h>
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/SHAMapHash.h>
|
||||
#include <xrpl/basics/Slice.h>
|
||||
#include <xrpl/basics/UnorderedContainers.h>
|
||||
#include <xrpl/basics/random.h>
|
||||
#include <xrpl/beast/unit_test/suite.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/xor_shift_engine.h>
|
||||
#include <xrpl/protocol/Serializer.h>
|
||||
#include <xrpl/protocol/digest.h>
|
||||
#include <xrpl/shamap/SHAMap.h>
|
||||
#include <xrpl/shamap/SHAMapItem.h>
|
||||
#include <xrpl/shamap/SHAMapMissingNode.h>
|
||||
#include <xrpl/shamap/SHAMapSyncFilter.h>
|
||||
#include <xrpl/shamap/SHAMapTreeNode.h>
|
||||
|
||||
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl::tests {
|
||||
|
||||
class FetchPack_test : public beast::unit_test::Suite
|
||||
{
|
||||
public:
|
||||
static constexpr auto kTableItems = 100;
|
||||
static constexpr auto kTableItemsExtra = 20;
|
||||
|
||||
using Map = hash_map<SHAMapHash, Blob>;
|
||||
using Table = SHAMap;
|
||||
using Item = SHAMapItem;
|
||||
|
||||
struct TestFilter : SHAMapSyncFilter
|
||||
{
|
||||
TestFilter(Map& map, beast::Journal journal) : map(map), journal(journal)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
gotNode(
|
||||
bool fromFilter,
|
||||
SHAMapHash const& nodeHash,
|
||||
std::uint32_t ledgerSeq,
|
||||
Blob&& nodeData, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
|
||||
SHAMapNodeType type) const override
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<Blob>
|
||||
getNode(SHAMapHash const& nodeHash) const override
|
||||
{
|
||||
auto const it = map.find(nodeHash);
|
||||
if (it == map.end())
|
||||
{
|
||||
JLOG(journal.fatal()) << "Test filter missing node";
|
||||
return std::nullopt;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Map& map;
|
||||
beast::Journal journal;
|
||||
};
|
||||
|
||||
static boost::intrusive_ptr<Item>
|
||||
makeRandomItemMember(beast::xor_shift_engine& r)
|
||||
{
|
||||
Serializer s;
|
||||
for (int d = 0; d < 3; ++d)
|
||||
s.add32(xrpl::randInt<std::uint32_t>(r));
|
||||
return makeShamapitem(s.getSHA512Half(), s.slice());
|
||||
}
|
||||
|
||||
static void
|
||||
addRandomItems(std::size_t n, Table& t, beast::xor_shift_engine& r)
|
||||
{
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
{
|
||||
auto const result(t.addItem(SHAMapNodeType::TnAccountState, makeRandomItemMember(r)));
|
||||
assert(result);
|
||||
(void)result;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
onFetch(Map& map, SHAMapHash const& hash, Blob const& blob)
|
||||
{
|
||||
BEAST_EXPECT(sha512Half(makeSlice(blob)) == hash.asUInt256());
|
||||
map.emplace(hash, blob);
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testFetchPack();
|
||||
}
|
||||
|
||||
// Exercises a fetch-pack round trip: build a SHAMap, serialize every node
|
||||
// into a pack keyed by node hash, then rebuild the map in a fresh SHAMap by
|
||||
// sourcing every node from the pack through a SHAMapSyncFilter and comparing
|
||||
// the result. This covers the filter-based reconstruction path (fetchRoot +
|
||||
// getMissingNodes with a SHAMapSyncFilter), complementing SHAMapSync_test,
|
||||
// which drives the getNodeFat/addKnownNode path.
|
||||
void
|
||||
testFetchPack()
|
||||
{
|
||||
test::SuiteJournal journal("FetchPack_test", *this);
|
||||
TestNodeFamily f(journal), f2(journal);
|
||||
beast::xor_shift_engine r;
|
||||
|
||||
// Build a source map. getHash() unshares the tree and computes every
|
||||
// node hash; this must happen before serializing nodes below, otherwise
|
||||
// inner nodes still carry stale cached hashes.
|
||||
auto const source = std::make_shared<Table>(SHAMapType::FREE, f);
|
||||
addRandomItems(kTableItems + kTableItemsExtra, *source, r);
|
||||
source->setImmutable();
|
||||
auto const rootHash = source->getHash();
|
||||
|
||||
// Turn the source into a fetch pack: node hash -> serialized node.
|
||||
Map map;
|
||||
source->visitNodes([this, &map](SHAMapTreeNode& node) {
|
||||
Serializer s;
|
||||
node.serializeWithPrefix(s);
|
||||
onFetch(map, node.getHash(), s.getData());
|
||||
return true;
|
||||
});
|
||||
|
||||
// Rebuild the map in a fresh family, sourcing every node from the pack
|
||||
// through the SHAMapSyncFilter.
|
||||
auto const rebuilt = std::make_shared<Table>(SHAMapType::FREE, rootHash.asUInt256(), f2);
|
||||
TestFilter filter(map, journal);
|
||||
rebuilt->setSynching();
|
||||
BEAST_EXPECT(rebuilt->fetchRoot(rootHash, &filter));
|
||||
|
||||
// Everything should be in the pack, so no nodes should be missing.
|
||||
BEAST_EXPECT(rebuilt->getMissingNodes(2048, &filter).empty());
|
||||
rebuilt->clearSynching();
|
||||
|
||||
BEAST_EXPECT(rebuilt->deepCompare(*source));
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(FetchPack, shamap, xrpl);
|
||||
|
||||
} // namespace xrpl::tests
|
||||
Reference in New Issue
Block a user