1#include <xrpl/basics/SHAMapHash.h>
2#include <xrpl/basics/Slice.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/random.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/xor_shift_engine.h>
7#include <xrpl/protocol/Serializer.h>
8#include <xrpl/shamap/SHAMap.h>
9#include <xrpl/shamap/SHAMapItem.h>
10#include <xrpl/shamap/SHAMapMissingNode.h>
11#include <xrpl/shamap/SHAMapTreeNode.h>
13#include <boost/smart_ptr/intrusive_ptr.hpp>
15#include <gtest/gtest.h>
16#include <helpers/TestSink.h>
17#include <shamap/common.h>
34 boost::intrusive_ptr<SHAMapItem>
37 static constexpr auto kWordsPerState = 3uz;
41 for (
auto word = 0uz; word < kWordsPerState; ++word)
55 for (
auto i = 0uz; i < count; ++i)
62 ADD_FAILURE() <<
"Unable to add item to map";
67 for (
auto const& item : items)
71 ADD_FAILURE() <<
"Unable to remove item from map";
76 if (beforeHash != map.
getHash())
78 ADD_FAILURE() <<
"Hashes do not match " << beforeHash <<
" " << map.
getHash();
92 static constexpr auto kItemCount = 10000uz;
93 static constexpr auto kInvariantInterval = 100uz;
94 static constexpr auto kNodesToConfuse = 500uz;
95 static constexpr auto kMaxNodesPerRequest = 2048;
97 for (
auto i = 0uz; i < kItemCount; ++i)
100 if (i % kInvariantInterval == 0)
105 ASSERT_TRUE(confuseMap(source, kNodesToConfuse));
111 source.
visitLeaves([&count]([[maybe_unused]]
auto const& item) { ++count; });
112 EXPECT_EQ(count, kItemCount);
115 source.
walkMap(missingNodes, kMaxNodesPerRequest);
116 EXPECT_TRUE(missingNodes.
empty());
125 ASSERT_FALSE(a.
empty()) <<
"NodeSize";
129 FAIL() <<
"Could not create node";
138 auto nodesMissing = destination.
getMissingNodes(kMaxNodesPerRequest,
nullptr);
140 if (nodesMissing.empty())
146 for (
auto& it : nodesMissing)
152 FAIL() <<
"Unable to fetch node";
159 FAIL() <<
"No nodes returned";
161 for (
auto const& i : b)
168 FAIL() <<
"Could not create node";
169 if (i.isLeaf != node->isLeaf())
170 FAIL() <<
"Node is not a leaf";
172 FAIL() <<
"Known node was not useful";
A generic endpoint for log messages.
void advance(std::chrono::duration< Rep, Period > const &elapsed)
Advance the clock by a duration.
Identifies a node inside a SHAMap.
static SHAMapTreeNodePtr makeFromWire(Slice rawNode)
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< SHAMapNodeData > &data, bool fatLeaves, std::uint32_t depth) const
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter const *filter)
Check for nodes in the SHAMap not available.
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
bool deepCompare(SHAMap &other) const
SHAMapAddNode addRootNode(SHAMapHash const &hash, SHAMapTreeNodePtr rootNode, SHAMapSyncFilter const *filter)
Add a root node to the SHAMap during synchronization.
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, SHAMapTreeNodePtr treeNode, SHAMapSyncFilter const *filter)
Add a known node at a specific position in the SHAMap during synchronization.
SHAMapHash getHash() const
bool delItem(uint256 const &id)
uint256 getSHA512Half() const
Slice slice() const noexcept
static TestSink & instance()
boost::intrusive_ptr< SHAMapItem > makeRandomAS()
bool confuseMap(SHAMap &map, std::size_t count)
beast::xor_shift_engine eng_
detail::XorShiftEngine<> xor_shift_engine
XOR-shift Generator.
TEST_F(SHAMapPathProof, verify_proof_path)
bool randBool(Engine &engine)
Return a random boolean value.
Integral randInt(Engine &engine, Integral min, Integral max)
Return a uniformly distributed random integer.
Slice makeSlice(std::array< T, N > const &a)
boost::intrusive_ptr< SHAMapItem > makeShamapitem(uint256 const &tag, Slice data)