xrpld
Loading...
Searching...
No Matches
SHAMap.h
1#pragma once
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/IntrusivePointer.h>
5#include <xrpl/basics/SHAMapHash.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/nodestore/NodeObject.h>
10#include <xrpl/protocol/Serializer.h>
11#include <xrpl/shamap/Family.h>
12#include <xrpl/shamap/SHAMapAddNode.h>
13#include <xrpl/shamap/SHAMapInnerNode.h>
14#include <xrpl/shamap/SHAMapItem.h>
15#include <xrpl/shamap/SHAMapLeafNode.h>
16#include <xrpl/shamap/SHAMapMissingNode.h>
17#include <xrpl/shamap/SHAMapNodeID.h>
18#include <xrpl/shamap/SHAMapTreeNode.h>
19
20#include <condition_variable>
21#include <cstddef>
22#include <cstdint>
23#include <deque>
24#include <functional>
25#include <iterator>
26#include <map>
27#include <memory>
28#include <mutex>
29#include <optional>
30#include <set>
31#include <stack>
32#include <tuple>
33#include <utility>
34#include <vector>
35
36namespace xrpl {
37
39
43enum class SHAMapState {
50
57
64
71};
72
97
103{
105 // The `data` field (a Blob, 8-byte aligned) needs 4 bytes of padding after the `nodeID` field
106 // (36 bytes, 4-byte aligned) regardless of what comes between them, so `isLeaf` costs nothing
107 // extra here. Moving it after `data` would add 8 bytes to the size of this struct instead.
108 bool isLeaf;
110};
111
113{
114private:
117
122
127
131 bool backed_ = true; // Map is backed by the database
132 mutable bool full_ = false; // Map is believed complete in database
133
134public:
139 static constexpr unsigned int kBranchFactor = SHAMapInnerNode::kBranchFactor;
140
144 static constexpr unsigned int kLeafDepth = 64;
145
146 using DeltaItem =
147 std::pair<boost::intrusive_ptr<SHAMapItem const>, boost::intrusive_ptr<SHAMapItem const>>;
149
150 SHAMap() = delete;
151 SHAMap(SHAMap const&) = delete;
152 SHAMap&
153 operator=(SHAMap const&) = delete;
154
155 // Take a snapshot of the given map:
156 SHAMap(SHAMap const& other, bool isMutable);
157
158 // build new map
159 SHAMap(SHAMapType t, Family& f);
160
161 SHAMap(SHAMapType t, UInt256 const& hash, Family& f);
162
163 ~SHAMap() = default;
164
165 Family const&
166 family() const
167 {
168 return f_;
169 }
170
171 Family&
173 {
174 return f_;
175 }
176
177 //--------------------------------------------------------------------------
178
184 class ConstIterator;
185
186 ConstIterator
187 begin() const;
188 ConstIterator
189 end() const;
190
191 //--------------------------------------------------------------------------
192
193 // Returns a new map that's a snapshot of this one.
194 // Handles copy on write for mutable snapshots.
196 snapShot(bool isMutable) const;
197
198 /* Mark this SHAMap as "should be full", indicating
199 that the local server wants all the corresponding nodes
200 in durable storage.
201 */
202 void
203 setFull();
204
205 void
207
208 bool
209 fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter const* filter);
210
211 // normal hash access functions
212
216 bool
217 hasItem(UInt256 const& id) const;
218
219 bool
220 delItem(UInt256 const& id);
221
222 bool
223 addItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
224
226 getHash() const;
227
228 // save a copy if you have a temporary anyway
229 bool
230 updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
231
232 bool
233 addGiveItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
234
235 // Save a copy if you need to extend the life
236 // of the SHAMapItem beyond this SHAMap
237 boost::intrusive_ptr<SHAMapItem const> const&
238 peekItem(UInt256 const& id) const;
239 boost::intrusive_ptr<SHAMapItem const> const&
240 peekItem(UInt256 const& id, SHAMapHash& hash) const;
241
242 // traverse functions
250 ConstIterator
251 upperBound(UInt256 const& id) const;
252
260 ConstIterator
261 lowerBound(UInt256 const& id) const;
262
269 void
270 visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
271
279 void
280 visitDifferences(SHAMap const* have, std::function<bool(SHAMapTreeNode const&)> const&) const;
281
287 void
288 visitLeaves(std::function<void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
289
290 // comparison/sync functions
291
304 getMissingNodes(int maxNodes, SHAMapSyncFilter const* filter);
305
306 [[nodiscard]] bool
308 SHAMapNodeID const& wanted,
310 bool fatLeaves,
311 std::uint32_t depth) const;
312
320 getProofPath(UInt256 const& key) const;
321
329 static bool
330 verifyProofPath(UInt256 const& rootHash, UInt256 const& key, std::vector<Blob> const& path);
331
335 void
336 serializeRoot(Serializer& s) const;
337
354 addRootNode(SHAMapHash const& hash, SHAMapTreeNodePtr rootNode, SHAMapSyncFilter const* filter);
355
374 SHAMapNodeID const& nodeID,
375 SHAMapTreeNodePtr treeNode,
376 SHAMapSyncFilter const* filter);
377
378 // status functions
379 void
380 setImmutable();
381 bool
382 isSynching() const;
383 void
384 setSynching();
385 void
387 bool
388 isValid() const;
389
390 // caution: otherMap must be accessed only by this function
391 // return value: true=successfully completed, false=too different
392 bool
393 compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
394
398 int
399 unshare();
400
404 int
406
407 void
408 walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
409 bool
410 walkMapParallel(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
411 bool
412 deepCompare(SHAMap& other) const; // Intended for debug/test only
413
414 void
415 setUnbacked();
416
417 void
418 dump(bool withHashes = false) const;
419 void
420 invariants() const;
421
422private:
433 {
434 public:
435 [[nodiscard]] bool
436 empty() const
437 {
438 return stack_.empty();
439 }
440
441 [[nodiscard]] std::size_t
442 size() const
443 {
444 return stack_.size();
445 }
446
448 top() const
449 {
450 XRPL_ASSERT(!stack_.empty(), "xrpl::SHAMap::NodePathStack::top : non-empty stack");
451 return stack_.top();
452 }
453
454 void
456 {
457 XRPL_ASSERT(!stack_.empty(), "xrpl::SHAMap::NodePathStack::pop : non-empty stack");
458 stack_.pop();
459 }
460
461 void
463 {
464 stack_ = {};
465 }
466
470 void
472 {
473 XRPL_ASSERT(stack_.empty(), "xrpl::SHAMap::NodePathStack::pushRoot : empty stack");
474 stack_.emplace(std::move(node), SHAMapNodeID{});
475 }
476
483 void
484 pushChild(SHAMapTreeNodePtr node, unsigned int branch)
485 {
486 XRPL_ASSERT(node, "xrpl::SHAMap::NodePathStack::pushChild : non-null node input");
487 XRPL_ASSERT(
488 !stack_.empty(), "xrpl::SHAMap::NodePathStack::pushChild : non-empty stack");
489 auto childID = stack_.top().second.getChildNodeID(branch);
490 XRPL_ASSERT_IF(
491 node->isInner(),
492 childID.getDepth() < kLeafDepth,
493 "xrpl::SHAMap::NodePathStack::pushChild : inner node above leaf depth");
494 XRPL_ASSERT_IF(
495 node->isLeaf(),
496 childID.isPrefixOf(leafKey(*node)),
497 "xrpl::SHAMap::NodePathStack::pushChild : leaf key below branch");
498 stack_.emplace(std::move(node), std::move(childID));
499 }
500
507 void
508 pushNode(SHAMapTreeNodePtr node, UInt256 const& target)
509 {
510 if (stack_.empty())
511 {
512 pushRoot(std::move(node));
513 }
514 else
515 {
516 pushChild(std::move(node), selectBranch(stack_.top().second, target));
517 }
518 }
519
520 private:
522 };
523
524 using DeltaRef =
525 std::pair<boost::intrusive_ptr<SHAMapItem const>, boost::intrusive_ptr<SHAMapItem const>>;
526
527 // tree node cache operations
529 cacheLookup(SHAMapHash const& hash) const;
530
531 void
532 canonicalize(SHAMapHash const& hash, SHAMapTreeNodePtr&) const;
533
534 // database operations
536 fetchNodeFromDB(SHAMapHash const& hash) const;
538 fetchNodeNT(SHAMapHash const& hash) const;
540 fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const;
542 fetchNode(SHAMapHash const& hash) const;
544 checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const;
545
549 void
550 dirtyUp(NodePathStack& stack, UInt256 const& target, SHAMapTreeNodePtr terminal);
551
558 walkTowardsKey(UInt256 const& id, NodePathStack* stack = nullptr) const;
563 findKey(UInt256 const& id) const;
564
568 template <class Node>
571
575 template <class Node>
578
584
585 // direction in which a scan walks an inner node's branches
586 enum class BelowDirection { First, Last };
587
593 belowHelper(NodePathStack& stack, BelowDirection direction) const;
594
606 ConstIterator
607 boundHelper(UInt256 const& id, BelowDirection direction) const;
608
609 // Simple descent
610 // Get a child of the specified node
612 descend(SHAMapInnerNode*, unsigned int branch) const;
614 descendThrow(SHAMapInnerNode*, unsigned int branch) const;
616 descend(SHAMapInnerNode&, unsigned int branch) const;
618 descendThrow(SHAMapInnerNode&, unsigned int branch) const;
619
620 // Descend with filter
621 // If pending, callback is called as if it called fetchNodeNT
625 SHAMapInnerNode* parent,
626 unsigned int branch,
627 SHAMapSyncFilter const* filter,
628 bool& pending,
629 DescendCallback&&) const;
630
632 descend(
633 SHAMapInnerNode* parent,
634 SHAMapNodeID const& parentID,
635 unsigned int branch,
636 SHAMapSyncFilter const* filter) const;
637
638 // Non-storing
639 // Does not hook the returned node to its parent
641 descendNoStore(SHAMapInnerNode&, unsigned int branch) const;
642
646 boost::intrusive_ptr<SHAMapItem const> const&
648
649 bool
650 hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
651 bool
652 hasLeafNode(UInt256 const& tag, SHAMapHash const& hash) const;
653
654 SHAMapLeafNode const*
655 peekFirstItem(NodePathStack& stack) const;
656 SHAMapLeafNode const*
657 peekNextItem(UInt256 const& id, NodePathStack& stack) const;
658 bool
660 SHAMapTreeNode* node,
661 boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
662 bool isFirstMap,
663 Delta& differences,
664 int& maxCount) const;
665 int
666 walkSubTree(bool doWrite, NodeObjectType t);
667
668 // Structure to track information about call to
669 // getMissingNodes while it's in progress
671 {
672 MissingNodes() = delete;
673 MissingNodes(MissingNodes const&) = delete;
675 operator=(MissingNodes const&) = delete;
676
677 // basic parameters
678 int max;
680 int const maxDefer;
682
683 // nodes we have discovered to be missing
686
687 // nodes we are in the process of traversing
689 SHAMapInnerNode*, // pointer to the node
690 SHAMapNodeID, // the node's ID
691 unsigned int, // which child we check first
692 unsigned int, // which child we check next
693 bool>; // whether we've found any missing children yet
694
695 // We explicitly choose to specify the use of std::deque here, because
696 // we need to ensure that pointers and/or references to existing
697 // elements will not be invalidated during the course of element
698 // insertion and removal. Containers that do not offer this guarantee,
699 // such as std::vector, can't be used here.
701
702 // nodes we may have acquired from deferred reads
704 SHAMapInnerNode*, // parent node
705 SHAMapNodeID, // parent node ID
706 unsigned int, // branch
707 SHAMapTreeNodePtr>; // node
708
713
714 // nodes we need to resume after we get their children from deferred
715 // reads
717
719 int max,
721 int maxDefer,
724 {
725 missingNodes.reserve(max);
726 finishedReads.reserve(maxDefer);
727 }
728 };
729
730 // getMissingNodes helper functions
731 void
732 gmnProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
733 static void
734 gmnProcessDeferredReads(MissingNodes&);
735
736 // fetch from DB helper function
738 finishFetch(SHAMapHash const& hash, std::shared_ptr<NodeObject> const& object) const;
739};
740
741inline void
743{
744 full_ = true;
745}
746
747inline void
752
753inline void
755{
756 XRPL_ASSERT(state_ != SHAMapState::Invalid, "xrpl::SHAMap::setImmutable : state is valid");
758}
759
760inline bool
762{
764}
765
766inline void
771
772inline void
777
778inline bool
780{
782}
783
784inline void
786{
787 backed_ = false;
788}
789
790//------------------------------------------------------------------------------
791
793{
794public:
798 using reference = value_type const&;
799 using pointer = value_type const*;
800
801private:
803 SHAMap const* map_ = nullptr;
804 pointer item_ = nullptr;
805
806public:
807 ConstIterator() = delete;
808
809 ConstIterator(ConstIterator const& other) = default;
811 operator=(ConstIterator const& other) = default;
812
813 ~ConstIterator() = default;
814
816 operator*() const;
817 pointer
818 operator->() const;
819
821 operator++();
823 operator++(int);
824
825private:
826 explicit ConstIterator(SHAMap const* map);
828 ConstIterator(SHAMap const* map, pointer item, NodePathStack&& stack);
829
830 friend bool
831 operator==(ConstIterator const& x, ConstIterator const& y);
832 friend class SHAMap;
833};
834
836{
837 XRPL_ASSERT(map_, "xrpl::SHAMap::ConstIterator::ConstIterator : non-null input");
838
839 if (auto temp = map_->peekFirstItem(stack_))
840 item_ = temp->peekItem().get();
841}
842
846
848 : stack_(std::move(stack)), map_(map), item_(item)
849{
850}
851
854{
855 return *item_;
856}
857
860{
861 return item_;
862}
863
866{
867 if (auto temp = map_->peekNextItem(item_->key(), stack_))
868 {
869 item_ = temp->peekItem().get();
870 }
871 else
872 {
873 item_ = nullptr;
874 }
875 return *this;
876}
877
880{
881 auto tmp = *this;
882 ++(*this);
883 return tmp;
884}
885
886inline bool
888{
889 XRPL_ASSERT(
890 x.map_ == y.map_,
891 "xrpl::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
892 "inputs map do match");
893 return x.item_ == y.item_;
894}
895
898{
899 return ConstIterator(this);
900}
901
904{
905 return ConstIterator(this, nullptr);
906}
907
908} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
static constexpr unsigned int kBranchFactor
Each inner node has 16 children (the 'radix tree' part of the map).
Identifies a node inside a SHAMap.
pointer operator->() const
Definition SHAMap.h:859
ConstIterator(ConstIterator const &other)=default
value_type const & reference
Definition SHAMap.h:798
ConstIterator & operator=(ConstIterator const &other)=default
friend bool operator==(ConstIterator const &x, ConstIterator const &y)
Definition SHAMap.h:887
SHAMap const * map_
Definition SHAMap.h:803
std::forward_iterator_tag iterator_category
Definition SHAMap.h:795
ConstIterator & operator++()
Definition SHAMap.h:865
value_type const * pointer
Definition SHAMap.h:799
reference operator*() const
Definition SHAMap.h:853
std::ptrdiff_t difference_type
Definition SHAMap.h:796
A path from the root of the map down to some node, pairing each node with the ID naming its position.
Definition SHAMap.h:433
std::pair< SHAMapTreeNodePtr, SHAMapNodeID > const & top() const
Definition SHAMap.h:448
std::stack< std::pair< SHAMapTreeNodePtr, SHAMapNodeID > > stack_
Definition SHAMap.h:521
void pushChild(SHAMapTreeNodePtr node, unsigned int branch)
Extend the path to the child of the current node reached by branch.
Definition SHAMap.h:484
void pushRoot(SHAMapTreeNodePtr node)
Start a path at the root of the map, whose ID is the zero-depth ID by definition.
Definition SHAMap.h:471
std::size_t size() const
Definition SHAMap.h:442
void pushNode(SHAMapTreeNodePtr node, UInt256 const &target)
Extend the path to a node lying on the path to target.
Definition SHAMap.h:508
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter const *filter)
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Family const & family() const
Definition SHAMap.h:166
SHAMapState state_
Definition SHAMap.h:129
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, unsigned int branch, SHAMapSyncFilter const *filter, bool &pending, DescendCallback &&) const
bool hasLeafNode(UInt256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
bool full_
Definition SHAMap.h:132
SHAMapTreeNode * descend(SHAMapInnerNode *, unsigned int branch) const
ConstIterator upperBound(UInt256 const &id) const
Find the first item after the given item.
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
Definition SHAMap.h:121
SHAMapTreeNodePtr finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
void setLedgerSeq(std::uint32_t lseq)
Definition SHAMap.h:748
static constexpr unsigned int kLeafDepth
The depth of the hash map: data is only present in the leaves.
Definition SHAMap.h:144
SHAMapTreeNodePtr fetchNodeFromDB(SHAMapHash const &hash) const
Family & f_
Definition SHAMap.h:115
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< SHAMapNodeData > &data, bool fatLeaves, std::uint32_t depth) const
std::pair< boost::intrusive_ptr< SHAMapItem const >, boost::intrusive_ptr< SHAMapItem const > > DeltaItem
Definition SHAMap.h:146
SHAMapTreeNodePtr cacheLookup(SHAMapHash const &hash) const
Family & family()
Definition SHAMap.h:172
~SHAMap()=default
bool hasItem(UInt256 const &id) const
Does the tree have an item with the given ID?
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
static void gmnProcessDeferredReads(MissingNodes &)
static constexpr unsigned int kBranchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map).
Definition SHAMap.h:139
SHAMapTreeNodePtr descendNoStore(SHAMapInnerNode &, unsigned int branch) const
std::pair< boost::intrusive_ptr< SHAMapItem const >, boost::intrusive_ptr< SHAMapItem const > > DeltaRef
Definition SHAMap.h:524
void dirtyUp(NodePathStack &stack, UInt256 const &target, SHAMapTreeNodePtr terminal)
Update hashes up to the root.
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)> const &) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
SHAMapTreeNodePtr fetchNode(SHAMapHash const &hash) const
void setUnbacked()
Definition SHAMap.h:785
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
void setSynching()
Definition SHAMap.h:767
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
SHAMap(SHAMap const &)=delete
bool isSynching() const
Definition SHAMap.h:761
bool deepCompare(SHAMap &other) const
void gmnProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
SHAMap & operator=(SHAMap const &)=delete
SHAMapLeafNode const * peekFirstItem(NodePathStack &stack) const
void dump(bool withHashes=false) const
beast::Journal journal_
Definition SHAMap.h:116
std::map< UInt256, DeltaItem > Delta
Definition SHAMap.h:148
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, unsigned int branch) const
void setFull()
Definition SHAMap.h:742
SHAMapAddNode addRootNode(SHAMapHash const &hash, SHAMapTreeNodePtr rootNode, SHAMapSyncFilter const *filter)
Add a root node to the SHAMap during synchronization.
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
bool backed_
Definition SHAMap.h:131
bool isValid() const
Definition SHAMap.h:779
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
int unshare()
Convert any modified nodes to shared.
bool delItem(UInt256 const &id)
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
SHAMapLeafNode * walkTowardsKey(UInt256 const &id, NodePathStack *stack=nullptr) const
Walk towards the specified id, returning the node.
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapType const type_
Definition SHAMap.h:130
SHAMap()=delete
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, SHAMapTreeNodePtr treeNode, SHAMapSyncFilter const *filter)
Add a known node at a specific position in the SHAMap during synchronization.
void canonicalize(SHAMapHash const &hash, SHAMapTreeNodePtr &) const
void setImmutable()
Definition SHAMap.h:754
SHAMapTreeNodePtr fetchNodeNT(SHAMapHash const &hash) const
void clearSynching()
Definition SHAMap.h:773
SHAMapTreeNodePtr checkFilter(SHAMapHash const &hash, SHAMapSyncFilter const *filter) const
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
std::function< void(SHAMapTreeNodePtr, SHAMapHash const &)> DescendCallback
Definition SHAMap.h:622
SHAMapTreeNodePtr root_
Definition SHAMap.h:128
ConstIterator end() const
Definition SHAMap.h:903
SHAMapTreeNodePtr writeNode(NodeObjectType t, SHAMapTreeNodePtr node) const
write and canonicalize modified node
SHAMapLeafNode * belowHelper(NodePathStack &stack, BelowDirection direction) const
Returns the first or last item at or below the node already on top of stack, extending stack with the...
ConstIterator boundHelper(UInt256 const &id, BelowDirection direction) const
Returns the nearest item strictly past id, in the given direction.
ConstIterator lowerBound(UInt256 const &id) const
Find the object with the greatest object id smaller than the input id.
intr_ptr::SharedPtr< Node > preFlushNode(intr_ptr::SharedPtr< Node > node) const
prepare a node to be modified before flushing
SHAMapLeafNode * findKey(UInt256 const &id) const
Return nullptr if key not found.
intr_ptr::SharedPtr< Node > unshareNode(intr_ptr::SharedPtr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition SHAMap.h:126
int walkSubTree(bool doWrite, NodeObjectType t)
std::vector< std::pair< SHAMapNodeID, UInt256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter const *filter)
Check for nodes in the SHAMap not available.
SHAMapHash getHash() const
ConstIterator begin() const
Definition SHAMap.h:897
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
std::optional< std::vector< Blob > > getProofPath(UInt256 const &key) const
Get the proof path of the key.
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
boost::intrusive_ptr< SHAMapItem const > const & peekItem(UInt256 const &id) const
SHAMapLeafNode const * peekNextItem(UInt256 const &id, NodePathStack &stack) const
static bool verifyProofPath(UInt256 const &rootHash, UInt256 const &key, std::vector< Blob > const &path)
Verify the proof path.
STL namespace.
SharedIntrusive< T > SharedPtr
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
intr_ptr::SharedPtr< SHAMapTreeNode > SHAMapTreeNodePtr
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
Definition base_uint.h:612
NodeObjectType
The types of node objects.
Definition NodeObject.h:18
BaseUInt< 256 > UInt256
Definition base_uint.h:580
UInt256 const & leafKey(SHAMapTreeNode const &node)
Return the key of the item held by a SHAMap leaf node.
unsigned int selectBranch(SHAMapNodeID const &id, UInt256 const &hash)
Returns the branch that would contain the given hash.
SHAMapState
Describes the current state of a given SHAMap.
Definition SHAMap.h:43
@ Immutable
The map is set in stone and cannot be changed.
Definition SHAMap.h:56
@ Invalid
The map is known to not be valid.
Definition SHAMap.h:70
@ Synching
The map's hash is fixed but valid nodes may be missing and can be added.
Definition SHAMap.h:63
@ Modifying
The map is in flux and objects can be added and removed.
Definition SHAMap.h:49
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
@ Invalid
Timely, but invalid signature.
Definition Manifest.h:329
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition SHAMap.h:103
SHAMapNodeID nodeID
Definition SHAMap.h:104
std::tuple< SHAMapInnerNode *, SHAMapNodeID, unsigned int, unsigned int, bool > StackEntry
Definition SHAMap.h:688
std::vector< std::pair< SHAMapNodeID, UInt256 > > missingNodes
Definition SHAMap.h:684
std::set< SHAMapHash > missingHashes
Definition SHAMap.h:685
std::tuple< SHAMapInnerNode *, SHAMapNodeID, unsigned int, SHAMapTreeNodePtr > DeferredNode
Definition SHAMap.h:703
std::vector< DeferredNode > finishedReads
Definition SHAMap.h:712
MissingNodes & operator=(MissingNodes const &)=delete
MissingNodes(int max, SHAMapSyncFilter const *filter, int maxDefer, std::uint32_t generation)
Definition SHAMap.h:718
std::uint32_t generation
Definition SHAMap.h:681
MissingNodes(MissingNodes const &)=delete
SHAMapSyncFilter const * filter
Definition SHAMap.h:679
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes
Definition SHAMap.h:716
std::stack< StackEntry, std::deque< StackEntry > > stack
Definition SHAMap.h:700
std::condition_variable deferCondVar
Definition SHAMap.h:711